Skip to content

Commit 4ab24e1

Browse files
committed
lift schema data to limit rerender
1 parent 41af17a commit 4ab24e1

File tree

2 files changed

+42
-60
lines changed

2 files changed

+42
-60
lines changed

app/[locale]/dashboard/organization/[organizationId]/dataset/[id]/edit/components/EditResource.tsx

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
Icon,
2626
IconButton,
2727
Select,
28+
Spinner,
2829
Text,
2930
TextField,
3031
toast,
@@ -460,23 +461,43 @@ export const EditResource = ({ reload, data }: any) => {
460461
<Text>See Preview</Text>
461462
</div>
462463
</div>*/}
463-
{resourceId &&
464-
payload?.datasetResources?.filter(
465-
(item: any) => item.id === resourceId
466-
) ? (
467-
<ResourceSchema
468-
setSchema={setSchema}
469-
resourceId={resourceId}
470-
isPending={isPending}
471-
schemaMutate={schemaMutate}
472-
isSchemaLoading={isSchemaLoading}
473-
data={
474-
payload?.datasetResources?.filter(
475-
(item: any) => item.id === resourceId
476-
)[0]?.schema
477-
}
478-
/>
479-
) : null}
464+
<div className="my-8">
465+
<div className="flex flex-wrap justify-between">
466+
<Text>Fields in the Resource</Text>
467+
<Button
468+
size="medium"
469+
kind="tertiary"
470+
variant="basic"
471+
onClick={() =>
472+
schemaMutate({
473+
resourceId: resourceId,
474+
})
475+
}
476+
>
477+
<div className="flex items-center gap-1">
478+
<Text>Reset Fields</Text>{' '}
479+
<Icon source={Icons.info} color="interactive" />
480+
</div>
481+
</Button>
482+
</div>
483+
<Text variant="headingXs" as="span" fontWeight="regular">
484+
The Field settings apply to the Resource on a master level and can not
485+
be changed in Access Models.
486+
</Text>
487+
{isPending || isSchemaLoading ? (
488+
<div className=" mt-8 flex justify-center">
489+
<Spinner size={30} />
490+
</div>
491+
) : resourceId && payload?.datasetResources?.filter(
492+
(item: any) => item.id === resourceId ).length > 0 ? (
493+
<ResourceSchema
494+
setSchema={setSchema}
495+
data={payload?.datasetResources?.filter((item: any) => item.id === resourceId)[0]?.schema}
496+
/>
497+
) : (
498+
<div className="my-8 flex justify-center"> Click on Reset Fields </div>
499+
)}
500+
</div>
480501
</div>
481502
);
482503
};

app/[locale]/dashboard/organization/[organizationId]/dataset/[id]/edit/components/ResourceSchema.tsx

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,7 @@ const DescriptionCell = ({
5555
);
5656
};
5757

58-
export const ResourceSchema = ({
59-
setSchema,
60-
resourceId,
61-
isPending,
62-
data,
63-
schemaMutate,
64-
isSchemaLoading
65-
}: any) => {
58+
export const ResourceSchema = ({ setSchema, data }: any) => {
6659

6760
const [updatedData, setUpdatedData] = React.useState<any>(data);
6861

@@ -123,7 +116,7 @@ export const ResourceSchema = ({
123116
{
124117
accessorKey: 'format',
125118
header: 'FORMAT',
126-
cell: (info: any) => {
119+
cell: (info: any) => {
127120
const rowIndex = info.row.index;
128121
const format = updatedData[rowIndex]?.format || '';
129122
return (
@@ -149,49 +142,17 @@ export const ResourceSchema = ({
149142
}));
150143
};
151144

152-
const setFields = () => {
153-
schemaMutate({
154-
resourceId: resourceId,
155-
});
156-
};
157-
158145
return (
159146
<>
160-
<div className="mt-8 flex justify-between">
161-
<Text>Fields in the Resource</Text>
162-
<div className="flex gap-4">
163-
<Button
164-
size="medium"
165-
kind="tertiary"
166-
variant="basic"
167-
onClick={setFields}
168-
>
169-
<div className="flex items-center gap-1">
170-
<Text>Reset Fields</Text>{' '}
171-
<Icon source={Icons.info} color="interactive" />
172-
</div>
173-
</Button>
174-
</div>
175-
</div>
176-
<Text variant="headingXs" as="span" fontWeight="regular">
177-
The Field settings apply to the Resource on a master level and can not
178-
be changed in Access Models.
179-
</Text>
180147
<div className="mt-3">
181-
{isPending || isSchemaLoading ? (
182-
<div className=" mt-8 flex justify-center">
183-
<Spinner size={30} />
184-
</div>
185-
) : data && data.length > 0 ? (
148+
{data && data.length > 0 ? (
186149
<DataTable
187150
columns={generateColumnData()}
188151
rows={generateTableData(data)}
189152
hideFooter={true}
190153
hideSelection
191154
/>
192-
) : (
193-
<div className="mt-8 flex justify-center">Click on Reset Fields</div>
194-
)}
155+
):<div className="mt-8 flex justify-center">Click on Reset Fields</div>}
195156
</div>
196157
</>
197158
);

0 commit comments

Comments
 (0)