Add noncompliance snapshots

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2025-08-28 17:22:20 +02:00
parent a0af20ea95
commit 7d80a7d5f4
27 changed files with 574 additions and 166 deletions

View File

@@ -37,7 +37,7 @@ export function SnapshotBanner({ snapshotId }: Props) {
<span className="font-medium text-warning-800">{__("Snapshot")} {snapshot.name}</span>
</div>
<p className="text-sm text-warning-700">
{__("You are viewing a snapshot of data from")} {dateFormat(snapshot.createdAt, { year: "numeric", month: "short", day: "numeric" })}
{__("You are viewing a snapshot from")} {dateFormat(snapshot.createdAt, { year: "numeric", month: "short", day: "numeric" })}
</p>
</div>
</div>

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<e9fde8de02cc2e3ec97ce64b67818bfe>>
* @generated SignedSource<<32724438ee7e1d53f9c53938a8129e4b>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -9,7 +9,7 @@
// @ts-nocheck
import { ReaderFragment } from 'relay-runtime';
export type SnapshotsType = "ASSETS" | "COMPLIANCE_REGISTRIES" | "DATA" | "NON_CONFORMITY_REGISTRIES" | "RISKS" | "VENDORS";
export type SnapshotsType = "ASSETS" | "COMPLIANCE_REGISTRIES" | "DATA" | "NONCONFORMITY_REGISTRIES" | "RISKS" | "VENDORS";
import { FragmentRefs } from "relay-runtime";
export type LinkedSnapshotsCardFragment$data = {
readonly createdAt: any;

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<b68d2b7e020579736ca058b633352dee>>
* @generated SignedSource<<f6c8c318141054ceb118dfdb145a756d>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -9,7 +9,7 @@
// @ts-nocheck
import { ReaderFragment } from 'relay-runtime';
export type SnapshotsType = "ASSETS" | "COMPLIANCE_REGISTRIES" | "DATA" | "NON_CONFORMITY_REGISTRIES" | "RISKS" | "VENDORS";
export type SnapshotsType = "ASSETS" | "COMPLIANCE_REGISTRIES" | "DATA" | "NONCONFORMITY_REGISTRIES" | "RISKS" | "VENDORS";
import { FragmentRefs } from "relay-runtime";
export type LinkedSnapshotsDialogFragment$data = {
readonly id: string;

View File

@@ -8,10 +8,10 @@ import { useMutationWithToasts } from "../useMutationWithToasts";
export const RegistriesConnectionKey = "RegistriesPage_nonconformityRegistries";
export const nonconformityRegistriesQuery = graphql`
query NonconformityRegistryGraphListQuery($organizationId: ID!) {
query NonconformityRegistryGraphListQuery($organizationId: ID!, $snapshotId: ID) {
node(id: $organizationId) {
... on Organization {
...NonconformityRegistriesPageFragment
...NonconformityRegistriesPageFragment @arguments(snapshotId: $snapshotId)
}
}
}

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<a6972659c0399779d3d646dc4057bc57>>
* @generated SignedSource<<b306072db6c1956ba956e52443ebf866>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -12,6 +12,7 @@ import { ConcreteRequest } from 'relay-runtime';
import { FragmentRefs } from "relay-runtime";
export type NonconformityRegistryGraphListQuery$variables = {
organizationId: string;
snapshotId?: string | null | undefined;
};
export type NonconformityRegistryGraphListQuery$data = {
readonly node: {
@@ -29,6 +30,11 @@ var v0 = [
"defaultValue": null,
"kind": "LocalArgument",
"name": "organizationId"
},
{
"defaultValue": null,
"kind": "LocalArgument",
"name": "snapshotId"
}
],
v1 = [
@@ -38,28 +44,40 @@ v1 = [
"variableName": "organizationId"
}
],
v2 = {
v2 = [
{
"kind": "Variable",
"name": "snapshotId",
"variableName": "snapshotId"
}
],
v3 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "__typename",
"storageKey": null
},
v3 = {
v4 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "id",
"storageKey": null
},
v4 = [
v5 = [
{
"fields": (v2/*: any*/),
"kind": "ObjectValue",
"name": "filter"
},
{
"kind": "Literal",
"name": "first",
"value": 10
}
],
v5 = {
v6 = {
"alias": null,
"args": null,
"kind": "ScalarField",
@@ -85,7 +103,7 @@ return {
"kind": "InlineFragment",
"selections": [
{
"args": null,
"args": (v2/*: any*/),
"kind": "FragmentSpread",
"name": "NonconformityRegistriesPageFragment"
}
@@ -114,14 +132,14 @@ return {
"name": "node",
"plural": false,
"selections": [
(v2/*: any*/),
(v3/*: any*/),
(v4/*: any*/),
{
"kind": "InlineFragment",
"selections": [
{
"alias": null,
"args": (v4/*: any*/),
"args": (v5/*: any*/),
"concreteType": "NonconformityRegistryConnection",
"kind": "LinkedField",
"name": "nonconformityRegistries",
@@ -150,7 +168,7 @@ return {
"name": "node",
"plural": false,
"selections": [
(v3/*: any*/),
(v4/*: any*/),
{
"alias": null,
"args": null,
@@ -215,8 +233,8 @@ return {
"name": "audit",
"plural": false,
"selections": [
(v3/*: any*/),
(v5/*: any*/),
(v4/*: any*/),
(v6/*: any*/),
{
"alias": null,
"args": null,
@@ -225,8 +243,8 @@ return {
"name": "framework",
"plural": false,
"selections": [
(v3/*: any*/),
(v5/*: any*/)
(v4/*: any*/),
(v6/*: any*/)
],
"storageKey": null
}
@@ -241,7 +259,7 @@ return {
"name": "owner",
"plural": false,
"selections": [
(v3/*: any*/),
(v4/*: any*/),
{
"alias": null,
"args": null,
@@ -266,7 +284,7 @@ return {
"name": "updatedAt",
"storageKey": null
},
(v2/*: any*/)
(v3/*: any*/)
],
"storageKey": null
},
@@ -318,12 +336,14 @@ return {
]
}
],
"storageKey": "nonconformityRegistries(first:10)"
"storageKey": null
},
{
"alias": null,
"args": (v4/*: any*/),
"filters": null,
"args": (v5/*: any*/),
"filters": [
"filter"
],
"handle": "connection",
"key": "RegistriesPage_nonconformityRegistries",
"kind": "LinkedHandle",
@@ -339,16 +359,16 @@ return {
]
},
"params": {
"cacheID": "2196012e8a68c64e7d479a2b85021ffd",
"cacheID": "727537500ac037fec1a9ffd04a5c651f",
"id": null,
"metadata": {},
"name": "NonconformityRegistryGraphListQuery",
"operationKind": "query",
"text": "query NonconformityRegistryGraphListQuery(\n $organizationId: ID!\n) {\n node(id: $organizationId) {\n __typename\n ... on Organization {\n ...NonconformityRegistriesPageFragment\n }\n id\n }\n}\n\nfragment NonconformityRegistriesPageFragment on Organization {\n id\n nonconformityRegistries(first: 10) {\n totalCount\n edges {\n node {\n id\n referenceId\n description\n status\n dateIdentified\n dueDate\n rootCause\n correctiveAction\n effectivenessCheck\n audit {\n id\n name\n framework {\n id\n name\n }\n }\n owner {\n id\n fullName\n }\n createdAt\n updatedAt\n __typename\n }\n cursor\n }\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n}\n"
"text": "query NonconformityRegistryGraphListQuery(\n $organizationId: ID!\n $snapshotId: ID\n) {\n node(id: $organizationId) {\n __typename\n ... on Organization {\n ...NonconformityRegistriesPageFragment_3iomuz\n }\n id\n }\n}\n\nfragment NonconformityRegistriesPageFragment_3iomuz on Organization {\n id\n nonconformityRegistries(first: 10, filter: {snapshotId: $snapshotId}) {\n totalCount\n edges {\n node {\n id\n referenceId\n description\n status\n dateIdentified\n dueDate\n rootCause\n correctiveAction\n effectivenessCheck\n audit {\n id\n name\n framework {\n id\n name\n }\n }\n owner {\n id\n fullName\n }\n createdAt\n updatedAt\n __typename\n }\n cursor\n }\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n}\n"
}
};
})();
(node as any).hash = "b8104dc2e4ccb9eecfe1f0d494084975";
(node as any).hash = "2bb77e5c9adce5860e4dd2c31f1155e4";
export default node;

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<459d0a122659971be9b24c79f47691e7>>
* @generated SignedSource<<9f17487d2517912ef9f93b0026eaa555>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -9,7 +9,7 @@
// @ts-nocheck
import { ConcreteRequest } from 'relay-runtime';
export type SnapshotsType = "ASSETS" | "COMPLIANCE_REGISTRIES" | "DATA" | "NON_CONFORMITY_REGISTRIES" | "RISKS" | "VENDORS";
export type SnapshotsType = "ASSETS" | "COMPLIANCE_REGISTRIES" | "DATA" | "NONCONFORMITY_REGISTRIES" | "RISKS" | "VENDORS";
export type CreateSnapshotInput = {
description?: string | null | undefined;
name: string;

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<5bcc9f9b743d01fc99fd749b970dccd3>>
* @generated SignedSource<<a490e7800ce4b387ced38d07b3e42bca>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -9,7 +9,7 @@
// @ts-nocheck
import { ConcreteRequest } from 'relay-runtime';
export type SnapshotsType = "ASSETS" | "COMPLIANCE_REGISTRIES" | "DATA" | "NON_CONFORMITY_REGISTRIES" | "RISKS" | "VENDORS";
export type SnapshotsType = "ASSETS" | "COMPLIANCE_REGISTRIES" | "DATA" | "NONCONFORMITY_REGISTRIES" | "RISKS" | "VENDORS";
export type SnapshotGraphNodeQuery$variables = {
snapshotId: string;
};

View File

@@ -29,6 +29,8 @@ import { useOrganizationId } from "/hooks/useOrganizationId";
import { CreateNonconformityRegistryDialog } from "./dialogs/CreateNonconformityRegistryDialog";
import { deleteNonconformityRegistryMutation, RegistriesConnectionKey } from "../../../hooks/graph/NonconformityRegistryGraph";
import { sprintf, promisifyMutation, getStatusVariant, getStatusLabel } from "@probo/helpers";
import { SnapshotBanner } from "/components/SnapshotBanner";
import { useParams } from "react-router";
import type { NonconformityRegistriesPageQuery } from "./__generated__/NonconformityRegistriesPageQuery.graphql";
import type {
NonconformityRegistriesPageFragment$key,
@@ -47,10 +49,15 @@ const nonconformityRegistriesPageFragment = graphql`
@argumentDefinitions(
first: { type: "Int", defaultValue: 10 }
after: { type: "CursorKey" }
snapshotId: { type: "ID", defaultValue: null }
) {
id
nonconformityRegistries(first: $first, after: $after)
@connection(key: "RegistriesPage_nonconformityRegistries") {
nonconformityRegistries(
first: $first
after: $after
filter: { snapshotId: $snapshotId }
)
@connection(key: "RegistriesPage_nonconformityRegistries", filters: ["filter"]) {
__id
totalCount
edges {
@@ -91,15 +98,17 @@ const nonconformityRegistriesPageFragment = graphql`
export default function NonconformityRegistriesPage({ queryRef }: NonconformityRegistriesPageProps) {
const { __ } = useTranslate();
const organizationId = useOrganizationId();
const { snapshotId } = useParams<{ snapshotId?: string }>();
const isSnapshotMode = Boolean(snapshotId);
usePageTitle(__("Nonconformity Registries"));
const organization = usePreloadedQuery(
graphql`
query NonconformityRegistriesPageQuery($organizationId: ID!) {
query NonconformityRegistriesPageQuery($organizationId: ID!, $snapshotId: ID) {
node(id: $organizationId) {
... on Organization {
...NonconformityRegistriesPageFragment
...NonconformityRegistriesPageFragment @arguments(snapshotId: $snapshotId)
}
}
}
@@ -112,20 +121,29 @@ export default function NonconformityRegistriesPage({ queryRef }: NonconformityR
organization.node as NonconformityRegistriesPageFragment$key
);
const connectionId = ConnectionHandler.getConnectionID(organizationId, RegistriesConnectionKey);
const connectionId = ConnectionHandler.getConnectionID(
organizationId,
RegistriesConnectionKey,
{ filter: { snapshotId: snapshotId || null } }
);
const registries: NonconformityRegistry[] = registriesData?.nonconformityRegistries?.edges?.map((edge) => edge.node) ?? [];
return (
<div className="space-y-6">
{isSnapshotMode && (
<SnapshotBanner snapshotId={snapshotId!} />
)}
<PageHeader
title={__("Nonconformity Registries")}
description={__(
"Manage your organization's non conformity registries."
)}
>
<CreateNonconformityRegistryDialog organizationId={organizationId} connection={connectionId}>
<Button icon={IconPlusLarge}>{__("Add nonconformity registry")}</Button>
</CreateNonconformityRegistryDialog>
{!isSnapshotMode && (
<CreateNonconformityRegistryDialog organizationId={organizationId} connection={connectionId}>
<Button icon={IconPlusLarge}>{__("Add nonconformity registry")}</Button>
</CreateNonconformityRegistryDialog>
)}
</PageHeader>
{registries.length === 0 ? (
@@ -150,7 +168,7 @@ export default function NonconformityRegistriesPage({ queryRef }: NonconformityR
<Th>{__("Audit")}</Th>
<Th>{__("Owner")}</Th>
<Th>{__("Due Date")}</Th>
<Th>{__("Actions")}</Th>
{!isSnapshotMode && (<Th>{__("Actions")}</Th>)}
</Tr>
</Thead>
<Tbody>
@@ -159,6 +177,8 @@ export default function NonconformityRegistriesPage({ queryRef }: NonconformityR
key={registry.id}
registry={registry}
connectionId={connectionId}
isSnapshotMode={isSnapshotMode}
snapshotId={snapshotId}
/>
))}
</Tbody>
@@ -186,9 +206,13 @@ export default function NonconformityRegistriesPage({ queryRef }: NonconformityR
function RegistryRow({
registry,
connectionId,
isSnapshotMode,
snapshotId,
}: {
registry: NonconformityRegistry;
connectionId: string;
isSnapshotMode: boolean;
snapshotId?: string;
}) {
const organizationId = useOrganizationId();
const { __ } = useTranslate();
@@ -199,6 +223,10 @@ function RegistryRow({
return new Date(dateString).toLocaleDateString();
};
const registryDetailUrl = isSnapshotMode
? `/organizations/${organizationId}/snapshots/${snapshotId}/nonconformity-registries/${registry.id}`
: `/organizations/${organizationId}/nonconformity-registries/${registry.id}`;
const handleDeleteRegistry = (registry: NonconformityRegistry) => {
if (!connectionId) return;
@@ -225,7 +253,7 @@ function RegistryRow({
};
return (
<Tr to={`/organizations/${organizationId}/nonconformity-registries/${registry.id}`}>
<Tr to={registryDetailUrl}>
<Td>
<span className="font-mono text-sm">{registry.referenceId}</span>
</Td>
@@ -257,17 +285,18 @@ function RegistryRow({
<span className="text-txt-tertiary">{__("No due date")}</span>
)}
</Td>
<Td noLink width={50} className="text-end">
<ActionDropdown>
<DropdownItem
icon={IconTrashCan}
variant="danger"
onSelect={() => handleDeleteRegistry(registry)}
>
{__("Delete")}
</DropdownItem>
</ActionDropdown>
</Td>
{!isSnapshotMode && (<Td noLink width={50} className="text-end">
<ActionDropdown>
<DropdownItem
icon={IconTrashCan}
variant="danger"
onSelect={() => handleDeleteRegistry(registry)}
>
{__("Delete")}
</DropdownItem>
</ActionDropdown>
</Td>
)}
</Tr>
);
}

View File

@@ -26,6 +26,8 @@ import {
import { useTranslate } from "@probo/i18n";
import { useOrganizationId } from "/hooks/useOrganizationId";
import { ControlledField } from "/components/form/ControlledField";
import { SnapshotBanner } from "/components/SnapshotBanner";
import { useParams } from "react-router";
import { PeopleSelectField } from "/components/form/PeopleSelectField";
import { AuditSelectField } from "/components/form/AuditSelectField";
import { useFormWithSchema } from "/hooks/useFormWithSchema";
@@ -58,10 +60,16 @@ export default function NonconformityRegistryDetailsPage(props: Props) {
const registry = data.node;
const { __ } = useTranslate();
const organizationId = useOrganizationId();
const { snapshotId } = useParams<{ snapshotId?: string }>();
const isSnapshotMode = Boolean(snapshotId);
const deleteRegistry = useDeleteNonconformityRegistry(
{ id: registry.id!, referenceId: registry.referenceId! },
ConnectionHandler.getConnectionID(organizationId, RegistriesConnectionKey)
ConnectionHandler.getConnectionID(
organizationId,
RegistriesConnectionKey,
{ filter: { snapshotId: snapshotId || null } }
)
);
const { control, formState, handleSubmit, register, reset } = useFormWithSchema(
@@ -119,13 +127,20 @@ export default function NonconformityRegistryDetailsPage(props: Props) {
const statusOptions = getNonconformityRegistryStatusOptions(__);
const breadcrumbNonconformityRegistriesUrl = isSnapshotMode
? `/organizations/${organizationId}/snapshots/${snapshotId}/nonconformity-registries`
: `/organizations/${organizationId}/nonconformity-registries`;
return (
<div className="space-y-6">
{isSnapshotMode && (
<SnapshotBanner snapshotId={snapshotId!} />
)}
<Breadcrumb
items={[
{
label: __("Nonconformity Registries"),
to: `/organizations/${organizationId}/nonconformity-registries`,
to: breadcrumbNonconformityRegistriesUrl,
},
{
label: registry.referenceId || __("Unknown Nonconformity Registry"),
@@ -142,15 +157,17 @@ export default function NonconformityRegistryDetailsPage(props: Props) {
{getStatusLabel(registry.status || "OPEN")}
</Badge>
</div>
<ActionDropdown variant="secondary">
<DropdownItem
variant="danger"
icon={IconTrashCan}
onClick={deleteRegistry}
>
{__("Delete")}
</DropdownItem>
</ActionDropdown>
{!isSnapshotMode && (
<ActionDropdown variant="secondary">
<DropdownItem
variant="danger"
icon={IconTrashCan}
onClick={deleteRegistry}
>
{__("Delete")}
</DropdownItem>
</ActionDropdown>
)}
</div>
<div className="max-w-4xl">
@@ -164,6 +181,7 @@ export default function NonconformityRegistryDetailsPage(props: Props) {
<Input
{...register("referenceId")}
placeholder={__("Enter reference ID")}
disabled={isSnapshotMode}
/>
</Field>
@@ -174,6 +192,7 @@ export default function NonconformityRegistryDetailsPage(props: Props) {
label={__("Audit")}
error={formState.errors.auditId?.message}
required
disabled={isSnapshotMode}
/>
<Field label={__("Description")}>
@@ -181,6 +200,7 @@ export default function NonconformityRegistryDetailsPage(props: Props) {
{...register("description")}
placeholder={__("Enter description")}
rows={3}
disabled={isSnapshotMode}
/>
</Field>
@@ -191,6 +211,7 @@ export default function NonconformityRegistryDetailsPage(props: Props) {
type="select"
label={__("Status")}
required
disabled={isSnapshotMode}
>
{statusOptions.map((option) => (
<Option key={option.value} value={option.value}>
@@ -206,16 +227,17 @@ export default function NonconformityRegistryDetailsPage(props: Props) {
label={__("Owner")}
error={formState.errors.ownerId?.message}
required
disabled={isSnapshotMode}
/>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<Field label={__("Date Identified")}>
<Input {...register("dateIdentified")} type="date" />
<Input {...register("dateIdentified")} type="date" disabled={isSnapshotMode} />
</Field>
<Field label={__("Due Date")}>
<Input {...register("dueDate")} type="date" />
<Input {...register("dueDate")} type="date" disabled={isSnapshotMode} />
</Field>
</div>
@@ -228,6 +250,7 @@ export default function NonconformityRegistryDetailsPage(props: Props) {
{...register("rootCause")}
placeholder={__("Enter root cause")}
rows={3}
disabled={isSnapshotMode}
/>
</Field>
@@ -236,6 +259,7 @@ export default function NonconformityRegistryDetailsPage(props: Props) {
{...register("correctiveAction")}
placeholder={__("Enter corrective action")}
rows={3}
disabled={isSnapshotMode}
/>
</Field>
@@ -244,11 +268,12 @@ export default function NonconformityRegistryDetailsPage(props: Props) {
{...register("effectivenessCheck")}
placeholder={__("Enter effectiveness check details")}
rows={3}
disabled={isSnapshotMode}
/>
</Field>
<div className="flex justify-end">
{formState.isDirty && (
{formState.isDirty && !isSnapshotMode && (
<Button type="submit" disabled={formState.isSubmitting}>
{formState.isSubmitting ? __("Updating...") : __("Update")}
</Button>

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<b883180c6334c3e1c4f7bd44785a0033>>
* @generated SignedSource<<fede190bc1e89813ce1034cf93d5ae95>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -86,6 +86,11 @@ return {
"defaultValue": 10,
"kind": "LocalArgument",
"name": "first"
},
{
"defaultValue": null,
"kind": "LocalArgument",
"name": "snapshotId"
}
],
"kind": "Fragment",
@@ -122,7 +127,19 @@ return {
(v1/*: any*/),
{
"alias": "nonconformityRegistries",
"args": null,
"args": [
{
"fields": [
{
"kind": "Variable",
"name": "snapshotId",
"variableName": "snapshotId"
}
],
"kind": "ObjectValue",
"name": "filter"
}
],
"concreteType": "NonconformityRegistryConnection",
"kind": "LinkedField",
"name": "__RegistriesPage_nonconformityRegistries_connection",
@@ -333,6 +350,6 @@ return {
};
})();
(node as any).hash = "34c06ec98cb50738cf479e6bd7cdc83e";
(node as any).hash = "ebde2010138ec4b17adb214f7bd24ac6";
export default node;

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<2720ef53c549871eb0b99b8a0214367d>>
* @generated SignedSource<<1ea20f794eca2a8b357e64ccf3ac6deb>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -12,6 +12,7 @@ import { ConcreteRequest } from 'relay-runtime';
import { FragmentRefs } from "relay-runtime";
export type NonconformityRegistriesPageQuery$variables = {
organizationId: string;
snapshotId?: string | null | undefined;
};
export type NonconformityRegistriesPageQuery$data = {
readonly node: {
@@ -29,6 +30,11 @@ var v0 = [
"defaultValue": null,
"kind": "LocalArgument",
"name": "organizationId"
},
{
"defaultValue": null,
"kind": "LocalArgument",
"name": "snapshotId"
}
],
v1 = [
@@ -38,28 +44,40 @@ v1 = [
"variableName": "organizationId"
}
],
v2 = {
v2 = [
{
"kind": "Variable",
"name": "snapshotId",
"variableName": "snapshotId"
}
],
v3 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "__typename",
"storageKey": null
},
v3 = {
v4 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "id",
"storageKey": null
},
v4 = [
v5 = [
{
"fields": (v2/*: any*/),
"kind": "ObjectValue",
"name": "filter"
},
{
"kind": "Literal",
"name": "first",
"value": 10
}
],
v5 = {
v6 = {
"alias": null,
"args": null,
"kind": "ScalarField",
@@ -85,7 +103,7 @@ return {
"kind": "InlineFragment",
"selections": [
{
"args": null,
"args": (v2/*: any*/),
"kind": "FragmentSpread",
"name": "NonconformityRegistriesPageFragment"
}
@@ -114,14 +132,14 @@ return {
"name": "node",
"plural": false,
"selections": [
(v2/*: any*/),
(v3/*: any*/),
(v4/*: any*/),
{
"kind": "InlineFragment",
"selections": [
{
"alias": null,
"args": (v4/*: any*/),
"args": (v5/*: any*/),
"concreteType": "NonconformityRegistryConnection",
"kind": "LinkedField",
"name": "nonconformityRegistries",
@@ -150,7 +168,7 @@ return {
"name": "node",
"plural": false,
"selections": [
(v3/*: any*/),
(v4/*: any*/),
{
"alias": null,
"args": null,
@@ -215,8 +233,8 @@ return {
"name": "audit",
"plural": false,
"selections": [
(v3/*: any*/),
(v5/*: any*/),
(v4/*: any*/),
(v6/*: any*/),
{
"alias": null,
"args": null,
@@ -225,8 +243,8 @@ return {
"name": "framework",
"plural": false,
"selections": [
(v3/*: any*/),
(v5/*: any*/)
(v4/*: any*/),
(v6/*: any*/)
],
"storageKey": null
}
@@ -241,7 +259,7 @@ return {
"name": "owner",
"plural": false,
"selections": [
(v3/*: any*/),
(v4/*: any*/),
{
"alias": null,
"args": null,
@@ -266,7 +284,7 @@ return {
"name": "updatedAt",
"storageKey": null
},
(v2/*: any*/)
(v3/*: any*/)
],
"storageKey": null
},
@@ -318,12 +336,14 @@ return {
]
}
],
"storageKey": "nonconformityRegistries(first:10)"
"storageKey": null
},
{
"alias": null,
"args": (v4/*: any*/),
"filters": null,
"args": (v5/*: any*/),
"filters": [
"filter"
],
"handle": "connection",
"key": "RegistriesPage_nonconformityRegistries",
"kind": "LinkedHandle",
@@ -339,16 +359,16 @@ return {
]
},
"params": {
"cacheID": "93352a54352d7b4fd8d2367bbe43e288",
"cacheID": "f2ec31e8e8ec0d13aeac353f53044f97",
"id": null,
"metadata": {},
"name": "NonconformityRegistriesPageQuery",
"operationKind": "query",
"text": "query NonconformityRegistriesPageQuery(\n $organizationId: ID!\n) {\n node(id: $organizationId) {\n __typename\n ... on Organization {\n ...NonconformityRegistriesPageFragment\n }\n id\n }\n}\n\nfragment NonconformityRegistriesPageFragment on Organization {\n id\n nonconformityRegistries(first: 10) {\n totalCount\n edges {\n node {\n id\n referenceId\n description\n status\n dateIdentified\n dueDate\n rootCause\n correctiveAction\n effectivenessCheck\n audit {\n id\n name\n framework {\n id\n name\n }\n }\n owner {\n id\n fullName\n }\n createdAt\n updatedAt\n __typename\n }\n cursor\n }\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n}\n"
"text": "query NonconformityRegistriesPageQuery(\n $organizationId: ID!\n $snapshotId: ID\n) {\n node(id: $organizationId) {\n __typename\n ... on Organization {\n ...NonconformityRegistriesPageFragment_3iomuz\n }\n id\n }\n}\n\nfragment NonconformityRegistriesPageFragment_3iomuz on Organization {\n id\n nonconformityRegistries(first: 10, filter: {snapshotId: $snapshotId}) {\n totalCount\n edges {\n node {\n id\n referenceId\n description\n status\n dateIdentified\n dueDate\n rootCause\n correctiveAction\n effectivenessCheck\n audit {\n id\n name\n framework {\n id\n name\n }\n }\n owner {\n id\n fullName\n }\n createdAt\n updatedAt\n __typename\n }\n cursor\n }\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n}\n"
}
};
})();
(node as any).hash = "22c4716894e332336d2e165756a2d021";
(node as any).hash = "180821c7fad7b6071d78444e1eac0742";
export default node;

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<9c75b7a7e17dd904d30ab786c40015d4>>
* @generated SignedSource<<c584903b5c82a59b575deef3f54379d9>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -14,6 +14,7 @@ export type NonconformityRegistriesPageRefetchQuery$variables = {
after?: any | null | undefined;
first?: number | null | undefined;
id: string;
snapshotId?: string | null | undefined;
};
export type NonconformityRegistriesPageRefetchQuery$data = {
readonly node: {
@@ -26,57 +27,74 @@ export type NonconformityRegistriesPageRefetchQuery = {
};
const node: ConcreteRequest = (function(){
var v0 = [
{
"defaultValue": null,
"kind": "LocalArgument",
"name": "after"
},
{
"defaultValue": 10,
"kind": "LocalArgument",
"name": "first"
},
{
"defaultValue": null,
"kind": "LocalArgument",
"name": "id"
}
],
v1 = [
var v0 = {
"defaultValue": null,
"kind": "LocalArgument",
"name": "after"
},
v1 = {
"defaultValue": 10,
"kind": "LocalArgument",
"name": "first"
},
v2 = {
"defaultValue": null,
"kind": "LocalArgument",
"name": "id"
},
v3 = {
"defaultValue": null,
"kind": "LocalArgument",
"name": "snapshotId"
},
v4 = [
{
"kind": "Variable",
"name": "id",
"variableName": "id"
}
],
v2 = [
{
"kind": "Variable",
"name": "after",
"variableName": "after"
},
{
"kind": "Variable",
"name": "first",
"variableName": "first"
}
],
v3 = {
v5 = {
"kind": "Variable",
"name": "after",
"variableName": "after"
},
v6 = {
"kind": "Variable",
"name": "first",
"variableName": "first"
},
v7 = {
"kind": "Variable",
"name": "snapshotId",
"variableName": "snapshotId"
},
v8 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "__typename",
"storageKey": null
},
v4 = {
v9 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "id",
"storageKey": null
},
v5 = {
v10 = [
(v5/*: any*/),
{
"fields": [
(v7/*: any*/)
],
"kind": "ObjectValue",
"name": "filter"
},
(v6/*: any*/)
],
v11 = {
"alias": null,
"args": null,
"kind": "ScalarField",
@@ -85,21 +103,30 @@ v5 = {
};
return {
"fragment": {
"argumentDefinitions": (v0/*: any*/),
"argumentDefinitions": [
(v0/*: any*/),
(v1/*: any*/),
(v2/*: any*/),
(v3/*: any*/)
],
"kind": "Fragment",
"metadata": null,
"name": "NonconformityRegistriesPageRefetchQuery",
"selections": [
{
"alias": null,
"args": (v1/*: any*/),
"args": (v4/*: any*/),
"concreteType": null,
"kind": "LinkedField",
"name": "node",
"plural": false,
"selections": [
{
"args": (v2/*: any*/),
"args": [
(v5/*: any*/),
(v6/*: any*/),
(v7/*: any*/)
],
"kind": "FragmentSpread",
"name": "NonconformityRegistriesPageFragment"
}
@@ -112,26 +139,31 @@ return {
},
"kind": "Request",
"operation": {
"argumentDefinitions": (v0/*: any*/),
"argumentDefinitions": [
(v0/*: any*/),
(v1/*: any*/),
(v3/*: any*/),
(v2/*: any*/)
],
"kind": "Operation",
"name": "NonconformityRegistriesPageRefetchQuery",
"selections": [
{
"alias": null,
"args": (v1/*: any*/),
"args": (v4/*: any*/),
"concreteType": null,
"kind": "LinkedField",
"name": "node",
"plural": false,
"selections": [
(v3/*: any*/),
(v4/*: any*/),
(v8/*: any*/),
(v9/*: any*/),
{
"kind": "InlineFragment",
"selections": [
{
"alias": null,
"args": (v2/*: any*/),
"args": (v10/*: any*/),
"concreteType": "NonconformityRegistryConnection",
"kind": "LinkedField",
"name": "nonconformityRegistries",
@@ -160,7 +192,7 @@ return {
"name": "node",
"plural": false,
"selections": [
(v4/*: any*/),
(v9/*: any*/),
{
"alias": null,
"args": null,
@@ -225,8 +257,8 @@ return {
"name": "audit",
"plural": false,
"selections": [
(v4/*: any*/),
(v5/*: any*/),
(v9/*: any*/),
(v11/*: any*/),
{
"alias": null,
"args": null,
@@ -235,8 +267,8 @@ return {
"name": "framework",
"plural": false,
"selections": [
(v4/*: any*/),
(v5/*: any*/)
(v9/*: any*/),
(v11/*: any*/)
],
"storageKey": null
}
@@ -251,7 +283,7 @@ return {
"name": "owner",
"plural": false,
"selections": [
(v4/*: any*/),
(v9/*: any*/),
{
"alias": null,
"args": null,
@@ -276,7 +308,7 @@ return {
"name": "updatedAt",
"storageKey": null
},
(v3/*: any*/)
(v8/*: any*/)
],
"storageKey": null
},
@@ -332,8 +364,10 @@ return {
},
{
"alias": null,
"args": (v2/*: any*/),
"filters": null,
"args": (v10/*: any*/),
"filters": [
"filter"
],
"handle": "connection",
"key": "RegistriesPage_nonconformityRegistries",
"kind": "LinkedHandle",
@@ -349,16 +383,16 @@ return {
]
},
"params": {
"cacheID": "c8a903834590297e238ea54aeea0dfbe",
"cacheID": "50e5771b4ff22e23d81c31bf7c92e619",
"id": null,
"metadata": {},
"name": "NonconformityRegistriesPageRefetchQuery",
"operationKind": "query",
"text": "query NonconformityRegistriesPageRefetchQuery(\n $after: CursorKey\n $first: Int = 10\n $id: ID!\n) {\n node(id: $id) {\n __typename\n ...NonconformityRegistriesPageFragment_2HEEH6\n id\n }\n}\n\nfragment NonconformityRegistriesPageFragment_2HEEH6 on Organization {\n id\n nonconformityRegistries(first: $first, after: $after) {\n totalCount\n edges {\n node {\n id\n referenceId\n description\n status\n dateIdentified\n dueDate\n rootCause\n correctiveAction\n effectivenessCheck\n audit {\n id\n name\n framework {\n id\n name\n }\n }\n owner {\n id\n fullName\n }\n createdAt\n updatedAt\n __typename\n }\n cursor\n }\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n}\n"
"text": "query NonconformityRegistriesPageRefetchQuery(\n $after: CursorKey\n $first: Int = 10\n $snapshotId: ID = null\n $id: ID!\n) {\n node(id: $id) {\n __typename\n ...NonconformityRegistriesPageFragment_35e0S5\n id\n }\n}\n\nfragment NonconformityRegistriesPageFragment_35e0S5 on Organization {\n id\n nonconformityRegistries(first: $first, after: $after, filter: {snapshotId: $snapshotId}) {\n totalCount\n edges {\n node {\n id\n referenceId\n description\n status\n dateIdentified\n dueDate\n rootCause\n correctiveAction\n effectivenessCheck\n audit {\n id\n name\n framework {\n id\n name\n }\n }\n owner {\n id\n fullName\n }\n createdAt\n updatedAt\n __typename\n }\n cursor\n }\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n}\n"
}
};
})();
(node as any).hash = "34c06ec98cb50738cf479e6bd7cdc83e";
(node as any).hash = "ebde2010138ec4b17adb214f7bd24ac6";
export default node;

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<05658205222e432a115cecc9c8f34d05>>
* @generated SignedSource<<515e309ba0b61b3cacd37ebd567203c4>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -9,7 +9,7 @@
// @ts-nocheck
import { ReaderFragment } from 'relay-runtime';
export type SnapshotsType = "ASSETS" | "COMPLIANCE_REGISTRIES" | "DATA" | "NON_CONFORMITY_REGISTRIES" | "RISKS" | "VENDORS";
export type SnapshotsType = "ASSETS" | "COMPLIANCE_REGISTRIES" | "DATA" | "NONCONFORMITY_REGISTRIES" | "RISKS" | "VENDORS";
import { FragmentRefs } from "relay-runtime";
export type SnapshotsPageFragment$data = {
readonly snapshots: {

View File

@@ -42,7 +42,7 @@ const snapshotCreateMutation = graphql`
const snapshotSchema = z.object({
name: z.string().min(2, { message: "Name is required" }),
description: z.string().optional(),
type: z.enum(["DATA"]),
type: z.enum(["DATA", "NONCONFORMITY_REGISTRIES"]),
});
type Props = {

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<22c84eaaec91c3555b99f0e067bea54f>>
* @generated SignedSource<<c6327f17cac8275a6ac5847f0b172905>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -9,7 +9,7 @@
// @ts-nocheck
import { ConcreteRequest } from 'relay-runtime';
export type SnapshotsType = "ASSETS" | "COMPLIANCE_REGISTRIES" | "DATA" | "NON_CONFORMITY_REGISTRIES" | "RISKS" | "VENDORS";
export type SnapshotsType = "ASSETS" | "COMPLIANCE_REGISTRIES" | "DATA" | "NONCONFORMITY_REGISTRIES" | "RISKS" | "VENDORS";
export type CreateSnapshotInput = {
description?: string | null | undefined;
name: string;

View File

@@ -9,8 +9,23 @@ export const nonconformityRegistryRoutes= [
{
path: "nonconformity-registries",
fallback: PageSkeleton,
queryLoader: ({ organizationId }: { organizationId: string }) =>
loadQuery(relayEnvironment, nonconformityRegistriesQuery, { organizationId }),
queryLoader: (params: Record<string, string>) =>
loadQuery(relayEnvironment, nonconformityRegistriesQuery, {
organizationId: params.organizationId,
snapshotId: null
}),
Component: lazy(
() => import("/pages/organizations/nonconformityRegistries/NonconformityRegistriesPage")
),
},
{
path: "snapshots/:snapshotId/nonconformity-registries",
fallback: PageSkeleton,
queryLoader: (params: Record<string, string>) =>
loadQuery(relayEnvironment, nonconformityRegistriesQuery, {
organizationId: params.organizationId,
snapshotId: params.snapshotId
}),
Component: lazy(
() => import("/pages/organizations/nonconformityRegistries/NonconformityRegistriesPage")
),
@@ -26,4 +41,15 @@ export const nonconformityRegistryRoutes= [
() => import("/pages/organizations/nonconformityRegistries/NonconformityRegistryDetailsPage")
),
},
{
path: "snapshots/:snapshotId/nonconformity-registries/:registryId",
fallback: PageSkeleton,
queryLoader: (params: Record<string, string>) =>
loadQuery(relayEnvironment, nonconformityRegistryNodeQuery, {
nonconformityRegistryId: params.registryId
}),
Component: lazy(
() => import("/pages/organizations/nonconformityRegistries/NonconformityRegistryDetailsPage")
),
},
] satisfies AppRoute[];

View File

@@ -2,6 +2,7 @@ type Translator = (s: string) => string;
export const snapshotTypes = [
"DATA",
"NONCONFORMITY_REGISTRIES",
] as const;
export function getSnapshotTypeLabel(__: Translator, type: string | null | undefined) {
@@ -18,7 +19,7 @@ export function getSnapshotTypeLabel(__: Translator, type: string | null | undef
return __("Assets");
case "DATA":
return __("Data");
case "NON_CONFORMITY_REGISTRIES":
case "NONCONFORMITY_REGISTRIES":
return __("Nonconformity Registries");
case "COMPLIANCE_REGISTRIES":
return __("Compliance Registries");
@@ -31,6 +32,8 @@ export function getSnapshotTypeUrlPath(type?: string): string {
switch (type) {
case "DATA":
return "/data";
case "NONCONFORMITY_REGISTRIES":
return "/nonconformity-registries";
default:
return "";
}

View File

@@ -0,0 +1,15 @@
ALTER TABLE nonconformity_registries ADD COLUMN snapshot_id TEXT;
ALTER TABLE nonconformity_registries ADD COLUMN source_id TEXT;
ALTER TABLE nonconformity_registries DROP CONSTRAINT IF EXISTS nonconformity_registries_audit_id_fkey;
ALTER TABLE nonconformity_registries ADD CONSTRAINT nonconformity_registries_audit_id_fkey
FOREIGN KEY (audit_id) REFERENCES audits(id) ON UPDATE CASCADE ON DELETE RESTRICT;
ALTER TABLE nonconformity_registries ADD CONSTRAINT nonconformity_registries_snapshot_id_fkey
FOREIGN KEY (snapshot_id)
REFERENCES snapshots(id)
ON UPDATE CASCADE
ON DELETE CASCADE;
ALTER TABLE nonconformity_registries ADD CONSTRAINT nonconformity_registries_source_id_snapshot_id_key
UNIQUE (source_id, snapshot_id);

View File

@@ -30,6 +30,8 @@ type (
NonconformityRegistry struct {
ID gid.GID `db:"id"`
OrganizationID gid.GID `db:"organization_id"`
SnapshotID *gid.GID `db:"snapshot_id"`
SourceID *gid.GID `db:"source_id"`
ReferenceID string `db:"reference_id"`
Description *string `db:"description"`
AuditID gid.GID `db:"audit_id"`
@@ -74,6 +76,8 @@ func (nr *NonconformityRegistry) LoadByID(
SELECT
id,
organization_id,
snapshot_id,
source_id,
reference_id,
description,
audit_id,
@@ -119,6 +123,7 @@ func (nrs *NonconformityRegistries) CountByOrganizationID(
conn pg.Conn,
scope Scoper,
organizationID gid.GID,
filter *NonconformityRegistryFilter,
) (int, error) {
q := `
SELECT
@@ -128,12 +133,14 @@ FROM
WHERE
%s
AND organization_id = @organization_id
AND %s
`
q = fmt.Sprintf(q, scope.SQLFragment())
q = fmt.Sprintf(q, scope.SQLFragment(), filter.SQLFragment())
args := pgx.StrictNamedArgs{"organization_id": organizationID}
maps.Copy(args, scope.SQLArguments())
maps.Copy(args, filter.SQLArguments())
row := conn.QueryRow(ctx, q, args)
@@ -152,11 +159,14 @@ func (nrs *NonconformityRegistries) LoadByOrganizationID(
scope Scoper,
organizationID gid.GID,
cursor *page.Cursor[NonconformityRegistryOrderField],
filter *NonconformityRegistryFilter,
) error {
q := `
SELECT
id,
organization_id,
snapshot_id,
source_id,
reference_id,
description,
audit_id,
@@ -175,12 +185,14 @@ WHERE
%s
AND organization_id = @organization_id
AND %s
AND %s
`
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
q = fmt.Sprintf(q, scope.SQLFragment(), filter.SQLFragment(), cursor.SQLFragment())
args := pgx.StrictNamedArgs{"organization_id": organizationID}
maps.Copy(args, scope.SQLArguments())
maps.Copy(args, filter.SQLArguments())
maps.Copy(args, cursor.SQLArguments())
rows, err := conn.Query(ctx, q, args)
@@ -287,6 +299,7 @@ SET
WHERE
%s
AND id = @id
AND snapshot_id IS NULL
`
q = fmt.Sprintf(q, scope.SQLFragment())
@@ -324,7 +337,7 @@ func (nr *NonconformityRegistry) Delete(
DELETE FROM nonconformity_registries
WHERE
%s
AND id = @id
AND id = @id AND snapshot_id IS NULL
`
q = fmt.Sprintf(q, scope.SQLFragment())
@@ -339,3 +352,64 @@ WHERE
return nil
}
func (nrs NonconformityRegistries) Snapshot(ctx context.Context, conn pg.Conn, scope Scoper, organizationID, snapshotID gid.GID) error {
query := `
INSERT INTO nonconformity_registries (
id,
tenant_id,
snapshot_id,
source_id,
organization_id,
reference_id,
description,
audit_id,
date_identified,
root_cause,
corrective_action,
owner_id,
due_date,
status,
effectiveness_check,
created_at,
updated_at
)
SELECT
generate_gid(decode_base64_unpadded(@tenant_id), @nonconformity_registry_entity_type),
@tenant_id,
@snapshot_id,
r.id,
r.organization_id,
r.reference_id,
r.description,
r.audit_id,
r.date_identified,
r.root_cause,
r.corrective_action,
r.owner_id,
r.due_date,
r.status,
r.effectiveness_check,
r.created_at,
r.updated_at
FROM nonconformity_registries r
WHERE %s AND r.organization_id = @organization_id AND r.snapshot_id IS NULL
`
query = fmt.Sprintf(query, scope.SQLFragment())
args := pgx.StrictNamedArgs{
"tenant_id": scope.GetTenantID(),
"snapshot_id": snapshotID,
"organization_id": organizationID,
"nonconformity_registry_entity_type": NonconformityRegistryEntityType,
}
maps.Copy(args, scope.SQLArguments())
_, err := conn.Exec(ctx, query, args)
if err != nil {
return fmt.Errorf("cannot insert data snapshots: %w", err)
}
return nil
}

View File

@@ -0,0 +1,60 @@
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package coredata
import (
"github.com/getprobo/probo/pkg/gid"
"github.com/jackc/pgx/v5"
)
type (
NonconformityRegistryFilter struct {
snapshotID **gid.GID
}
)
func NewNonconformityRegistryFilter() *NonconformityRegistryFilter {
return &NonconformityRegistryFilter{
snapshotID: nil,
}
}
func NewNonconformityRegistryFilterBySnapshotID(snapshotID **gid.GID) *NonconformityRegistryFilter {
return &NonconformityRegistryFilter{
snapshotID: snapshotID,
}
}
func (f *NonconformityRegistryFilter) SQLArguments() pgx.NamedArgs {
args := pgx.NamedArgs{}
if f.snapshotID != nil && *f.snapshotID != nil {
args["filter_snapshot_id"] = **f.snapshotID
}
return args
}
func (f *NonconformityRegistryFilter) SQLFragment() string {
if f.snapshotID == nil {
return "TRUE"
}
if *f.snapshotID == nil {
return "snapshot_id IS NULL"
} else {
return "snapshot_id = @filter_snapshot_id"
}
}

View File

@@ -30,6 +30,8 @@ func GetSnapshottable(snapshotType SnapshotsType) (Snapshottable, error) {
switch snapshotType {
case SnapshotsTypeData:
return Data{}, nil
case SnapshotsTypeNonConformityRegistries:
return NonconformityRegistries{}, nil
default:
return nil, fmt.Errorf("unsupported snapshot type: %s", snapshotType)
}

View File

@@ -221,13 +221,14 @@ func (s NonconformityRegistryService) ListForOrganizationID(
ctx context.Context,
organizationID gid.GID,
cursor *page.Cursor[coredata.NonconformityRegistryOrderField],
filter *coredata.NonconformityRegistryFilter,
) (*page.Page[*coredata.NonconformityRegistry, coredata.NonconformityRegistryOrderField], error) {
var registries coredata.NonconformityRegistries
err := s.svc.pg.WithConn(
ctx,
func(conn pg.Conn) error {
err := registries.LoadByOrganizationID(ctx, conn, s.svc.scope, organizationID, cursor)
err := registries.LoadByOrganizationID(ctx, conn, s.svc.scope, organizationID, cursor, filter)
if err != nil {
return fmt.Errorf("cannot load nonconformity registries: %w", err)
}
@@ -246,6 +247,7 @@ func (s NonconformityRegistryService) ListForOrganizationID(
func (s NonconformityRegistryService) CountForOrganizationID(
ctx context.Context,
organizationID gid.GID,
filter *coredata.NonconformityRegistryFilter,
) (int, error) {
var count int
@@ -253,7 +255,7 @@ func (s NonconformityRegistryService) CountForOrganizationID(
ctx,
func(conn pg.Conn) (err error) {
registries := coredata.NonconformityRegistries{}
count, err = registries.CountByOrganizationID(ctx, conn, s.svc.scope, organizationID)
count, err = registries.CountByOrganizationID(ctx, conn, s.svc.scope, organizationID, filter)
if err != nil {
return fmt.Errorf("cannot count nonconformity registries: %w", err)
}

View File

@@ -1106,6 +1106,10 @@ input DatumFilter {
snapshotId: ID
}
input NonconformityRegistryFilter {
snapshotId: ID
}
# Core Types
type TrustCenter implements Node {
id: ID!
@@ -1245,6 +1249,7 @@ type Organization implements Node {
last: Int
before: CursorKey
orderBy: NonconformityRegistryOrder
filter: NonconformityRegistryFilter
): NonconformityRegistryConnection! @goField(forceResolver: true)
complianceRegistries(

View File

@@ -881,7 +881,7 @@ type ComplexityRoot struct {
LogoURL func(childComplexity int) int
Measures func(childComplexity int, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.MeasureOrderBy, filter *types.MeasureFilter) int
Name func(childComplexity int) int
NonconformityRegistries func(childComplexity int, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.NonconformityRegistryOrderBy) int
NonconformityRegistries func(childComplexity int, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.NonconformityRegistryOrderBy, filter *types.NonconformityRegistryFilter) int
Peoples func(childComplexity int, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.PeopleOrderBy, filter *types.PeopleFilter) int
ProcessingActivityRegistries func(childComplexity int, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.ProcessingActivityRegistryOrderBy) int
Risks func(childComplexity int, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.RiskOrderBy, filter *types.RiskFilter) int
@@ -1666,7 +1666,7 @@ type OrganizationResolver interface {
Assets(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.AssetOrderBy) (*types.AssetConnection, error)
Data(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.DatumOrderBy, filter *types.DatumFilter) (*types.DatumConnection, error)
Audits(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.AuditOrderBy) (*types.AuditConnection, error)
NonconformityRegistries(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.NonconformityRegistryOrderBy) (*types.NonconformityRegistryConnection, error)
NonconformityRegistries(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.NonconformityRegistryOrderBy, filter *types.NonconformityRegistryFilter) (*types.NonconformityRegistryConnection, error)
ComplianceRegistries(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.ComplianceRegistryOrderBy) (*types.ComplianceRegistryConnection, error)
ContinualImprovementRegistries(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.ContinualImprovementRegistriesOrderBy) (*types.ContinualImprovementRegistryConnection, error)
ProcessingActivityRegistries(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.ProcessingActivityRegistryOrderBy) (*types.ProcessingActivityRegistryConnection, error)
@@ -5478,7 +5478,7 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin
return 0, false
}
return e.complexity.Organization.NonconformityRegistries(childComplexity, args["first"].(*int), args["after"].(*page.CursorKey), args["last"].(*int), args["before"].(*page.CursorKey), args["orderBy"].(*types.NonconformityRegistryOrderBy)), true
return e.complexity.Organization.NonconformityRegistries(childComplexity, args["first"].(*int), args["after"].(*page.CursorKey), args["last"].(*int), args["before"].(*page.CursorKey), args["orderBy"].(*types.NonconformityRegistryOrderBy), args["filter"].(*types.NonconformityRegistryFilter)), true
case "Organization.peoples":
if e.complexity.Organization.Peoples == nil {
@@ -7724,6 +7724,7 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler {
ec.unmarshalInputInviteUserInput,
ec.unmarshalInputMeasureFilter,
ec.unmarshalInputMeasureOrder,
ec.unmarshalInputNonconformityRegistryFilter,
ec.unmarshalInputNonconformityRegistryOrder,
ec.unmarshalInputOrganizationFilter,
ec.unmarshalInputOrganizationOrder,
@@ -8981,6 +8982,10 @@ input DatumFilter {
snapshotId: ID
}
input NonconformityRegistryFilter {
snapshotId: ID
}
# Core Types
type TrustCenter implements Node {
id: ID!
@@ -9120,6 +9125,7 @@ type Organization implements Node {
last: Int
before: CursorKey
orderBy: NonconformityRegistryOrder
filter: NonconformityRegistryFilter
): NonconformityRegistryConnection! @goField(forceResolver: true)
complianceRegistries(
@@ -16801,6 +16807,11 @@ func (ec *executionContext) field_Organization_nonconformityRegistries_args(ctx
return nil, err
}
args["orderBy"] = arg4
arg5, err := ec.field_Organization_nonconformityRegistries_argsFilter(ctx, rawArgs)
if err != nil {
return nil, err
}
args["filter"] = arg5
return args, nil
}
func (ec *executionContext) field_Organization_nonconformityRegistries_argsFirst(
@@ -16868,6 +16879,19 @@ func (ec *executionContext) field_Organization_nonconformityRegistries_argsOrder
return zeroVal, nil
}
func (ec *executionContext) field_Organization_nonconformityRegistries_argsFilter(
ctx context.Context,
rawArgs map[string]any,
) (*types.NonconformityRegistryFilter, error) {
ctx = graphql.WithPathContext(ctx, graphql.NewPathWithField("filter"))
if tmp, ok := rawArgs["filter"]; ok {
return ec.unmarshalONonconformityRegistryFilter2ᚖgithubᚗcomᚋgetproboᚋproboᚋpkgᚋserverᚋapiᚋconsoleᚋv1ᚋtypesᚐNonconformityRegistryFilter(ctx, tmp)
}
var zeroVal *types.NonconformityRegistryFilter
return zeroVal, nil
}
func (ec *executionContext) field_Organization_peoples_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) {
var err error
args := map[string]any{}
@@ -41754,7 +41778,7 @@ func (ec *executionContext) _Organization_nonconformityRegistries(ctx context.Co
}()
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (any, error) {
ctx = rctx // use context from middleware stack in children
return ec.resolvers.Organization().NonconformityRegistries(rctx, obj, fc.Args["first"].(*int), fc.Args["after"].(*page.CursorKey), fc.Args["last"].(*int), fc.Args["before"].(*page.CursorKey), fc.Args["orderBy"].(*types.NonconformityRegistryOrderBy))
return ec.resolvers.Organization().NonconformityRegistries(rctx, obj, fc.Args["first"].(*int), fc.Args["after"].(*page.CursorKey), fc.Args["last"].(*int), fc.Args["before"].(*page.CursorKey), fc.Args["orderBy"].(*types.NonconformityRegistryOrderBy), fc.Args["filter"].(*types.NonconformityRegistryFilter))
})
if err != nil {
ec.Error(ctx, err)
@@ -62770,6 +62794,33 @@ func (ec *executionContext) unmarshalInputMeasureOrder(ctx context.Context, obj
return it, nil
}
func (ec *executionContext) unmarshalInputNonconformityRegistryFilter(ctx context.Context, obj any) (types.NonconformityRegistryFilter, error) {
var it types.NonconformityRegistryFilter
asMap := map[string]any{}
for k, v := range obj.(map[string]any) {
asMap[k] = v
}
fieldsInOrder := [...]string{"snapshotId"}
for _, k := range fieldsInOrder {
v, ok := asMap[k]
if !ok {
continue
}
switch k {
case "snapshotId":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("snapshotId"))
data, err := ec.unmarshalOID2ᚖgithubᚗcomᚋgetproboᚋproboᚋpkgᚋgidᚐGID(ctx, v)
if err != nil {
return it, err
}
it.SnapshotID = data
}
}
return it, nil
}
func (ec *executionContext) unmarshalInputNonconformityRegistryOrder(ctx context.Context, obj any) (types.NonconformityRegistryOrderBy, error) {
var it types.NonconformityRegistryOrderBy
asMap := map[string]any{}
@@ -87078,6 +87129,14 @@ var (
}
)
func (ec *executionContext) unmarshalONonconformityRegistryFilter2ᚖgithubᚗcomᚋgetproboᚋproboᚋpkgᚋserverᚋapiᚋconsoleᚋv1ᚋtypesᚐNonconformityRegistryFilter(ctx context.Context, v any) (*types.NonconformityRegistryFilter, error) {
if v == nil {
return nil, nil
}
res, err := ec.unmarshalInputNonconformityRegistryFilter(ctx, v)
return &res, graphql.ErrorOnPath(ctx, err)
}
func (ec *executionContext) unmarshalONonconformityRegistryOrder2ᚖgithubᚗcomᚋgetproboᚋproboᚋpkgᚋserverᚋapiᚋconsoleᚋv1ᚋtypesᚐNonconformityRegistryOrderBy(ctx context.Context, v any) (*types.NonconformityRegistryOrderBy, error) {
if v == nil {
return nil, nil

View File

@@ -30,6 +30,7 @@ type (
Resolver any
ParentID gid.GID
Filter *NonconformityRegistryFilter
}
)
@@ -37,6 +38,7 @@ func NewNonconformityRegistryConnection(
p *page.Page[*coredata.NonconformityRegistry, coredata.NonconformityRegistryOrderField],
parentType any,
parentID gid.GID,
filter *NonconformityRegistryFilter,
) *NonconformityRegistryConnection {
edges := make([]*NonconformityRegistryEdge, len(p.Data))
for i, registry := range p.Data {
@@ -49,6 +51,7 @@ func NewNonconformityRegistryConnection(
Resolver: parentType,
ParentID: parentID,
Filter: filter,
}
}

View File

@@ -1138,6 +1138,10 @@ type NonconformityRegistryEdge struct {
Node *NonconformityRegistry `json:"node"`
}
type NonconformityRegistryFilter struct {
SnapshotID *gid.GID `json:"snapshotId,omitempty"`
}
type Organization struct {
ID gid.GID `json:"id"`
Name string `json:"name"`

View File

@@ -3313,7 +3313,12 @@ func (r *nonconformityRegistryConnectionResolver) TotalCount(ctx context.Context
switch obj.Resolver.(type) {
case *organizationResolver:
count, err := prb.NonconformityRegistries.CountForOrganizationID(ctx, obj.ParentID)
nonconformityRegistryFilter := coredata.NewNonconformityRegistryFilterBySnapshotID(nil)
if obj.Filter != nil {
nonconformityRegistryFilter = coredata.NewNonconformityRegistryFilterBySnapshotID(&obj.Filter.SnapshotID)
}
count, err := prb.NonconformityRegistries.CountForOrganizationID(ctx, obj.ParentID, nonconformityRegistryFilter)
if err != nil {
return 0, fmt.Errorf("cannot count nonconformity registries: %w", err)
}
@@ -3686,7 +3691,7 @@ func (r *organizationResolver) Audits(ctx context.Context, obj *types.Organizati
}
// NonconformityRegistries is the resolver for the nonconformityRegistries field.
func (r *organizationResolver) NonconformityRegistries(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.NonconformityRegistryOrderBy) (*types.NonconformityRegistryConnection, error) {
func (r *organizationResolver) NonconformityRegistries(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.NonconformityRegistryOrderBy, filter *types.NonconformityRegistryFilter) (*types.NonconformityRegistryConnection, error) {
prb := r.ProboService(ctx, obj.ID.TenantID())
pageOrderBy := page.OrderBy[coredata.NonconformityRegistryOrderField]{
@@ -3702,12 +3707,17 @@ func (r *organizationResolver) NonconformityRegistries(ctx context.Context, obj
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
page, err := prb.NonconformityRegistries.ListForOrganizationID(ctx, obj.ID, cursor)
nonconformityRegistryFilter := coredata.NewNonconformityRegistryFilterBySnapshotID(nil)
if filter != nil {
nonconformityRegistryFilter = coredata.NewNonconformityRegistryFilterBySnapshotID(&filter.SnapshotID)
}
page, err := prb.NonconformityRegistries.ListForOrganizationID(ctx, obj.ID, cursor, nonconformityRegistryFilter)
if err != nil {
return nil, fmt.Errorf("cannot list organization nonconformity registries: %w", err)
}
return types.NewNonconformityRegistryConnection(page, r, obj.ID), nil
return types.NewNonconformityRegistryConnection(page, r, obj.ID, filter), nil
}
// ComplianceRegistries is the resolver for the complianceRegistries field.