-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into HJ-92_persist-monitor-execution
- Loading branch information
Showing
24 changed files
with
734 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
clients/admin-ui/src/features/data-catalog/utils/urnParsing.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { | ||
parseResourceBreadcrumbsNoProject, | ||
parseResourceBreadcrumbsWithProject, | ||
} from "~/features/data-catalog/utils/urnParsing"; | ||
|
||
const URL_PREFIX = "/url-prefix"; | ||
|
||
describe(parseResourceBreadcrumbsWithProject.name, () => { | ||
const URN = "monitor.project.dataset.table.field"; | ||
const EXPECTED_TITLES = ["project", "dataset", "table", "field"]; | ||
const EXPECTED_HREFS = [ | ||
"/url-prefix/monitor.project", | ||
"/url-prefix/monitor.project/monitor.project.dataset", | ||
"/url-prefix/monitor.project/monitor.project.dataset.table", | ||
undefined, | ||
]; | ||
|
||
it("should return no breadcrumbs without a URN", () => { | ||
const result = parseResourceBreadcrumbsWithProject(undefined, URL_PREFIX); | ||
expect(result).toEqual([]); | ||
}); | ||
|
||
it("should return no breadcrumbs with a short URN", () => { | ||
const result = parseResourceBreadcrumbsWithProject("monitor", URL_PREFIX); | ||
expect(result).toEqual([]); | ||
}); | ||
|
||
it("should return the correct breadcrumbs when URN is provided", () => { | ||
const result = parseResourceBreadcrumbsWithProject(URN, URL_PREFIX); | ||
result.forEach((breadcrumb, idx) => { | ||
expect(breadcrumb.title).toEqual(EXPECTED_TITLES[idx]); | ||
expect(breadcrumb.href).toEqual(EXPECTED_HREFS[idx]); | ||
}); | ||
}); | ||
}); | ||
|
||
describe(parseResourceBreadcrumbsNoProject.name, () => { | ||
const URN = "monitor.dataset.table.field"; | ||
const EXPECTED_TITLES = ["dataset", "table", "field"]; | ||
const EXPECTED_HREFS = [ | ||
"/url-prefix/monitor.dataset", | ||
"/url-prefix/monitor.dataset.table", | ||
undefined, | ||
]; | ||
|
||
it("should return no breadcrumbs without a URN", () => { | ||
const result = parseResourceBreadcrumbsNoProject(undefined, URL_PREFIX); | ||
expect(result).toEqual([]); | ||
}); | ||
|
||
it("should return no breadcrumbs with a short URN", () => { | ||
const result = parseResourceBreadcrumbsNoProject("monitor", URL_PREFIX); | ||
expect(result).toEqual([]); | ||
}); | ||
|
||
it("should return the correct breadcrumbs when URN is provided", () => { | ||
const result = parseResourceBreadcrumbsNoProject(URN, URL_PREFIX); | ||
result.forEach((breadcrumb, idx) => { | ||
expect(breadcrumb.title).toEqual(EXPECTED_TITLES[idx]); | ||
expect(breadcrumb.href).toEqual(EXPECTED_HREFS[idx]); | ||
}); | ||
}); | ||
}); |
80 changes: 80 additions & 0 deletions
80
clients/admin-ui/src/features/data-catalog/utils/urnParsing.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { Icons } from "fidesui"; | ||
|
||
import { NextBreadcrumbProps } from "~/features/common/nav/v2/NextBreadcrumb"; | ||
|
||
const URN_SEPARATOR = "."; | ||
|
||
export const getProjectName = (urn: string) => { | ||
const urnParts = urn.split(URN_SEPARATOR); | ||
return urnParts[1]; | ||
}; | ||
|
||
const RESOURCE_ICONS = [ | ||
<Icons.Layers key="layers" />, | ||
<Icons.Table key="table" />, | ||
<Icons.ShowDataCards key="field" style={{ transform: "rotate(-90deg)" }} />, | ||
]; | ||
|
||
export const parseResourceBreadcrumbsWithProject = ( | ||
urn: string | undefined, | ||
urlPrefix: string, | ||
) => { | ||
if (!urn) { | ||
return []; | ||
} | ||
const urnParts = urn.split(URN_SEPARATOR); | ||
if (urnParts.length < 2) { | ||
return []; | ||
} | ||
const projectUrn = urnParts.splice(0, 2).join(URN_SEPARATOR); | ||
const subResourceUrns: NextBreadcrumbProps["items"] = []; | ||
|
||
urnParts.reduce((prev, current, idx) => { | ||
const isLast = idx === urnParts.length - 1; | ||
const next = `${prev}${URN_SEPARATOR}${current}`; | ||
subResourceUrns.push({ | ||
title: current, | ||
href: !isLast ? `${urlPrefix}/${projectUrn}/${next}` : undefined, | ||
icon: RESOURCE_ICONS[idx], | ||
}); | ||
return next; | ||
}, projectUrn); | ||
|
||
return [ | ||
{ | ||
title: getProjectName(projectUrn), | ||
href: `${urlPrefix}/${projectUrn}`, | ||
icon: <Icons.Db2Database />, | ||
}, | ||
...subResourceUrns, | ||
]; | ||
}; | ||
|
||
export const parseResourceBreadcrumbsNoProject = ( | ||
urn: string | undefined, | ||
urlPrefix: string, | ||
) => { | ||
if (!urn) { | ||
return []; | ||
} | ||
|
||
const urnParts = urn.split(URN_SEPARATOR); | ||
if (urnParts.length < 2) { | ||
return []; | ||
} | ||
const monitorId = urnParts.shift(); | ||
const subResourceUrns: NextBreadcrumbProps["items"] = []; | ||
|
||
urnParts.reduce((prev, current, idx) => { | ||
const isLast = idx === urnParts.length - 1; | ||
const next = `${prev}${URN_SEPARATOR}${current}`; | ||
subResourceUrns.push({ | ||
title: current, | ||
href: !isLast ? `${urlPrefix}/${next}` : undefined, | ||
icon: RESOURCE_ICONS[idx], | ||
}); | ||
return next; | ||
}, monitorId); | ||
|
||
return subResourceUrns; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.