Check snapshot type and id from url
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -32,7 +32,7 @@ export function PageError({ resetErrorBoundary, error: propsError }: Props) {
|
||||
}
|
||||
}, [location, resetErrorBoundary]);
|
||||
|
||||
if (!error) {
|
||||
if (!error || (error && error.toString().includes("PAGE_NOT_FOUND"))) {
|
||||
return (
|
||||
<div className={classNames.wrapper}>
|
||||
<h1 className={classNames.title}>
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { IconClock } from "@probo/ui";
|
||||
import { useTranslate } from "@probo/i18n";
|
||||
import { useLazyLoadQuery, graphql } from "react-relay";
|
||||
import { useLocation } from "react-router";
|
||||
import type { SnapshotBannerQuery } from "./__generated__/SnapshotBannerQuery.graphql";
|
||||
import { getSnapshotTypeUrlPath } from "@probo/helpers";
|
||||
|
||||
const snapshotQuery = graphql`
|
||||
query SnapshotBannerQuery($snapshotId: ID!) {
|
||||
@@ -9,18 +11,25 @@ const snapshotQuery = graphql`
|
||||
... on Snapshot {
|
||||
id
|
||||
name
|
||||
type
|
||||
createdAt
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const isSnapshotTypeValidForUrl = (type: string, pathname: string) => {
|
||||
const urlPath = getSnapshotTypeUrlPath(type);
|
||||
return pathname.includes(urlPath);
|
||||
};
|
||||
|
||||
type Props = {
|
||||
snapshotId: string;
|
||||
};
|
||||
|
||||
export function SnapshotBanner({ snapshotId }: Props) {
|
||||
const { __, dateFormat } = useTranslate();
|
||||
const location = useLocation();
|
||||
|
||||
const data = useLazyLoadQuery<SnapshotBannerQuery>(snapshotQuery, { snapshotId });
|
||||
const snapshot = data.node;
|
||||
@@ -29,6 +38,10 @@ export function SnapshotBanner({ snapshotId }: Props) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (snapshot.type && !isSnapshotTypeValidForUrl(snapshot.type, location.pathname)) {
|
||||
throw new Error("PAGE_NOT_FOUND");
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="bg-warning rounded-lg p-4 flex items-center gap-3">
|
||||
<IconClock className="text-warning-600 flex-shrink-0" size={20} />
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @generated SignedSource<<a11c48ca33ac17dd7eaf6eeca4a0c20d>>
|
||||
* @generated SignedSource<<3c8b528580116deec511c979e209cfc3>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
@@ -9,6 +9,7 @@
|
||||
// @ts-nocheck
|
||||
|
||||
import { ConcreteRequest } from 'relay-runtime';
|
||||
export type SnapshotsType = "ASSETS" | "COMPLIANCE_REGISTRIES" | "DATA" | "NONCONFORMITY_REGISTRIES" | "RISKS" | "VENDORS";
|
||||
export type SnapshotBannerQuery$variables = {
|
||||
snapshotId: string;
|
||||
};
|
||||
@@ -17,6 +18,7 @@ export type SnapshotBannerQuery$data = {
|
||||
readonly createdAt?: any;
|
||||
readonly id?: string;
|
||||
readonly name?: string;
|
||||
readonly type?: SnapshotsType;
|
||||
};
|
||||
};
|
||||
export type SnapshotBannerQuery = {
|
||||
@@ -54,6 +56,13 @@ v3 = {
|
||||
"storageKey": null
|
||||
},
|
||||
v4 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "type",
|
||||
"storageKey": null
|
||||
},
|
||||
v5 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
@@ -80,7 +89,8 @@ return {
|
||||
"selections": [
|
||||
(v2/*: any*/),
|
||||
(v3/*: any*/),
|
||||
(v4/*: any*/)
|
||||
(v4/*: any*/),
|
||||
(v5/*: any*/)
|
||||
],
|
||||
"type": "Snapshot",
|
||||
"abstractKey": null
|
||||
@@ -118,7 +128,8 @@ return {
|
||||
"kind": "InlineFragment",
|
||||
"selections": [
|
||||
(v3/*: any*/),
|
||||
(v4/*: any*/)
|
||||
(v4/*: any*/),
|
||||
(v5/*: any*/)
|
||||
],
|
||||
"type": "Snapshot",
|
||||
"abstractKey": null
|
||||
@@ -129,16 +140,16 @@ return {
|
||||
]
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "8f21371ececf96444bb6b00e52783573",
|
||||
"cacheID": "7e026c7c030cd116b4794260934c394f",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "SnapshotBannerQuery",
|
||||
"operationKind": "query",
|
||||
"text": "query SnapshotBannerQuery(\n $snapshotId: ID!\n) {\n node(id: $snapshotId) {\n __typename\n ... on Snapshot {\n id\n name\n createdAt\n }\n id\n }\n}\n"
|
||||
"text": "query SnapshotBannerQuery(\n $snapshotId: ID!\n) {\n node(id: $snapshotId) {\n __typename\n ... on Snapshot {\n id\n name\n type\n createdAt\n }\n id\n }\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
(node as any).hash = "1602d5b6c0ae4a3122998e4d3419af05";
|
||||
(node as any).hash = "e50a4bb5133d8e918b8b2b9d2a42f1d1";
|
||||
|
||||
export default node;
|
||||
|
||||
@@ -19,6 +19,7 @@ export const datumNodeQuery = graphql`
|
||||
node(id: $dataId) {
|
||||
... on Datum {
|
||||
id
|
||||
snapshotId
|
||||
name
|
||||
dataClassification
|
||||
owner {
|
||||
|
||||
@@ -22,6 +22,7 @@ export const nonconformityRegistryNodeQuery = graphql`
|
||||
node(id: $nonconformityRegistryId) {
|
||||
... on NonconformityRegistry {
|
||||
id
|
||||
snapshotId
|
||||
referenceId
|
||||
description
|
||||
dateIdentified
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @generated SignedSource<<ff7246a675948a19ab124dbf6095b3bb>>
|
||||
* @generated SignedSource<<5cfbdbc980894977800a18064306f2c1>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
@@ -27,6 +27,7 @@ export type DatumGraphNodeQuery$data = {
|
||||
readonly fullName: string;
|
||||
readonly id: string;
|
||||
};
|
||||
readonly snapshotId?: string | null | undefined;
|
||||
readonly updatedAt?: any;
|
||||
readonly vendors?: {
|
||||
readonly edges: ReadonlyArray<{
|
||||
@@ -71,17 +72,24 @@ v3 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "name",
|
||||
"name": "snapshotId",
|
||||
"storageKey": null
|
||||
},
|
||||
v4 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "dataClassification",
|
||||
"name": "name",
|
||||
"storageKey": null
|
||||
},
|
||||
v5 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "dataClassification",
|
||||
"storageKey": null
|
||||
},
|
||||
v6 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "People",
|
||||
@@ -100,7 +108,7 @@ v5 = {
|
||||
],
|
||||
"storageKey": null
|
||||
},
|
||||
v6 = {
|
||||
v7 = {
|
||||
"alias": null,
|
||||
"args": [
|
||||
{
|
||||
@@ -131,7 +139,7 @@ v6 = {
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v2/*: any*/),
|
||||
(v3/*: any*/),
|
||||
(v4/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
@@ -155,7 +163,7 @@ v6 = {
|
||||
],
|
||||
"storageKey": "vendors(first:50)"
|
||||
},
|
||||
v7 = {
|
||||
v8 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "Organization",
|
||||
@@ -167,14 +175,14 @@ v7 = {
|
||||
],
|
||||
"storageKey": null
|
||||
},
|
||||
v8 = {
|
||||
v9 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "createdAt",
|
||||
"storageKey": null
|
||||
},
|
||||
v9 = {
|
||||
v10 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
@@ -206,7 +214,8 @@ return {
|
||||
(v6/*: any*/),
|
||||
(v7/*: any*/),
|
||||
(v8/*: any*/),
|
||||
(v9/*: any*/)
|
||||
(v9/*: any*/),
|
||||
(v10/*: any*/)
|
||||
],
|
||||
"type": "Datum",
|
||||
"abstractKey": null
|
||||
@@ -249,7 +258,8 @@ return {
|
||||
(v6/*: any*/),
|
||||
(v7/*: any*/),
|
||||
(v8/*: any*/),
|
||||
(v9/*: any*/)
|
||||
(v9/*: any*/),
|
||||
(v10/*: any*/)
|
||||
],
|
||||
"type": "Datum",
|
||||
"abstractKey": null
|
||||
@@ -260,16 +270,16 @@ return {
|
||||
]
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "7dcd0ba0b57e917592a333f2368f65c4",
|
||||
"cacheID": "6ed49a3413c0214dc95da9a422e484b4",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "DatumGraphNodeQuery",
|
||||
"operationKind": "query",
|
||||
"text": "query DatumGraphNodeQuery(\n $dataId: ID!\n) {\n node(id: $dataId) {\n __typename\n ... on Datum {\n id\n name\n dataClassification\n owner {\n id\n fullName\n }\n vendors(first: 50) {\n edges {\n node {\n id\n name\n websiteUrl\n category\n }\n }\n }\n organization {\n id\n }\n createdAt\n updatedAt\n }\n id\n }\n}\n"
|
||||
"text": "query DatumGraphNodeQuery(\n $dataId: ID!\n) {\n node(id: $dataId) {\n __typename\n ... on Datum {\n id\n snapshotId\n name\n dataClassification\n owner {\n id\n fullName\n }\n vendors(first: 50) {\n edges {\n node {\n id\n name\n websiteUrl\n category\n }\n }\n }\n organization {\n id\n }\n createdAt\n updatedAt\n }\n id\n }\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
(node as any).hash = "c8a8fc6a37cce32b83f53379317d8f67";
|
||||
(node as any).hash = "2f4df20b67f8b21eda5f510f250abda1";
|
||||
|
||||
export default node;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @generated SignedSource<<7b7982ce6c305e82103ca4422bbb7c2f>>
|
||||
* @generated SignedSource<<4ea62d99e8a73491f8125cb3e8d8e4b5>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
@@ -39,6 +39,7 @@ export type NonconformityRegistryGraphNodeQuery$data = {
|
||||
};
|
||||
readonly referenceId?: string;
|
||||
readonly rootCause?: string;
|
||||
readonly snapshotId?: string | null | undefined;
|
||||
readonly status?: NonconformityRegistryStatus;
|
||||
readonly updatedAt?: any;
|
||||
};
|
||||
@@ -74,59 +75,66 @@ v3 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "referenceId",
|
||||
"name": "snapshotId",
|
||||
"storageKey": null
|
||||
},
|
||||
v4 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "description",
|
||||
"name": "referenceId",
|
||||
"storageKey": null
|
||||
},
|
||||
v5 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "dateIdentified",
|
||||
"name": "description",
|
||||
"storageKey": null
|
||||
},
|
||||
v6 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "rootCause",
|
||||
"name": "dateIdentified",
|
||||
"storageKey": null
|
||||
},
|
||||
v7 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "correctiveAction",
|
||||
"name": "rootCause",
|
||||
"storageKey": null
|
||||
},
|
||||
v8 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "dueDate",
|
||||
"name": "correctiveAction",
|
||||
"storageKey": null
|
||||
},
|
||||
v9 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "status",
|
||||
"name": "dueDate",
|
||||
"storageKey": null
|
||||
},
|
||||
v10 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "status",
|
||||
"storageKey": null
|
||||
},
|
||||
v11 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "effectivenessCheck",
|
||||
"storageKey": null
|
||||
},
|
||||
v11 = [
|
||||
v12 = [
|
||||
(v2/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
@@ -136,7 +144,7 @@ v11 = [
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
v12 = {
|
||||
v13 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "Audit",
|
||||
@@ -152,13 +160,13 @@ v12 = {
|
||||
"kind": "LinkedField",
|
||||
"name": "framework",
|
||||
"plural": false,
|
||||
"selections": (v11/*: any*/),
|
||||
"selections": (v12/*: any*/),
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
},
|
||||
v13 = {
|
||||
v14 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "People",
|
||||
@@ -177,24 +185,24 @@ v13 = {
|
||||
],
|
||||
"storageKey": null
|
||||
},
|
||||
v14 = {
|
||||
v15 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "Organization",
|
||||
"kind": "LinkedField",
|
||||
"name": "organization",
|
||||
"plural": false,
|
||||
"selections": (v11/*: any*/),
|
||||
"selections": (v12/*: any*/),
|
||||
"storageKey": null
|
||||
},
|
||||
v15 = {
|
||||
v16 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "createdAt",
|
||||
"storageKey": null
|
||||
},
|
||||
v16 = {
|
||||
v17 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
@@ -228,11 +236,12 @@ return {
|
||||
(v8/*: any*/),
|
||||
(v9/*: any*/),
|
||||
(v10/*: any*/),
|
||||
(v12/*: any*/),
|
||||
(v11/*: any*/),
|
||||
(v13/*: any*/),
|
||||
(v14/*: any*/),
|
||||
(v15/*: any*/),
|
||||
(v16/*: any*/)
|
||||
(v16/*: any*/),
|
||||
(v17/*: any*/)
|
||||
],
|
||||
"type": "NonconformityRegistry",
|
||||
"abstractKey": null
|
||||
@@ -277,11 +286,12 @@ return {
|
||||
(v8/*: any*/),
|
||||
(v9/*: any*/),
|
||||
(v10/*: any*/),
|
||||
(v12/*: any*/),
|
||||
(v11/*: any*/),
|
||||
(v13/*: any*/),
|
||||
(v14/*: any*/),
|
||||
(v15/*: any*/),
|
||||
(v16/*: any*/)
|
||||
(v16/*: any*/),
|
||||
(v17/*: any*/)
|
||||
],
|
||||
"type": "NonconformityRegistry",
|
||||
"abstractKey": null
|
||||
@@ -292,16 +302,16 @@ return {
|
||||
]
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "fd9bf2453d001f33ed1e32ad5784b647",
|
||||
"cacheID": "ab9100da91dff02cc103e6cf3f04b9e2",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "NonconformityRegistryGraphNodeQuery",
|
||||
"operationKind": "query",
|
||||
"text": "query NonconformityRegistryGraphNodeQuery(\n $nonconformityRegistryId: ID!\n) {\n node(id: $nonconformityRegistryId) {\n __typename\n ... on NonconformityRegistry {\n id\n referenceId\n description\n dateIdentified\n rootCause\n correctiveAction\n dueDate\n status\n effectivenessCheck\n audit {\n id\n framework {\n id\n name\n }\n }\n owner {\n id\n fullName\n }\n organization {\n id\n name\n }\n createdAt\n updatedAt\n }\n id\n }\n}\n"
|
||||
"text": "query NonconformityRegistryGraphNodeQuery(\n $nonconformityRegistryId: ID!\n) {\n node(id: $nonconformityRegistryId) {\n __typename\n ... on NonconformityRegistry {\n id\n snapshotId\n referenceId\n description\n dateIdentified\n rootCause\n correctiveAction\n dueDate\n status\n effectivenessCheck\n audit {\n id\n framework {\n id\n name\n }\n }\n owner {\n id\n fullName\n }\n organization {\n id\n name\n }\n createdAt\n updatedAt\n }\n id\n }\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
(node as any).hash = "3395719bf2203fba19ccc94d6f740014";
|
||||
(node as any).hash = "207465c315f95b9b26e7687c4ef17cbf";
|
||||
|
||||
export default node;
|
||||
|
||||
@@ -27,6 +27,7 @@ import { VendorsMultiSelectField } from "/components/form/VendorsMultiSelectFiel
|
||||
import { useFormWithSchema } from "/hooks/useFormWithSchema";
|
||||
import z from "zod";
|
||||
import { SnapshotBanner } from "/components/SnapshotBanner";
|
||||
import { validateSnapshotConsistency } from "@probo/helpers";
|
||||
import type { DatumGraphNodeQuery } from "/hooks/graph/__generated__/DatumGraphNodeQuery.graphql";
|
||||
|
||||
const updateDatumSchema = z.object({
|
||||
@@ -51,6 +52,8 @@ export default function DatumDetailsPage(props: Props) {
|
||||
|
||||
const datumEntry = queryData.node;
|
||||
|
||||
validateSnapshotConsistency(datumEntry, snapshotId);
|
||||
|
||||
const { __ } = useTranslate();
|
||||
const organizationId = useOrganizationId();
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ import { PeopleSelectField } from "/components/form/PeopleSelectField";
|
||||
import { AuditSelectField } from "/components/form/AuditSelectField";
|
||||
import { useFormWithSchema } from "/hooks/useFormWithSchema";
|
||||
import z from "zod";
|
||||
import { getStatusVariant, getStatusLabel, formatDatetime, getNonconformityRegistryStatusOptions } from "@probo/helpers";
|
||||
import { getStatusVariant, getStatusLabel, formatDatetime, getNonconformityRegistryStatusOptions, validateSnapshotConsistency } from "@probo/helpers";
|
||||
import type { NonconformityRegistryGraphNodeQuery } from "/hooks/graph/__generated__/NonconformityRegistryGraphNodeQuery.graphql";
|
||||
|
||||
const updateRegistrySchema = z.object({
|
||||
@@ -63,6 +63,8 @@ export default function NonconformityRegistryDetailsPage(props: Props) {
|
||||
const { snapshotId } = useParams<{ snapshotId?: string }>();
|
||||
const isSnapshotMode = Boolean(snapshotId);
|
||||
|
||||
validateSnapshotConsistency(registry, snapshotId);
|
||||
|
||||
const deleteRegistry = useDeleteNonconformityRegistry(
|
||||
{ id: registry.id!, referenceId: registry.referenceId! },
|
||||
ConnectionHandler.getConnectionID(
|
||||
|
||||
Reference in New Issue
Block a user