Skip to content

Commit

Permalink
Fix Custom Fields Overwriting (#2766)
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveDMurphy authored Mar 7, 2023
2 parents 507ae1f + b29801f commit 3364358
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions clients/admin-ui/src/features/common/custom-fields/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ export const useCustomFields = ({
useGetCustomFieldDefinitionsByResourceTypeQuery(resourceType, {
skip: !isEnabled,
});
const customFieldsQuery = useGetCustomFieldsForResourceQuery(
resourceFidesKey ?? "",
{
skip: queryFidesKey !== "" && !(isEnabled && queryFidesKey),
}
);
const {
data,
isLoading: isCustomFieldIsLoading,
error,
isError,
} = useGetCustomFieldsForResourceQuery(resourceFidesKey ?? "", {
skip: queryFidesKey !== "" && !(isEnabled && queryFidesKey),
});

// The `fixedCacheKey` options will ensure that components referencing the same resource will
// share mutation info. That won't be too useful, though, because `upsertCustomField` can issue
Expand All @@ -57,7 +59,7 @@ export const useCustomFields = ({
const isLoading =
allAllowListQuery.isLoading ||
customFieldDefinitionsQuery.isLoading ||
customFieldsQuery.isLoading ||
isCustomFieldIsLoading ||
upsertCustomFieldMutationResult.isLoading ||
deleteCustomFieldMutationResult.isLoading;

Expand Down Expand Up @@ -91,16 +93,16 @@ export const useCustomFields = ({
[activeCustomFieldDefinition]
);

const definitionIdToCustomField = useMemo(
() =>
new Map(
filterWithId(customFieldsQuery.data).map((fd) => [
fd.custom_field_definition_id,
fd,
])
),
[customFieldsQuery]
);
const definitionIdToCustomField = useMemo(() => {
// @ts-ignore
if (isError && error?.status === 404) {
return new Map();
}
const newMap = new Map(
filterWithId(data).map((fd) => [fd.custom_field_definition_id, fd])
);
return newMap;
}, [data, isError, error]);

const sortedCustomFieldDefinitionIds = useMemo(() => {
const ids = [...idToCustomFieldDefinition.keys()];
Expand Down

0 comments on commit 3364358

Please sign in to comment.