Skip to content

Commit ed07bb8

Browse files
nickwesselmanclaude
andcommitted
DRY up shortcut and link rendering in DevSessionUI
Extract devStatusShortcuts array with shortcutLabel, linkLabel, url, condition, and action fields. Both the keyboard shortcut hints and the URL list are now rendered by iterating over the same collection, eliminating duplicated conditions and labels. Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent 880aac9 commit ed07bb8

File tree

2 files changed

+69
-81
lines changed

2 files changed

+69
-81
lines changed

packages/app/src/cli/services/dev/ui/components/DevSessionUI.tsx

Lines changed: 65 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Spinner} from './Spinner.js'
2-
import {TabPanel, Tab} from './TabPanel.js'
2+
import {TabPanel, Tab, TabShortcut} from './TabPanel.js'
33
import metadata from '../../../../metadata.js'
44
import {
55
DevSessionStatus,
@@ -119,85 +119,78 @@ 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 metadata.addPublicMetadata(() => ({
146+
cmd_dev_preview_url_opened: true,
147+
}))
148+
await openURL(buildDevConsoleURL(shopFqdn))
149+
},
150+
},
151+
{
152+
key: 'g',
153+
shortcutLabel: 'Open GraphiQL (Admin API)',
154+
linkLabel: 'GraphiQL',
155+
url: status.graphiqlURL,
156+
condition: () => Boolean(status.isReady && status.graphiqlURL),
157+
action: async () => {
158+
await metadata.addPublicMetadata(() => ({
159+
cmd_dev_graphiql_opened: true,
160+
}))
161+
if (status.graphiqlURL) {
162+
await openURL(status.graphiqlURL)
163+
}
164+
},
165+
},
166+
]
167+
168+
const activeShortcuts = devStatusShortcuts.filter((shortcut) => shortcut.condition?.() ?? true)
169+
122170
const tabs: {[key: string]: Tab} = {
123171
// eslint-disable-next-line id-length
124172
d: {
125173
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 metadata.addPublicMetadata(() => ({
156-
cmd_dev_preview_url_opened: true,
157-
}))
158-
await openURL(buildDevConsoleURL(shopFqdn))
159-
},
160-
},
161-
],
174+
shortcuts: devStatusShortcuts,
162175
content: (
163176
<>
164177
{status.statusMessage && (
165178
<Text>
166179
{getStatusIndicator(status.statusMessage.type)} {status.statusMessage.message}
167180
</Text>
168181
)}
169-
{canUseShortcuts && (
182+
{canUseShortcuts && activeShortcuts.length > 0 && (
170183
<Box marginTop={1} flexDirection="column">
171-
{status.isReady && status.previewURL ? (
172-
<Text>
173-
{figures.pointerSmall} <Text bold>(p)</Text>{' '}
174-
{terminalSupportsHyperlinks() ? (
175-
<Link url={status.previewURL} label="Open app preview" />
176-
) : (
177-
'Open app preview'
178-
)}
179-
</Text>
180-
) : null}
181-
{status.isReady && !status.appEmbedded ? (
182-
<Text>
183-
{figures.pointerSmall} <Text bold>(c)</Text>{' '}
184-
{terminalSupportsHyperlinks() ? (
185-
<Link url={buildDevConsoleURL(shopFqdn)} label="Open Dev Console for extension previews" />
186-
) : (
187-
'Open Dev Console for extension previews'
188-
)}
189-
</Text>
190-
) : null}
191-
{status.isReady && status.graphiqlURL ? (
192-
<Text>
193-
{figures.pointerSmall} <Text bold>(g)</Text>{' '}
194-
{terminalSupportsHyperlinks() ? (
195-
<Link url={status.graphiqlURL} label="Open GraphiQL (Admin API)" />
184+
{activeShortcuts.map((shortcut) => (
185+
<Text key={shortcut.key}>
186+
{figures.pointerSmall} <Text bold>({shortcut.key})</Text>{' '}
187+
{terminalSupportsHyperlinks() && shortcut.url ? (
188+
<Link url={shortcut.url} label={shortcut.shortcutLabel} />
196189
) : (
197-
'Open GraphiQL (Admin API)'
190+
shortcut.shortcutLabel
198191
)}
199192
</Text>
200-
) : null}
193+
))}
201194
</Box>
202195
)}
203196
<Box marginTop={canUseShortcuts ? 1 : 0} flexDirection="column">
@@ -207,21 +200,13 @@ const DevSessionUI: FunctionComponent<DevSesionUIProps> = ({
207200
<>
208201
{status.isReady && !(canUseShortcuts && terminalSupportsHyperlinks()) && (
209202
<>
210-
{status.previewURL ? (
211-
<Text>
212-
Preview URL: <Link url={status.previewURL} />
213-
</Text>
214-
) : null}
215-
{status.appEmbedded === false ? (
216-
<Text>
217-
Dev Console URL: <Link url={buildDevConsoleURL(shopFqdn)} />
218-
</Text>
219-
) : null}
220-
{status.graphiqlURL ? (
221-
<Text>
222-
GraphiQL URL: <Link url={status.graphiqlURL} />
223-
</Text>
224-
) : null}
203+
{activeShortcuts
204+
.filter((shortcut) => shortcut.url)
205+
.map((shortcut) => (
206+
<Text key={shortcut.key}>
207+
{shortcut.linkLabel} URL: <Link url={shortcut.url!} />
208+
</Text>
209+
))}
225210
</>
226211
)}
227212
</>

packages/app/src/cli/services/dev/ui/components/TabPanel.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ export interface Tab {
88
action?: () => Promise<void>
99
}
1010

11-
interface TabShortcut {
11+
export interface TabShortcut {
1212
key: string
13+
shortcutLabel?: string
14+
linkLabel?: string
15+
url?: string
1316
condition?: () => boolean
1417
action: () => Promise<void>
1518
}

0 commit comments

Comments
 (0)