Skip to content

Commit

Permalink
FIX: separate urn with non-nested-pattern for now (#5383)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucano Vera <[email protected]>
  • Loading branch information
2 people authored and Kelsey-Ethyca committed Oct 16, 2024
1 parent 9d076ea commit 3c760e5
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 86 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The types of changes are:

### Fixed
- Fixed a bug where D&D tables were rendering stale data [#5372](https://github.com/ethyca/fides/pull/5372)
- Fixed issue where Dataset with nested fields was unable to edit Categories [#5383](https://github.com/ethyca/fides/pull/5383)

### Developer Experience
- Fix warning messages from slowapi and docker [#5385](https://github.com/ethyca/fides/pull/5385)
Expand Down
4 changes: 4 additions & 0 deletions clients/admin-ui/src/features/common/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ const Breadcrumbs = ({
{breadcrumbs.map((breadcumbItem, index) => {
const isLast = index + 1 === breadcrumbs.length;

if (!breadcumbItem.title) {
return null;
}

return (
<BreadcrumbItem
{...normalItemStyles}
Expand Down
15 changes: 10 additions & 5 deletions clients/admin-ui/src/features/dataset/EditCollectionDrawer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { errorToastParams, successToastParams } from "common/toast";
import { ConfirmationModal, Text, useDisclosure, useToast } from "fidesui";
import { useMemo } from "react";

import EditDrawer, {
EditDrawerFooter,
Expand All @@ -19,8 +20,8 @@ import {
const DESCRIPTION =
"Collections are an array of objects that describe the Dataset's collections. Provide additional context to this collection by filling out the fields below.";
interface Props {
dataset?: Dataset;
collection?: DatasetCollection;
dataset: Dataset;
collection: DatasetCollection;
isOpen: boolean;
onClose: () => void;
}
Expand All @@ -30,7 +31,11 @@ const EditCollectionDrawer = ({
isOpen,
onClose,
}: Props) => {
const collectionIndex = dataset?.collections.indexOf(collection!);
const collectionIndex = useMemo(
() => dataset?.collections.indexOf(collection),
// eslint-disable-next-line react-hooks/exhaustive-deps
[],
);
const [updateDataset] = useUpdateDatasetMutation();
const toast = useToast();
const {
Expand All @@ -42,7 +47,7 @@ const EditCollectionDrawer = ({
const handleSubmit = async (
values: Pick<DatasetCollection, "description" | "data_categories">,
) => {
const updatedCollection = { ...collection!, ...values };
const updatedCollection = { ...collection, ...values };
const updatedDataset = getUpdatedDatasetFromCollection(
dataset!,
updatedCollection,
Expand Down Expand Up @@ -92,7 +97,7 @@ const EditCollectionDrawer = ({
}
>
<EditCollectionOrFieldForm
values={collection!}
values={collection}
onSubmit={handleSubmit}
dataType="collection"
showDataCategories={false}
Expand Down
5 changes: 4 additions & 1 deletion clients/admin-ui/src/features/dataset/EditFieldDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import EditDrawer, {
} from "~/features/common/EditDrawer";
import { Dataset, DatasetField } from "~/types/api";

import { URN_SEPARATOR } from "./constants";
import { useUpdateDatasetMutation } from "./dataset.slice";
import EditCollectionOrFieldForm, {
FORM_ID,
Expand Down Expand Up @@ -47,7 +48,9 @@ const EditFieldDrawer = ({
const pathToField = getDatasetPath({
dataset: dataset!,
collectionName,
subfieldUrn: subfieldUrn ? `${subfieldUrn}.${field?.name}` : field?.name,
subfieldUrn: subfieldUrn
? `${subfieldUrn}${URN_SEPARATOR}${field?.name}`
: field?.name,
});

const updatedField = { ...field!, ...values };
Expand Down
2 changes: 2 additions & 0 deletions clients/admin-ui/src/features/dataset/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ export const FIELD = {
"Arrays of Data Category resources, identified by fides_key, that apply to this field.",
},
};

export const URN_SEPARATOR = "/";
4 changes: 3 additions & 1 deletion clients/admin-ui/src/features/dataset/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { get } from "lodash";

import { Dataset, DatasetCollection, DatasetField } from "~/types/api";

import { URN_SEPARATOR } from "./constants";

/**
* Because there is only one /dataset endpoint which handles dataset, collection,
* and field modifications, and always takes a whole dataset object, it is convenient
Expand Down Expand Up @@ -97,7 +99,7 @@ export const getDatasetPath = ({
return path;
}

const subfieldParts = subfieldUrn.split(".");
const subfieldParts = subfieldUrn.split(URN_SEPARATOR);
subfieldParts.forEach((subfieldName) => {
const field: DatasetField = get(dataset, path);
const subfieldIndex = field.fields!.findIndex(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
useGetDatasetByKeyQuery,
useUpdateDatasetMutation,
} from "~/features/dataset";
import { URN_SEPARATOR } from "~/features/dataset/constants";
import DatasetBreadcrumbs from "~/features/dataset/DatasetBreadcrumbs";
import EditFieldDrawer from "~/features/dataset/EditFieldDrawer";
import { getDatasetPath } from "~/features/dataset/helpers";
Expand Down Expand Up @@ -94,7 +95,7 @@ const FieldsDetailPage: NextPage = () => {
const pathToField = getDatasetPath({
dataset: dataset!,
collectionName,
subfieldUrn: `${subfieldUrn}.${field.name}`,
subfieldUrn: `${subfieldUrn}${URN_SEPARATOR}${field?.name}`,
});

const updatedDataset = cloneDeep(dataset!);
Expand All @@ -119,7 +120,7 @@ const FieldsDetailPage: NextPage = () => {
const pathToField = getDatasetPath({
dataset: dataset!,
collectionName,
subfieldUrn: `${subfieldUrn}.${field.name}`,
subfieldUrn: `${subfieldUrn}${URN_SEPARATOR}${field?.name}`,
});

const updatedDataset = cloneDeep(dataset!);
Expand Down Expand Up @@ -206,6 +207,7 @@ const FieldsDetailPage: NextPage = () => {
<DefaultHeaderCell value="Data categories" {...props} />
),
size: 300,
meta: { disableRowClick: true },
}),

columnHelper.display({
Expand Down Expand Up @@ -260,46 +262,48 @@ const FieldsDetailPage: NextPage = () => {
DatasetField | undefined
>();

const breadcrumbs = useMemo(() => {
return [
{
title: "All datasets",
icon: <DatabaseIcon boxSize={4} />,
link: DATASET_ROUTE,
},
{
title: datasetId,
link: {
pathname: DATASET_DETAIL_ROUTE,
query: { datasetId },
},
icon: <DatasetIcon boxSize={5} />,
},
{
title: collectionName,
icon: <TableIcon boxSize={5} />,
link: {
pathname: DATASET_COLLECTION_DETAIL_ROUTE,
query: { datasetId, collectionName },
},
},
...subfieldParts.map((subFieldName, index) => ({
title: subFieldName,
link: {
pathname: DATASET_COLLECTION_SUBFIELD_DETAIL_ROUTE,
query: {
datasetId,
collectionName,
subfieldUrn: subfieldParts.slice(0, index + 1).join("."),
},
},
icon: <FieldIcon boxSize={5} />,
})),
];
}, [datasetId, collectionName, subfieldParts]);

return (
<Layout title={`Dataset - ${datasetId}`} mainProps={{ paddingTop: 0 }}>
<PageHeader breadcrumbs={[{ title: "Datasets" }]}>
<DatasetBreadcrumbs
breadcrumbs={[
{
title: "All datasets",
icon: <DatabaseIcon boxSize={4} />,
link: DATASET_ROUTE,
},
{
title: datasetId,
link: {
pathname: DATASET_DETAIL_ROUTE,
query: { datasetId },
},
icon: <DatasetIcon boxSize={5} />,
},
{
title: collectionName,
icon: <TableIcon boxSize={5} />,
link: {
pathname: DATASET_COLLECTION_DETAIL_ROUTE,
query: { datasetId, collectionName },
},
},
...subfieldParts.map((subFieldName, index) => ({
title: subFieldName,
link: {
pathname: DATASET_COLLECTION_SUBFIELD_DETAIL_ROUTE,
query: {
datasetId,
collectionName,
subfieldUrn: subfieldParts.slice(0, index + 1).join("."),
},
},
icon: <FieldIcon boxSize={5} />,
})),
]}
/>
<DatasetBreadcrumbs breadcrumbs={breadcrumbs} />
</PageHeader>

{isLoading ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ const FieldsDetailPage: NextPage = () => {
<DefaultHeaderCell value="Data categories" {...props} />
),
size: 300,
meta: { disableRowClick: true },
}),

columnHelper.display({
Expand Down Expand Up @@ -248,30 +249,32 @@ const FieldsDetailPage: NextPage = () => {
DatasetField | undefined
>();

const breadcrumbs = useMemo(() => {
return [
{
title: "All datasets",
icon: <DatabaseIcon boxSize={4} />,
link: DATASET_ROUTE,
},
{
title: datasetId,
link: {
pathname: DATASET_DETAIL_ROUTE,
query: { datasetId },
},
icon: <DatasetIcon boxSize={5} />,
},
{
title: collectionName,
icon: <TableIcon boxSize={5} />,
},
];
}, [datasetId, collectionName]);

return (
<Layout title={`Dataset - ${datasetId}`} mainProps={{ paddingTop: 0 }}>
<PageHeader breadcrumbs={[{ title: "Datasets" }]}>
<DatasetBreadcrumbs
breadcrumbs={[
{
title: "All datasets",
icon: <DatabaseIcon boxSize={4} />,
link: DATASET_ROUTE,
},
{
title: datasetId,
link: {
pathname: DATASET_DETAIL_ROUTE,
query: { datasetId },
},
icon: <DatasetIcon boxSize={5} />,
},
{
title: collectionName,
icon: <TableIcon boxSize={5} />,
},
]}
/>
<DatasetBreadcrumbs breadcrumbs={breadcrumbs} />
</PageHeader>

{isLoading ? (
Expand Down
42 changes: 23 additions & 19 deletions clients/admin-ui/src/pages/dataset/[datasetId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,24 @@ const DatasetDetailPage: NextPage = () => {
});
};

const breadcrumbs = useMemo(() => {
return [
{
title: "All datasets",
icon: <DatabaseIcon boxSize={4} />,
link: DATASET_ROUTE,
},
{
title: datasetId,
icon: <DatasetIcon boxSize={5} />,
},
];
}, [datasetId]);

return (
<Layout title={`Dataset - ${datasetId}`} mainProps={{ paddingTop: 0 }}>
<PageHeader breadcrumbs={[{ title: "Datasets" }]}>
<DatasetBreadcrumbs
breadcrumbs={[
{
title: "All datasets",
icon: <DatabaseIcon boxSize={4} />,
link: DATASET_ROUTE,
},
{
title: datasetId,
icon: <DatasetIcon boxSize={5} />,
},
]}
/>
<DatasetBreadcrumbs breadcrumbs={breadcrumbs} />
</PageHeader>

{isLoading ? (
Expand All @@ -174,12 +176,14 @@ const DatasetDetailPage: NextPage = () => {
</Box>
)}

<EditCollectionDrawer
dataset={dataset!}
collection={selectedCollectionForEditing}
isOpen={isEditingCollection}
onClose={() => setIsEditingCollection(false)}
/>
{dataset && selectedCollectionForEditing && (
<EditCollectionDrawer
dataset={dataset}
collection={selectedCollectionForEditing}
isOpen={isEditingCollection}
onClose={() => setIsEditingCollection(false)}
/>
)}
</Layout>
);
};
Expand Down

0 comments on commit 3c760e5

Please sign in to comment.