Skip to content

Commit e971c42

Browse files
committed
Show version selector when branch/tag not found
When a project is loaded but the URL contains an invalid branch/tag, show the version selector in the toolbar so users can navigate to a valid version instead of only showing an error message.
1 parent 2468e2a commit e971c42

File tree

3 files changed

+42
-30
lines changed

3 files changed

+42
-30
lines changed

src/features/projects/view/toolbar/MobileToolbar.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const MobileToolbar = () => {
1414
selectVersion,
1515
selectSpecification
1616
} = useProjectSelection()
17-
if (!project || !version || !specification) {
17+
if (!project) {
1818
return <></>
1919
}
2020
return (
@@ -25,20 +25,23 @@ const MobileToolbar = () => {
2525
>
2626
<Selector
2727
items={project.versions}
28-
selection={version.id}
28+
selection={version?.id}
29+
placeholder="Select version..."
2930
onSelect={selectVersion}
3031
sx={{ width: "100%" }}
3132
/>
32-
<Selector
33-
items={version.specifications.map(spec => ({
34-
id: spec.id,
35-
name: spec.name,
36-
hasChanges: isDiffFeatureEnabled && !!spec.diffURL
37-
}))}
38-
selection={specification.id}
39-
onSelect={selectSpecification}
40-
sx={{ width: "100%" }}
41-
/>
33+
{version && (
34+
<Selector
35+
items={version.specifications.map(spec => ({
36+
id: spec.id,
37+
name: spec.name,
38+
hasChanges: isDiffFeatureEnabled && !!spec.diffURL
39+
}))}
40+
selection={specification?.id}
41+
onSelect={selectSpecification}
42+
sx={{ width: "100%" }}
43+
/>
44+
)}
4245
</Stack>
4346
)
4447
}

src/features/projects/view/toolbar/Selector.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ interface SelectorItem {
1919
const Selector = ({
2020
items,
2121
selection,
22+
placeholder,
2223
onSelect,
2324
sx
2425
}: {
2526
items: SelectorItem[]
26-
selection: string
27+
selection?: string
28+
placeholder?: string
2729
onSelect: (itemId: string) => void
2830
sx?: SxProps
2931
}) => {
@@ -33,7 +35,9 @@ const Selector = ({
3335
return (
3436
<FormControl sx={{ m: 1, margin: 0, ...sx }} size="small">
3537
<Select
36-
defaultValue={selection}
38+
value={selection || ""}
39+
displayEmpty
40+
renderValue={(value) => value || placeholder || "Select..."}
3741
onChange={handleChange}
3842
inputProps={{
3943
IconComponent: () => null,

src/features/projects/view/toolbar/TrailingToolbarItem.tsx

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ const TrailingToolbarItem = () => {
1717
selectVersion,
1818
selectSpecification
1919
} = useProjectSelection()
20-
if (!project || !version || !specification) {
20+
if (!project) {
2121
return <></>
2222
}
23-
const projectNameURL = version.url || project.url
23+
const projectNameURL = version?.url || project.url
2424
return (
2525
<>
2626
<Stack
@@ -55,25 +55,30 @@ const TrailingToolbarItem = () => {
5555
<Typography variant="h6" sx={{ marginRight: 1 }}>/</Typography>
5656
<Selector
5757
items={project.versions}
58-
selection={version.id}
58+
selection={version?.id}
59+
placeholder="Select version..."
5960
onSelect={selectVersion}
6061
sx={{ marginRight: 1 }}
6162
/>
62-
<Typography variant="h6" sx={{ marginRight: 1 }}>/</Typography>
63-
<Selector
64-
items={version.specifications.map(spec => ({
65-
id: spec.id,
66-
name: spec.name,
67-
hasChanges: isDiffFeatureEnabled && !!spec.diffURL
68-
}))}
69-
selection={specification.id}
70-
onSelect={selectSpecification}
71-
sx={{ marginRight: 0.5 }}
72-
/>
73-
{specification.editURL &&
63+
{version && (
64+
<>
65+
<Typography variant="h6" sx={{ marginRight: 1 }}>/</Typography>
66+
<Selector
67+
items={version.specifications.map(spec => ({
68+
id: spec.id,
69+
name: spec.name,
70+
hasChanges: isDiffFeatureEnabled && !!spec.diffURL
71+
}))}
72+
selection={specification?.id}
73+
onSelect={selectSpecification}
74+
sx={{ marginRight: 0.5 }}
75+
/>
76+
</>
77+
)}
78+
{specification?.editURL &&
7479
<Divider orientation="vertical" flexItem sx={{ marginLeft: 1, marginRight: 1 }} />
7580
}
76-
{specification.editURL &&
81+
{specification?.editURL &&
7782
<Tooltip title={`Edit ${specification.name}`} sx={{ marginLeft: 0.5, marginRight: 0.5 }}>
7883
<IconButton
7984
href={specification.editURL}

0 commit comments

Comments
 (0)