Skip to content

Commit d22ecc0

Browse files
committed
add unpublish dataset feature
1 parent a986546 commit d22ecc0

File tree

1 file changed

+66
-16
lines changed
  • app/[locale]/dashboard/[entityType]/[entitySlug]/dataset

1 file changed

+66
-16
lines changed

app/[locale]/dashboard/[entityType]/[entitySlug]/dataset/page.tsx

Lines changed: 66 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useRouter } from 'next/navigation';
55
import { graphql } from '@/gql';
66
import { useMutation, useQuery } from '@tanstack/react-query';
77
import { parseAsString, useQueryState } from 'next-usequerystate';
8-
import { DataTable, IconButton, toast } from 'opub-ui';
8+
import { Button, DataTable, IconButton, toast } from 'opub-ui';
99

1010
import { GraphQL } from '@/lib/api';
1111
import { Icons } from '@/components/icons';
@@ -50,6 +50,19 @@ const deleteDatasetMutationDoc: any = graphql(`
5050
}
5151
`);
5252

53+
const unPublishDataset: any = graphql(`
54+
mutation unPublishDatasetMutation($datasetId: UUID!) {
55+
unPublishDataset(datasetId: $datasetId) {
56+
__typename
57+
... on TypeDataset {
58+
id
59+
title
60+
created
61+
}
62+
}
63+
}
64+
`);
65+
5366
export default function DatasetPage({
5467
params,
5568
}: {
@@ -72,6 +85,7 @@ export default function DatasetPage({
7285
},
7386
];
7487

88+
7589
const AllDatasetsQuery: { data: any; isLoading: boolean; refetch: any } =
7690
useQuery(
7791
[`fetch_datasets_org_dashboard`],
@@ -124,7 +138,6 @@ export default function DatasetPage({
124138
},
125139
}
126140
);
127-
128141
const CreateDatasetMutation: { mutate: any; isLoading: boolean; error: any } =
129142
useMutation(
130143
() =>
@@ -146,6 +159,30 @@ export default function DatasetPage({
146159
},
147160
}
148161
);
162+
const UnpublishDatasetMutation: {
163+
mutate: any;
164+
isLoading: boolean;
165+
error: any;
166+
} = useMutation(
167+
[`unpublish_dataset`],
168+
(data: { datasetId: string }) =>
169+
GraphQL(
170+
unPublishDataset,
171+
{
172+
[params.entityType]: params.entitySlug,
173+
},
174+
{ datasetId: data.datasetId }
175+
),
176+
{
177+
onSuccess: () => {
178+
toast(`Unpublished dataset successfully`);
179+
AllDatasetsQuery.refetch();
180+
},
181+
onError: (err: any) => {
182+
toast('Error: ' + err.message.split(':')[0]);
183+
},
184+
}
185+
);
149186

150187
const datasetsListColumns = [
151188
{
@@ -166,20 +203,33 @@ export default function DatasetPage({
166203
{
167204
accessorKey: 'delete',
168205
header: 'Delete',
169-
cell: ({ row }: any) => (
170-
<IconButton
171-
size="medium"
172-
icon={Icons.delete}
173-
color="interactive"
174-
onClick={() => {
175-
DeleteDatasetMutation.mutate({
176-
datasetId: row.original?.id,
177-
});
178-
}}
179-
>
180-
Delete
181-
</IconButton>
182-
),
206+
cell: ({ row }: any) =>
207+
navigationTab === 'published' ? (
208+
<Button
209+
size="medium"
210+
kind='tertiary'
211+
onClick={() => {
212+
UnpublishDatasetMutation.mutate({
213+
datasetId: row.original?.id,
214+
});
215+
}}
216+
>
217+
Unpublish
218+
</Button>
219+
) : (
220+
<IconButton
221+
size="medium"
222+
icon={Icons.delete}
223+
color="interactive"
224+
onClick={() => {
225+
DeleteDatasetMutation.mutate({
226+
datasetId: row.original?.id,
227+
});
228+
}}
229+
>
230+
Delete
231+
</IconButton>
232+
),
183233
},
184234
];
185235

0 commit comments

Comments
 (0)