45
apps/console/src/components/SnapshotBanner.tsx
Normal file
45
apps/console/src/components/SnapshotBanner.tsx
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import { IconClock } from "@probo/ui";
|
||||||
|
import { useTranslate } from "@probo/i18n";
|
||||||
|
import { useLazyLoadQuery, graphql } from "react-relay";
|
||||||
|
import type { SnapshotBannerQuery } from "./__generated__/SnapshotBannerQuery.graphql";
|
||||||
|
|
||||||
|
const snapshotQuery = graphql`
|
||||||
|
query SnapshotBannerQuery($snapshotId: ID!) {
|
||||||
|
node(id: $snapshotId) {
|
||||||
|
... on Snapshot {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
createdAt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
snapshotId: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function SnapshotBanner({ snapshotId }: Props) {
|
||||||
|
const { __, dateFormat } = useTranslate();
|
||||||
|
|
||||||
|
const data = useLazyLoadQuery<SnapshotBannerQuery>(snapshotQuery, { snapshotId });
|
||||||
|
const snapshot = data.node;
|
||||||
|
|
||||||
|
if (!snapshot) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="bg-warning rounded-lg p-4 flex items-center gap-3">
|
||||||
|
<IconClock className="text-warning-600 flex-shrink-0" size={20} />
|
||||||
|
<div className="flex-1">
|
||||||
|
<div className="flex items-center gap-2 mb-1">
|
||||||
|
<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" })}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
144
apps/console/src/components/__generated__/SnapshotBannerQuery.graphql.ts
generated
Normal file
144
apps/console/src/components/__generated__/SnapshotBannerQuery.graphql.ts
generated
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
/**
|
||||||
|
* @generated SignedSource<<a11c48ca33ac17dd7eaf6eeca4a0c20d>>
|
||||||
|
* @lightSyntaxTransform
|
||||||
|
* @nogrep
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* tslint:disable */
|
||||||
|
/* eslint-disable */
|
||||||
|
// @ts-nocheck
|
||||||
|
|
||||||
|
import { ConcreteRequest } from 'relay-runtime';
|
||||||
|
export type SnapshotBannerQuery$variables = {
|
||||||
|
snapshotId: string;
|
||||||
|
};
|
||||||
|
export type SnapshotBannerQuery$data = {
|
||||||
|
readonly node: {
|
||||||
|
readonly createdAt?: any;
|
||||||
|
readonly id?: string;
|
||||||
|
readonly name?: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
export type SnapshotBannerQuery = {
|
||||||
|
response: SnapshotBannerQuery$data;
|
||||||
|
variables: SnapshotBannerQuery$variables;
|
||||||
|
};
|
||||||
|
|
||||||
|
const node: ConcreteRequest = (function(){
|
||||||
|
var v0 = [
|
||||||
|
{
|
||||||
|
"defaultValue": null,
|
||||||
|
"kind": "LocalArgument",
|
||||||
|
"name": "snapshotId"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
v1 = [
|
||||||
|
{
|
||||||
|
"kind": "Variable",
|
||||||
|
"name": "id",
|
||||||
|
"variableName": "snapshotId"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
v2 = {
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "id",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
v3 = {
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "name",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
v4 = {
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "createdAt",
|
||||||
|
"storageKey": null
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
"fragment": {
|
||||||
|
"argumentDefinitions": (v0/*: any*/),
|
||||||
|
"kind": "Fragment",
|
||||||
|
"metadata": null,
|
||||||
|
"name": "SnapshotBannerQuery",
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": (v1/*: any*/),
|
||||||
|
"concreteType": null,
|
||||||
|
"kind": "LinkedField",
|
||||||
|
"name": "node",
|
||||||
|
"plural": false,
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"kind": "InlineFragment",
|
||||||
|
"selections": [
|
||||||
|
(v2/*: any*/),
|
||||||
|
(v3/*: any*/),
|
||||||
|
(v4/*: any*/)
|
||||||
|
],
|
||||||
|
"type": "Snapshot",
|
||||||
|
"abstractKey": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"storageKey": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"type": "Query",
|
||||||
|
"abstractKey": null
|
||||||
|
},
|
||||||
|
"kind": "Request",
|
||||||
|
"operation": {
|
||||||
|
"argumentDefinitions": (v0/*: any*/),
|
||||||
|
"kind": "Operation",
|
||||||
|
"name": "SnapshotBannerQuery",
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": (v1/*: any*/),
|
||||||
|
"concreteType": null,
|
||||||
|
"kind": "LinkedField",
|
||||||
|
"name": "node",
|
||||||
|
"plural": false,
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "__typename",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
(v2/*: any*/),
|
||||||
|
{
|
||||||
|
"kind": "InlineFragment",
|
||||||
|
"selections": [
|
||||||
|
(v3/*: any*/),
|
||||||
|
(v4/*: any*/)
|
||||||
|
],
|
||||||
|
"type": "Snapshot",
|
||||||
|
"abstractKey": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"storageKey": null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"params": {
|
||||||
|
"cacheID": "8f21371ececf96444bb6b00e52783573",
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
(node as any).hash = "1602d5b6c0ae4a3122998e4d3419af05";
|
||||||
|
|
||||||
|
export default node;
|
||||||
17
apps/console/src/components/form/SnapshotTypeOptions.tsx
Normal file
17
apps/console/src/components/form/SnapshotTypeOptions.tsx
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { useTranslate } from "@probo/i18n";
|
||||||
|
import { Option } from "@probo/ui";
|
||||||
|
import { snapshotTypes, getSnapshotTypeLabel } from "@probo/helpers";
|
||||||
|
|
||||||
|
export function SnapshotTypeOptions() {
|
||||||
|
const { __ } = useTranslate();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{snapshotTypes.map((type) => (
|
||||||
|
<Option key={type} value={type}>
|
||||||
|
{getSnapshotTypeLabel(__, type)}
|
||||||
|
</Option>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,23 +1,32 @@
|
|||||||
import { Avatar, Field, Option, Select, Badge, Button, IconCrossLargeX } from "@probo/ui";
|
import { Avatar, Field, Option, Select, Badge, Button, IconCrossLargeX } from "@probo/ui";
|
||||||
import { Suspense, useState, type ComponentProps } from "react";
|
import { Suspense, useState, type ComponentProps } from "react";
|
||||||
import { useTranslate } from "@probo/i18n";
|
import { useTranslate } from "@probo/i18n";
|
||||||
import { type Control, Controller } from "react-hook-form";
|
import { type Control, Controller, type FieldValues } from "react-hook-form";
|
||||||
import { useVendors } from "/hooks/graph/VendorGraph.ts";
|
import { useVendors } from "/hooks/graph/VendorGraph.ts";
|
||||||
import { faviconUrl } from "@probo/helpers";
|
import { faviconUrl } from "@probo/helpers";
|
||||||
|
import type { Path } from "react-hook-form";
|
||||||
|
|
||||||
type Props = {
|
type Vendor = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
websiteUrl: string | null | undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
type Props<T extends FieldValues = FieldValues> = {
|
||||||
organizationId: string;
|
organizationId: string;
|
||||||
control: Control<any>;
|
control: Control<T>;
|
||||||
name: string;
|
name: string;
|
||||||
label?: string;
|
label?: string;
|
||||||
error?: string;
|
error?: string;
|
||||||
|
selectedVendors?: Vendor[];
|
||||||
} & ComponentProps<typeof Field>;
|
} & ComponentProps<typeof Field>;
|
||||||
|
|
||||||
export function VendorsMultiSelectField({
|
export function VendorsMultiSelectField<T extends FieldValues = FieldValues>({
|
||||||
organizationId,
|
organizationId,
|
||||||
control,
|
control,
|
||||||
|
selectedVendors = [],
|
||||||
...props
|
...props
|
||||||
}: Props) {
|
}: Props<T>) {
|
||||||
return (
|
return (
|
||||||
<Field {...props}>
|
<Field {...props}>
|
||||||
<Suspense
|
<Suspense
|
||||||
@@ -28,29 +37,40 @@ export function VendorsMultiSelectField({
|
|||||||
control={control}
|
control={control}
|
||||||
name={props.name}
|
name={props.name}
|
||||||
disabled={props.disabled}
|
disabled={props.disabled}
|
||||||
|
selectedVendors={selectedVendors}
|
||||||
/>
|
/>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</Field>
|
</Field>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function VendorsMultiSelectWithQuery(
|
function VendorsMultiSelectWithQuery<T extends FieldValues = FieldValues>(
|
||||||
props: Pick<Props, "organizationId" | "control" | "name" | "disabled">
|
props: Pick<Props<T>, "organizationId" | "control" | "name" | "disabled" | "selectedVendors">
|
||||||
) {
|
) {
|
||||||
const { __ } = useTranslate();
|
const { __ } = useTranslate();
|
||||||
const { name, organizationId, control } = props;
|
const { name, organizationId, control, selectedVendors = [] } = props;
|
||||||
const vendors = useVendors(organizationId);
|
const vendors = useVendors(organizationId);
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
|
||||||
|
const allVendors = [...vendors];
|
||||||
|
if (props.disabled) {
|
||||||
|
selectedVendors.forEach(selectedVendor => {
|
||||||
|
if (!allVendors.find(v => v.id === selectedVendor.id)) {
|
||||||
|
allVendors.push(selectedVendor);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
name={name}
|
name={name as Path<T>}
|
||||||
render={({ field }) => {
|
render={({ field }) => {
|
||||||
const selectedVendorIds = Array.isArray(field.value) ? field.value : [];
|
const selectedVendorIds = (Array.isArray(field.value) ? field.value : []) as string[];
|
||||||
const selectedVendors = vendors.filter(v => selectedVendorIds.includes(v.id));
|
|
||||||
const availableVendors = vendors.filter(v => !selectedVendorIds.includes(v.id));
|
const selectedVendors = allVendors.filter(v => selectedVendorIds.includes(v.id));
|
||||||
|
const availableVendors = allVendors.filter(v => !selectedVendorIds.includes(v.id));
|
||||||
|
|
||||||
const handleAddVendor = (vendorId: string) => {
|
const handleAddVendor = (vendorId: string) => {
|
||||||
const newValue = [...selectedVendorIds, vendorId];
|
const newValue = [...selectedVendorIds, vendorId];
|
||||||
@@ -65,7 +85,7 @@ function VendorsMultiSelectWithQuery(
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
{availableVendors.length > 0 && (
|
{availableVendors.length > 0 && !props.disabled && (
|
||||||
<Select
|
<Select
|
||||||
disabled={props.disabled}
|
disabled={props.disabled}
|
||||||
id={name}
|
id={name}
|
||||||
@@ -108,12 +128,14 @@ function VendorsMultiSelectWithQuery(
|
|||||||
size="s"
|
size="s"
|
||||||
/>
|
/>
|
||||||
<span>{vendor.name}</span>
|
<span>{vendor.name}</span>
|
||||||
|
{!props.disabled && (
|
||||||
<Button
|
<Button
|
||||||
variant="tertiary"
|
variant="tertiary"
|
||||||
icon={IconCrossLargeX}
|
icon={IconCrossLargeX}
|
||||||
onClick={() => handleRemoveVendor(vendor.id)}
|
onClick={() => handleRemoveVendor(vendor.id)}
|
||||||
className="h-4 w-4 p-0 hover:bg-transparent"
|
className="h-4 w-4 p-0 hover:bg-transparent"
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
</Badge>
|
</Badge>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ import { useTranslate } from "@probo/i18n";
|
|||||||
import { promisifyMutation, sprintf } from "@probo/helpers";
|
import { promisifyMutation, sprintf } from "@probo/helpers";
|
||||||
|
|
||||||
export const dataQuery = graphql`
|
export const dataQuery = graphql`
|
||||||
query DatumGraphListQuery($organizationId: ID!) {
|
query DatumGraphListQuery($organizationId: ID!, $snapshotId: ID = null) {
|
||||||
node(id: $organizationId) {
|
node(id: $organizationId) {
|
||||||
... on Organization {
|
... on Organization {
|
||||||
...DataPageFragment
|
...DataPageFragment @arguments(snapshotId: $snapshotId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,7 @@ export const createDatumMutation = graphql`
|
|||||||
id
|
id
|
||||||
fullName
|
fullName
|
||||||
}
|
}
|
||||||
vendors(first: 10) {
|
vendors(first: 50) {
|
||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
id
|
id
|
||||||
|
|||||||
129
apps/console/src/hooks/graph/SnapshotGraph.ts
Normal file
129
apps/console/src/hooks/graph/SnapshotGraph.ts
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
import { graphql } from "relay-runtime";
|
||||||
|
import { useMutation } from "react-relay";
|
||||||
|
import { useConfirm } from "@probo/ui";
|
||||||
|
import { useTranslate } from "@probo/i18n";
|
||||||
|
import { promisifyMutation, sprintf } from "@probo/helpers";
|
||||||
|
import { useMutationWithToasts } from "../useMutationWithToasts";
|
||||||
|
|
||||||
|
export const SnapshotsConnectionKey = "SnapshotsPage_snapshots";
|
||||||
|
|
||||||
|
export const snapshotsQuery = graphql`
|
||||||
|
query SnapshotGraphListQuery($organizationId: ID!) {
|
||||||
|
organization: node(id: $organizationId) {
|
||||||
|
... on Organization {
|
||||||
|
...SnapshotsPageFragment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const snapshotNodeQuery = graphql`
|
||||||
|
query SnapshotGraphNodeQuery($snapshotId: ID!) {
|
||||||
|
node(id: $snapshotId) {
|
||||||
|
... on Snapshot {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
description
|
||||||
|
type
|
||||||
|
organization {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
}
|
||||||
|
createdAt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const createSnapshotMutation = graphql`
|
||||||
|
mutation SnapshotGraphCreateMutation(
|
||||||
|
$input: CreateSnapshotInput!
|
||||||
|
$connections: [ID!]!
|
||||||
|
) {
|
||||||
|
createSnapshot(input: $input) {
|
||||||
|
snapshotEdge @prependEdge(connections: $connections) {
|
||||||
|
node {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
description
|
||||||
|
type
|
||||||
|
createdAt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const deleteSnapshotMutation = graphql`
|
||||||
|
mutation SnapshotGraphDeleteMutation(
|
||||||
|
$input: DeleteSnapshotInput!
|
||||||
|
$connections: [ID!]!
|
||||||
|
) {
|
||||||
|
deleteSnapshot(input: $input) {
|
||||||
|
deletedSnapshotId @deleteEdge(connections: $connections)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const useDeleteSnapshot = (
|
||||||
|
snapshot: { id: string; name: string },
|
||||||
|
connectionId: string
|
||||||
|
) => {
|
||||||
|
const { __ } = useTranslate();
|
||||||
|
const [mutate] = useMutationWithToasts(deleteSnapshotMutation, {
|
||||||
|
successMessage: __("Snapshot deleted successfully"),
|
||||||
|
errorMessage: __("Failed to delete snapshot"),
|
||||||
|
});
|
||||||
|
const confirm = useConfirm();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
confirm(
|
||||||
|
() =>
|
||||||
|
mutate({
|
||||||
|
variables: {
|
||||||
|
input: {
|
||||||
|
snapshotId: snapshot.id,
|
||||||
|
},
|
||||||
|
connections: [connectionId],
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
message: sprintf(
|
||||||
|
__(
|
||||||
|
"This will permanently delete the snapshot %s. This action cannot be undone."
|
||||||
|
),
|
||||||
|
snapshot.name
|
||||||
|
),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useCreateSnapshot = (connectionId: string) => {
|
||||||
|
const [mutate] = useMutation(createSnapshotMutation);
|
||||||
|
const { __ } = useTranslate();
|
||||||
|
|
||||||
|
return (input: {
|
||||||
|
organizationId: string;
|
||||||
|
name: string;
|
||||||
|
description?: string;
|
||||||
|
}) => {
|
||||||
|
if (!input.organizationId) {
|
||||||
|
return alert(__("Failed to create snapshot: organization is required"));
|
||||||
|
}
|
||||||
|
if (!input.name) {
|
||||||
|
return alert(__("Failed to create snapshot: name is required"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return promisifyMutation(mutate)({
|
||||||
|
variables: {
|
||||||
|
input: {
|
||||||
|
organizationId: input.organizationId,
|
||||||
|
name: input.name,
|
||||||
|
description: input.description,
|
||||||
|
},
|
||||||
|
connections: [connectionId],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -188,9 +188,13 @@ const vendorsSelectQuery = graphql`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
export function useVendors(organizationId: string) {
|
export function useVendors(organizationId: string) {
|
||||||
const data = useLazyLoadQuery<VendorGraphSelectQuery>(vendorsSelectQuery, {
|
const data = useLazyLoadQuery<VendorGraphSelectQuery>(
|
||||||
|
vendorsSelectQuery,
|
||||||
|
{
|
||||||
organizationId: organizationId,
|
organizationId: organizationId,
|
||||||
});
|
},
|
||||||
|
{ fetchPolicy: "network-only" }
|
||||||
|
);
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
return data.organization?.vendors?.edges.map((edge) => edge.node) ?? [];
|
return data.organization?.vendors?.edges.map((edge) => edge.node) ?? [];
|
||||||
}, [data]);
|
}, [data]);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* @generated SignedSource<<36898ed088182687925ddd9d0b08b66a>>
|
* @generated SignedSource<<43b67fe6155860e492f2a36543727d49>>
|
||||||
* @lightSyntaxTransform
|
* @lightSyntaxTransform
|
||||||
* @nogrep
|
* @nogrep
|
||||||
*/
|
*/
|
||||||
@@ -133,7 +133,7 @@ v5 = {
|
|||||||
{
|
{
|
||||||
"kind": "Literal",
|
"kind": "Literal",
|
||||||
"name": "first",
|
"name": "first",
|
||||||
"value": 10
|
"value": 50
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"concreteType": "VendorConnection",
|
"concreteType": "VendorConnection",
|
||||||
@@ -173,7 +173,7 @@ v5 = {
|
|||||||
"storageKey": null
|
"storageKey": null
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"storageKey": "vendors(first:10)"
|
"storageKey": "vendors(first:50)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"alias": null,
|
"alias": null,
|
||||||
@@ -254,16 +254,16 @@ return {
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"params": {
|
"params": {
|
||||||
"cacheID": "31d614c716382bedf677502633969fac",
|
"cacheID": "23ff315b0cc090bcaca7739d945d8d1b",
|
||||||
"id": null,
|
"id": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"name": "DatumGraphCreateMutation",
|
"name": "DatumGraphCreateMutation",
|
||||||
"operationKind": "mutation",
|
"operationKind": "mutation",
|
||||||
"text": "mutation DatumGraphCreateMutation(\n $input: CreateDatumInput!\n) {\n createDatum(input: $input) {\n datumEdge {\n node {\n id\n name\n dataClassification\n owner {\n id\n fullName\n }\n vendors(first: 10) {\n edges {\n node {\n id\n name\n websiteUrl\n }\n }\n }\n createdAt\n }\n }\n }\n}\n"
|
"text": "mutation DatumGraphCreateMutation(\n $input: CreateDatumInput!\n) {\n createDatum(input: $input) {\n datumEdge {\n node {\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 }\n }\n }\n createdAt\n }\n }\n }\n}\n"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
(node as any).hash = "b99929d8e7d004f77b06510051ee2e04";
|
(node as any).hash = "b148ef55d18d3a45c04b5072581f2285";
|
||||||
|
|
||||||
export default node;
|
export default node;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* @generated SignedSource<<157213d294566208969ddbfd7e79fd91>>
|
* @generated SignedSource<<453e3cd4a7a9fdbacd183d097ec95a05>>
|
||||||
* @lightSyntaxTransform
|
* @lightSyntaxTransform
|
||||||
* @nogrep
|
* @nogrep
|
||||||
*/
|
*/
|
||||||
@@ -12,6 +12,7 @@ import { ConcreteRequest } from 'relay-runtime';
|
|||||||
import { FragmentRefs } from "relay-runtime";
|
import { FragmentRefs } from "relay-runtime";
|
||||||
export type DatumGraphListQuery$variables = {
|
export type DatumGraphListQuery$variables = {
|
||||||
organizationId: string;
|
organizationId: string;
|
||||||
|
snapshotId?: string | null | undefined;
|
||||||
};
|
};
|
||||||
export type DatumGraphListQuery$data = {
|
export type DatumGraphListQuery$data = {
|
||||||
readonly node: {
|
readonly node: {
|
||||||
@@ -29,6 +30,11 @@ var v0 = [
|
|||||||
"defaultValue": null,
|
"defaultValue": null,
|
||||||
"kind": "LocalArgument",
|
"kind": "LocalArgument",
|
||||||
"name": "organizationId"
|
"name": "organizationId"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"defaultValue": null,
|
||||||
|
"kind": "LocalArgument",
|
||||||
|
"name": "snapshotId"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
v1 = [
|
v1 = [
|
||||||
@@ -38,28 +44,40 @@ v1 = [
|
|||||||
"variableName": "organizationId"
|
"variableName": "organizationId"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
v2 = {
|
v2 = [
|
||||||
|
{
|
||||||
|
"kind": "Variable",
|
||||||
|
"name": "snapshotId",
|
||||||
|
"variableName": "snapshotId"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
v3 = {
|
||||||
"alias": null,
|
"alias": null,
|
||||||
"args": null,
|
"args": null,
|
||||||
"kind": "ScalarField",
|
"kind": "ScalarField",
|
||||||
"name": "__typename",
|
"name": "__typename",
|
||||||
"storageKey": null
|
"storageKey": null
|
||||||
},
|
},
|
||||||
v3 = {
|
v4 = {
|
||||||
"alias": null,
|
"alias": null,
|
||||||
"args": null,
|
"args": null,
|
||||||
"kind": "ScalarField",
|
"kind": "ScalarField",
|
||||||
"name": "id",
|
"name": "id",
|
||||||
"storageKey": null
|
"storageKey": null
|
||||||
},
|
},
|
||||||
v4 = [
|
v5 = [
|
||||||
|
{
|
||||||
|
"fields": (v2/*: any*/),
|
||||||
|
"kind": "ObjectValue",
|
||||||
|
"name": "filter"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"kind": "Literal",
|
"kind": "Literal",
|
||||||
"name": "first",
|
"name": "first",
|
||||||
"value": 10
|
"value": 10
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
v5 = {
|
v6 = {
|
||||||
"alias": null,
|
"alias": null,
|
||||||
"args": null,
|
"args": null,
|
||||||
"kind": "ScalarField",
|
"kind": "ScalarField",
|
||||||
@@ -85,7 +103,7 @@ return {
|
|||||||
"kind": "InlineFragment",
|
"kind": "InlineFragment",
|
||||||
"selections": [
|
"selections": [
|
||||||
{
|
{
|
||||||
"args": null,
|
"args": (v2/*: any*/),
|
||||||
"kind": "FragmentSpread",
|
"kind": "FragmentSpread",
|
||||||
"name": "DataPageFragment"
|
"name": "DataPageFragment"
|
||||||
}
|
}
|
||||||
@@ -114,14 +132,14 @@ return {
|
|||||||
"name": "node",
|
"name": "node",
|
||||||
"plural": false,
|
"plural": false,
|
||||||
"selections": [
|
"selections": [
|
||||||
(v2/*: any*/),
|
|
||||||
(v3/*: any*/),
|
(v3/*: any*/),
|
||||||
|
(v4/*: any*/),
|
||||||
{
|
{
|
||||||
"kind": "InlineFragment",
|
"kind": "InlineFragment",
|
||||||
"selections": [
|
"selections": [
|
||||||
{
|
{
|
||||||
"alias": null,
|
"alias": null,
|
||||||
"args": (v4/*: any*/),
|
"args": (v5/*: any*/),
|
||||||
"concreteType": "DatumConnection",
|
"concreteType": "DatumConnection",
|
||||||
"kind": "LinkedField",
|
"kind": "LinkedField",
|
||||||
"name": "data",
|
"name": "data",
|
||||||
@@ -143,8 +161,8 @@ return {
|
|||||||
"name": "node",
|
"name": "node",
|
||||||
"plural": false,
|
"plural": false,
|
||||||
"selections": [
|
"selections": [
|
||||||
(v3/*: any*/),
|
(v4/*: any*/),
|
||||||
(v5/*: any*/),
|
(v6/*: any*/),
|
||||||
{
|
{
|
||||||
"alias": null,
|
"alias": null,
|
||||||
"args": null,
|
"args": null,
|
||||||
@@ -167,7 +185,7 @@ return {
|
|||||||
"name": "fullName",
|
"name": "fullName",
|
||||||
"storageKey": null
|
"storageKey": null
|
||||||
},
|
},
|
||||||
(v3/*: any*/)
|
(v4/*: any*/)
|
||||||
],
|
],
|
||||||
"storageKey": null
|
"storageKey": null
|
||||||
},
|
},
|
||||||
@@ -201,8 +219,8 @@ return {
|
|||||||
"name": "node",
|
"name": "node",
|
||||||
"plural": false,
|
"plural": false,
|
||||||
"selections": [
|
"selections": [
|
||||||
(v3/*: any*/),
|
(v4/*: any*/),
|
||||||
(v5/*: any*/),
|
(v6/*: any*/),
|
||||||
{
|
{
|
||||||
"alias": null,
|
"alias": null,
|
||||||
"args": null,
|
"args": null,
|
||||||
@@ -226,7 +244,7 @@ return {
|
|||||||
"name": "createdAt",
|
"name": "createdAt",
|
||||||
"storageKey": null
|
"storageKey": null
|
||||||
},
|
},
|
||||||
(v2/*: any*/)
|
(v3/*: any*/)
|
||||||
],
|
],
|
||||||
"storageKey": null
|
"storageKey": null
|
||||||
},
|
},
|
||||||
@@ -292,13 +310,14 @@ return {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"storageKey": "data(first:10)"
|
"storageKey": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"alias": null,
|
"alias": null,
|
||||||
"args": (v4/*: any*/),
|
"args": (v5/*: any*/),
|
||||||
"filters": [
|
"filters": [
|
||||||
"orderBy"
|
"orderBy",
|
||||||
|
"filter"
|
||||||
],
|
],
|
||||||
"handle": "connection",
|
"handle": "connection",
|
||||||
"key": "DataPage_data",
|
"key": "DataPage_data",
|
||||||
@@ -315,16 +334,16 @@ return {
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"params": {
|
"params": {
|
||||||
"cacheID": "93f16f8bcd6ae56a947a18b90146fac4",
|
"cacheID": "7200b7cf37859346d740de3f96f1d443",
|
||||||
"id": null,
|
"id": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"name": "DatumGraphListQuery",
|
"name": "DatumGraphListQuery",
|
||||||
"operationKind": "query",
|
"operationKind": "query",
|
||||||
"text": "query DatumGraphListQuery(\n $organizationId: ID!\n) {\n node(id: $organizationId) {\n __typename\n ... on Organization {\n ...DataPageFragment\n }\n id\n }\n}\n\nfragment DataPageFragment on Organization {\n data(first: 10) {\n edges {\n node {\n id\n name\n dataClassification\n owner {\n fullName\n id\n }\n vendors(first: 50) {\n edges {\n node {\n id\n name\n websiteUrl\n }\n }\n }\n createdAt\n __typename\n }\n cursor\n }\n pageInfo {\n endCursor\n hasNextPage\n hasPreviousPage\n startCursor\n }\n }\n id\n}\n"
|
"text": "query DatumGraphListQuery(\n $organizationId: ID!\n $snapshotId: ID = null\n) {\n node(id: $organizationId) {\n __typename\n ... on Organization {\n ...DataPageFragment_3iomuz\n }\n id\n }\n}\n\nfragment DataPageFragment_3iomuz on Organization {\n data(first: 10, filter: {snapshotId: $snapshotId}) {\n edges {\n node {\n id\n name\n dataClassification\n owner {\n fullName\n id\n }\n vendors(first: 50) {\n edges {\n node {\n id\n name\n websiteUrl\n }\n }\n }\n createdAt\n __typename\n }\n cursor\n }\n pageInfo {\n endCursor\n hasNextPage\n hasPreviousPage\n startCursor\n }\n }\n id\n}\n"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
(node as any).hash = "ebacc146f9ff0dc7fac8dcfcb8e6f74a";
|
(node as any).hash = "e0782332e7e82bd1a5e7f5e40ada2dae";
|
||||||
|
|
||||||
export default node;
|
export default node;
|
||||||
|
|||||||
194
apps/console/src/hooks/graph/__generated__/SnapshotGraphCreateMutation.graphql.ts
generated
Normal file
194
apps/console/src/hooks/graph/__generated__/SnapshotGraphCreateMutation.graphql.ts
generated
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
/**
|
||||||
|
* @generated SignedSource<<459d0a122659971be9b24c79f47691e7>>
|
||||||
|
* @lightSyntaxTransform
|
||||||
|
* @nogrep
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* tslint:disable */
|
||||||
|
/* eslint-disable */
|
||||||
|
// @ts-nocheck
|
||||||
|
|
||||||
|
import { ConcreteRequest } from 'relay-runtime';
|
||||||
|
export type SnapshotsType = "ASSETS" | "COMPLIANCE_REGISTRIES" | "DATA" | "NON_CONFORMITY_REGISTRIES" | "RISKS" | "VENDORS";
|
||||||
|
export type CreateSnapshotInput = {
|
||||||
|
description?: string | null | undefined;
|
||||||
|
name: string;
|
||||||
|
organizationId: string;
|
||||||
|
type: SnapshotsType;
|
||||||
|
};
|
||||||
|
export type SnapshotGraphCreateMutation$variables = {
|
||||||
|
connections: ReadonlyArray<string>;
|
||||||
|
input: CreateSnapshotInput;
|
||||||
|
};
|
||||||
|
export type SnapshotGraphCreateMutation$data = {
|
||||||
|
readonly createSnapshot: {
|
||||||
|
readonly snapshotEdge: {
|
||||||
|
readonly node: {
|
||||||
|
readonly createdAt: any;
|
||||||
|
readonly description: string | null | undefined;
|
||||||
|
readonly id: string;
|
||||||
|
readonly name: string;
|
||||||
|
readonly type: SnapshotsType;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
export type SnapshotGraphCreateMutation = {
|
||||||
|
response: SnapshotGraphCreateMutation$data;
|
||||||
|
variables: SnapshotGraphCreateMutation$variables;
|
||||||
|
};
|
||||||
|
|
||||||
|
const node: ConcreteRequest = (function(){
|
||||||
|
var v0 = {
|
||||||
|
"defaultValue": null,
|
||||||
|
"kind": "LocalArgument",
|
||||||
|
"name": "connections"
|
||||||
|
},
|
||||||
|
v1 = {
|
||||||
|
"defaultValue": null,
|
||||||
|
"kind": "LocalArgument",
|
||||||
|
"name": "input"
|
||||||
|
},
|
||||||
|
v2 = [
|
||||||
|
{
|
||||||
|
"kind": "Variable",
|
||||||
|
"name": "input",
|
||||||
|
"variableName": "input"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
v3 = {
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"concreteType": "SnapshotEdge",
|
||||||
|
"kind": "LinkedField",
|
||||||
|
"name": "snapshotEdge",
|
||||||
|
"plural": false,
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"concreteType": "Snapshot",
|
||||||
|
"kind": "LinkedField",
|
||||||
|
"name": "node",
|
||||||
|
"plural": false,
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "id",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "name",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "description",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "type",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "createdAt",
|
||||||
|
"storageKey": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"storageKey": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"storageKey": null
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
"fragment": {
|
||||||
|
"argumentDefinitions": [
|
||||||
|
(v0/*: any*/),
|
||||||
|
(v1/*: any*/)
|
||||||
|
],
|
||||||
|
"kind": "Fragment",
|
||||||
|
"metadata": null,
|
||||||
|
"name": "SnapshotGraphCreateMutation",
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": (v2/*: any*/),
|
||||||
|
"concreteType": "CreateSnapshotPayload",
|
||||||
|
"kind": "LinkedField",
|
||||||
|
"name": "createSnapshot",
|
||||||
|
"plural": false,
|
||||||
|
"selections": [
|
||||||
|
(v3/*: any*/)
|
||||||
|
],
|
||||||
|
"storageKey": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"type": "Mutation",
|
||||||
|
"abstractKey": null
|
||||||
|
},
|
||||||
|
"kind": "Request",
|
||||||
|
"operation": {
|
||||||
|
"argumentDefinitions": [
|
||||||
|
(v1/*: any*/),
|
||||||
|
(v0/*: any*/)
|
||||||
|
],
|
||||||
|
"kind": "Operation",
|
||||||
|
"name": "SnapshotGraphCreateMutation",
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": (v2/*: any*/),
|
||||||
|
"concreteType": "CreateSnapshotPayload",
|
||||||
|
"kind": "LinkedField",
|
||||||
|
"name": "createSnapshot",
|
||||||
|
"plural": false,
|
||||||
|
"selections": [
|
||||||
|
(v3/*: any*/),
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"filters": null,
|
||||||
|
"handle": "prependEdge",
|
||||||
|
"key": "",
|
||||||
|
"kind": "LinkedHandle",
|
||||||
|
"name": "snapshotEdge",
|
||||||
|
"handleArgs": [
|
||||||
|
{
|
||||||
|
"kind": "Variable",
|
||||||
|
"name": "connections",
|
||||||
|
"variableName": "connections"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"storageKey": null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"params": {
|
||||||
|
"cacheID": "aa2e8ace42f6154271b5d035ae18cad2",
|
||||||
|
"id": null,
|
||||||
|
"metadata": {},
|
||||||
|
"name": "SnapshotGraphCreateMutation",
|
||||||
|
"operationKind": "mutation",
|
||||||
|
"text": "mutation SnapshotGraphCreateMutation(\n $input: CreateSnapshotInput!\n) {\n createSnapshot(input: $input) {\n snapshotEdge {\n node {\n id\n name\n description\n type\n createdAt\n }\n }\n }\n}\n"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
(node as any).hash = "97d681687efde567b46938fc0541635f";
|
||||||
|
|
||||||
|
export default node;
|
||||||
132
apps/console/src/hooks/graph/__generated__/SnapshotGraphDeleteMutation.graphql.ts
generated
Normal file
132
apps/console/src/hooks/graph/__generated__/SnapshotGraphDeleteMutation.graphql.ts
generated
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
/**
|
||||||
|
* @generated SignedSource<<6a696f2d1ebd4a2e733bd9d1b3c42017>>
|
||||||
|
* @lightSyntaxTransform
|
||||||
|
* @nogrep
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* tslint:disable */
|
||||||
|
/* eslint-disable */
|
||||||
|
// @ts-nocheck
|
||||||
|
|
||||||
|
import { ConcreteRequest } from 'relay-runtime';
|
||||||
|
export type DeleteSnapshotInput = {
|
||||||
|
snapshotId: string;
|
||||||
|
};
|
||||||
|
export type SnapshotGraphDeleteMutation$variables = {
|
||||||
|
connections: ReadonlyArray<string>;
|
||||||
|
input: DeleteSnapshotInput;
|
||||||
|
};
|
||||||
|
export type SnapshotGraphDeleteMutation$data = {
|
||||||
|
readonly deleteSnapshot: {
|
||||||
|
readonly deletedSnapshotId: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
export type SnapshotGraphDeleteMutation = {
|
||||||
|
response: SnapshotGraphDeleteMutation$data;
|
||||||
|
variables: SnapshotGraphDeleteMutation$variables;
|
||||||
|
};
|
||||||
|
|
||||||
|
const node: ConcreteRequest = (function(){
|
||||||
|
var v0 = {
|
||||||
|
"defaultValue": null,
|
||||||
|
"kind": "LocalArgument",
|
||||||
|
"name": "connections"
|
||||||
|
},
|
||||||
|
v1 = {
|
||||||
|
"defaultValue": null,
|
||||||
|
"kind": "LocalArgument",
|
||||||
|
"name": "input"
|
||||||
|
},
|
||||||
|
v2 = [
|
||||||
|
{
|
||||||
|
"kind": "Variable",
|
||||||
|
"name": "input",
|
||||||
|
"variableName": "input"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
v3 = {
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "deletedSnapshotId",
|
||||||
|
"storageKey": null
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
"fragment": {
|
||||||
|
"argumentDefinitions": [
|
||||||
|
(v0/*: any*/),
|
||||||
|
(v1/*: any*/)
|
||||||
|
],
|
||||||
|
"kind": "Fragment",
|
||||||
|
"metadata": null,
|
||||||
|
"name": "SnapshotGraphDeleteMutation",
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": (v2/*: any*/),
|
||||||
|
"concreteType": "DeleteSnapshotPayload",
|
||||||
|
"kind": "LinkedField",
|
||||||
|
"name": "deleteSnapshot",
|
||||||
|
"plural": false,
|
||||||
|
"selections": [
|
||||||
|
(v3/*: any*/)
|
||||||
|
],
|
||||||
|
"storageKey": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"type": "Mutation",
|
||||||
|
"abstractKey": null
|
||||||
|
},
|
||||||
|
"kind": "Request",
|
||||||
|
"operation": {
|
||||||
|
"argumentDefinitions": [
|
||||||
|
(v1/*: any*/),
|
||||||
|
(v0/*: any*/)
|
||||||
|
],
|
||||||
|
"kind": "Operation",
|
||||||
|
"name": "SnapshotGraphDeleteMutation",
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": (v2/*: any*/),
|
||||||
|
"concreteType": "DeleteSnapshotPayload",
|
||||||
|
"kind": "LinkedField",
|
||||||
|
"name": "deleteSnapshot",
|
||||||
|
"plural": false,
|
||||||
|
"selections": [
|
||||||
|
(v3/*: any*/),
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"filters": null,
|
||||||
|
"handle": "deleteEdge",
|
||||||
|
"key": "",
|
||||||
|
"kind": "ScalarHandle",
|
||||||
|
"name": "deletedSnapshotId",
|
||||||
|
"handleArgs": [
|
||||||
|
{
|
||||||
|
"kind": "Variable",
|
||||||
|
"name": "connections",
|
||||||
|
"variableName": "connections"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"storageKey": null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"params": {
|
||||||
|
"cacheID": "f5f81e50b61dbc8d5668e421cf88223f",
|
||||||
|
"id": null,
|
||||||
|
"metadata": {},
|
||||||
|
"name": "SnapshotGraphDeleteMutation",
|
||||||
|
"operationKind": "mutation",
|
||||||
|
"text": "mutation SnapshotGraphDeleteMutation(\n $input: DeleteSnapshotInput!\n) {\n deleteSnapshot(input: $input) {\n deletedSnapshotId\n }\n}\n"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
(node as any).hash = "cc7cb0955bf74c611136392354ff8dcf";
|
||||||
|
|
||||||
|
export default node;
|
||||||
253
apps/console/src/hooks/graph/__generated__/SnapshotGraphListQuery.graphql.ts
generated
Normal file
253
apps/console/src/hooks/graph/__generated__/SnapshotGraphListQuery.graphql.ts
generated
Normal file
@@ -0,0 +1,253 @@
|
|||||||
|
/**
|
||||||
|
* @generated SignedSource<<f4a719bca36d682b094afe419b9129e8>>
|
||||||
|
* @lightSyntaxTransform
|
||||||
|
* @nogrep
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* tslint:disable */
|
||||||
|
/* eslint-disable */
|
||||||
|
// @ts-nocheck
|
||||||
|
|
||||||
|
import { ConcreteRequest } from 'relay-runtime';
|
||||||
|
import { FragmentRefs } from "relay-runtime";
|
||||||
|
export type SnapshotGraphListQuery$variables = {
|
||||||
|
organizationId: string;
|
||||||
|
};
|
||||||
|
export type SnapshotGraphListQuery$data = {
|
||||||
|
readonly organization: {
|
||||||
|
readonly " $fragmentSpreads": FragmentRefs<"SnapshotsPageFragment">;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
export type SnapshotGraphListQuery = {
|
||||||
|
response: SnapshotGraphListQuery$data;
|
||||||
|
variables: SnapshotGraphListQuery$variables;
|
||||||
|
};
|
||||||
|
|
||||||
|
const node: ConcreteRequest = (function(){
|
||||||
|
var v0 = [
|
||||||
|
{
|
||||||
|
"defaultValue": null,
|
||||||
|
"kind": "LocalArgument",
|
||||||
|
"name": "organizationId"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
v1 = [
|
||||||
|
{
|
||||||
|
"kind": "Variable",
|
||||||
|
"name": "id",
|
||||||
|
"variableName": "organizationId"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
v2 = {
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "__typename",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
v3 = [
|
||||||
|
{
|
||||||
|
"kind": "Literal",
|
||||||
|
"name": "first",
|
||||||
|
"value": 100
|
||||||
|
}
|
||||||
|
],
|
||||||
|
v4 = {
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "id",
|
||||||
|
"storageKey": null
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
"fragment": {
|
||||||
|
"argumentDefinitions": (v0/*: any*/),
|
||||||
|
"kind": "Fragment",
|
||||||
|
"metadata": null,
|
||||||
|
"name": "SnapshotGraphListQuery",
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": "organization",
|
||||||
|
"args": (v1/*: any*/),
|
||||||
|
"concreteType": null,
|
||||||
|
"kind": "LinkedField",
|
||||||
|
"name": "node",
|
||||||
|
"plural": false,
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"kind": "InlineFragment",
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"args": null,
|
||||||
|
"kind": "FragmentSpread",
|
||||||
|
"name": "SnapshotsPageFragment"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"type": "Organization",
|
||||||
|
"abstractKey": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"storageKey": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"type": "Query",
|
||||||
|
"abstractKey": null
|
||||||
|
},
|
||||||
|
"kind": "Request",
|
||||||
|
"operation": {
|
||||||
|
"argumentDefinitions": (v0/*: any*/),
|
||||||
|
"kind": "Operation",
|
||||||
|
"name": "SnapshotGraphListQuery",
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": "organization",
|
||||||
|
"args": (v1/*: any*/),
|
||||||
|
"concreteType": null,
|
||||||
|
"kind": "LinkedField",
|
||||||
|
"name": "node",
|
||||||
|
"plural": false,
|
||||||
|
"selections": [
|
||||||
|
(v2/*: any*/),
|
||||||
|
{
|
||||||
|
"kind": "InlineFragment",
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": (v3/*: any*/),
|
||||||
|
"concreteType": "SnapshotConnection",
|
||||||
|
"kind": "LinkedField",
|
||||||
|
"name": "snapshots",
|
||||||
|
"plural": false,
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"concreteType": "SnapshotEdge",
|
||||||
|
"kind": "LinkedField",
|
||||||
|
"name": "edges",
|
||||||
|
"plural": true,
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"concreteType": "Snapshot",
|
||||||
|
"kind": "LinkedField",
|
||||||
|
"name": "node",
|
||||||
|
"plural": false,
|
||||||
|
"selections": [
|
||||||
|
(v4/*: any*/),
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "name",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "description",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "type",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "createdAt",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
(v2/*: any*/)
|
||||||
|
],
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "cursor",
|
||||||
|
"storageKey": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"concreteType": "PageInfo",
|
||||||
|
"kind": "LinkedField",
|
||||||
|
"name": "pageInfo",
|
||||||
|
"plural": false,
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "endCursor",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "hasNextPage",
|
||||||
|
"storageKey": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": "ClientExtension",
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "__id",
|
||||||
|
"storageKey": null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"storageKey": "snapshots(first:100)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": (v3/*: any*/),
|
||||||
|
"filters": null,
|
||||||
|
"handle": "connection",
|
||||||
|
"key": "SnapshotsGraphListQuery__snapshots",
|
||||||
|
"kind": "LinkedHandle",
|
||||||
|
"name": "snapshots"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"type": "Organization",
|
||||||
|
"abstractKey": null
|
||||||
|
},
|
||||||
|
(v4/*: any*/)
|
||||||
|
],
|
||||||
|
"storageKey": null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"params": {
|
||||||
|
"cacheID": "eda538d8a5e4e94551012bbb6b8da92f",
|
||||||
|
"id": null,
|
||||||
|
"metadata": {},
|
||||||
|
"name": "SnapshotGraphListQuery",
|
||||||
|
"operationKind": "query",
|
||||||
|
"text": "query SnapshotGraphListQuery(\n $organizationId: ID!\n) {\n organization: node(id: $organizationId) {\n __typename\n ... on Organization {\n ...SnapshotsPageFragment\n }\n id\n }\n}\n\nfragment SnapshotsPageFragment on Organization {\n snapshots(first: 100) {\n edges {\n node {\n id\n name\n description\n type\n createdAt\n __typename\n }\n cursor\n }\n pageInfo {\n endCursor\n hasNextPage\n }\n }\n}\n"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
(node as any).hash = "0f264bca502a59b7f8b8ec729d0ce1ff";
|
||||||
|
|
||||||
|
export default node;
|
||||||
184
apps/console/src/hooks/graph/__generated__/SnapshotGraphNodeQuery.graphql.ts
generated
Normal file
184
apps/console/src/hooks/graph/__generated__/SnapshotGraphNodeQuery.graphql.ts
generated
Normal file
@@ -0,0 +1,184 @@
|
|||||||
|
/**
|
||||||
|
* @generated SignedSource<<5bcc9f9b743d01fc99fd749b970dccd3>>
|
||||||
|
* @lightSyntaxTransform
|
||||||
|
* @nogrep
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* tslint:disable */
|
||||||
|
/* eslint-disable */
|
||||||
|
// @ts-nocheck
|
||||||
|
|
||||||
|
import { ConcreteRequest } from 'relay-runtime';
|
||||||
|
export type SnapshotsType = "ASSETS" | "COMPLIANCE_REGISTRIES" | "DATA" | "NON_CONFORMITY_REGISTRIES" | "RISKS" | "VENDORS";
|
||||||
|
export type SnapshotGraphNodeQuery$variables = {
|
||||||
|
snapshotId: string;
|
||||||
|
};
|
||||||
|
export type SnapshotGraphNodeQuery$data = {
|
||||||
|
readonly node: {
|
||||||
|
readonly createdAt?: any;
|
||||||
|
readonly description?: string | null | undefined;
|
||||||
|
readonly id?: string;
|
||||||
|
readonly name?: string;
|
||||||
|
readonly organization?: {
|
||||||
|
readonly id: string;
|
||||||
|
readonly name: string;
|
||||||
|
};
|
||||||
|
readonly type?: SnapshotsType;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
export type SnapshotGraphNodeQuery = {
|
||||||
|
response: SnapshotGraphNodeQuery$data;
|
||||||
|
variables: SnapshotGraphNodeQuery$variables;
|
||||||
|
};
|
||||||
|
|
||||||
|
const node: ConcreteRequest = (function(){
|
||||||
|
var v0 = [
|
||||||
|
{
|
||||||
|
"defaultValue": null,
|
||||||
|
"kind": "LocalArgument",
|
||||||
|
"name": "snapshotId"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
v1 = [
|
||||||
|
{
|
||||||
|
"kind": "Variable",
|
||||||
|
"name": "id",
|
||||||
|
"variableName": "snapshotId"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
v2 = {
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "id",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
v3 = {
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "name",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
v4 = {
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "description",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
v5 = {
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "type",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
v6 = {
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"concreteType": "Organization",
|
||||||
|
"kind": "LinkedField",
|
||||||
|
"name": "organization",
|
||||||
|
"plural": false,
|
||||||
|
"selections": [
|
||||||
|
(v2/*: any*/),
|
||||||
|
(v3/*: any*/)
|
||||||
|
],
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
v7 = {
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "createdAt",
|
||||||
|
"storageKey": null
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
"fragment": {
|
||||||
|
"argumentDefinitions": (v0/*: any*/),
|
||||||
|
"kind": "Fragment",
|
||||||
|
"metadata": null,
|
||||||
|
"name": "SnapshotGraphNodeQuery",
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": (v1/*: any*/),
|
||||||
|
"concreteType": null,
|
||||||
|
"kind": "LinkedField",
|
||||||
|
"name": "node",
|
||||||
|
"plural": false,
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"kind": "InlineFragment",
|
||||||
|
"selections": [
|
||||||
|
(v2/*: any*/),
|
||||||
|
(v3/*: any*/),
|
||||||
|
(v4/*: any*/),
|
||||||
|
(v5/*: any*/),
|
||||||
|
(v6/*: any*/),
|
||||||
|
(v7/*: any*/)
|
||||||
|
],
|
||||||
|
"type": "Snapshot",
|
||||||
|
"abstractKey": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"storageKey": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"type": "Query",
|
||||||
|
"abstractKey": null
|
||||||
|
},
|
||||||
|
"kind": "Request",
|
||||||
|
"operation": {
|
||||||
|
"argumentDefinitions": (v0/*: any*/),
|
||||||
|
"kind": "Operation",
|
||||||
|
"name": "SnapshotGraphNodeQuery",
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": (v1/*: any*/),
|
||||||
|
"concreteType": null,
|
||||||
|
"kind": "LinkedField",
|
||||||
|
"name": "node",
|
||||||
|
"plural": false,
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "__typename",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
(v2/*: any*/),
|
||||||
|
{
|
||||||
|
"kind": "InlineFragment",
|
||||||
|
"selections": [
|
||||||
|
(v3/*: any*/),
|
||||||
|
(v4/*: any*/),
|
||||||
|
(v5/*: any*/),
|
||||||
|
(v6/*: any*/),
|
||||||
|
(v7/*: any*/)
|
||||||
|
],
|
||||||
|
"type": "Snapshot",
|
||||||
|
"abstractKey": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"storageKey": null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"params": {
|
||||||
|
"cacheID": "8dafbbd8ecc8442fa065d19bba932ce2",
|
||||||
|
"id": null,
|
||||||
|
"metadata": {},
|
||||||
|
"name": "SnapshotGraphNodeQuery",
|
||||||
|
"operationKind": "query",
|
||||||
|
"text": "query SnapshotGraphNodeQuery(\n $snapshotId: ID!\n) {\n node(id: $snapshotId) {\n __typename\n ... on Snapshot {\n id\n name\n description\n type\n organization {\n id\n name\n }\n createdAt\n }\n id\n }\n}\n"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
(node as any).hash = "b687d3da56dbfa333e66f4f2c9c0c824";
|
||||||
|
|
||||||
|
export default node;
|
||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
IconBank,
|
IconBank,
|
||||||
IconBook,
|
IconBook,
|
||||||
IconCircleQuestionmark,
|
IconCircleQuestionmark,
|
||||||
|
IconClock,
|
||||||
IconCrossLargeX,
|
IconCrossLargeX,
|
||||||
IconFire3,
|
IconFire3,
|
||||||
IconGroup1,
|
IconGroup1,
|
||||||
@@ -150,6 +151,11 @@ export function MainLayout() {
|
|||||||
icon={IconBook}
|
icon={IconBook}
|
||||||
to={`${prefix}/complianceRegistries`}
|
to={`${prefix}/complianceRegistries`}
|
||||||
/>
|
/>
|
||||||
|
<SidebarItem
|
||||||
|
label={__("Snapshots")}
|
||||||
|
icon={IconClock}
|
||||||
|
to={`${prefix}/snapshots`}
|
||||||
|
/>
|
||||||
<SidebarItem
|
<SidebarItem
|
||||||
label={__("Trust Center")}
|
label={__("Trust Center")}
|
||||||
icon={IconShield}
|
icon={IconShield}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import {
|
|||||||
usePreloadedQuery,
|
usePreloadedQuery,
|
||||||
type PreloadedQuery,
|
type PreloadedQuery,
|
||||||
} from "react-relay";
|
} from "react-relay";
|
||||||
|
import { useParams } from "react-router";
|
||||||
import { useOrganizationId } from "/hooks/useOrganizationId";
|
import { useOrganizationId } from "/hooks/useOrganizationId";
|
||||||
import { CreateDatumDialog } from "./dialogs/CreateDatumDialog";
|
import { CreateDatumDialog } from "./dialogs/CreateDatumDialog";
|
||||||
import { useDeleteDatum, dataQuery } from "../../../hooks/graph/DatumGraph";
|
import { useDeleteDatum, dataQuery } from "../../../hooks/graph/DatumGraph";
|
||||||
@@ -28,27 +29,31 @@ import type { DatumGraphListQuery } from "/hooks/graph/__generated__/DatumGraphL
|
|||||||
import { faviconUrl } from "@probo/helpers";
|
import { faviconUrl } from "@probo/helpers";
|
||||||
import type { NodeOf } from "/types";
|
import type { NodeOf } from "/types";
|
||||||
import type {
|
import type {
|
||||||
DataPageFragment$data,
|
|
||||||
DataPageFragment$key,
|
DataPageFragment$key,
|
||||||
|
DataPageFragment$data
|
||||||
} from "./__generated__/DataPageFragment.graphql";
|
} from "./__generated__/DataPageFragment.graphql";
|
||||||
|
import type { DataListQuery } from "./__generated__/DataListQuery.graphql";
|
||||||
import { SortableTable } from "/components/SortableTable";
|
import { SortableTable } from "/components/SortableTable";
|
||||||
|
import { SnapshotBanner } from "/components/SnapshotBanner";
|
||||||
|
|
||||||
const paginatedDataFragment = graphql`
|
const paginatedDataFragment = graphql`
|
||||||
fragment DataPageFragment on Organization
|
fragment DataPageFragment on Organization
|
||||||
@refetchable(queryName: "DataListQuery")
|
@refetchable(queryName: "DataListQuery")
|
||||||
@argumentDefinitions(
|
@argumentDefinitions(
|
||||||
first: { type: "Int", defaultValue: 10 }
|
first: { type: "Int", defaultValue: 10 }
|
||||||
orderBy: { type: "DatumOrder", defaultValue: null }
|
order: { type: "DatumOrder", defaultValue: null }
|
||||||
after: { type: "CursorKey", defaultValue: null }
|
after: { type: "CursorKey", defaultValue: null }
|
||||||
before: { type: "CursorKey", defaultValue: null }
|
before: { type: "CursorKey", defaultValue: null }
|
||||||
last: { type: "Int", defaultValue: null }
|
last: { type: "Int", defaultValue: null }
|
||||||
|
snapshotId: { type: "ID", defaultValue: null }
|
||||||
) {
|
) {
|
||||||
data(
|
data(
|
||||||
first: $first
|
first: $first
|
||||||
after: $after
|
after: $after
|
||||||
last: $last
|
last: $last
|
||||||
before: $before
|
before: $before
|
||||||
orderBy: $orderBy
|
orderBy: $order
|
||||||
|
filter: { snapshotId: $snapshotId }
|
||||||
) @connection(key: "DataPage_data") {
|
) @connection(key: "DataPage_data") {
|
||||||
__id
|
__id
|
||||||
edges {
|
edges {
|
||||||
@@ -84,34 +89,61 @@ type Props = {
|
|||||||
export default function DataPage(props: Props) {
|
export default function DataPage(props: Props) {
|
||||||
const { __ } = useTranslate();
|
const { __ } = useTranslate();
|
||||||
const organizationId = useOrganizationId();
|
const organizationId = useOrganizationId();
|
||||||
|
const { snapshotId } = useParams<{ snapshotId?: string }>();
|
||||||
|
const isSnapshotMode = Boolean(snapshotId);
|
||||||
|
|
||||||
const data = usePreloadedQuery(dataQuery, props.queryRef);
|
const queryData = usePreloadedQuery<DatumGraphListQuery>(
|
||||||
const pagination = usePaginationFragment(
|
dataQuery,
|
||||||
|
props.queryRef
|
||||||
|
);
|
||||||
|
|
||||||
|
const data = queryData.node;
|
||||||
|
|
||||||
|
const pagination = usePaginationFragment<DataListQuery, DataPageFragment$key>(
|
||||||
paginatedDataFragment,
|
paginatedDataFragment,
|
||||||
data.node as DataPageFragment$key
|
data
|
||||||
);
|
);
|
||||||
|
|
||||||
const dataEntries = pagination.data.data.edges.map((edge) => edge.node);
|
const dataEntries = pagination.data.data.edges.map((edge) => edge.node);
|
||||||
const connectionId = pagination.data.data.__id;
|
const connectionId = pagination.data.data.__id;
|
||||||
|
|
||||||
|
const refetch = ({ order }: { order: { direction: string; field: string } }) => {
|
||||||
|
pagination.refetch({
|
||||||
|
snapshotId,
|
||||||
|
order: {
|
||||||
|
direction: order.direction as "ASC" | "DESC",
|
||||||
|
field: order.field as "CREATED_AT" | "DATA_CLASSIFICATION" | "NAME"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
usePageTitle(__("Data"));
|
usePageTitle(__("Data"));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
|
{isSnapshotMode && snapshotId && (
|
||||||
|
<SnapshotBanner snapshotId={snapshotId} />
|
||||||
|
)}
|
||||||
<PageHeader
|
<PageHeader
|
||||||
title={__("Data")}
|
title={__("Data")}
|
||||||
description={__(
|
description={__(
|
||||||
"Manage your organization's data assets and their classifications."
|
"Manage your organization's data assets and their classifications."
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
|
{!snapshotId && (
|
||||||
<CreateDatumDialog
|
<CreateDatumDialog
|
||||||
connection={connectionId}
|
connection={connectionId}
|
||||||
organizationId={organizationId}
|
organizationId={organizationId}
|
||||||
|
onCreated={() => pagination.refetch({ snapshotId })}
|
||||||
>
|
>
|
||||||
<Button icon={IconPlusLarge}>{__("Add data")}</Button>
|
<Button icon={IconPlusLarge}>{__("Add data")}</Button>
|
||||||
</CreateDatumDialog>
|
</CreateDatumDialog>
|
||||||
|
)}
|
||||||
</PageHeader>
|
</PageHeader>
|
||||||
<SortableTable {...pagination}>
|
<SortableTable
|
||||||
|
{...pagination}
|
||||||
|
refetch={refetch}
|
||||||
|
>
|
||||||
<Thead>
|
<Thead>
|
||||||
<Tr>
|
<Tr>
|
||||||
<Th>{__("Name")}</Th>
|
<Th>{__("Name")}</Th>
|
||||||
@@ -123,7 +155,7 @@ export default function DataPage(props: Props) {
|
|||||||
</Thead>
|
</Thead>
|
||||||
<Tbody>
|
<Tbody>
|
||||||
{dataEntries.map((entry) => (
|
{dataEntries.map((entry) => (
|
||||||
<DataRow key={entry.id} entry={entry} connectionId={connectionId} />
|
<DataRow key={entry.id} entry={entry} connectionId={connectionId} snapshotId={snapshotId} />
|
||||||
))}
|
))}
|
||||||
</Tbody>
|
</Tbody>
|
||||||
</SortableTable>
|
</SortableTable>
|
||||||
@@ -134,17 +166,23 @@ export default function DataPage(props: Props) {
|
|||||||
function DataRow({
|
function DataRow({
|
||||||
entry,
|
entry,
|
||||||
connectionId,
|
connectionId,
|
||||||
|
snapshotId,
|
||||||
}: {
|
}: {
|
||||||
entry: DataEntry;
|
entry: DataEntry;
|
||||||
connectionId: string;
|
connectionId: string;
|
||||||
|
snapshotId?: string;
|
||||||
}) {
|
}) {
|
||||||
const organizationId = useOrganizationId();
|
const organizationId = useOrganizationId();
|
||||||
const { __ } = useTranslate();
|
const { __ } = useTranslate();
|
||||||
const deleteDatum = useDeleteDatum(entry, connectionId);
|
const deleteDatum = useDeleteDatum(entry, connectionId);
|
||||||
const vendors = entry.vendors?.edges.map((edge) => edge.node) ?? [];
|
const vendors = entry.vendors?.edges.map((edge) => edge.node) ?? [];
|
||||||
|
|
||||||
|
const detailUrl = snapshotId
|
||||||
|
? `/organizations/${organizationId}/snapshots/${snapshotId}/data/${entry.id}`
|
||||||
|
: `/organizations/${organizationId}/data/${entry.id}`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tr to={`/organizations/${organizationId}/data/${entry.id}`}>
|
<Tr to={detailUrl}>
|
||||||
<Td>{entry.name}</Td>
|
<Td>{entry.name}</Td>
|
||||||
<Td>
|
<Td>
|
||||||
<Badge variant="info">{entry.dataClassification}</Badge>
|
<Badge variant="info">{entry.dataClassification}</Badge>
|
||||||
@@ -178,7 +216,7 @@ function DataRow({
|
|||||||
)}
|
)}
|
||||||
</Td>
|
</Td>
|
||||||
<Td noLink width={50} className="text-end">
|
<Td noLink width={50} className="text-end">
|
||||||
<ActionDropdown>
|
{!snapshotId && (<ActionDropdown>
|
||||||
<DropdownItem
|
<DropdownItem
|
||||||
onClick={deleteDatum}
|
onClick={deleteDatum}
|
||||||
variant="danger"
|
variant="danger"
|
||||||
@@ -187,6 +225,7 @@ function DataRow({
|
|||||||
{__("Delete")}
|
{__("Delete")}
|
||||||
</DropdownItem>
|
</DropdownItem>
|
||||||
</ActionDropdown>
|
</ActionDropdown>
|
||||||
|
)}
|
||||||
</Td>
|
</Td>
|
||||||
</Tr>
|
</Tr>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
type PreloadedQuery,
|
type PreloadedQuery,
|
||||||
usePreloadedQuery,
|
usePreloadedQuery,
|
||||||
} from "react-relay";
|
} from "react-relay";
|
||||||
|
import { useParams } from "react-router";
|
||||||
import {
|
import {
|
||||||
datumNodeQuery,
|
datumNodeQuery,
|
||||||
useDeleteDatum,
|
useDeleteDatum,
|
||||||
@@ -25,7 +26,8 @@ import { PeopleSelectField } from "/components/form/PeopleSelectField";
|
|||||||
import { VendorsMultiSelectField } from "/components/form/VendorsMultiSelectField";
|
import { VendorsMultiSelectField } from "/components/form/VendorsMultiSelectField";
|
||||||
import { useFormWithSchema } from "/hooks/useFormWithSchema";
|
import { useFormWithSchema } from "/hooks/useFormWithSchema";
|
||||||
import z from "zod";
|
import z from "zod";
|
||||||
import type { DatumGraphNodeQuery } from "/hooks/graph/__generated__/DatumGraphNodeQuery.graphql.ts";
|
import { SnapshotBanner } from "/components/SnapshotBanner";
|
||||||
|
import type { DatumGraphNodeQuery } from "/hooks/graph/__generated__/DatumGraphNodeQuery.graphql";
|
||||||
|
|
||||||
const updateDatumSchema = z.object({
|
const updateDatumSchema = z.object({
|
||||||
name: z.string().min(1, "Name is required"),
|
name: z.string().min(1, "Name is required"),
|
||||||
@@ -39,17 +41,26 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function DatumDetailsPage(props: Props) {
|
export default function DatumDetailsPage(props: Props) {
|
||||||
const datum = usePreloadedQuery(datumNodeQuery, props.queryRef);
|
const { snapshotId } = useParams<{ snapshotId?: string }>();
|
||||||
const datumEntry = datum.node;
|
const isSnapshotMode = Boolean(snapshotId);
|
||||||
|
|
||||||
|
const queryData = usePreloadedQuery<DatumGraphNodeQuery>(
|
||||||
|
datumNodeQuery,
|
||||||
|
props.queryRef
|
||||||
|
);
|
||||||
|
|
||||||
|
const datumEntry = queryData.node;
|
||||||
|
|
||||||
const { __ } = useTranslate();
|
const { __ } = useTranslate();
|
||||||
const organizationId = useOrganizationId();
|
const organizationId = useOrganizationId();
|
||||||
|
|
||||||
const deleteDatum = useDeleteDatum(
|
const deleteDatum = useDeleteDatum(
|
||||||
datumEntry,
|
datumEntry,
|
||||||
ConnectionHandler.getConnectionID(organizationId, "DataPage_data"),
|
ConnectionHandler.getConnectionID(organizationId, "DataPage_data"),
|
||||||
);
|
);
|
||||||
|
|
||||||
const vendors = datumEntry?.vendors?.edges.map((edge) => edge.node) ?? [];
|
const vendors = datumEntry?.vendors?.edges.map(edge => edge.node) ?? [];
|
||||||
const vendorIds = vendors.map((vendor) => vendor.id);
|
const vendorIds = vendors.map(vendor => vendor.id);
|
||||||
|
|
||||||
const { control, formState, handleSubmit, register, reset } =
|
const { control, formState, handleSubmit, register, reset } =
|
||||||
useFormWithSchema(updateDatumSchema, {
|
useFormWithSchema(updateDatumSchema, {
|
||||||
@@ -64,7 +75,7 @@ export default function DatumDetailsPage(props: Props) {
|
|||||||
const updateDatum = useUpdateDatum();
|
const updateDatum = useUpdateDatum();
|
||||||
|
|
||||||
const onSubmit = handleSubmit(async (formData) => {
|
const onSubmit = handleSubmit(async (formData) => {
|
||||||
if (!datumEntry.id) {
|
if (!datumEntry?.id) {
|
||||||
alert("id is missing from data");
|
alert("id is missing from data");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -79,25 +90,33 @@ export default function DatumDetailsPage(props: Props) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
const breadcrumbDataUrl = isSnapshotMode
|
||||||
<div className="space-y-6">
|
? `/organizations/${organizationId}/snapshots/${snapshotId}/data`
|
||||||
<Breadcrumb
|
: `/organizations/${organizationId}/data`;
|
||||||
items={[
|
|
||||||
|
const breadcrumbItems = [
|
||||||
{
|
{
|
||||||
label: __("Data"),
|
label: __("Data"),
|
||||||
to: `/organizations/${organizationId}/data`,
|
to: breadcrumbDataUrl,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: datumEntry?.name ?? "",
|
label: datumEntry?.name || "",
|
||||||
},
|
},
|
||||||
]}
|
];
|
||||||
/>
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-6">
|
||||||
|
{isSnapshotMode && snapshotId && (
|
||||||
|
<SnapshotBanner snapshotId={snapshotId} />
|
||||||
|
)}
|
||||||
|
<Breadcrumb items={breadcrumbItems} />
|
||||||
|
|
||||||
<div className="flex justify-between items-start">
|
<div className="flex justify-between items-start">
|
||||||
<div className="flex items-center gap-4">
|
<div className="flex items-center gap-4">
|
||||||
<div className="text-2xl">{datumEntry?.name}</div>
|
<div className="text-2xl">{datumEntry?.name}</div>
|
||||||
<Badge variant="info">{datumEntry?.dataClassification}</Badge>
|
<Badge variant="info">{datumEntry?.dataClassification}</Badge>
|
||||||
</div>
|
</div>
|
||||||
|
{!isSnapshotMode && (
|
||||||
<ActionDropdown variant="secondary">
|
<ActionDropdown variant="secondary">
|
||||||
<DropdownItem
|
<DropdownItem
|
||||||
variant="danger"
|
variant="danger"
|
||||||
@@ -107,16 +126,23 @@ export default function DatumDetailsPage(props: Props) {
|
|||||||
{__("Delete")}
|
{__("Delete")}
|
||||||
</DropdownItem>
|
</DropdownItem>
|
||||||
</ActionDropdown>
|
</ActionDropdown>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form onSubmit={onSubmit} className="space-y-6 max-w-2xl">
|
<form onSubmit={onSubmit} className="space-y-6 max-w-2xl">
|
||||||
<Field label={__("Name")} {...register("name")} type="text" />
|
<Field
|
||||||
|
label={__("Name")}
|
||||||
|
{...register("name")}
|
||||||
|
type="text"
|
||||||
|
disabled={isSnapshotMode}
|
||||||
|
/>
|
||||||
|
|
||||||
<ControlledField
|
<ControlledField
|
||||||
control={control}
|
control={control}
|
||||||
name="dataClassification"
|
name="dataClassification"
|
||||||
type="select"
|
type="select"
|
||||||
label={__("Classification")}
|
label={__("Classification")}
|
||||||
|
disabled={isSnapshotMode}
|
||||||
>
|
>
|
||||||
<Option value="PUBLIC">{__("Public")}</Option>
|
<Option value="PUBLIC">{__("Public")}</Option>
|
||||||
<Option value="INTERNAL">{__("Internal")}</Option>
|
<Option value="INTERNAL">{__("Internal")}</Option>
|
||||||
@@ -129,6 +155,7 @@ export default function DatumDetailsPage(props: Props) {
|
|||||||
control={control}
|
control={control}
|
||||||
name="ownerId"
|
name="ownerId"
|
||||||
label={__("Owner")}
|
label={__("Owner")}
|
||||||
|
disabled={isSnapshotMode}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<VendorsMultiSelectField
|
<VendorsMultiSelectField
|
||||||
@@ -136,8 +163,11 @@ export default function DatumDetailsPage(props: Props) {
|
|||||||
control={control}
|
control={control}
|
||||||
name="vendorIds"
|
name="vendorIds"
|
||||||
label={__("Vendors")}
|
label={__("Vendors")}
|
||||||
|
disabled={isSnapshotMode}
|
||||||
|
selectedVendors={vendors}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{!isSnapshotMode && (
|
||||||
<div className="flex justify-end">
|
<div className="flex justify-end">
|
||||||
{formState.isDirty && (
|
{formState.isDirty && (
|
||||||
<Button type="submit" disabled={formState.isSubmitting}>
|
<Button type="submit" disabled={formState.isSubmitting}>
|
||||||
@@ -145,6 +175,7 @@ export default function DatumDetailsPage(props: Props) {
|
|||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* @generated SignedSource<<4894c4387072fb7ac2f379ab04b4168a>>
|
* @generated SignedSource<<8364d9457b59a3ef50b508ab55991638>>
|
||||||
* @lightSyntaxTransform
|
* @lightSyntaxTransform
|
||||||
* @nogrep
|
* @nogrep
|
||||||
*/
|
*/
|
||||||
@@ -22,7 +22,8 @@ export type DataListQuery$variables = {
|
|||||||
first?: number | null | undefined;
|
first?: number | null | undefined;
|
||||||
id: string;
|
id: string;
|
||||||
last?: number | null | undefined;
|
last?: number | null | undefined;
|
||||||
orderBy?: DatumOrder | null | undefined;
|
order?: DatumOrder | null | undefined;
|
||||||
|
snapshotId?: string | null | undefined;
|
||||||
};
|
};
|
||||||
export type DataListQuery$data = {
|
export type DataListQuery$data = {
|
||||||
readonly node: {
|
readonly node: {
|
||||||
@@ -63,57 +64,78 @@ v4 = {
|
|||||||
v5 = {
|
v5 = {
|
||||||
"defaultValue": null,
|
"defaultValue": null,
|
||||||
"kind": "LocalArgument",
|
"kind": "LocalArgument",
|
||||||
"name": "orderBy"
|
"name": "order"
|
||||||
},
|
},
|
||||||
v6 = [
|
v6 = {
|
||||||
|
"defaultValue": null,
|
||||||
|
"kind": "LocalArgument",
|
||||||
|
"name": "snapshotId"
|
||||||
|
},
|
||||||
|
v7 = [
|
||||||
{
|
{
|
||||||
"kind": "Variable",
|
"kind": "Variable",
|
||||||
"name": "id",
|
"name": "id",
|
||||||
"variableName": "id"
|
"variableName": "id"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
v7 = [
|
v8 = {
|
||||||
{
|
|
||||||
"kind": "Variable",
|
"kind": "Variable",
|
||||||
"name": "after",
|
"name": "after",
|
||||||
"variableName": "after"
|
"variableName": "after"
|
||||||
},
|
},
|
||||||
{
|
v9 = {
|
||||||
"kind": "Variable",
|
"kind": "Variable",
|
||||||
"name": "before",
|
"name": "before",
|
||||||
"variableName": "before"
|
"variableName": "before"
|
||||||
},
|
},
|
||||||
{
|
v10 = {
|
||||||
"kind": "Variable",
|
"kind": "Variable",
|
||||||
"name": "first",
|
"name": "first",
|
||||||
"variableName": "first"
|
"variableName": "first"
|
||||||
},
|
},
|
||||||
{
|
v11 = {
|
||||||
"kind": "Variable",
|
"kind": "Variable",
|
||||||
"name": "last",
|
"name": "last",
|
||||||
"variableName": "last"
|
"variableName": "last"
|
||||||
},
|
},
|
||||||
{
|
v12 = {
|
||||||
"kind": "Variable",
|
"kind": "Variable",
|
||||||
"name": "orderBy",
|
"name": "snapshotId",
|
||||||
"variableName": "orderBy"
|
"variableName": "snapshotId"
|
||||||
}
|
},
|
||||||
],
|
v13 = {
|
||||||
v8 = {
|
|
||||||
"alias": null,
|
"alias": null,
|
||||||
"args": null,
|
"args": null,
|
||||||
"kind": "ScalarField",
|
"kind": "ScalarField",
|
||||||
"name": "__typename",
|
"name": "__typename",
|
||||||
"storageKey": null
|
"storageKey": null
|
||||||
},
|
},
|
||||||
v9 = {
|
v14 = {
|
||||||
"alias": null,
|
"alias": null,
|
||||||
"args": null,
|
"args": null,
|
||||||
"kind": "ScalarField",
|
"kind": "ScalarField",
|
||||||
"name": "id",
|
"name": "id",
|
||||||
"storageKey": null
|
"storageKey": null
|
||||||
},
|
},
|
||||||
v10 = {
|
v15 = [
|
||||||
|
(v8/*: any*/),
|
||||||
|
(v9/*: any*/),
|
||||||
|
{
|
||||||
|
"fields": [
|
||||||
|
(v12/*: any*/)
|
||||||
|
],
|
||||||
|
"kind": "ObjectValue",
|
||||||
|
"name": "filter"
|
||||||
|
},
|
||||||
|
(v10/*: any*/),
|
||||||
|
(v11/*: any*/),
|
||||||
|
{
|
||||||
|
"kind": "Variable",
|
||||||
|
"name": "orderBy",
|
||||||
|
"variableName": "order"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
v16 = {
|
||||||
"alias": null,
|
"alias": null,
|
||||||
"args": null,
|
"args": null,
|
||||||
"kind": "ScalarField",
|
"kind": "ScalarField",
|
||||||
@@ -128,7 +150,8 @@ return {
|
|||||||
(v2/*: any*/),
|
(v2/*: any*/),
|
||||||
(v3/*: any*/),
|
(v3/*: any*/),
|
||||||
(v4/*: any*/),
|
(v4/*: any*/),
|
||||||
(v5/*: any*/)
|
(v5/*: any*/),
|
||||||
|
(v6/*: any*/)
|
||||||
],
|
],
|
||||||
"kind": "Fragment",
|
"kind": "Fragment",
|
||||||
"metadata": null,
|
"metadata": null,
|
||||||
@@ -136,14 +159,25 @@ return {
|
|||||||
"selections": [
|
"selections": [
|
||||||
{
|
{
|
||||||
"alias": null,
|
"alias": null,
|
||||||
"args": (v6/*: any*/),
|
"args": (v7/*: any*/),
|
||||||
"concreteType": null,
|
"concreteType": null,
|
||||||
"kind": "LinkedField",
|
"kind": "LinkedField",
|
||||||
"name": "node",
|
"name": "node",
|
||||||
"plural": false,
|
"plural": false,
|
||||||
"selections": [
|
"selections": [
|
||||||
{
|
{
|
||||||
"args": (v7/*: any*/),
|
"args": [
|
||||||
|
(v8/*: any*/),
|
||||||
|
(v9/*: any*/),
|
||||||
|
(v10/*: any*/),
|
||||||
|
(v11/*: any*/),
|
||||||
|
{
|
||||||
|
"kind": "Variable",
|
||||||
|
"name": "order",
|
||||||
|
"variableName": "order"
|
||||||
|
},
|
||||||
|
(v12/*: any*/)
|
||||||
|
],
|
||||||
"kind": "FragmentSpread",
|
"kind": "FragmentSpread",
|
||||||
"name": "DataPageFragment"
|
"name": "DataPageFragment"
|
||||||
}
|
}
|
||||||
@@ -162,6 +196,7 @@ return {
|
|||||||
(v2/*: any*/),
|
(v2/*: any*/),
|
||||||
(v4/*: any*/),
|
(v4/*: any*/),
|
||||||
(v5/*: any*/),
|
(v5/*: any*/),
|
||||||
|
(v6/*: any*/),
|
||||||
(v3/*: any*/)
|
(v3/*: any*/)
|
||||||
],
|
],
|
||||||
"kind": "Operation",
|
"kind": "Operation",
|
||||||
@@ -169,20 +204,20 @@ return {
|
|||||||
"selections": [
|
"selections": [
|
||||||
{
|
{
|
||||||
"alias": null,
|
"alias": null,
|
||||||
"args": (v6/*: any*/),
|
"args": (v7/*: any*/),
|
||||||
"concreteType": null,
|
"concreteType": null,
|
||||||
"kind": "LinkedField",
|
"kind": "LinkedField",
|
||||||
"name": "node",
|
"name": "node",
|
||||||
"plural": false,
|
"plural": false,
|
||||||
"selections": [
|
"selections": [
|
||||||
(v8/*: any*/),
|
(v13/*: any*/),
|
||||||
(v9/*: any*/),
|
(v14/*: any*/),
|
||||||
{
|
{
|
||||||
"kind": "InlineFragment",
|
"kind": "InlineFragment",
|
||||||
"selections": [
|
"selections": [
|
||||||
{
|
{
|
||||||
"alias": null,
|
"alias": null,
|
||||||
"args": (v7/*: any*/),
|
"args": (v15/*: any*/),
|
||||||
"concreteType": "DatumConnection",
|
"concreteType": "DatumConnection",
|
||||||
"kind": "LinkedField",
|
"kind": "LinkedField",
|
||||||
"name": "data",
|
"name": "data",
|
||||||
@@ -204,8 +239,8 @@ return {
|
|||||||
"name": "node",
|
"name": "node",
|
||||||
"plural": false,
|
"plural": false,
|
||||||
"selections": [
|
"selections": [
|
||||||
(v9/*: any*/),
|
(v14/*: any*/),
|
||||||
(v10/*: any*/),
|
(v16/*: any*/),
|
||||||
{
|
{
|
||||||
"alias": null,
|
"alias": null,
|
||||||
"args": null,
|
"args": null,
|
||||||
@@ -228,7 +263,7 @@ return {
|
|||||||
"name": "fullName",
|
"name": "fullName",
|
||||||
"storageKey": null
|
"storageKey": null
|
||||||
},
|
},
|
||||||
(v9/*: any*/)
|
(v14/*: any*/)
|
||||||
],
|
],
|
||||||
"storageKey": null
|
"storageKey": null
|
||||||
},
|
},
|
||||||
@@ -262,8 +297,8 @@ return {
|
|||||||
"name": "node",
|
"name": "node",
|
||||||
"plural": false,
|
"plural": false,
|
||||||
"selections": [
|
"selections": [
|
||||||
(v9/*: any*/),
|
(v14/*: any*/),
|
||||||
(v10/*: any*/),
|
(v16/*: any*/),
|
||||||
{
|
{
|
||||||
"alias": null,
|
"alias": null,
|
||||||
"args": null,
|
"args": null,
|
||||||
@@ -287,7 +322,7 @@ return {
|
|||||||
"name": "createdAt",
|
"name": "createdAt",
|
||||||
"storageKey": null
|
"storageKey": null
|
||||||
},
|
},
|
||||||
(v8/*: any*/)
|
(v13/*: any*/)
|
||||||
],
|
],
|
||||||
"storageKey": null
|
"storageKey": null
|
||||||
},
|
},
|
||||||
@@ -357,9 +392,10 @@ return {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"alias": null,
|
"alias": null,
|
||||||
"args": (v7/*: any*/),
|
"args": (v15/*: any*/),
|
||||||
"filters": [
|
"filters": [
|
||||||
"orderBy"
|
"orderBy",
|
||||||
|
"filter"
|
||||||
],
|
],
|
||||||
"handle": "connection",
|
"handle": "connection",
|
||||||
"key": "DataPage_data",
|
"key": "DataPage_data",
|
||||||
@@ -376,16 +412,16 @@ return {
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"params": {
|
"params": {
|
||||||
"cacheID": "d6742fb1de534407018aeb39ca1438d5",
|
"cacheID": "dbca2ff147e8b1e367a266fcf016b184",
|
||||||
"id": null,
|
"id": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"name": "DataListQuery",
|
"name": "DataListQuery",
|
||||||
"operationKind": "query",
|
"operationKind": "query",
|
||||||
"text": "query DataListQuery(\n $after: CursorKey = null\n $before: CursorKey = null\n $first: Int = 10\n $last: Int = null\n $orderBy: DatumOrder = null\n $id: ID!\n) {\n node(id: $id) {\n __typename\n ...DataPageFragment_sdb03\n id\n }\n}\n\nfragment DataPageFragment_sdb03 on Organization {\n data(first: $first, after: $after, last: $last, before: $before, orderBy: $orderBy) {\n edges {\n node {\n id\n name\n dataClassification\n owner {\n fullName\n id\n }\n vendors(first: 50) {\n edges {\n node {\n id\n name\n websiteUrl\n }\n }\n }\n createdAt\n __typename\n }\n cursor\n }\n pageInfo {\n endCursor\n hasNextPage\n hasPreviousPage\n startCursor\n }\n }\n id\n}\n"
|
"text": "query DataListQuery(\n $after: CursorKey = null\n $before: CursorKey = null\n $first: Int = 10\n $last: Int = null\n $order: DatumOrder = null\n $snapshotId: ID = null\n $id: ID!\n) {\n node(id: $id) {\n __typename\n ...DataPageFragment_25MC8O\n id\n }\n}\n\nfragment DataPageFragment_25MC8O on Organization {\n data(first: $first, after: $after, last: $last, before: $before, orderBy: $order, filter: {snapshotId: $snapshotId}) {\n edges {\n node {\n id\n name\n dataClassification\n owner {\n fullName\n id\n }\n vendors(first: 50) {\n edges {\n node {\n id\n name\n websiteUrl\n }\n }\n }\n createdAt\n __typename\n }\n cursor\n }\n pageInfo {\n endCursor\n hasNextPage\n hasPreviousPage\n startCursor\n }\n }\n id\n}\n"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
(node as any).hash = "a797d00b7f2cac2876322b23aa781efa";
|
(node as any).hash = "a60d9b34a83df89eb59ffcd359903ce8";
|
||||||
|
|
||||||
export default node;
|
export default node;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* @generated SignedSource<<0eb94f0da29f50445248a3d133714be2>>
|
* @generated SignedSource<<17f6d8607b6d2a1b575e1251019b8375>>
|
||||||
* @lightSyntaxTransform
|
* @lightSyntaxTransform
|
||||||
* @nogrep
|
* @nogrep
|
||||||
*/
|
*/
|
||||||
@@ -88,7 +88,12 @@ return {
|
|||||||
{
|
{
|
||||||
"defaultValue": null,
|
"defaultValue": null,
|
||||||
"kind": "LocalArgument",
|
"kind": "LocalArgument",
|
||||||
"name": "orderBy"
|
"name": "order"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"defaultValue": null,
|
||||||
|
"kind": "LocalArgument",
|
||||||
|
"name": "snapshotId"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"kind": "Fragment",
|
"kind": "Fragment",
|
||||||
@@ -128,10 +133,21 @@ return {
|
|||||||
{
|
{
|
||||||
"alias": "data",
|
"alias": "data",
|
||||||
"args": [
|
"args": [
|
||||||
|
{
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"kind": "Variable",
|
||||||
|
"name": "snapshotId",
|
||||||
|
"variableName": "snapshotId"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"kind": "ObjectValue",
|
||||||
|
"name": "filter"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"kind": "Variable",
|
"kind": "Variable",
|
||||||
"name": "orderBy",
|
"name": "orderBy",
|
||||||
"variableName": "orderBy"
|
"variableName": "order"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"concreteType": "DatumConnection",
|
"concreteType": "DatumConnection",
|
||||||
@@ -318,6 +334,6 @@ return {
|
|||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
(node as any).hash = "a797d00b7f2cac2876322b23aa781efa";
|
(node as any).hash = "a60d9b34a83df89eb59ffcd359903ce8";
|
||||||
|
|
||||||
export default node;
|
export default node;
|
||||||
|
|||||||
@@ -27,12 +27,14 @@ type Props = {
|
|||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
connection: string;
|
connection: string;
|
||||||
organizationId: string;
|
organizationId: string;
|
||||||
|
onCreated?: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function CreateDatumDialog({
|
export function CreateDatumDialog({
|
||||||
children,
|
children,
|
||||||
connection,
|
connection,
|
||||||
organizationId,
|
organizationId,
|
||||||
|
onCreated,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const { __ } = useTranslate();
|
const { __ } = useTranslate();
|
||||||
const { control, handleSubmit, register, formState, reset } =
|
const { control, handleSubmit, register, formState, reset } =
|
||||||
@@ -55,6 +57,7 @@ export function CreateDatumDialog({
|
|||||||
});
|
});
|
||||||
ref.current?.close();
|
ref.current?.close();
|
||||||
reset();
|
reset();
|
||||||
|
onCreated?.();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to create datum:", error);
|
console.error("Failed to create datum:", error);
|
||||||
}
|
}
|
||||||
|
|||||||
176
apps/console/src/pages/organizations/snapshots/SnapshotsPage.tsx
Normal file
176
apps/console/src/pages/organizations/snapshots/SnapshotsPage.tsx
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
import type { SnapshotGraphListQuery } from "/hooks/graph/__generated__/SnapshotGraphListQuery.graphql";
|
||||||
|
import {
|
||||||
|
useFragment,
|
||||||
|
usePreloadedQuery,
|
||||||
|
type PreloadedQuery,
|
||||||
|
} from "react-relay";
|
||||||
|
import { useTranslate } from "@probo/i18n";
|
||||||
|
import { getSnapshotTypeLabel } from "@probo/helpers";
|
||||||
|
import {
|
||||||
|
ActionDropdown,
|
||||||
|
Button,
|
||||||
|
DropdownItem,
|
||||||
|
IconPlusLarge,
|
||||||
|
IconTrashCan,
|
||||||
|
PageHeader,
|
||||||
|
Table,
|
||||||
|
Tbody,
|
||||||
|
Td,
|
||||||
|
Th,
|
||||||
|
Thead,
|
||||||
|
Tr,
|
||||||
|
} from "@probo/ui";
|
||||||
|
import {
|
||||||
|
snapshotsQuery,
|
||||||
|
useDeleteSnapshot,
|
||||||
|
} from "/hooks/graph/SnapshotGraph";
|
||||||
|
import { graphql } from "relay-runtime";
|
||||||
|
import type {
|
||||||
|
SnapshotsPageFragment$data,
|
||||||
|
SnapshotsPageFragment$key,
|
||||||
|
} from "./__generated__/SnapshotsPageFragment.graphql";
|
||||||
|
import type { NodeOf } from "/types";
|
||||||
|
import SnapshotFormDialog from "./dialog/SnapshotFormDialog";
|
||||||
|
import { usePageTitle } from "@probo/hooks";
|
||||||
|
import { useOrganizationId } from "/hooks/useOrganizationId";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
queryRef: PreloadedQuery<SnapshotGraphListQuery>;
|
||||||
|
};
|
||||||
|
|
||||||
|
const snapshotsFragment = graphql`
|
||||||
|
fragment SnapshotsPageFragment on Organization {
|
||||||
|
snapshots(first: 100) @connection(key: "SnapshotsGraphListQuery__snapshots") {
|
||||||
|
__id
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
description
|
||||||
|
type
|
||||||
|
createdAt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default function SnapshotsPage(props: Props) {
|
||||||
|
const { __ } = useTranslate();
|
||||||
|
const organizationId = useOrganizationId();
|
||||||
|
const organization = usePreloadedQuery(
|
||||||
|
snapshotsQuery,
|
||||||
|
props.queryRef
|
||||||
|
).organization;
|
||||||
|
const data = useFragment<SnapshotsPageFragment$key>(
|
||||||
|
snapshotsFragment,
|
||||||
|
organization
|
||||||
|
);
|
||||||
|
const connectionId = data.snapshots.__id;
|
||||||
|
const snapshots = data.snapshots.edges.map((edge) => edge.node);
|
||||||
|
usePageTitle(__("Snapshots"));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-6">
|
||||||
|
<PageHeader
|
||||||
|
title={__("Snapshots")}
|
||||||
|
description={__(
|
||||||
|
"Snapshots capture point-in-time views of your organization's compliance state. Create snapshots to track progress over time."
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<SnapshotFormDialog connection={connectionId}>
|
||||||
|
<Button variant="primary" icon={IconPlusLarge}>
|
||||||
|
{__("New snapshot")}
|
||||||
|
</Button>
|
||||||
|
</SnapshotFormDialog>
|
||||||
|
</PageHeader>
|
||||||
|
|
||||||
|
{snapshots.length > 0 ? (
|
||||||
|
<Table>
|
||||||
|
<Thead>
|
||||||
|
<Tr>
|
||||||
|
<Th>{__("Name")}</Th>
|
||||||
|
<Th>{__("Type")}</Th>
|
||||||
|
<Th>{__("Description")}</Th>
|
||||||
|
<Th>{__("Created")}</Th>
|
||||||
|
<Th></Th>
|
||||||
|
</Tr>
|
||||||
|
</Thead>
|
||||||
|
<Tbody>
|
||||||
|
{snapshots.map((snapshot) => (
|
||||||
|
<SnapshotRow
|
||||||
|
key={snapshot.id}
|
||||||
|
snapshot={snapshot}
|
||||||
|
connectionId={connectionId}
|
||||||
|
organizationId={organizationId}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</Tbody>
|
||||||
|
</Table>
|
||||||
|
) : (
|
||||||
|
<div className="text-center py-12">
|
||||||
|
<h3 className="text-lg font-medium text-txt-secondary mb-2">
|
||||||
|
{__("No snapshots yet")}
|
||||||
|
</h3>
|
||||||
|
<p className="text-txt-tertiary mb-6">
|
||||||
|
{__("Create your first snapshot to get started")}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
type SnapshotRowProps = {
|
||||||
|
snapshot: NodeOf<SnapshotsPageFragment$data["snapshots"]>;
|
||||||
|
connectionId: string;
|
||||||
|
organizationId: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
function SnapshotRow(props: SnapshotRowProps) {
|
||||||
|
const { __, dateFormat } = useTranslate();
|
||||||
|
const deleteSnapshot = useDeleteSnapshot(props.snapshot, props.connectionId);
|
||||||
|
|
||||||
|
const getSnapshotUrl = (snapshot: SnapshotRowProps["snapshot"]) => {
|
||||||
|
const baseUrl = `/organizations/${props.organizationId}/snapshots/${snapshot.id}`;
|
||||||
|
|
||||||
|
switch (snapshot.type) {
|
||||||
|
case "DATA":
|
||||||
|
return `${baseUrl}/data`;
|
||||||
|
case "VENDORS":
|
||||||
|
return `${baseUrl}/vendors`;
|
||||||
|
case "RISKS":
|
||||||
|
return `${baseUrl}/risks`;
|
||||||
|
case "ASSETS":
|
||||||
|
return `${baseUrl}/assets`;
|
||||||
|
default:
|
||||||
|
return baseUrl;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tr to={getSnapshotUrl(props.snapshot)}>
|
||||||
|
<Td className="font-medium">{props.snapshot.name}</Td>
|
||||||
|
<Td className="text-txt-secondary">
|
||||||
|
{getSnapshotTypeLabel(__, props.snapshot.type)}
|
||||||
|
</Td>
|
||||||
|
<Td className="text-txt-secondary">
|
||||||
|
{props.snapshot.description || __("No description")}
|
||||||
|
</Td>
|
||||||
|
<Td className="text-txt-tertiary">
|
||||||
|
{dateFormat(props.snapshot.createdAt, { year: "numeric", month: "short", day: "numeric" })}
|
||||||
|
</Td>
|
||||||
|
<Td noLink width={50} className="text-end">
|
||||||
|
<ActionDropdown>
|
||||||
|
<DropdownItem
|
||||||
|
onClick={deleteSnapshot}
|
||||||
|
variant="danger"
|
||||||
|
icon={IconTrashCan}
|
||||||
|
>
|
||||||
|
{__("Delete")}
|
||||||
|
</DropdownItem>
|
||||||
|
</ActionDropdown>
|
||||||
|
</Td>
|
||||||
|
</Tr>
|
||||||
|
);
|
||||||
|
}
|
||||||
177
apps/console/src/pages/organizations/snapshots/__generated__/SnapshotsPageFragment.graphql.ts
generated
Normal file
177
apps/console/src/pages/organizations/snapshots/__generated__/SnapshotsPageFragment.graphql.ts
generated
Normal file
@@ -0,0 +1,177 @@
|
|||||||
|
/**
|
||||||
|
* @generated SignedSource<<05658205222e432a115cecc9c8f34d05>>
|
||||||
|
* @lightSyntaxTransform
|
||||||
|
* @nogrep
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* tslint:disable */
|
||||||
|
/* eslint-disable */
|
||||||
|
// @ts-nocheck
|
||||||
|
|
||||||
|
import { ReaderFragment } from 'relay-runtime';
|
||||||
|
export type SnapshotsType = "ASSETS" | "COMPLIANCE_REGISTRIES" | "DATA" | "NON_CONFORMITY_REGISTRIES" | "RISKS" | "VENDORS";
|
||||||
|
import { FragmentRefs } from "relay-runtime";
|
||||||
|
export type SnapshotsPageFragment$data = {
|
||||||
|
readonly snapshots: {
|
||||||
|
readonly __id: string;
|
||||||
|
readonly edges: ReadonlyArray<{
|
||||||
|
readonly node: {
|
||||||
|
readonly createdAt: any;
|
||||||
|
readonly description: string | null | undefined;
|
||||||
|
readonly id: string;
|
||||||
|
readonly name: string;
|
||||||
|
readonly type: SnapshotsType;
|
||||||
|
};
|
||||||
|
}>;
|
||||||
|
};
|
||||||
|
readonly " $fragmentType": "SnapshotsPageFragment";
|
||||||
|
};
|
||||||
|
export type SnapshotsPageFragment$key = {
|
||||||
|
readonly " $data"?: SnapshotsPageFragment$data;
|
||||||
|
readonly " $fragmentSpreads": FragmentRefs<"SnapshotsPageFragment">;
|
||||||
|
};
|
||||||
|
|
||||||
|
const node: ReaderFragment = {
|
||||||
|
"argumentDefinitions": [],
|
||||||
|
"kind": "Fragment",
|
||||||
|
"metadata": {
|
||||||
|
"connection": [
|
||||||
|
{
|
||||||
|
"count": null,
|
||||||
|
"cursor": null,
|
||||||
|
"direction": "forward",
|
||||||
|
"path": [
|
||||||
|
"snapshots"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"name": "SnapshotsPageFragment",
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": "snapshots",
|
||||||
|
"args": null,
|
||||||
|
"concreteType": "SnapshotConnection",
|
||||||
|
"kind": "LinkedField",
|
||||||
|
"name": "__SnapshotsGraphListQuery__snapshots_connection",
|
||||||
|
"plural": false,
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"concreteType": "SnapshotEdge",
|
||||||
|
"kind": "LinkedField",
|
||||||
|
"name": "edges",
|
||||||
|
"plural": true,
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"concreteType": "Snapshot",
|
||||||
|
"kind": "LinkedField",
|
||||||
|
"name": "node",
|
||||||
|
"plural": false,
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "id",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "name",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "description",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "type",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "createdAt",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "__typename",
|
||||||
|
"storageKey": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "cursor",
|
||||||
|
"storageKey": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"concreteType": "PageInfo",
|
||||||
|
"kind": "LinkedField",
|
||||||
|
"name": "pageInfo",
|
||||||
|
"plural": false,
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "endCursor",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "hasNextPage",
|
||||||
|
"storageKey": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": "ClientExtension",
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "__id",
|
||||||
|
"storageKey": null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"storageKey": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"type": "Organization",
|
||||||
|
"abstractKey": null
|
||||||
|
};
|
||||||
|
|
||||||
|
(node as any).hash = "700dede55fd00f2b57dbbb6ed2e2613d";
|
||||||
|
|
||||||
|
export default node;
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogFooter,
|
||||||
|
Input,
|
||||||
|
Label,
|
||||||
|
PropertyRow,
|
||||||
|
Textarea,
|
||||||
|
useDialogRef,
|
||||||
|
} from "@probo/ui";
|
||||||
|
import type { ReactNode } from "react";
|
||||||
|
import { useTranslate } from "@probo/i18n";
|
||||||
|
import { Breadcrumb } from "@probo/ui";
|
||||||
|
import { graphql } from "relay-runtime";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { useFormWithSchema } from "/hooks/useFormWithSchema";
|
||||||
|
import { useMutationWithToasts } from "/hooks/useMutationWithToasts";
|
||||||
|
import { useOrganizationId } from "/hooks/useOrganizationId";
|
||||||
|
import { ControlledField } from "/components/form/ControlledField";
|
||||||
|
import { SnapshotTypeOptions } from "/components/form/SnapshotTypeOptions";
|
||||||
|
|
||||||
|
const snapshotCreateMutation = graphql`
|
||||||
|
mutation SnapshotFormDialogCreateMutation(
|
||||||
|
$input: CreateSnapshotInput!
|
||||||
|
$connections: [ID!]!
|
||||||
|
) {
|
||||||
|
createSnapshot(input: $input) {
|
||||||
|
snapshotEdge @prependEdge(connections: $connections) {
|
||||||
|
node {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
description
|
||||||
|
type
|
||||||
|
createdAt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const snapshotSchema = z.object({
|
||||||
|
name: z.string().min(2, { message: "Name is required" }),
|
||||||
|
description: z.string().optional(),
|
||||||
|
type: z.enum(["RISKS", "VENDORS", "ASSETS", "DATA", "NON_CONFORMITY_REGISTRIES", "COMPLIANCE_REGISTRIES"]),
|
||||||
|
});
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
children?: ReactNode;
|
||||||
|
connection?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function SnapshotFormDialog(props: Props) {
|
||||||
|
const { __ } = useTranslate();
|
||||||
|
const dialogRef = useDialogRef();
|
||||||
|
const organizationId = useOrganizationId();
|
||||||
|
const [mutate] = useMutationWithToasts(snapshotCreateMutation, {
|
||||||
|
successMessage: __("Snapshot created successfully."),
|
||||||
|
errorMessage: __("Failed to create snapshot. Please try again."),
|
||||||
|
});
|
||||||
|
|
||||||
|
const { handleSubmit, register, reset, control, formState: { errors } } =
|
||||||
|
useFormWithSchema(snapshotSchema, {
|
||||||
|
defaultValues: {
|
||||||
|
name: "",
|
||||||
|
description: "",
|
||||||
|
type: "RISKS",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const onSubmit = handleSubmit(async (data) => {
|
||||||
|
await mutate({
|
||||||
|
variables: {
|
||||||
|
input: {
|
||||||
|
organizationId,
|
||||||
|
name: data.name,
|
||||||
|
description: data.description || undefined,
|
||||||
|
type: data.type,
|
||||||
|
},
|
||||||
|
connections: props.connection ? [props.connection] : [],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
reset();
|
||||||
|
dialogRef.current?.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog
|
||||||
|
ref={dialogRef}
|
||||||
|
trigger={props.children}
|
||||||
|
title={
|
||||||
|
<Breadcrumb
|
||||||
|
items={[
|
||||||
|
__("Snapshots"),
|
||||||
|
__("New Snapshot"),
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<form onSubmit={onSubmit}>
|
||||||
|
<DialogContent className="grid grid-cols-[1fr_420px]">
|
||||||
|
<div className="py-8 px-10 space-y-4">
|
||||||
|
<Input
|
||||||
|
id="name"
|
||||||
|
required
|
||||||
|
variant="title"
|
||||||
|
placeholder={__("Snapshot name")}
|
||||||
|
{...register("name")}
|
||||||
|
/>
|
||||||
|
<Textarea
|
||||||
|
id="description"
|
||||||
|
variant="ghost"
|
||||||
|
autogrow
|
||||||
|
placeholder={__("Add description (optional)")}
|
||||||
|
{...register("description")}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{/* Properties form */}
|
||||||
|
<div className="py-5 px-6 bg-subtle">
|
||||||
|
<Label>{__("Properties")}</Label>
|
||||||
|
|
||||||
|
<PropertyRow
|
||||||
|
id="type"
|
||||||
|
label={__("Type")}
|
||||||
|
error={errors.type?.message}
|
||||||
|
>
|
||||||
|
<ControlledField
|
||||||
|
control={control}
|
||||||
|
name="type"
|
||||||
|
type="select"
|
||||||
|
>
|
||||||
|
<SnapshotTypeOptions />
|
||||||
|
</ControlledField>
|
||||||
|
</PropertyRow>
|
||||||
|
</div>
|
||||||
|
</DialogContent>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button type="submit">
|
||||||
|
{__("Create snapshot")}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</form>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,194 @@
|
|||||||
|
/**
|
||||||
|
* @generated SignedSource<<22c84eaaec91c3555b99f0e067bea54f>>
|
||||||
|
* @lightSyntaxTransform
|
||||||
|
* @nogrep
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* tslint:disable */
|
||||||
|
/* eslint-disable */
|
||||||
|
// @ts-nocheck
|
||||||
|
|
||||||
|
import { ConcreteRequest } from 'relay-runtime';
|
||||||
|
export type SnapshotsType = "ASSETS" | "COMPLIANCE_REGISTRIES" | "DATA" | "NON_CONFORMITY_REGISTRIES" | "RISKS" | "VENDORS";
|
||||||
|
export type CreateSnapshotInput = {
|
||||||
|
description?: string | null | undefined;
|
||||||
|
name: string;
|
||||||
|
organizationId: string;
|
||||||
|
type: SnapshotsType;
|
||||||
|
};
|
||||||
|
export type SnapshotFormDialogCreateMutation$variables = {
|
||||||
|
connections: ReadonlyArray<string>;
|
||||||
|
input: CreateSnapshotInput;
|
||||||
|
};
|
||||||
|
export type SnapshotFormDialogCreateMutation$data = {
|
||||||
|
readonly createSnapshot: {
|
||||||
|
readonly snapshotEdge: {
|
||||||
|
readonly node: {
|
||||||
|
readonly createdAt: any;
|
||||||
|
readonly description: string | null | undefined;
|
||||||
|
readonly id: string;
|
||||||
|
readonly name: string;
|
||||||
|
readonly type: SnapshotsType;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
export type SnapshotFormDialogCreateMutation = {
|
||||||
|
response: SnapshotFormDialogCreateMutation$data;
|
||||||
|
variables: SnapshotFormDialogCreateMutation$variables;
|
||||||
|
};
|
||||||
|
|
||||||
|
const node: ConcreteRequest = (function(){
|
||||||
|
var v0 = {
|
||||||
|
"defaultValue": null,
|
||||||
|
"kind": "LocalArgument",
|
||||||
|
"name": "connections"
|
||||||
|
},
|
||||||
|
v1 = {
|
||||||
|
"defaultValue": null,
|
||||||
|
"kind": "LocalArgument",
|
||||||
|
"name": "input"
|
||||||
|
},
|
||||||
|
v2 = [
|
||||||
|
{
|
||||||
|
"kind": "Variable",
|
||||||
|
"name": "input",
|
||||||
|
"variableName": "input"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
v3 = {
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"concreteType": "SnapshotEdge",
|
||||||
|
"kind": "LinkedField",
|
||||||
|
"name": "snapshotEdge",
|
||||||
|
"plural": false,
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"concreteType": "Snapshot",
|
||||||
|
"kind": "LinkedField",
|
||||||
|
"name": "node",
|
||||||
|
"plural": false,
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "id",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "name",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "description",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "type",
|
||||||
|
"storageKey": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"kind": "ScalarField",
|
||||||
|
"name": "createdAt",
|
||||||
|
"storageKey": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"storageKey": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"storageKey": null
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
"fragment": {
|
||||||
|
"argumentDefinitions": [
|
||||||
|
(v0/*: any*/),
|
||||||
|
(v1/*: any*/)
|
||||||
|
],
|
||||||
|
"kind": "Fragment",
|
||||||
|
"metadata": null,
|
||||||
|
"name": "SnapshotFormDialogCreateMutation",
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": (v2/*: any*/),
|
||||||
|
"concreteType": "CreateSnapshotPayload",
|
||||||
|
"kind": "LinkedField",
|
||||||
|
"name": "createSnapshot",
|
||||||
|
"plural": false,
|
||||||
|
"selections": [
|
||||||
|
(v3/*: any*/)
|
||||||
|
],
|
||||||
|
"storageKey": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"type": "Mutation",
|
||||||
|
"abstractKey": null
|
||||||
|
},
|
||||||
|
"kind": "Request",
|
||||||
|
"operation": {
|
||||||
|
"argumentDefinitions": [
|
||||||
|
(v1/*: any*/),
|
||||||
|
(v0/*: any*/)
|
||||||
|
],
|
||||||
|
"kind": "Operation",
|
||||||
|
"name": "SnapshotFormDialogCreateMutation",
|
||||||
|
"selections": [
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": (v2/*: any*/),
|
||||||
|
"concreteType": "CreateSnapshotPayload",
|
||||||
|
"kind": "LinkedField",
|
||||||
|
"name": "createSnapshot",
|
||||||
|
"plural": false,
|
||||||
|
"selections": [
|
||||||
|
(v3/*: any*/),
|
||||||
|
{
|
||||||
|
"alias": null,
|
||||||
|
"args": null,
|
||||||
|
"filters": null,
|
||||||
|
"handle": "prependEdge",
|
||||||
|
"key": "",
|
||||||
|
"kind": "LinkedHandle",
|
||||||
|
"name": "snapshotEdge",
|
||||||
|
"handleArgs": [
|
||||||
|
{
|
||||||
|
"kind": "Variable",
|
||||||
|
"name": "connections",
|
||||||
|
"variableName": "connections"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"storageKey": null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"params": {
|
||||||
|
"cacheID": "e60d598bc7f5c4958168405725664334",
|
||||||
|
"id": null,
|
||||||
|
"metadata": {},
|
||||||
|
"name": "SnapshotFormDialogCreateMutation",
|
||||||
|
"operationKind": "mutation",
|
||||||
|
"text": "mutation SnapshotFormDialogCreateMutation(\n $input: CreateSnapshotInput!\n) {\n createSnapshot(input: $input) {\n snapshotEdge {\n node {\n id\n name\n description\n type\n createdAt\n }\n }\n }\n}\n"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
(node as any).hash = "b03087e1699a90953aad7cdedaeee1a4";
|
||||||
|
|
||||||
|
export default node;
|
||||||
@@ -31,6 +31,7 @@ import { auditRoutes } from "./routes/auditRoutes.ts";
|
|||||||
import { trustCenterRoutes } from "./routes/trustCenterRoutes.ts";
|
import { trustCenterRoutes } from "./routes/trustCenterRoutes.ts";
|
||||||
import { nonconformityRegistryRoutes } from "./routes/nonconformityRegistryRoutes.ts";
|
import { nonconformityRegistryRoutes } from "./routes/nonconformityRegistryRoutes.ts";
|
||||||
import { complianceRegistryRoutes } from "./routes/complianceRegistryRoutes.ts";
|
import { complianceRegistryRoutes } from "./routes/complianceRegistryRoutes.ts";
|
||||||
|
import { snapshotsRoutes } from "./routes/snapshotsRoutes.ts";
|
||||||
import { lazy } from "@probo/react-lazy";
|
import { lazy } from "@probo/react-lazy";
|
||||||
|
|
||||||
export type AppRoute = Omit<RouteObject, "Component" | "children"> & {
|
export type AppRoute = Omit<RouteObject, "Component" | "children"> & {
|
||||||
@@ -153,6 +154,7 @@ const routes = [
|
|||||||
...auditRoutes,
|
...auditRoutes,
|
||||||
...nonconformityRegistryRoutes,
|
...nonconformityRegistryRoutes,
|
||||||
...complianceRegistryRoutes,
|
...complianceRegistryRoutes,
|
||||||
|
...snapshotsRoutes,
|
||||||
...trustCenterRoutes,
|
...trustCenterRoutes,
|
||||||
{
|
{
|
||||||
path: "*",
|
path: "*",
|
||||||
|
|||||||
@@ -9,7 +9,22 @@ export const dataRoutes = [
|
|||||||
path: "data",
|
path: "data",
|
||||||
fallback: PageSkeleton,
|
fallback: PageSkeleton,
|
||||||
queryLoader: (params: Record<string, string>) =>
|
queryLoader: (params: Record<string, string>) =>
|
||||||
loadQuery(relayEnvironment, dataQuery, { organizationId: params.organizationId }),
|
loadQuery(relayEnvironment, dataQuery, {
|
||||||
|
organizationId: params.organizationId,
|
||||||
|
snapshotId: null
|
||||||
|
}),
|
||||||
|
Component: lazy(
|
||||||
|
() => import("/pages/organizations/data/DataPage")
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "snapshots/:snapshotId/data",
|
||||||
|
fallback: PageSkeleton,
|
||||||
|
queryLoader: (params: Record<string, string>) =>
|
||||||
|
loadQuery(relayEnvironment, dataQuery, {
|
||||||
|
organizationId: params.organizationId,
|
||||||
|
snapshotId: params.snapshotId
|
||||||
|
}),
|
||||||
Component: lazy(
|
Component: lazy(
|
||||||
() => import("/pages/organizations/data/DataPage")
|
() => import("/pages/organizations/data/DataPage")
|
||||||
),
|
),
|
||||||
@@ -23,4 +38,13 @@ export const dataRoutes = [
|
|||||||
() => import("../pages/organizations/data/DatumDetailsPage")
|
() => import("../pages/organizations/data/DatumDetailsPage")
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: "snapshots/:snapshotId/data/:dataId",
|
||||||
|
fallback: PageSkeleton,
|
||||||
|
queryLoader: (params: Record<string, string>) =>
|
||||||
|
loadQuery(relayEnvironment, datumNodeQuery, { dataId: params.dataId }),
|
||||||
|
Component: lazy(
|
||||||
|
() => import("../pages/organizations/data/DatumDetailsPage")
|
||||||
|
),
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|||||||
18
apps/console/src/routes/snapshotsRoutes.ts
Normal file
18
apps/console/src/routes/snapshotsRoutes.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { loadQuery } from "react-relay";
|
||||||
|
import { PageSkeleton } from "/components/skeletons/PageSkeleton";
|
||||||
|
import { relayEnvironment } from "/providers/RelayProviders";
|
||||||
|
import { snapshotsQuery } from "/hooks/graph/SnapshotGraph";
|
||||||
|
import type { AppRoute } from "/routes";
|
||||||
|
import { lazy } from "@probo/react-lazy";
|
||||||
|
|
||||||
|
export const snapshotsRoutes = [
|
||||||
|
{
|
||||||
|
path: "snapshots",
|
||||||
|
fallback: PageSkeleton,
|
||||||
|
queryLoader: ({ organizationId }) =>
|
||||||
|
loadQuery(relayEnvironment, snapshotsQuery, { organizationId }),
|
||||||
|
Component: lazy(
|
||||||
|
() => import("/pages/organizations/snapshots/SnapshotsPage")
|
||||||
|
),
|
||||||
|
},
|
||||||
|
] satisfies AppRoute[];
|
||||||
@@ -15,6 +15,7 @@ export { certificationCategoryLabel, certifications } from "./certifications";
|
|||||||
export { availableFrameworks } from "./frameworks";
|
export { availableFrameworks } from "./frameworks";
|
||||||
export { getDocumentTypeLabel, documentTypes } from "./documents";
|
export { getDocumentTypeLabel, documentTypes } from "./documents";
|
||||||
export { getAssetTypeVariant, getCriticityVariant } from "./assets";
|
export { getAssetTypeVariant, getCriticityVariant } from "./assets";
|
||||||
|
export { getSnapshotTypeLabel, snapshotTypes } from "./snapshots";
|
||||||
export { getAuditStateLabel, getAuditStateVariant, auditStates } from "./audits";
|
export { getAuditStateLabel, getAuditStateVariant, auditStates } from "./audits";
|
||||||
export { getStatusVariant, getStatusLabel, getNonconformityRegistryStatusOptions, getComplianceRegistryStatusOptions, registryStatuses } from "./registryStatus";
|
export { getStatusVariant, getStatusLabel, getNonconformityRegistryStatusOptions, getComplianceRegistryStatusOptions, registryStatuses } from "./registryStatus";
|
||||||
export { promisifyMutation } from "./relay";
|
export { promisifyMutation } from "./relay";
|
||||||
|
|||||||
33
packages/helpers/src/snapshots.ts
Normal file
33
packages/helpers/src/snapshots.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
type Translator = (s: string) => string;
|
||||||
|
|
||||||
|
export const snapshotTypes = [
|
||||||
|
"RISKS",
|
||||||
|
"VENDORS",
|
||||||
|
"ASSETS",
|
||||||
|
"DATA",
|
||||||
|
"NON_CONFORMITY_REGISTRIES",
|
||||||
|
"COMPLIANCE_REGISTRIES"
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
export function getSnapshotTypeLabel(__: Translator, type: string | null | undefined) {
|
||||||
|
if (!type) {
|
||||||
|
return __("Unknown");
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case "RISKS":
|
||||||
|
return __("Risks");
|
||||||
|
case "VENDORS":
|
||||||
|
return __("Vendors");
|
||||||
|
case "ASSETS":
|
||||||
|
return __("Assets");
|
||||||
|
case "DATA":
|
||||||
|
return __("Data");
|
||||||
|
case "NON_CONFORMITY_REGISTRIES":
|
||||||
|
return __("Non Conformity Registries");
|
||||||
|
case "COMPLIANCE_REGISTRIES":
|
||||||
|
return __("Compliance Registries");
|
||||||
|
default:
|
||||||
|
return __("Unknown");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,11 +33,17 @@ type (
|
|||||||
OrganizationID gid.GID `db:"organization_id"`
|
OrganizationID gid.GID `db:"organization_id"`
|
||||||
OwnerID gid.GID `db:"owner_id"`
|
OwnerID gid.GID `db:"owner_id"`
|
||||||
DataClassification DataClassification `db:"data_classification"`
|
DataClassification DataClassification `db:"data_classification"`
|
||||||
|
SnapshotID *gid.GID `db:"snapshot_id"`
|
||||||
|
SourceID *gid.GID `db:"source_id"`
|
||||||
CreatedAt time.Time `db:"created_at"`
|
CreatedAt time.Time `db:"created_at"`
|
||||||
UpdatedAt time.Time `db:"updated_at"`
|
UpdatedAt time.Time `db:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
Data []*Datum
|
Data []*Datum
|
||||||
|
|
||||||
|
DataSnapshotter interface {
|
||||||
|
InsertDataSnapshots(ctx context.Context, conn pg.Conn, scope Scoper, organizationID, snapshotID gid.GID) error
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (d *Datum) CursorKey(field DatumOrderField) page.CursorKey {
|
func (d *Datum) CursorKey(field DatumOrderField) page.CursorKey {
|
||||||
@@ -66,6 +72,8 @@ SELECT
|
|||||||
owner_id,
|
owner_id,
|
||||||
organization_id,
|
organization_id,
|
||||||
data_classification,
|
data_classification,
|
||||||
|
snapshot_id,
|
||||||
|
source_id,
|
||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
FROM
|
FROM
|
||||||
@@ -108,6 +116,8 @@ SELECT
|
|||||||
owner_id,
|
owner_id,
|
||||||
organization_id,
|
organization_id,
|
||||||
data_classification,
|
data_classification,
|
||||||
|
snapshot_id,
|
||||||
|
source_id,
|
||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
FROM
|
FROM
|
||||||
@@ -176,6 +186,7 @@ func (d *Data) LoadByOrganizationID(
|
|||||||
scope Scoper,
|
scope Scoper,
|
||||||
organizationID gid.GID,
|
organizationID gid.GID,
|
||||||
cursor *page.Cursor[DatumOrderField],
|
cursor *page.Cursor[DatumOrderField],
|
||||||
|
filter *DatumFilter,
|
||||||
) error {
|
) error {
|
||||||
q := `
|
q := `
|
||||||
SELECT
|
SELECT
|
||||||
@@ -184,6 +195,8 @@ SELECT
|
|||||||
organization_id,
|
organization_id,
|
||||||
owner_id,
|
owner_id,
|
||||||
data_classification,
|
data_classification,
|
||||||
|
snapshot_id,
|
||||||
|
source_id,
|
||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
FROM
|
FROM
|
||||||
@@ -192,12 +205,14 @@ WHERE
|
|||||||
%s
|
%s
|
||||||
AND organization_id = @organization_id
|
AND organization_id = @organization_id
|
||||||
AND %s
|
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}
|
args := pgx.StrictNamedArgs{"organization_id": organizationID}
|
||||||
maps.Copy(args, scope.SQLArguments())
|
maps.Copy(args, scope.SQLArguments())
|
||||||
|
maps.Copy(args, filter.SQLArguments())
|
||||||
maps.Copy(args, cursor.SQLArguments())
|
maps.Copy(args, cursor.SQLArguments())
|
||||||
|
|
||||||
rows, err := conn.Query(ctx, q, args)
|
rows, err := conn.Query(ctx, q, args)
|
||||||
@@ -228,6 +243,8 @@ INSERT INTO data (
|
|||||||
owner_id,
|
owner_id,
|
||||||
organization_id,
|
organization_id,
|
||||||
data_classification,
|
data_classification,
|
||||||
|
snapshot_id,
|
||||||
|
source_id,
|
||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
) VALUES (
|
) VALUES (
|
||||||
@@ -237,6 +254,8 @@ INSERT INTO data (
|
|||||||
@owner_id,
|
@owner_id,
|
||||||
@organization_id,
|
@organization_id,
|
||||||
@data_classification,
|
@data_classification,
|
||||||
|
@snapshot_id,
|
||||||
|
@source_id,
|
||||||
@created_at,
|
@created_at,
|
||||||
@updated_at
|
@updated_at
|
||||||
)
|
)
|
||||||
@@ -249,6 +268,8 @@ INSERT INTO data (
|
|||||||
"owner_id": d.OwnerID,
|
"owner_id": d.OwnerID,
|
||||||
"organization_id": d.OrganizationID,
|
"organization_id": d.OrganizationID,
|
||||||
"data_classification": d.DataClassification,
|
"data_classification": d.DataClassification,
|
||||||
|
"snapshot_id": d.SnapshotID,
|
||||||
|
"source_id": d.SourceID,
|
||||||
"created_at": d.CreatedAt,
|
"created_at": d.CreatedAt,
|
||||||
"updated_at": d.UpdatedAt,
|
"updated_at": d.UpdatedAt,
|
||||||
}
|
}
|
||||||
@@ -276,12 +297,15 @@ SET
|
|||||||
WHERE
|
WHERE
|
||||||
%s
|
%s
|
||||||
AND id = @id
|
AND id = @id
|
||||||
|
AND snapshot_id IS NULL
|
||||||
RETURNING
|
RETURNING
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
owner_id,
|
owner_id,
|
||||||
organization_id,
|
organization_id,
|
||||||
data_classification,
|
data_classification,
|
||||||
|
snapshot_id,
|
||||||
|
source_id,
|
||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
`
|
`
|
||||||
@@ -322,6 +346,7 @@ DELETE FROM data
|
|||||||
WHERE
|
WHERE
|
||||||
%s
|
%s
|
||||||
AND id = @id
|
AND id = @id
|
||||||
|
AND snapshot_id IS NULL
|
||||||
`
|
`
|
||||||
|
|
||||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||||
@@ -336,3 +361,73 @@ WHERE
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d Data) Snapshot(ctx context.Context, conn pg.Conn, scope Scoper, organizationID, snapshotID gid.GID) error {
|
||||||
|
snapshotters := []DataSnapshotter{Data{}, Vendors{}, DatumVendors{}}
|
||||||
|
|
||||||
|
for _, snapshotter := range snapshotters {
|
||||||
|
if err := snapshotter.InsertDataSnapshots(ctx, conn, scope, organizationID, snapshotID); err != nil {
|
||||||
|
return fmt.Errorf("cannot create data snapshots: (%T) %w", snapshotter, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d Data) InsertDataSnapshots(
|
||||||
|
ctx context.Context,
|
||||||
|
conn pg.Conn,
|
||||||
|
scope Scoper,
|
||||||
|
organizationID gid.GID,
|
||||||
|
snapshotID gid.GID,
|
||||||
|
) error {
|
||||||
|
query := `
|
||||||
|
WITH
|
||||||
|
source_data AS (
|
||||||
|
SELECT *
|
||||||
|
FROM data
|
||||||
|
WHERE %s AND organization_id = @organization_id AND snapshot_id IS NULL
|
||||||
|
)
|
||||||
|
INSERT INTO data (
|
||||||
|
tenant_id,
|
||||||
|
id,
|
||||||
|
snapshot_id,
|
||||||
|
source_id,
|
||||||
|
name,
|
||||||
|
organization_id,
|
||||||
|
owner_id,
|
||||||
|
data_classification,
|
||||||
|
created_at,
|
||||||
|
updated_at
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
@tenant_id,
|
||||||
|
generate_gid(decode_base64_unpadded(@tenant_id), @datum_entity_type),
|
||||||
|
@snapshot_id,
|
||||||
|
d.id,
|
||||||
|
d.name,
|
||||||
|
d.organization_id,
|
||||||
|
d.owner_id,
|
||||||
|
d.data_classification,
|
||||||
|
d.created_at,
|
||||||
|
d.updated_at
|
||||||
|
FROM source_data d
|
||||||
|
`
|
||||||
|
|
||||||
|
query = fmt.Sprintf(query, scope.SQLFragment())
|
||||||
|
|
||||||
|
args := pgx.StrictNamedArgs{
|
||||||
|
"tenant_id": scope.GetTenantID(),
|
||||||
|
"snapshot_id": snapshotID,
|
||||||
|
"organization_id": organizationID,
|
||||||
|
"datum_entity_type": DatumEntityType,
|
||||||
|
}
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|||||||
60
pkg/coredata/datum_filter.go
Normal file
60
pkg/coredata/datum_filter.go
Normal 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 (
|
||||||
|
DatumFilter struct {
|
||||||
|
snapshotID **gid.GID
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewDatumFilter() *DatumFilter {
|
||||||
|
return &DatumFilter{
|
||||||
|
snapshotID: nil,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDatumFilterBySnapshotID(snapshotID **gid.GID) *DatumFilter {
|
||||||
|
return &DatumFilter{
|
||||||
|
snapshotID: snapshotID,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *DatumFilter) SQLArguments() pgx.NamedArgs {
|
||||||
|
args := pgx.NamedArgs{}
|
||||||
|
|
||||||
|
if f.snapshotID != nil && *f.snapshotID != nil {
|
||||||
|
args["filter_snapshot_id"] = **f.snapshotID
|
||||||
|
}
|
||||||
|
|
||||||
|
return args
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *DatumFilter) SQLFragment() string {
|
||||||
|
if f.snapshotID == nil {
|
||||||
|
return "TRUE"
|
||||||
|
}
|
||||||
|
|
||||||
|
if *f.snapshotID == nil {
|
||||||
|
return "snapshot_id IS NULL"
|
||||||
|
} else {
|
||||||
|
return "snapshot_id = @filter_snapshot_id"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@ package coredata
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"maps"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/getprobo/probo/pkg/gid"
|
"github.com/getprobo/probo/pkg/gid"
|
||||||
@@ -28,7 +29,7 @@ type (
|
|||||||
DatumVendor struct {
|
DatumVendor struct {
|
||||||
DatumID gid.GID `db:"datum_id"`
|
DatumID gid.GID `db:"datum_id"`
|
||||||
VendorID gid.GID `db:"vendor_id"`
|
VendorID gid.GID `db:"vendor_id"`
|
||||||
TenantID gid.TenantID `db:"tenant_id"`
|
SnapshotID *gid.GID `db:"snapshot_id"`
|
||||||
CreatedAt time.Time `db:"created_at"`
|
CreatedAt time.Time `db:"created_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,3 +113,61 @@ FROM vendor_ids
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d DatumVendors) InsertDataSnapshots(
|
||||||
|
ctx context.Context,
|
||||||
|
conn pg.Conn,
|
||||||
|
scope Scoper,
|
||||||
|
organizationID gid.GID,
|
||||||
|
snapshotID gid.GID,
|
||||||
|
) error {
|
||||||
|
query := `
|
||||||
|
WITH
|
||||||
|
source_data AS (
|
||||||
|
SELECT id
|
||||||
|
FROM data
|
||||||
|
WHERE organization_id = @organization_id AND snapshot_id IS NULL
|
||||||
|
),
|
||||||
|
snapshot_data AS (
|
||||||
|
SELECT id, source_id
|
||||||
|
FROM data
|
||||||
|
WHERE organization_id = @organization_id AND snapshot_id = @snapshot_id
|
||||||
|
),
|
||||||
|
snapshot_vendors AS (
|
||||||
|
SELECT id, source_id
|
||||||
|
FROM vendors
|
||||||
|
WHERE organization_id = @organization_id AND snapshot_id = @snapshot_id
|
||||||
|
),
|
||||||
|
source_data_vendors AS (
|
||||||
|
SELECT datum_id, vendor_id, snapshot_id, created_at
|
||||||
|
FROM data_vendors
|
||||||
|
WHERE %s AND datum_id = ANY(SELECT id FROM source_data)
|
||||||
|
)
|
||||||
|
INSERT INTO data_vendors (tenant_id, datum_id, vendor_id, snapshot_id, created_at)
|
||||||
|
SELECT
|
||||||
|
@tenant_id,
|
||||||
|
sd.id,
|
||||||
|
sv.id,
|
||||||
|
@snapshot_id,
|
||||||
|
dv.created_at
|
||||||
|
FROM source_data_vendors dv
|
||||||
|
JOIN snapshot_data sd ON sd.source_id = dv.datum_id
|
||||||
|
JOIN snapshot_vendors sv ON sv.source_id = dv.vendor_id
|
||||||
|
`
|
||||||
|
|
||||||
|
query = fmt.Sprintf(query, scope.SQLFragment())
|
||||||
|
|
||||||
|
args := pgx.StrictNamedArgs{
|
||||||
|
"tenant_id": scope.GetTenantID(),
|
||||||
|
"snapshot_id": snapshotID,
|
||||||
|
"organization_id": organizationID,
|
||||||
|
}
|
||||||
|
maps.Copy(args, scope.SQLArguments())
|
||||||
|
|
||||||
|
_, err := conn.Exec(ctx, query, args)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot insert datum vendor snapshots: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -46,4 +46,5 @@ const (
|
|||||||
NonconformityRegistryEntityType
|
NonconformityRegistryEntityType
|
||||||
ComplianceRegistryEntityType
|
ComplianceRegistryEntityType
|
||||||
VendorServiceEntityType
|
VendorServiceEntityType
|
||||||
|
SnapshotEntityType
|
||||||
)
|
)
|
||||||
|
|||||||
24
pkg/coredata/migrations/20250819T102905Z.sql
Normal file
24
pkg/coredata/migrations/20250819T102905Z.sql
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
CREATE TYPE snapshots_type AS ENUM (
|
||||||
|
'RISKS',
|
||||||
|
'VENDORS',
|
||||||
|
'ASSETS',
|
||||||
|
'DATA',
|
||||||
|
'NON_CONFORMITY_REGISTRIES',
|
||||||
|
'COMPLIANCE_REGISTRIES'
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE snapshots (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
tenant_id TEXT NOT NULL,
|
||||||
|
organization_id TEXT NOT NULL,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
type snapshots_type NOT NULL,
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||||
|
|
||||||
|
CONSTRAINT snapshots_organization_id_fkey
|
||||||
|
FOREIGN KEY (organization_id)
|
||||||
|
REFERENCES organizations(id)
|
||||||
|
ON UPDATE CASCADE
|
||||||
|
ON DELETE CASCADE
|
||||||
|
);
|
||||||
31
pkg/coredata/migrations/20250822T123225Z.sql
Normal file
31
pkg/coredata/migrations/20250822T123225Z.sql
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
ALTER TABLE data ADD COLUMN snapshot_id TEXT;
|
||||||
|
ALTER TABLE data ADD COLUMN source_id TEXT;
|
||||||
|
|
||||||
|
ALTER TABLE data ADD CONSTRAINT data_snapshot_id_fkey
|
||||||
|
FOREIGN KEY (snapshot_id)
|
||||||
|
REFERENCES snapshots(id)
|
||||||
|
ON UPDATE CASCADE
|
||||||
|
ON DELETE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE data ADD CONSTRAINT data_source_id_snapshot_id_key
|
||||||
|
UNIQUE (source_id, snapshot_id);
|
||||||
|
|
||||||
|
ALTER TABLE vendors ADD COLUMN snapshot_id TEXT;
|
||||||
|
ALTER TABLE vendors ADD COLUMN source_id TEXT;
|
||||||
|
|
||||||
|
ALTER TABLE vendors ADD CONSTRAINT vendors_snapshot_id_fkey
|
||||||
|
FOREIGN KEY (snapshot_id)
|
||||||
|
REFERENCES snapshots(id)
|
||||||
|
ON UPDATE CASCADE
|
||||||
|
ON DELETE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE vendors ADD CONSTRAINT vendors_source_id_snapshot_id_key
|
||||||
|
UNIQUE (source_id, snapshot_id);
|
||||||
|
|
||||||
|
ALTER TABLE data_vendors ADD COLUMN snapshot_id TEXT;
|
||||||
|
|
||||||
|
ALTER TABLE data_vendors ADD CONSTRAINT data_vendors_snapshot_id_fkey
|
||||||
|
FOREIGN KEY (snapshot_id)
|
||||||
|
REFERENCES snapshots(id)
|
||||||
|
ON UPDATE CASCADE
|
||||||
|
ON DELETE CASCADE;
|
||||||
239
pkg/coredata/snapshot.go
Normal file
239
pkg/coredata/snapshot.go
Normal file
@@ -0,0 +1,239 @@
|
|||||||
|
// 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 (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"maps"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/getprobo/probo/pkg/gid"
|
||||||
|
"github.com/getprobo/probo/pkg/page"
|
||||||
|
"github.com/jackc/pgx/v5"
|
||||||
|
"go.gearno.de/kit/pg"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
Snapshot struct {
|
||||||
|
ID gid.GID `db:"id"`
|
||||||
|
OrganizationID gid.GID `db:"organization_id"`
|
||||||
|
Name string `db:"name"`
|
||||||
|
Description *string `db:"description"`
|
||||||
|
Type SnapshotsType `db:"type"`
|
||||||
|
CreatedAt time.Time `db:"created_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
Snapshots []*Snapshot
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *Snapshot) CursorKey(field SnapshotOrderField) page.CursorKey {
|
||||||
|
switch field {
|
||||||
|
case SnapshotOrderFieldCreatedAt:
|
||||||
|
return page.NewCursorKey(s.ID, s.CreatedAt)
|
||||||
|
case SnapshotOrderFieldName:
|
||||||
|
return page.NewCursorKey(s.ID, s.Name)
|
||||||
|
case SnapshotOrderFieldType:
|
||||||
|
return page.NewCursorKey(s.ID, s.Type)
|
||||||
|
}
|
||||||
|
|
||||||
|
panic(fmt.Sprintf("unsupported order by: %s", field))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Snapshot) LoadByID(
|
||||||
|
ctx context.Context,
|
||||||
|
conn pg.Conn,
|
||||||
|
scope Scoper,
|
||||||
|
snapshotID gid.GID,
|
||||||
|
) error {
|
||||||
|
q := `
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
organization_id,
|
||||||
|
name,
|
||||||
|
description,
|
||||||
|
type,
|
||||||
|
created_at
|
||||||
|
FROM
|
||||||
|
snapshots
|
||||||
|
WHERE
|
||||||
|
%s
|
||||||
|
AND id = @snapshot_id
|
||||||
|
LIMIT 1;
|
||||||
|
`
|
||||||
|
|
||||||
|
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||||
|
|
||||||
|
args := pgx.StrictNamedArgs{"snapshot_id": snapshotID}
|
||||||
|
maps.Copy(args, scope.SQLArguments())
|
||||||
|
|
||||||
|
rows, err := conn.Query(ctx, q, args)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot query snapshots: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
snapshot, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[Snapshot])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot collect snapshot: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
*s = snapshot
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Snapshots) CountByOrganizationID(
|
||||||
|
ctx context.Context,
|
||||||
|
conn pg.Conn,
|
||||||
|
scope Scoper,
|
||||||
|
organizationID gid.GID,
|
||||||
|
) (int, error) {
|
||||||
|
q := `
|
||||||
|
SELECT
|
||||||
|
COUNT(id)
|
||||||
|
FROM
|
||||||
|
snapshots
|
||||||
|
WHERE
|
||||||
|
%s
|
||||||
|
AND organization_id = @organization_id
|
||||||
|
`
|
||||||
|
|
||||||
|
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||||
|
|
||||||
|
args := pgx.StrictNamedArgs{"organization_id": organizationID}
|
||||||
|
maps.Copy(args, scope.SQLArguments())
|
||||||
|
|
||||||
|
row := conn.QueryRow(ctx, q, args)
|
||||||
|
|
||||||
|
var count int
|
||||||
|
if err := row.Scan(&count); err != nil {
|
||||||
|
return 0, fmt.Errorf("cannot scan count: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return count, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Snapshots) LoadByOrganizationID(
|
||||||
|
ctx context.Context,
|
||||||
|
conn pg.Conn,
|
||||||
|
scope Scoper,
|
||||||
|
organizationID gid.GID,
|
||||||
|
cursor *page.Cursor[SnapshotOrderField],
|
||||||
|
) error {
|
||||||
|
q := `
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
organization_id,
|
||||||
|
name,
|
||||||
|
description,
|
||||||
|
type,
|
||||||
|
created_at
|
||||||
|
FROM
|
||||||
|
snapshots
|
||||||
|
WHERE
|
||||||
|
%s
|
||||||
|
AND organization_id = @organization_id
|
||||||
|
AND %s
|
||||||
|
`
|
||||||
|
|
||||||
|
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
|
||||||
|
|
||||||
|
args := pgx.StrictNamedArgs{"organization_id": organizationID}
|
||||||
|
maps.Copy(args, scope.SQLArguments())
|
||||||
|
maps.Copy(args, cursor.SQLArguments())
|
||||||
|
|
||||||
|
rows, err := conn.Query(ctx, q, args)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot query snapshots: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
snapshots, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[Snapshot])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot collect snapshots: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
*s = snapshots
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Snapshot) Insert(
|
||||||
|
ctx context.Context,
|
||||||
|
conn pg.Conn,
|
||||||
|
scope Scoper,
|
||||||
|
) error {
|
||||||
|
q := `
|
||||||
|
INSERT INTO snapshots (
|
||||||
|
id,
|
||||||
|
tenant_id,
|
||||||
|
organization_id,
|
||||||
|
name,
|
||||||
|
description,
|
||||||
|
type,
|
||||||
|
created_at
|
||||||
|
) VALUES (
|
||||||
|
@id,
|
||||||
|
@tenant_id,
|
||||||
|
@organization_id,
|
||||||
|
@name,
|
||||||
|
@description,
|
||||||
|
@type,
|
||||||
|
@created_at
|
||||||
|
)
|
||||||
|
`
|
||||||
|
|
||||||
|
args := pgx.StrictNamedArgs{
|
||||||
|
"id": s.ID,
|
||||||
|
"tenant_id": scope.GetTenantID(),
|
||||||
|
"organization_id": s.OrganizationID,
|
||||||
|
"name": s.Name,
|
||||||
|
"description": s.Description,
|
||||||
|
"type": s.Type,
|
||||||
|
"created_at": s.CreatedAt,
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := conn.Exec(ctx, q, args)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot insert snapshot: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Snapshot) Delete(
|
||||||
|
ctx context.Context,
|
||||||
|
conn pg.Conn,
|
||||||
|
scope Scoper,
|
||||||
|
) error {
|
||||||
|
q := `
|
||||||
|
DELETE FROM snapshots
|
||||||
|
WHERE
|
||||||
|
%s
|
||||||
|
AND organization_id = @organization_id
|
||||||
|
AND id = @id
|
||||||
|
`
|
||||||
|
|
||||||
|
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||||
|
|
||||||
|
args := pgx.StrictNamedArgs{"id": s.ID, "organization_id": s.OrganizationID}
|
||||||
|
maps.Copy(args, scope.SQLArguments())
|
||||||
|
|
||||||
|
_, err := conn.Exec(ctx, q, args)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot delete snapshot: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
51
pkg/coredata/snapshot_order_field.go
Normal file
51
pkg/coredata/snapshot_order_field.go
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
// 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 (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SnapshotOrderField string
|
||||||
|
|
||||||
|
const (
|
||||||
|
SnapshotOrderFieldCreatedAt SnapshotOrderField = "CREATED_AT"
|
||||||
|
SnapshotOrderFieldName SnapshotOrderField = "NAME"
|
||||||
|
SnapshotOrderFieldType SnapshotOrderField = "TYPE"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (p SnapshotOrderField) Column() string {
|
||||||
|
return string(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p SnapshotOrderField) String() string {
|
||||||
|
return string(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p SnapshotOrderField) MarshalText() ([]byte, error) {
|
||||||
|
return []byte(p.String()), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *SnapshotOrderField) UnmarshalText(text []byte) error {
|
||||||
|
val := string(text)
|
||||||
|
switch val {
|
||||||
|
case string(SnapshotOrderFieldCreatedAt),
|
||||||
|
string(SnapshotOrderFieldName),
|
||||||
|
string(SnapshotOrderFieldType):
|
||||||
|
*p = SnapshotOrderField(val)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("invalid SnapshotOrderField value: %q", val)
|
||||||
|
}
|
||||||
71
pkg/coredata/snapshots_type.go
Normal file
71
pkg/coredata/snapshots_type.go
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
// 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 (
|
||||||
|
"database/sql/driver"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
SnapshotsType string
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
SnapshotsTypeRisks SnapshotsType = "RISKS"
|
||||||
|
SnapshotsTypeVendors SnapshotsType = "VENDORS"
|
||||||
|
SnapshotsTypeAssets SnapshotsType = "ASSETS"
|
||||||
|
SnapshotsTypeData SnapshotsType = "DATA"
|
||||||
|
SnapshotsTypeNonConformityRegistries SnapshotsType = "NON_CONFORMITY_REGISTRIES"
|
||||||
|
SnapshotsTypeComplianceRegistries SnapshotsType = "COMPLIANCE_REGISTRIES"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (st SnapshotsType) String() string {
|
||||||
|
return string(st)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (st *SnapshotsType) Scan(value any) error {
|
||||||
|
var s string
|
||||||
|
switch v := value.(type) {
|
||||||
|
case string:
|
||||||
|
s = v
|
||||||
|
case []byte:
|
||||||
|
s = string(v)
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("unsupported type for SnapshotsType: %T", value)
|
||||||
|
}
|
||||||
|
|
||||||
|
switch s {
|
||||||
|
case SnapshotsTypeRisks.String():
|
||||||
|
*st = SnapshotsTypeRisks
|
||||||
|
case SnapshotsTypeVendors.String():
|
||||||
|
*st = SnapshotsTypeVendors
|
||||||
|
case SnapshotsTypeAssets.String():
|
||||||
|
*st = SnapshotsTypeAssets
|
||||||
|
case SnapshotsTypeData.String():
|
||||||
|
*st = SnapshotsTypeData
|
||||||
|
case SnapshotsTypeNonConformityRegistries.String():
|
||||||
|
*st = SnapshotsTypeNonConformityRegistries
|
||||||
|
case SnapshotsTypeComplianceRegistries.String():
|
||||||
|
*st = SnapshotsTypeComplianceRegistries
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("invalid SnapshotsType value: %q", s)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (st SnapshotsType) Value() (driver.Value, error) {
|
||||||
|
return st.String(), nil
|
||||||
|
}
|
||||||
36
pkg/coredata/snapshottable.go
Normal file
36
pkg/coredata/snapshottable.go
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
// 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 (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/getprobo/probo/pkg/gid"
|
||||||
|
"go.gearno.de/kit/pg"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Snapshottable interface {
|
||||||
|
Snapshot(ctx context.Context, conn pg.Conn, scope Scoper, organizationID, snapshotID gid.GID) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetSnapshottable(snapshotType SnapshotsType) (Snapshottable, error) {
|
||||||
|
switch snapshotType {
|
||||||
|
case SnapshotsTypeData:
|
||||||
|
return Data{}, nil
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unsupported snapshot type: %s", snapshotType)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -50,6 +50,8 @@ type (
|
|||||||
SecurityPageURL *string `db:"security_page_url"`
|
SecurityPageURL *string `db:"security_page_url"`
|
||||||
TrustPageURL *string `db:"trust_page_url"`
|
TrustPageURL *string `db:"trust_page_url"`
|
||||||
ShowOnTrustCenter bool `db:"show_on_trust_center"`
|
ShowOnTrustCenter bool `db:"show_on_trust_center"`
|
||||||
|
SnapshotID *gid.GID `db:"snapshot_id"`
|
||||||
|
SourceID *gid.GID `db:"source_id"`
|
||||||
CreatedAt time.Time `db:"created_at"`
|
CreatedAt time.Time `db:"created_at"`
|
||||||
UpdatedAt time.Time `db:"updated_at"`
|
UpdatedAt time.Time `db:"updated_at"`
|
||||||
}
|
}
|
||||||
@@ -100,6 +102,8 @@ SELECT
|
|||||||
security_page_url,
|
security_page_url,
|
||||||
trust_page_url,
|
trust_page_url,
|
||||||
show_on_trust_center,
|
show_on_trust_center,
|
||||||
|
snapshot_id,
|
||||||
|
source_id,
|
||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
FROM
|
FROM
|
||||||
@@ -161,6 +165,8 @@ INSERT INTO
|
|||||||
security_page_url,
|
security_page_url,
|
||||||
trust_page_url,
|
trust_page_url,
|
||||||
show_on_trust_center,
|
show_on_trust_center,
|
||||||
|
snapshot_id,
|
||||||
|
source_id,
|
||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
)
|
)
|
||||||
@@ -187,6 +193,8 @@ VALUES (
|
|||||||
@security_page_url,
|
@security_page_url,
|
||||||
@trust_page_url,
|
@trust_page_url,
|
||||||
@show_on_trust_center,
|
@show_on_trust_center,
|
||||||
|
@snapshot_id,
|
||||||
|
@source_id,
|
||||||
@created_at,
|
@created_at,
|
||||||
@updated_at
|
@updated_at
|
||||||
)
|
)
|
||||||
@@ -215,6 +223,8 @@ VALUES (
|
|||||||
"security_page_url": v.SecurityPageURL,
|
"security_page_url": v.SecurityPageURL,
|
||||||
"trust_page_url": v.TrustPageURL,
|
"trust_page_url": v.TrustPageURL,
|
||||||
"show_on_trust_center": v.ShowOnTrustCenter,
|
"show_on_trust_center": v.ShowOnTrustCenter,
|
||||||
|
"snapshot_id": v.SnapshotID,
|
||||||
|
"source_id": v.SourceID,
|
||||||
"created_at": v.CreatedAt,
|
"created_at": v.CreatedAt,
|
||||||
"updated_at": v.UpdatedAt,
|
"updated_at": v.UpdatedAt,
|
||||||
}
|
}
|
||||||
@@ -304,6 +314,8 @@ SELECT
|
|||||||
security_page_url,
|
security_page_url,
|
||||||
trust_page_url,
|
trust_page_url,
|
||||||
show_on_trust_center,
|
show_on_trust_center,
|
||||||
|
snapshot_id,
|
||||||
|
source_id,
|
||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
FROM
|
FROM
|
||||||
@@ -504,6 +516,8 @@ WITH vend AS (
|
|||||||
v.security_page_url,
|
v.security_page_url,
|
||||||
v.trust_page_url,
|
v.trust_page_url,
|
||||||
v.show_on_trust_center,
|
v.show_on_trust_center,
|
||||||
|
v.snapshot_id,
|
||||||
|
v.source_id,
|
||||||
v.created_at,
|
v.created_at,
|
||||||
v.updated_at
|
v.updated_at
|
||||||
FROM
|
FROM
|
||||||
@@ -536,6 +550,8 @@ SELECT
|
|||||||
security_page_url,
|
security_page_url,
|
||||||
trust_page_url,
|
trust_page_url,
|
||||||
show_on_trust_center,
|
show_on_trust_center,
|
||||||
|
snapshot_id,
|
||||||
|
source_id,
|
||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
FROM
|
FROM
|
||||||
@@ -635,6 +651,8 @@ WITH vend AS (
|
|||||||
v.security_page_url,
|
v.security_page_url,
|
||||||
v.trust_page_url,
|
v.trust_page_url,
|
||||||
v.show_on_trust_center,
|
v.show_on_trust_center,
|
||||||
|
v.snapshot_id,
|
||||||
|
v.source_id,
|
||||||
v.created_at,
|
v.created_at,
|
||||||
v.updated_at
|
v.updated_at
|
||||||
FROM
|
FROM
|
||||||
@@ -667,6 +685,8 @@ SELECT
|
|||||||
security_page_url,
|
security_page_url,
|
||||||
trust_page_url,
|
trust_page_url,
|
||||||
show_on_trust_center,
|
show_on_trust_center,
|
||||||
|
snapshot_id,
|
||||||
|
source_id,
|
||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
FROM
|
FROM
|
||||||
@@ -694,3 +714,103 @@ WHERE %s
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d Vendors) InsertDataSnapshots(
|
||||||
|
ctx context.Context,
|
||||||
|
conn pg.Conn,
|
||||||
|
scope Scoper,
|
||||||
|
organizationID gid.GID,
|
||||||
|
snapshotID gid.GID,
|
||||||
|
) error {
|
||||||
|
query := `
|
||||||
|
WITH
|
||||||
|
source_data AS (
|
||||||
|
SELECT id
|
||||||
|
FROM data
|
||||||
|
WHERE organization_id = @organization_id AND snapshot_id IS NULL
|
||||||
|
),
|
||||||
|
source_data_vendors AS (
|
||||||
|
SELECT datum_id, vendor_id, snapshot_id, created_at
|
||||||
|
FROM data_vendors
|
||||||
|
WHERE datum_id = ANY(SELECT id FROM source_data)
|
||||||
|
),
|
||||||
|
source_vendors AS (
|
||||||
|
SELECT *
|
||||||
|
FROM vendors
|
||||||
|
WHERE %s AND id = ANY(SELECT vendor_id FROM source_data_vendors)
|
||||||
|
)
|
||||||
|
INSERT INTO vendors (
|
||||||
|
tenant_id,
|
||||||
|
id,
|
||||||
|
snapshot_id,
|
||||||
|
source_id,
|
||||||
|
organization_id,
|
||||||
|
name,
|
||||||
|
description,
|
||||||
|
category,
|
||||||
|
headquarter_address,
|
||||||
|
legal_name,
|
||||||
|
website_url,
|
||||||
|
privacy_policy_url,
|
||||||
|
service_level_agreement_url,
|
||||||
|
data_processing_agreement_url,
|
||||||
|
business_associate_agreement_url,
|
||||||
|
subprocessors_list_url,
|
||||||
|
certifications,
|
||||||
|
business_owner_id,
|
||||||
|
security_owner_id,
|
||||||
|
status_page_url,
|
||||||
|
terms_of_service_url,
|
||||||
|
security_page_url,
|
||||||
|
trust_page_url,
|
||||||
|
show_on_trust_center,
|
||||||
|
created_at,
|
||||||
|
updated_at
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
@tenant_id,
|
||||||
|
generate_gid(decode_base64_unpadded(@tenant_id), @vendor_entity_type),
|
||||||
|
@snapshot_id,
|
||||||
|
v.id,
|
||||||
|
v.organization_id,
|
||||||
|
v.name,
|
||||||
|
v.description,
|
||||||
|
v.category,
|
||||||
|
v.headquarter_address,
|
||||||
|
v.legal_name,
|
||||||
|
v.website_url,
|
||||||
|
v.privacy_policy_url,
|
||||||
|
v.service_level_agreement_url,
|
||||||
|
v.data_processing_agreement_url,
|
||||||
|
v.business_associate_agreement_url,
|
||||||
|
v.subprocessors_list_url,
|
||||||
|
v.certifications,
|
||||||
|
v.business_owner_id,
|
||||||
|
v.security_owner_id,
|
||||||
|
v.status_page_url,
|
||||||
|
v.terms_of_service_url,
|
||||||
|
v.security_page_url,
|
||||||
|
v.trust_page_url,
|
||||||
|
v.show_on_trust_center,
|
||||||
|
v.created_at,
|
||||||
|
v.updated_at
|
||||||
|
FROM source_vendors v
|
||||||
|
`
|
||||||
|
|
||||||
|
query = fmt.Sprintf(query, scope.SQLFragment())
|
||||||
|
|
||||||
|
args := pgx.StrictNamedArgs{
|
||||||
|
"tenant_id": scope.GetTenantID(),
|
||||||
|
"snapshot_id": snapshotID,
|
||||||
|
"organization_id": organizationID,
|
||||||
|
"vendor_entity_type": VendorEntityType,
|
||||||
|
}
|
||||||
|
maps.Copy(args, scope.SQLArguments())
|
||||||
|
|
||||||
|
_, err := conn.Exec(ctx, query, args)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot insert vendor snapshots: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,12 +15,14 @@
|
|||||||
package coredata
|
package coredata
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/getprobo/probo/pkg/gid"
|
||||||
"github.com/jackc/pgx/v5"
|
"github.com/jackc/pgx/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
VendorFilter struct {
|
VendorFilter struct {
|
||||||
showOnTrustCenter *bool
|
showOnTrustCenter *bool
|
||||||
|
snapshotID **gid.GID
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -35,20 +37,51 @@ func NewVendorTrustCenterFilter() *VendorFilter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *VendorFilter) SQLArguments() pgx.NamedArgs {
|
func NewVendorFilterBySnapshotID(snapshotID **gid.GID) *VendorFilter {
|
||||||
args := pgx.NamedArgs{}
|
return &VendorFilter{
|
||||||
|
snapshotID: snapshotID,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *VendorFilter) SQLArguments() pgx.StrictNamedArgs {
|
||||||
|
args := pgx.StrictNamedArgs{}
|
||||||
|
|
||||||
if f.showOnTrustCenter != nil {
|
if f.showOnTrustCenter != nil {
|
||||||
args["show_on_trust_center"] = *f.showOnTrustCenter
|
args["show_on_trust_center"] = *f.showOnTrustCenter
|
||||||
|
} else {
|
||||||
|
args["show_on_trust_center"] = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if f.snapshotID == nil {
|
||||||
|
args["has_snapshot_filter"] = false
|
||||||
|
args["filter_snapshot_id"] = nil
|
||||||
|
} else if *f.snapshotID == nil {
|
||||||
|
args["has_snapshot_filter"] = true
|
||||||
|
args["filter_snapshot_id"] = nil
|
||||||
|
} else {
|
||||||
|
args["has_snapshot_filter"] = true
|
||||||
|
args["filter_snapshot_id"] = **f.snapshotID
|
||||||
}
|
}
|
||||||
|
|
||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *VendorFilter) SQLFragment() string {
|
func (f *VendorFilter) SQLFragment() string {
|
||||||
if f.showOnTrustCenter != nil {
|
return `
|
||||||
return "show_on_trust_center = @show_on_trust_center"
|
(
|
||||||
}
|
CASE
|
||||||
|
WHEN @show_on_trust_center::boolean IS NOT NULL THEN
|
||||||
return "TRUE"
|
show_on_trust_center = @show_on_trust_center::boolean
|
||||||
|
ELSE TRUE
|
||||||
|
END
|
||||||
|
AND
|
||||||
|
CASE
|
||||||
|
WHEN @has_snapshot_filter::boolean = false THEN TRUE
|
||||||
|
WHEN @has_snapshot_filter::boolean = true AND @filter_snapshot_id::text IS NOT NULL THEN
|
||||||
|
snapshot_id = @filter_snapshot_id::text
|
||||||
|
WHEN @has_snapshot_filter::boolean = true AND @filter_snapshot_id::text IS NULL THEN
|
||||||
|
snapshot_id IS NULL
|
||||||
|
ELSE TRUE
|
||||||
|
END
|
||||||
|
)`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,6 +115,7 @@ func (s DatumService) ListForOrganizationID(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
organizationID gid.GID,
|
organizationID gid.GID,
|
||||||
cursor *page.Cursor[coredata.DatumOrderField],
|
cursor *page.Cursor[coredata.DatumOrderField],
|
||||||
|
filter *coredata.DatumFilter,
|
||||||
) (*page.Page[*coredata.Datum, coredata.DatumOrderField], error) {
|
) (*page.Page[*coredata.Datum, coredata.DatumOrderField], error) {
|
||||||
var data coredata.Data
|
var data coredata.Data
|
||||||
|
|
||||||
@@ -127,6 +128,7 @@ func (s DatumService) ListForOrganizationID(
|
|||||||
s.svc.scope,
|
s.svc.scope,
|
||||||
organizationID,
|
organizationID,
|
||||||
cursor,
|
cursor,
|
||||||
|
filter,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ type (
|
|||||||
TrustCenterAccesses *TrustCenterAccessService
|
TrustCenterAccesses *TrustCenterAccessService
|
||||||
NonconformityRegistries *NonconformityRegistryService
|
NonconformityRegistries *NonconformityRegistryService
|
||||||
ComplianceRegistries *ComplianceRegistryService
|
ComplianceRegistries *ComplianceRegistryService
|
||||||
|
Snapshots *SnapshotService
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -179,5 +180,6 @@ func (s *Service) WithTenant(tenantID gid.TenantID) *TenantService {
|
|||||||
}
|
}
|
||||||
tenantService.NonconformityRegistries = &NonconformityRegistryService{svc: tenantService}
|
tenantService.NonconformityRegistries = &NonconformityRegistryService{svc: tenantService}
|
||||||
tenantService.ComplianceRegistries = &ComplianceRegistryService{svc: tenantService}
|
tenantService.ComplianceRegistries = &ComplianceRegistryService{svc: tenantService}
|
||||||
|
tenantService.Snapshots = &SnapshotService{svc: tenantService}
|
||||||
return tenantService
|
return tenantService
|
||||||
}
|
}
|
||||||
|
|||||||
186
pkg/probo/snapshot_service.go
Normal file
186
pkg/probo/snapshot_service.go
Normal file
@@ -0,0 +1,186 @@
|
|||||||
|
// 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 probo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/getprobo/probo/pkg/coredata"
|
||||||
|
"github.com/getprobo/probo/pkg/gid"
|
||||||
|
"github.com/getprobo/probo/pkg/page"
|
||||||
|
"go.gearno.de/kit/pg"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SnapshotService struct {
|
||||||
|
svc *TenantService
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
CreateSnapshotRequest struct {
|
||||||
|
OrganizationID gid.GID
|
||||||
|
Name string
|
||||||
|
Description *string
|
||||||
|
Type coredata.SnapshotsType
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateSnapshotRequest struct {
|
||||||
|
ID gid.GID
|
||||||
|
Name *string
|
||||||
|
Description **string
|
||||||
|
Type *coredata.SnapshotsType
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *SnapshotService) Get(
|
||||||
|
ctx context.Context,
|
||||||
|
snapshotID gid.GID,
|
||||||
|
) (*coredata.Snapshot, error) {
|
||||||
|
snapshot := &coredata.Snapshot{}
|
||||||
|
|
||||||
|
err := s.svc.pg.WithConn(
|
||||||
|
ctx,
|
||||||
|
func(conn pg.Conn) error {
|
||||||
|
return snapshot.LoadByID(ctx, conn, s.svc.scope, snapshotID)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return snapshot, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SnapshotService) Create(
|
||||||
|
ctx context.Context,
|
||||||
|
req *CreateSnapshotRequest,
|
||||||
|
) (*coredata.Snapshot, error) {
|
||||||
|
now := time.Now()
|
||||||
|
|
||||||
|
snapshot := &coredata.Snapshot{
|
||||||
|
ID: gid.New(s.svc.scope.GetTenantID(), coredata.SnapshotEntityType),
|
||||||
|
OrganizationID: req.OrganizationID,
|
||||||
|
Name: req.Name,
|
||||||
|
Description: req.Description,
|
||||||
|
Type: req.Type,
|
||||||
|
CreatedAt: now,
|
||||||
|
}
|
||||||
|
|
||||||
|
err := s.svc.pg.WithTx(
|
||||||
|
ctx,
|
||||||
|
func(conn pg.Conn) error {
|
||||||
|
organization := &coredata.Organization{}
|
||||||
|
if err := organization.LoadByID(ctx, conn, s.svc.scope, req.OrganizationID); err != nil {
|
||||||
|
return fmt.Errorf("cannot load organization: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := snapshot.Insert(ctx, conn, s.svc.scope); err != nil {
|
||||||
|
return fmt.Errorf("cannot insert snapshot: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
snapshottable, err := coredata.GetSnapshottable(req.Type)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := snapshottable.Snapshot(ctx, conn, s.svc.scope, req.OrganizationID, snapshot.ID); err != nil {
|
||||||
|
return fmt.Errorf("cannot create snapshot: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return snapshot, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SnapshotService) Delete(
|
||||||
|
ctx context.Context,
|
||||||
|
snapshotID gid.GID,
|
||||||
|
) error {
|
||||||
|
err := s.svc.pg.WithConn(
|
||||||
|
ctx,
|
||||||
|
func(conn pg.Conn) error {
|
||||||
|
snapshot := &coredata.Snapshot{}
|
||||||
|
if err := snapshot.LoadByID(ctx, conn, s.svc.scope, snapshotID); err != nil {
|
||||||
|
return fmt.Errorf("cannot load snapshot: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := snapshot.Delete(ctx, conn, s.svc.scope); err != nil {
|
||||||
|
return fmt.Errorf("cannot delete snapshot: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SnapshotService) ListForOrganizationID(
|
||||||
|
ctx context.Context,
|
||||||
|
organizationID gid.GID,
|
||||||
|
cursor *page.Cursor[coredata.SnapshotOrderField],
|
||||||
|
) (*page.Page[*coredata.Snapshot, coredata.SnapshotOrderField], error) {
|
||||||
|
snapshots := coredata.Snapshots{}
|
||||||
|
|
||||||
|
err := s.svc.pg.WithConn(
|
||||||
|
ctx,
|
||||||
|
func(conn pg.Conn) error {
|
||||||
|
if err := snapshots.LoadByOrganizationID(ctx, conn, s.svc.scope, organizationID, cursor); err != nil {
|
||||||
|
return fmt.Errorf("cannot load snapshots: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return page.NewPage(snapshots, cursor), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SnapshotService) CountForOrganizationID(
|
||||||
|
ctx context.Context,
|
||||||
|
organizationID gid.GID,
|
||||||
|
) (int, error) {
|
||||||
|
var count int
|
||||||
|
|
||||||
|
err := s.svc.pg.WithConn(
|
||||||
|
ctx,
|
||||||
|
func(conn pg.Conn) (err error) {
|
||||||
|
snapshots := coredata.Snapshots{}
|
||||||
|
count, err = snapshots.CountByOrganizationID(ctx, conn, s.svc.scope, organizationID)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot count snapshots: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return count, nil
|
||||||
|
}
|
||||||
@@ -120,6 +120,7 @@ func (s VendorService) ListForOrganizationID(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
organizationID gid.GID,
|
organizationID gid.GID,
|
||||||
cursor *page.Cursor[coredata.VendorOrderField],
|
cursor *page.Cursor[coredata.VendorOrderField],
|
||||||
|
filter *coredata.VendorFilter,
|
||||||
) (*page.Page[*coredata.Vendor, coredata.VendorOrderField], error) {
|
) (*page.Page[*coredata.Vendor, coredata.VendorOrderField], error) {
|
||||||
var vendors coredata.Vendors
|
var vendors coredata.Vendors
|
||||||
organization := &coredata.Organization{}
|
organization := &coredata.Organization{}
|
||||||
@@ -131,7 +132,6 @@ func (s VendorService) ListForOrganizationID(
|
|||||||
return fmt.Errorf("cannot load organization: %w", err)
|
return fmt.Errorf("cannot load organization: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
filter := coredata.NewVendorFilter()
|
|
||||||
return vendors.LoadByOrganizationID(
|
return vendors.LoadByOrganizationID(
|
||||||
ctx,
|
ctx,
|
||||||
conn,
|
conn,
|
||||||
|
|||||||
@@ -686,6 +686,50 @@ enum TrustCenterAccessOrderField
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum SnapshotsType
|
||||||
|
@goModel(model: "github.com/getprobo/probo/pkg/coredata.SnapshotsType") {
|
||||||
|
RISKS
|
||||||
|
@goEnum(
|
||||||
|
value: "github.com/getprobo/probo/pkg/coredata.SnapshotsTypeRisks"
|
||||||
|
)
|
||||||
|
VENDORS
|
||||||
|
@goEnum(
|
||||||
|
value: "github.com/getprobo/probo/pkg/coredata.SnapshotsTypeVendors"
|
||||||
|
)
|
||||||
|
ASSETS
|
||||||
|
@goEnum(
|
||||||
|
value: "github.com/getprobo/probo/pkg/coredata.SnapshotsTypeAssets"
|
||||||
|
)
|
||||||
|
DATA
|
||||||
|
@goEnum(
|
||||||
|
value: "github.com/getprobo/probo/pkg/coredata.SnapshotsTypeData"
|
||||||
|
)
|
||||||
|
NON_CONFORMITY_REGISTRIES
|
||||||
|
@goEnum(
|
||||||
|
value: "github.com/getprobo/probo/pkg/coredata.SnapshotsTypeNonConformityRegistries"
|
||||||
|
)
|
||||||
|
COMPLIANCE_REGISTRIES
|
||||||
|
@goEnum(
|
||||||
|
value: "github.com/getprobo/probo/pkg/coredata.SnapshotsTypeComplianceRegistries"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
enum SnapshotOrderField
|
||||||
|
@goModel(model: "github.com/getprobo/probo/pkg/coredata.SnapshotOrderField") {
|
||||||
|
CREATED_AT
|
||||||
|
@goEnum(
|
||||||
|
value: "github.com/getprobo/probo/pkg/coredata.SnapshotOrderFieldCreatedAt"
|
||||||
|
)
|
||||||
|
NAME
|
||||||
|
@goEnum(
|
||||||
|
value: "github.com/getprobo/probo/pkg/coredata.SnapshotOrderFieldName"
|
||||||
|
)
|
||||||
|
TYPE
|
||||||
|
@goEnum(
|
||||||
|
value: "github.com/getprobo/probo/pkg/coredata.SnapshotOrderFieldType"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
# Input Types
|
# Input Types
|
||||||
input UserOrder
|
input UserOrder
|
||||||
@goModel(
|
@goModel(
|
||||||
@@ -841,6 +885,14 @@ input DocumentVersionOrder
|
|||||||
field: DocumentVersionOrderField!
|
field: DocumentVersionOrderField!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input SnapshotOrder
|
||||||
|
@goModel(
|
||||||
|
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.SnapshotOrderBy"
|
||||||
|
) {
|
||||||
|
direction: OrderDirection!
|
||||||
|
field: SnapshotOrderField!
|
||||||
|
}
|
||||||
|
|
||||||
input DocumentVersionFilter {
|
input DocumentVersionFilter {
|
||||||
status: DocumentStatus
|
status: DocumentStatus
|
||||||
}
|
}
|
||||||
@@ -874,6 +926,10 @@ input TrustCenterFilter {
|
|||||||
slug: String
|
slug: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input DatumFilter {
|
||||||
|
snapshotId: ID
|
||||||
|
}
|
||||||
|
|
||||||
# Core Types
|
# Core Types
|
||||||
type TrustCenter implements Node {
|
type TrustCenter implements Node {
|
||||||
id: ID!
|
id: ID!
|
||||||
@@ -996,6 +1052,7 @@ type Organization implements Node {
|
|||||||
last: Int
|
last: Int
|
||||||
before: CursorKey
|
before: CursorKey
|
||||||
orderBy: DatumOrder
|
orderBy: DatumOrder
|
||||||
|
filter: DatumFilter
|
||||||
): DatumConnection! @goField(forceResolver: true)
|
): DatumConnection! @goField(forceResolver: true)
|
||||||
|
|
||||||
audits(
|
audits(
|
||||||
@@ -1022,6 +1079,14 @@ type Organization implements Node {
|
|||||||
orderBy: ComplianceRegistryOrder
|
orderBy: ComplianceRegistryOrder
|
||||||
): ComplianceRegistryConnection! @goField(forceResolver: true)
|
): ComplianceRegistryConnection! @goField(forceResolver: true)
|
||||||
|
|
||||||
|
snapshots(
|
||||||
|
first: Int
|
||||||
|
after: CursorKey
|
||||||
|
last: Int
|
||||||
|
before: CursorKey
|
||||||
|
orderBy: SnapshotOrder
|
||||||
|
): SnapshotConnection! @goField(forceResolver: true)
|
||||||
|
|
||||||
trustCenter: TrustCenter @goField(forceResolver: true)
|
trustCenter: TrustCenter @goField(forceResolver: true)
|
||||||
|
|
||||||
createdAt: Datetime!
|
createdAt: Datetime!
|
||||||
@@ -1466,6 +1531,15 @@ type ComplianceRegistry implements Node {
|
|||||||
updatedAt: Datetime!
|
updatedAt: Datetime!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Snapshot implements Node {
|
||||||
|
id: ID!
|
||||||
|
organization: Organization! @goField(forceResolver: true)
|
||||||
|
name: String!
|
||||||
|
description: String
|
||||||
|
type: SnapshotsType!
|
||||||
|
createdAt: Datetime!
|
||||||
|
}
|
||||||
|
|
||||||
type Report implements Node {
|
type Report implements Node {
|
||||||
id: ID!
|
id: ID!
|
||||||
objectKey: String!
|
objectKey: String!
|
||||||
@@ -1788,6 +1862,20 @@ type ComplianceRegistryEdge {
|
|||||||
node: ComplianceRegistry!
|
node: ComplianceRegistry!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SnapshotConnection
|
||||||
|
@goModel(
|
||||||
|
model: "github.com/getprobo/probo/pkg/server/api/console/v1/types.SnapshotConnection"
|
||||||
|
) {
|
||||||
|
totalCount: Int! @goField(forceResolver: true)
|
||||||
|
edges: [SnapshotEdge!]!
|
||||||
|
pageInfo: PageInfo!
|
||||||
|
}
|
||||||
|
|
||||||
|
type SnapshotEdge {
|
||||||
|
cursor: CursorKey!
|
||||||
|
node: Snapshot!
|
||||||
|
}
|
||||||
|
|
||||||
# Root Types
|
# Root Types
|
||||||
type Query {
|
type Query {
|
||||||
node(id: ID!): Node!
|
node(id: ID!): Node!
|
||||||
@@ -2038,6 +2126,10 @@ type Mutation {
|
|||||||
deleteComplianceRegistry(
|
deleteComplianceRegistry(
|
||||||
input: DeleteComplianceRegistryInput!
|
input: DeleteComplianceRegistryInput!
|
||||||
): DeleteComplianceRegistryPayload!
|
): DeleteComplianceRegistryPayload!
|
||||||
|
|
||||||
|
# Snapshot mutations
|
||||||
|
createSnapshot(input: CreateSnapshotInput!): CreateSnapshotPayload!
|
||||||
|
deleteSnapshot(input: DeleteSnapshotInput!): DeleteSnapshotPayload!
|
||||||
}
|
}
|
||||||
|
|
||||||
# Input Types
|
# Input Types
|
||||||
@@ -2593,6 +2685,17 @@ input DeleteComplianceRegistryInput {
|
|||||||
complianceRegistryId: ID!
|
complianceRegistryId: ID!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input CreateSnapshotInput {
|
||||||
|
organizationId: ID!
|
||||||
|
name: String!
|
||||||
|
description: String
|
||||||
|
type: SnapshotsType!
|
||||||
|
}
|
||||||
|
|
||||||
|
input DeleteSnapshotInput {
|
||||||
|
snapshotId: ID!
|
||||||
|
}
|
||||||
|
|
||||||
# Payload Types
|
# Payload Types
|
||||||
type CreateOrganizationPayload {
|
type CreateOrganizationPayload {
|
||||||
organizationEdge: OrganizationEdge!
|
organizationEdge: OrganizationEdge!
|
||||||
@@ -3302,3 +3405,11 @@ type UpdateComplianceRegistryPayload {
|
|||||||
type DeleteComplianceRegistryPayload {
|
type DeleteComplianceRegistryPayload {
|
||||||
deletedComplianceRegistryId: ID!
|
deletedComplianceRegistryId: ID!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CreateSnapshotPayload {
|
||||||
|
snapshotEdge: SnapshotEdge!
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeleteSnapshotPayload {
|
||||||
|
deletedSnapshotId: ID!
|
||||||
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
70
pkg/server/api/console/v1/types/snapshot.go
Normal file
70
pkg/server/api/console/v1/types/snapshot.go
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
// 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 types
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/getprobo/probo/pkg/coredata"
|
||||||
|
"github.com/getprobo/probo/pkg/gid"
|
||||||
|
"github.com/getprobo/probo/pkg/page"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
SnapshotOrderBy OrderBy[coredata.SnapshotOrderField]
|
||||||
|
|
||||||
|
SnapshotConnection struct {
|
||||||
|
TotalCount int
|
||||||
|
Edges []*SnapshotEdge
|
||||||
|
PageInfo PageInfo
|
||||||
|
|
||||||
|
Resolver any
|
||||||
|
ParentID gid.GID
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewSnapshotConnection(
|
||||||
|
p *page.Page[*coredata.Snapshot, coredata.SnapshotOrderField],
|
||||||
|
parentType any,
|
||||||
|
parentID gid.GID,
|
||||||
|
) *SnapshotConnection {
|
||||||
|
edges := make([]*SnapshotEdge, len(p.Data))
|
||||||
|
for i, snapshot := range p.Data {
|
||||||
|
edges[i] = NewSnapshotEdge(snapshot, p.Cursor.OrderBy.Field)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &SnapshotConnection{
|
||||||
|
Edges: edges,
|
||||||
|
PageInfo: *NewPageInfo(p),
|
||||||
|
|
||||||
|
Resolver: parentType,
|
||||||
|
ParentID: parentID,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSnapshot(s *coredata.Snapshot) *Snapshot {
|
||||||
|
return &Snapshot{
|
||||||
|
ID: s.ID,
|
||||||
|
Name: s.Name,
|
||||||
|
Type: s.Type,
|
||||||
|
Description: s.Description,
|
||||||
|
CreatedAt: s.CreatedAt,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSnapshotEdge(s *coredata.Snapshot, orderField coredata.SnapshotOrderField) *SnapshotEdge {
|
||||||
|
return &SnapshotEdge{
|
||||||
|
Node: NewSnapshot(s),
|
||||||
|
Cursor: s.CursorKey(orderField),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -430,6 +430,17 @@ type CreateRiskPayload struct {
|
|||||||
RiskEdge *RiskEdge `json:"riskEdge"`
|
RiskEdge *RiskEdge `json:"riskEdge"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CreateSnapshotInput struct {
|
||||||
|
OrganizationID gid.GID `json:"organizationId"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Description *string `json:"description,omitempty"`
|
||||||
|
Type coredata.SnapshotsType `json:"type"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreateSnapshotPayload struct {
|
||||||
|
SnapshotEdge *SnapshotEdge `json:"snapshotEdge"`
|
||||||
|
}
|
||||||
|
|
||||||
type CreateTaskInput struct {
|
type CreateTaskInput struct {
|
||||||
OrganizationID gid.GID `json:"organizationId"`
|
OrganizationID gid.GID `json:"organizationId"`
|
||||||
MeasureID *gid.GID `json:"measureId,omitempty"`
|
MeasureID *gid.GID `json:"measureId,omitempty"`
|
||||||
@@ -537,6 +548,10 @@ type DatumEdge struct {
|
|||||||
Node *Datum `json:"node"`
|
Node *Datum `json:"node"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DatumFilter struct {
|
||||||
|
SnapshotID *gid.GID `json:"snapshotId,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type DeleteAssetInput struct {
|
type DeleteAssetInput struct {
|
||||||
AssetID gid.GID `json:"assetId"`
|
AssetID gid.GID `json:"assetId"`
|
||||||
}
|
}
|
||||||
@@ -707,6 +722,14 @@ type DeleteRiskPayload struct {
|
|||||||
DeletedRiskID gid.GID `json:"deletedRiskId"`
|
DeletedRiskID gid.GID `json:"deletedRiskId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DeleteSnapshotInput struct {
|
||||||
|
SnapshotID gid.GID `json:"snapshotId"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeleteSnapshotPayload struct {
|
||||||
|
DeletedSnapshotID gid.GID `json:"deletedSnapshotId"`
|
||||||
|
}
|
||||||
|
|
||||||
type DeleteTaskInput struct {
|
type DeleteTaskInput struct {
|
||||||
TaskID gid.GID `json:"taskId"`
|
TaskID gid.GID `json:"taskId"`
|
||||||
}
|
}
|
||||||
@@ -1039,6 +1062,7 @@ type Organization struct {
|
|||||||
Audits *AuditConnection `json:"audits"`
|
Audits *AuditConnection `json:"audits"`
|
||||||
NonconformityRegistries *NonconformityRegistryConnection `json:"nonconformityRegistries"`
|
NonconformityRegistries *NonconformityRegistryConnection `json:"nonconformityRegistries"`
|
||||||
ComplianceRegistries *ComplianceRegistryConnection `json:"complianceRegistries"`
|
ComplianceRegistries *ComplianceRegistryConnection `json:"complianceRegistries"`
|
||||||
|
Snapshots *SnapshotConnection `json:"snapshots"`
|
||||||
TrustCenter *TrustCenter `json:"trustCenter,omitempty"`
|
TrustCenter *TrustCenter `json:"trustCenter,omitempty"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
UpdatedAt time.Time `json:"updatedAt"`
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
@@ -1201,6 +1225,23 @@ type Session struct {
|
|||||||
ExpiresAt time.Time `json:"expiresAt"`
|
ExpiresAt time.Time `json:"expiresAt"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Snapshot struct {
|
||||||
|
ID gid.GID `json:"id"`
|
||||||
|
Organization *Organization `json:"organization"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Description *string `json:"description,omitempty"`
|
||||||
|
Type coredata.SnapshotsType `json:"type"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Snapshot) IsNode() {}
|
||||||
|
func (this Snapshot) GetID() gid.GID { return this.ID }
|
||||||
|
|
||||||
|
type SnapshotEdge struct {
|
||||||
|
Cursor page.CursorKey `json:"cursor"`
|
||||||
|
Node *Snapshot `json:"node"`
|
||||||
|
}
|
||||||
|
|
||||||
type Task struct {
|
type Task struct {
|
||||||
ID gid.GID `json:"id"`
|
ID gid.GID `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|||||||
@@ -2995,6 +2995,38 @@ func (r *mutationResolver) DeleteComplianceRegistry(ctx context.Context, input t
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateSnapshot is the resolver for the createSnapshot field.
|
||||||
|
func (r *mutationResolver) CreateSnapshot(ctx context.Context, input types.CreateSnapshotInput) (*types.CreateSnapshotPayload, error) {
|
||||||
|
prb := r.ProboService(ctx, input.OrganizationID.TenantID())
|
||||||
|
|
||||||
|
snapshot, err := prb.Snapshots.Create(ctx, &probo.CreateSnapshotRequest{
|
||||||
|
OrganizationID: input.OrganizationID,
|
||||||
|
Name: input.Name,
|
||||||
|
Description: input.Description,
|
||||||
|
Type: input.Type,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("cannot create snapshot: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.CreateSnapshotPayload{
|
||||||
|
SnapshotEdge: types.NewSnapshotEdge(snapshot, coredata.SnapshotOrderFieldCreatedAt),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteSnapshot is the resolver for the deleteSnapshot field.
|
||||||
|
func (r *mutationResolver) DeleteSnapshot(ctx context.Context, input types.DeleteSnapshotInput) (*types.DeleteSnapshotPayload, error) {
|
||||||
|
prb := r.ProboService(ctx, input.SnapshotID.TenantID())
|
||||||
|
|
||||||
|
if err := prb.Snapshots.Delete(ctx, input.SnapshotID); err != nil {
|
||||||
|
panic(fmt.Errorf("cannot delete snapshot: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.DeleteSnapshotPayload{
|
||||||
|
DeletedSnapshotID: input.SnapshotID,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Organization is the resolver for the organization field.
|
// Organization is the resolver for the organization field.
|
||||||
func (r *nonconformityRegistryResolver) Organization(ctx context.Context, obj *types.NonconformityRegistry) (*types.Organization, error) {
|
func (r *nonconformityRegistryResolver) Organization(ctx context.Context, obj *types.NonconformityRegistry) (*types.Organization, error) {
|
||||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||||
@@ -3188,8 +3220,10 @@ func (r *organizationResolver) Vendors(ctx context.Context, obj *types.Organizat
|
|||||||
}
|
}
|
||||||
|
|
||||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||||
|
var nilSnapshotID *gid.GID = nil
|
||||||
|
vendorFilter := coredata.NewVendorFilterBySnapshotID(&nilSnapshotID)
|
||||||
|
|
||||||
page, err := prb.Vendors.ListForOrganizationID(ctx, obj.ID, cursor)
|
page, err := prb.Vendors.ListForOrganizationID(ctx, obj.ID, cursor, vendorFilter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Errorf("cannot list organization vendors: %w", err))
|
panic(fmt.Errorf("cannot list organization vendors: %w", err))
|
||||||
}
|
}
|
||||||
@@ -3368,7 +3402,7 @@ func (r *organizationResolver) Assets(ctx context.Context, obj *types.Organizati
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Assets is the resolver for the assets field.
|
// Assets is the resolver for the assets field.
|
||||||
func (r *organizationResolver) Data(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.DatumOrderBy) (*types.DatumConnection, error) {
|
func (r *organizationResolver) 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) {
|
||||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||||
|
|
||||||
pageOrderBy := page.OrderBy[coredata.DatumOrderField]{
|
pageOrderBy := page.OrderBy[coredata.DatumOrderField]{
|
||||||
@@ -3384,7 +3418,12 @@ func (r *organizationResolver) Data(ctx context.Context, obj *types.Organization
|
|||||||
|
|
||||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||||
|
|
||||||
page, err := prb.Data.ListForOrganizationID(ctx, obj.ID, cursor)
|
datumFilter := coredata.NewDatumFilterBySnapshotID(nil)
|
||||||
|
if filter != nil {
|
||||||
|
datumFilter = coredata.NewDatumFilterBySnapshotID(&filter.SnapshotID)
|
||||||
|
}
|
||||||
|
|
||||||
|
page, err := prb.Data.ListForOrganizationID(ctx, obj.ID, cursor, datumFilter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Errorf("cannot list organization data: %w", err))
|
panic(fmt.Errorf("cannot list organization data: %w", err))
|
||||||
}
|
}
|
||||||
@@ -3467,6 +3506,31 @@ func (r *organizationResolver) ComplianceRegistries(ctx context.Context, obj *ty
|
|||||||
return types.NewComplianceRegistryConnection(page, r, obj.ID), nil
|
return types.NewComplianceRegistryConnection(page, r, obj.ID), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Snapshots is the resolver for the snapshots field.
|
||||||
|
func (r *organizationResolver) Snapshots(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.SnapshotOrderBy) (*types.SnapshotConnection, error) {
|
||||||
|
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||||
|
|
||||||
|
pageOrderBy := page.OrderBy[coredata.SnapshotOrderField]{
|
||||||
|
Field: coredata.SnapshotOrderFieldCreatedAt,
|
||||||
|
Direction: page.OrderDirectionDesc,
|
||||||
|
}
|
||||||
|
if orderBy != nil {
|
||||||
|
pageOrderBy = page.OrderBy[coredata.SnapshotOrderField]{
|
||||||
|
Field: orderBy.Field,
|
||||||
|
Direction: orderBy.Direction,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||||
|
|
||||||
|
page, err := prb.Snapshots.ListForOrganizationID(ctx, obj.ID, cursor)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("cannot list organization snapshots: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
return types.NewSnapshotConnection(page, r, obj.ID), nil
|
||||||
|
}
|
||||||
|
|
||||||
// TrustCenter is the resolver for the trustCenter field.
|
// TrustCenter is the resolver for the trustCenter field.
|
||||||
func (r *organizationResolver) TrustCenter(ctx context.Context, obj *types.Organization) (*types.TrustCenter, error) {
|
func (r *organizationResolver) TrustCenter(ctx context.Context, obj *types.Organization) (*types.TrustCenter, error) {
|
||||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||||
@@ -3634,6 +3698,12 @@ func (r *queryResolver) Node(ctx context.Context, id gid.GID) (types.Node, error
|
|||||||
panic(fmt.Errorf("cannot get report: %w", err))
|
panic(fmt.Errorf("cannot get report: %w", err))
|
||||||
}
|
}
|
||||||
return types.NewReport(report), nil
|
return types.NewReport(report), nil
|
||||||
|
case coredata.SnapshotEntityType:
|
||||||
|
snapshot, err := prb.Snapshots.Get(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("cannot get snapshot: %w", err))
|
||||||
|
}
|
||||||
|
return types.NewSnapshot(snapshot), nil
|
||||||
case coredata.TrustCenterEntityType:
|
case coredata.TrustCenterEntityType:
|
||||||
trustCenter, err := prb.TrustCenters.Get(ctx, id)
|
trustCenter, err := prb.TrustCenters.Get(ctx, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -3823,6 +3893,39 @@ func (r *riskConnectionResolver) TotalCount(ctx context.Context, obj *types.Risk
|
|||||||
panic(fmt.Errorf("unsupported resolver: %T", obj.Resolver))
|
panic(fmt.Errorf("unsupported resolver: %T", obj.Resolver))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Organization is the resolver for the organization field.
|
||||||
|
func (r *snapshotResolver) Organization(ctx context.Context, obj *types.Snapshot) (*types.Organization, error) {
|
||||||
|
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||||
|
|
||||||
|
snapshot, err := prb.Snapshots.Get(ctx, obj.ID)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("cannot get snapshot: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
organization, err := prb.Organizations.Get(ctx, snapshot.OrganizationID)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("cannot get organization: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
return types.NewOrganization(organization), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// TotalCount is the resolver for the totalCount field.
|
||||||
|
func (r *snapshotConnectionResolver) TotalCount(ctx context.Context, obj *types.SnapshotConnection) (int, error) {
|
||||||
|
prb := r.ProboService(ctx, obj.ParentID.TenantID())
|
||||||
|
|
||||||
|
switch obj.Resolver.(type) {
|
||||||
|
case *organizationResolver:
|
||||||
|
count, err := prb.Snapshots.CountForOrganizationID(ctx, obj.ParentID)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("cannot count snapshots: %w", err))
|
||||||
|
}
|
||||||
|
return count, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
panic(fmt.Errorf("unsupported resolver: %T", obj.Resolver))
|
||||||
|
}
|
||||||
|
|
||||||
// AssignedTo is the resolver for the assignedTo field.
|
// AssignedTo is the resolver for the assignedTo field.
|
||||||
func (r *taskResolver) AssignedTo(ctx context.Context, obj *types.Task) (*types.People, error) {
|
func (r *taskResolver) AssignedTo(ctx context.Context, obj *types.Task) (*types.People, error) {
|
||||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||||
@@ -4470,6 +4573,14 @@ func (r *Resolver) Risk() schema.RiskResolver { return &riskResolver{r} }
|
|||||||
// RiskConnection returns schema.RiskConnectionResolver implementation.
|
// RiskConnection returns schema.RiskConnectionResolver implementation.
|
||||||
func (r *Resolver) RiskConnection() schema.RiskConnectionResolver { return &riskConnectionResolver{r} }
|
func (r *Resolver) RiskConnection() schema.RiskConnectionResolver { return &riskConnectionResolver{r} }
|
||||||
|
|
||||||
|
// Snapshot returns schema.SnapshotResolver implementation.
|
||||||
|
func (r *Resolver) Snapshot() schema.SnapshotResolver { return &snapshotResolver{r} }
|
||||||
|
|
||||||
|
// SnapshotConnection returns schema.SnapshotConnectionResolver implementation.
|
||||||
|
func (r *Resolver) SnapshotConnection() schema.SnapshotConnectionResolver {
|
||||||
|
return &snapshotConnectionResolver{r}
|
||||||
|
}
|
||||||
|
|
||||||
// Task returns schema.TaskResolver implementation.
|
// Task returns schema.TaskResolver implementation.
|
||||||
func (r *Resolver) Task() schema.TaskResolver { return &taskResolver{r} }
|
func (r *Resolver) Task() schema.TaskResolver { return &taskResolver{r} }
|
||||||
|
|
||||||
@@ -4548,6 +4659,8 @@ type queryResolver struct{ *Resolver }
|
|||||||
type reportResolver struct{ *Resolver }
|
type reportResolver struct{ *Resolver }
|
||||||
type riskResolver struct{ *Resolver }
|
type riskResolver struct{ *Resolver }
|
||||||
type riskConnectionResolver struct{ *Resolver }
|
type riskConnectionResolver struct{ *Resolver }
|
||||||
|
type snapshotResolver struct{ *Resolver }
|
||||||
|
type snapshotConnectionResolver struct{ *Resolver }
|
||||||
type taskResolver struct{ *Resolver }
|
type taskResolver struct{ *Resolver }
|
||||||
type taskConnectionResolver struct{ *Resolver }
|
type taskConnectionResolver struct{ *Resolver }
|
||||||
type trustCenterResolver struct{ *Resolver }
|
type trustCenterResolver struct{ *Resolver }
|
||||||
|
|||||||
Reference in New Issue
Block a user