Skip to content

Commit ee9ada8

Browse files
authored
fix: Navigate to the view tab on config page view (#2802)
* fix: Config tab navigation * Updated the redirect flow to wait on view loading/errors and fixed view tab highlighting by matching activeTabName to the view ID.
1 parent 01d48f2 commit ee9ada8

File tree

4 files changed

+35
-13
lines changed

4 files changed

+35
-13
lines changed

src/components/Configs/ConfigDetailsTabs.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function ConfigDetailsTabs({
4545
const { data: configItem, isLoading: isLoadingConfig } =
4646
useGetConfigByIdQuery(id!);
4747

48-
const configTabList = useConfigDetailsTabs(configItem?.summary);
48+
const { tabs: configTabList } = useConfigDetailsTabs(configItem?.summary);
4949

5050
return (
5151
<>

src/components/Configs/ConfigTabsLinks.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,18 @@ type ConfigDetailsTab = {
1414
search?: string;
1515
};
1616

17-
export function useConfigDetailsTabs(
18-
countSummary?: ConfigItem["summary"]
19-
): ConfigDetailsTab[] {
17+
export function useConfigDetailsTabs(countSummary?: ConfigItem["summary"]): {
18+
isLoading: boolean;
19+
isError: boolean;
20+
tabs: ConfigDetailsTab[];
21+
} {
2022
const { id } = useParams<{ id: string }>();
2123

22-
const { data: views = [] } = useQuery({
24+
const {
25+
data: views = [],
26+
isLoading,
27+
isError
28+
} = useQuery({
2329
queryKey: ["views", id],
2430
queryFn: () => getViewsByConfigId(id!),
2531
enabled: !!id
@@ -105,9 +111,9 @@ export function useConfigDetailsTabs(
105111
}));
106112

107113
if (viewTabs.length === 0) {
108-
return staticTabs;
114+
return { isLoading, isError, tabs: staticTabs };
109115
}
110116

111117
// Views configured for a config should appear ahead of the built-in tabs.
112-
return [...viewTabs, ...staticTabs];
118+
return { isLoading, isError, tabs: [...viewTabs, ...staticTabs] };
113119
}

src/pages/config/details/ConfigDetailsIndexRedirect.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,17 @@ export function ConfigDetailsIndexRedirect() {
1717
isError: isConfigError
1818
} = useGetConfigByIdQuery(idParam);
1919

20-
const tabs = useConfigDetailsTabs(configDetails?.summary);
20+
const {
21+
tabs,
22+
isLoading,
23+
isError: isViewsError
24+
} = useConfigDetailsTabs(configDetails?.summary);
2125

2226
useEffect(() => {
27+
if (isLoading || isViewsError) {
28+
return;
29+
}
30+
2331
if (!id || tabs.length === 0) {
2432
return;
2533
}
@@ -37,20 +45,28 @@ export function ConfigDetailsIndexRedirect() {
3745
},
3846
{ replace: true }
3947
);
40-
}, [id, tabs, navigate, location.pathname, location.search]);
48+
}, [
49+
isLoading,
50+
isViewsError,
51+
id,
52+
tabs,
53+
navigate,
54+
location.pathname,
55+
location.search
56+
]);
4157

42-
if (isConfigLoading) {
58+
if (isConfigLoading || isLoading) {
4359
return (
4460
<div className="flex h-full items-center justify-center">
4561
<Loading />
4662
</div>
4763
);
4864
}
4965

50-
if (isConfigError) {
66+
if (isConfigError || isViewsError) {
5167
return (
5268
<div className="flex h-full items-center justify-center text-gray-500">
53-
Failed to load config
69+
Failed to load config or views
5470
</div>
5571
);
5672
}

src/pages/config/details/ConfigDetailsViewPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function ConfigDetailsViewPage() {
2929
<ConfigDetailsTabs
3030
pageTitlePrefix={`Config View - ${displayName}`}
3131
isLoading={isLoading}
32-
activeTabName={displayName}
32+
activeTabName={viewId ?? ""}
3333
refetch={handleForceRefresh}
3434
>
3535
<div className="">

0 commit comments

Comments
 (0)