Skip to content

Commit 64532fa

Browse files
committed
Enhance dataset mutation response structure and error handling in EditMetadata and Content components
1 parent 42b2349 commit 64532fa

File tree

4 files changed

+55
-51
lines changed

4 files changed

+55
-51
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,13 @@ const metadataQueryDoc: any = graphql(`
9696
const updateMetadataMutationDoc: any = graphql(`
9797
mutation SaveMetadata($UpdateMetadataInput: UpdateMetadataInput!) {
9898
addUpdateDatasetMetadata(updateMetadataInput: $UpdateMetadataInput) {
99-
__typename
100-
... on TypeDataset {
99+
success
100+
errors {
101+
fieldErrors {
102+
messages
103+
}
104+
}
105+
data {
101106
id
102107
description
103108
title
@@ -215,13 +220,15 @@ export function EditMetadata({ id }: { id: string }) {
215220
`metadata_fields_list_${id}`,
216221
],
217222
});
218-
const updatedData = defaultValuesPrepFn(res.addUpdateDatasetMetadata);
223+
const updatedData = defaultValuesPrepFn(
224+
res.addUpdateDatasetMetadata.data
225+
);
219226
setFormData(updatedData);
220227
setPreviousFormData(updatedData);
221228
// getDatasetMetadata.refetch();
222229
},
223230
onError: (err: any) => {
224-
toast('Error: ' + err.message.split(':')[0]);
231+
toast('Error: ' + err.message);
225232
},
226233
}
227234
);
@@ -425,6 +432,7 @@ export function EditMetadata({ id }: { id: string }) {
425432
<Input
426433
type="date"
427434
name={metadataFormItem.id}
435+
max={new Date().toISOString().split('T')[0]}
428436
value={formData[metadataFormItem.id] || ''}
429437
label={metadataFormItem.label}
430438
disabled={
@@ -490,10 +498,11 @@ export function EditMetadata({ id }: { id: string }) {
490498
<div className="w-full">
491499
<TextField
492500
key="description"
493-
multiline={3}
501+
multiline={4}
494502
name="description"
495503
label={'Description'}
496504
value={formData.description}
505+
helpText="Character limit: 1000"
497506
onChange={(e) => handleChange('description', e)}
498507
onBlur={() => handleSave(formData)} // Save on blur
499508
/>

app/[locale]/dashboard/[entityType]/[entitySlug]/dataset/components/content.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ import { GraphQL } from '@/lib/api';
1010
import { Icons } from '@/components/icons';
1111

1212
const createDatasetMutationDoc: any = graphql(`
13-
mutation GenerateDatasetName {
13+
mutation Generate_Dataset_Name {
1414
addDataset {
15-
__typename
16-
... on TypeDataset {
15+
success
16+
errors {
17+
fieldErrors {
18+
messages
19+
}
20+
}
21+
data {
1722
id
23+
title
1824
created
1925
}
20-
... on OperationInfo {
21-
messages {
22-
kind
23-
message
24-
}
25-
}
2626
}
2727
}
2828
`);
@@ -46,7 +46,7 @@ export const Content = ({
4646
{
4747
onSuccess: (data: any) => {
4848
router.push(
49-
`/dashboard/${params.entityType}/${params.entitySlug}/dataset/${data?.addDataset?.id}/edit/metadata`
49+
`/dashboard/${params.entityType}/${params.entitySlug}/dataset/${data?.addDataset?.data?.id}/edit/metadata`
5050
);
5151
},
5252
onError: (err: any) => {

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ import { ActionBar } from './components/action-bar';
99
import { Content } from './components/content';
1010

1111
const createDatasetMutationDoc: any = graphql(`
12-
mutation GenerateDatasetName {
12+
mutation GenerateDatasetname {
1313
addDataset {
14-
__typename
15-
... on TypeDataset {
14+
success
15+
errors {
16+
fieldErrors {
17+
messages
18+
}
19+
}
20+
data {
1621
id
22+
title
1723
created
1824
}
19-
... on OperationInfo {
20-
messages {
21-
kind
22-
message
23-
}
24-
}
2525
}
2626
}
2727
`);

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

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ const allDatasetsQueryDoc: any = graphql(`
2929
const createDatasetMutationDoc: any = graphql(`
3030
mutation GenerateDatasetName {
3131
addDataset {
32-
__typename
33-
... on TypeDataset {
32+
success
33+
errors {
34+
fieldErrors {
35+
messages
36+
}
37+
}
38+
data {
3439
id
40+
title
3541
created
3642
}
37-
... on OperationInfo {
38-
messages {
39-
kind
40-
message
41-
}
42-
}
4343
}
4444
}
4545
`);
@@ -86,25 +86,19 @@ export default function DatasetPage({
8686
];
8787

8888
const AllDatasetsQuery: { data: any; isLoading: boolean; refetch: any } =
89-
useQuery(
90-
[`fetch_datasets_org_dashboard`],
91-
() =>
92-
GraphQL(
93-
allDatasetsQueryDoc,
94-
{
95-
[params.entityType]: params.entitySlug,
89+
useQuery([`fetch_datasets_org_dashboard`], () =>
90+
GraphQL(
91+
allDatasetsQueryDoc,
92+
{
93+
[params.entityType]: params.entitySlug,
94+
},
95+
{
96+
filters: {
97+
status: navigationTab === 'published' ? 'PUBLISHED' : 'DRAFT',
9698
},
97-
{
98-
filters: {
99-
status: navigationTab === 'published' ? 'PUBLISHED' : 'DRAFT',
100-
},
101-
order: { modified: 'DESC' },
102-
}
103-
),
104-
{
105-
refetchOnMount: true,
106-
refetchOnReconnect: true,
107-
}
99+
order: { modified: 'DESC' },
100+
}
101+
)
108102
);
109103

110104
useEffect(() => {
@@ -149,8 +143,9 @@ export default function DatasetPage({
149143
),
150144
{
151145
onSuccess: (data: any) => {
146+
152147
router.push(
153-
`/dashboard/${params.entityType}/${params.entitySlug}/dataset/${data?.addDataset?.id}/edit/metadata`
148+
`/dashboard/${params.entityType}/${params.entitySlug}/dataset/${data?.addDataset?.data?.id}/edit/metadata`
154149
);
155150
},
156151
onError: (err: any) => {

0 commit comments

Comments
 (0)