11import { Spinner } from './Spinner.js'
2- import { TabPanel , Tab } from './TabPanel.js'
2+ import { TabPanel , Tab , TabShortcut } from './TabPanel.js'
33import metadata from '../../../../metadata.js'
44import {
55 DevSessionStatus ,
@@ -119,82 +119,75 @@ const DevSessionUI: FunctionComponent<DevSesionUIProps> = ({
119119 }
120120 }
121121
122+ const devStatusShortcuts : TabShortcut [ ] = [
123+ {
124+ key : 'p' ,
125+ shortcutLabel : 'Open app preview' ,
126+ linkLabel : 'Preview' ,
127+ url : status . previewURL ,
128+ condition : ( ) => Boolean ( status . isReady && status . previewURL ) ,
129+ action : async ( ) => {
130+ await metadata . addPublicMetadata ( ( ) => ( {
131+ cmd_dev_preview_url_opened : true ,
132+ } ) )
133+ if ( status . previewURL ) {
134+ await openURL ( status . previewURL )
135+ }
136+ } ,
137+ } ,
138+ {
139+ key : 'c' ,
140+ shortcutLabel : 'Open Dev Console for extension previews' ,
141+ linkLabel : 'Dev Console' ,
142+ url : buildDevConsoleURL ( shopFqdn ) ,
143+ condition : ( ) => Boolean ( status . isReady && ! status . appEmbedded ) ,
144+ action : async ( ) => {
145+ await openURL ( buildDevConsoleURL ( shopFqdn ) )
146+ } ,
147+ } ,
148+ {
149+ key : 'g' ,
150+ shortcutLabel : 'Open GraphiQL (Admin API)' ,
151+ linkLabel : 'GraphiQL' ,
152+ url : status . graphiqlURL ,
153+ condition : ( ) => Boolean ( status . isReady && status . graphiqlURL ) ,
154+ action : async ( ) => {
155+ await metadata . addPublicMetadata ( ( ) => ( {
156+ cmd_dev_graphiql_opened : true ,
157+ } ) )
158+ if ( status . graphiqlURL ) {
159+ await openURL ( status . graphiqlURL )
160+ }
161+ } ,
162+ } ,
163+ ]
164+
165+ const activeShortcuts = devStatusShortcuts . filter ( ( s ) => s . condition ?.( ) ?? true )
166+
122167 const tabs : { [ key : string ] : Tab } = {
123168 // eslint-disable-next-line id-length
124169 d : {
125170 label : 'Dev status' ,
126- shortcuts : [
127- {
128- key : 'p' ,
129- condition : ( ) => Boolean ( status . isReady && status . previewURL ) ,
130- action : async ( ) => {
131- await metadata . addPublicMetadata ( ( ) => ( {
132- cmd_dev_preview_url_opened : true ,
133- } ) )
134- if ( status . previewURL ) {
135- await openURL ( status . previewURL )
136- }
137- } ,
138- } ,
139- {
140- key : 'g' ,
141- condition : ( ) => Boolean ( status . isReady && status . graphiqlURL ) ,
142- action : async ( ) => {
143- await metadata . addPublicMetadata ( ( ) => ( {
144- cmd_dev_graphiql_opened : true ,
145- } ) )
146- if ( status . graphiqlURL ) {
147- await openURL ( status . graphiqlURL )
148- }
149- } ,
150- } ,
151- {
152- key : 'c' ,
153- condition : ( ) => Boolean ( status . isReady && ! status . appEmbedded ) ,
154- action : async ( ) => {
155- await openURL ( buildDevConsoleURL ( shopFqdn ) )
156- } ,
157- } ,
158- ] ,
171+ shortcuts : devStatusShortcuts ,
159172 content : (
160173 < >
161174 { status . statusMessage && (
162175 < Text >
163176 { getStatusIndicator ( status . statusMessage . type ) } { status . statusMessage . message }
164177 </ Text >
165178 ) }
166- { canUseShortcuts && (
179+ { canUseShortcuts && activeShortcuts . length > 0 && (
167180 < Box marginTop = { 1 } flexDirection = "column" >
168- { status . isReady && status . previewURL ? (
169- < Text >
170- { figures . pointerSmall } < Text bold > (p)</ Text > { ' ' }
171- { terminalSupportsHyperlinks ( ) ? (
172- < Link url = { status . previewURL } label = "Open app preview" />
173- ) : (
174- 'Open app preview'
175- ) }
176- </ Text >
177- ) : null }
178- { status . isReady && ! status . appEmbedded ? (
179- < Text >
180- { figures . pointerSmall } < Text bold > (c)</ Text > { ' ' }
181- { terminalSupportsHyperlinks ( ) ? (
182- < Link url = { buildDevConsoleURL ( shopFqdn ) } label = "Open Dev Console for extension previews" />
183- ) : (
184- 'Open Dev Console for extension previews'
185- ) }
186- </ Text >
187- ) : null }
188- { status . isReady && status . graphiqlURL ? (
189- < Text >
190- { figures . pointerSmall } < Text bold > (g)</ Text > { ' ' }
191- { terminalSupportsHyperlinks ( ) ? (
192- < Link url = { status . graphiqlURL } label = "Open GraphiQL (Admin API)" />
181+ { activeShortcuts . map ( ( shortcut ) => (
182+ < Text key = { shortcut . key } >
183+ { figures . pointerSmall } < Text bold > ({ shortcut . key } )</ Text > { ' ' }
184+ { terminalSupportsHyperlinks ( ) && shortcut . url ? (
185+ < Link url = { shortcut . url } label = { shortcut . shortcutLabel ! } />
193186 ) : (
194- 'Open GraphiQL (Admin API)'
187+ shortcut . shortcutLabel
195188 ) }
196189 </ Text >
197- ) : null }
190+ ) ) }
198191 </ Box >
199192 ) }
200193 < Box marginTop = { canUseShortcuts ? 1 : 0 } flexDirection = "column" >
@@ -204,21 +197,13 @@ const DevSessionUI: FunctionComponent<DevSesionUIProps> = ({
204197 < >
205198 { status . isReady && ! ( canUseShortcuts && terminalSupportsHyperlinks ( ) ) && (
206199 < >
207- { status . previewURL ? (
208- < Text >
209- Preview URL: < Link url = { status . previewURL } />
210- </ Text >
211- ) : null }
212- { ! status . appEmbedded ? (
213- < Text >
214- Dev Console URL: < Link url = { buildDevConsoleURL ( shopFqdn ) } />
215- </ Text >
216- ) : null }
217- { status . graphiqlURL ? (
218- < Text >
219- GraphiQL URL: < Link url = { status . graphiqlURL } />
220- </ Text >
221- ) : null }
200+ { activeShortcuts
201+ . filter ( ( s ) => s . url )
202+ . map ( ( shortcut ) => (
203+ < Text key = { shortcut . key } >
204+ { shortcut . linkLabel } URL: < Link url = { shortcut . url ! } />
205+ </ Text >
206+ ) ) }
222207 </ >
223208 ) }
224209 </ >
0 commit comments