Skip to content

Commit 72f6c95

Browse files
committed
make the component controlled to fix the tab change issue after metadata save
Also remove spinner for the dataset name header
1 parent a31fde2 commit 72f6c95

File tree

1 file changed

+31
-19
lines changed
  • app/[locale]/dashboard/[entityType]/[entitySlug]/dataset/[id]/edit/components

1 file changed

+31
-19
lines changed

app/[locale]/dashboard/[entityType]/[entitySlug]/dataset/[id]/edit/components/EditLayout.tsx

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import React, { useState } from 'react';
3+
import { ReactNode, useEffect, useState } from 'react';
44
import Link from 'next/link';
55
import { useParams, usePathname, useRouter } from 'next/navigation';
66
import { graphql } from '@/gql';
@@ -13,7 +13,6 @@ import {
1313
FormLayout,
1414
Icon,
1515
Input,
16-
Spinner,
1716
Tab,
1817
TabList,
1918
Tabs,
@@ -54,7 +53,7 @@ const updateDatasetTitleMutationDoc: any = graphql(`
5453
`);
5554

5655
interface LayoutProps {
57-
children?: React.ReactNode;
56+
children?: ReactNode;
5857
params: { id: string };
5958
}
6059

@@ -126,9 +125,7 @@ export function EditLayout({ children, params }: LayoutProps) {
126125
return (
127126
<div className="flex h-full flex-col lg:mt-8">
128127
{getDatasetTitleRes.isLoading ? (
129-
<div className="flex flex-row items-center justify-center">
130-
<Spinner size={24} />
131-
</div>
128+
<></>
132129
) : (
133130
<Header
134131
dataset={getDatasetTitleRes?.data?.datasets[0]}
@@ -257,56 +254,71 @@ const Navigation = ({
257254
organization: string;
258255
entityType: string;
259256
}) => {
257+
const router = useRouter();
258+
260259
let links = [
261260
{
262261
label: 'Resources',
262+
id: 'resources',
263263
url: `/dashboard/${entityType}/${organization}/dataset/${id}/edit/resources`,
264-
selected: pathItem === 'resources',
264+
// selected: pathItem === 'resources',
265265
},
266266
...(process.env.NEXT_PUBLIC_ENABLE_ACCESSMODEL === 'true'
267267
? [
268268
{
269269
label: 'Access Models',
270+
id: 'access',
270271
url: `/dashboard/${entityType}/${organization}/dataset/${id}/edit/access?list=true`,
271-
selected: pathItem === 'access',
272+
// selected: pathItem === 'access',
272273
},
273274
]
274275
: []),
275276
{
276277
label: 'Charts',
278+
id: 'charts',
277279
url: `/dashboard/${entityType}/${organization}/dataset/${id}/edit/charts?type=list`,
278-
selected: pathItem === 'charts',
280+
// selected: pathItem === 'charts',
279281
},
280282
{
281283
label: 'Metadata',
284+
id: 'metadata',
282285
url: `/dashboard/${entityType}/${organization}/dataset/${id}/edit/metadata`,
283-
selected: pathItem === 'metadata',
286+
// selected: pathItem === 'metadata',
284287
},
285288
{
286289
label: 'Publish',
290+
id: 'publish',
287291
url: `/dashboard/${entityType}/${organization}/dataset/${id}/edit/publish`,
288-
selected: pathItem === 'publish',
292+
// selected: pathItem === 'publish',
289293
},
290294
];
291295

292-
const router = useRouter();
296+
const [selectedTab, setSelectedTab] = useState(pathItem || 'distributions');
293297

294-
const handleTabClick = (url: string) => {
295-
router.replace(url);
298+
const handleTabClick = (item: {
299+
label: string;
300+
url: string;
301+
// selected: boolean;
302+
}) => {
303+
if (item.label !== selectedTab) {
304+
setSelectedTab(item.label);
305+
router.replace(item.url);
306+
}
296307
};
297308

298-
const initialTabLabel =
299-
links.find((option) => option.selected)?.label || 'Distributions';
309+
useEffect(() => {
310+
setSelectedTab(pathItem); // Update selected tab on path change
311+
}, [pathItem]);
300312

301313
return (
302314
<div>
303-
<Tabs defaultValue={initialTabLabel}>
315+
<Tabs value={selectedTab}>
304316
<TabList fitted>
305317
{links.map((item, index) => (
306318
<Tab
307-
value={item.label}
319+
value={item.id}
308320
key={index}
309-
onClick={() => handleTabClick(item.url)}
321+
onClick={() => handleTabClick(item)}
310322
>
311323
{item.label}
312324
</Tab>

0 commit comments

Comments
 (0)