From 71ea84beea889a2518f4f7e2e49dd772e9c5ca06 Mon Sep 17 00:00:00 2001 From: Dinika Saxena Date: Tue, 20 Feb 2024 17:28:48 +0100 Subject: [PATCH] Remove metadata when updating studios or workspaces Signed-off-by: Dinika Saxena --- src/shared/containers/DataTableContainer.tsx | 3 ++- src/subapps/studioLegacy/containers/StudioContainer.tsx | 6 +++++- .../studioLegacy/containers/WorkspaceFormContainer.tsx | 3 ++- .../studioLegacy/containers/WorkspaceMenuContainer.tsx | 9 +++++---- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/shared/containers/DataTableContainer.tsx b/src/shared/containers/DataTableContainer.tsx index 779d139ac..69a85f2a4 100644 --- a/src/shared/containers/DataTableContainer.tsx +++ b/src/shared/containers/DataTableContainer.tsx @@ -37,6 +37,7 @@ import { DataPanelEvent, } from '../organisms/DataPanel/DataPanel'; import { TResourceTableData } from '../molecules/MyDataTable/MyDataTable'; +import { resourceWithoutMetadata } from '../../subapps/studioLegacy/containers/StudioContainer'; export type TableColumn = { '@type': string; @@ -290,7 +291,7 @@ const DataTableContainer: React.FC = ({ projectLabel, encodeURIComponent(data['@id']), latest._rev, - { ...latest, ...data } + { ...resourceWithoutMetadata(latest), ...resourceWithoutMetadata(data) } ); } const resource = await nexus.Resource.create(orgLabel, projectLabel, data); diff --git a/src/subapps/studioLegacy/containers/StudioContainer.tsx b/src/subapps/studioLegacy/containers/StudioContainer.tsx index edc1ae343..f886c408c 100644 --- a/src/subapps/studioLegacy/containers/StudioContainer.tsx +++ b/src/subapps/studioLegacy/containers/StudioContainer.tsx @@ -16,6 +16,10 @@ import useNotification, { parseNexusError, } from '../../../shared/hooks/useNotification'; +export const resourceWithoutMetadata = ( + studioResource: StudioResource | Resource +) => omitBy(studioResource, (_, key) => key.trim().startsWith('_')); + const resourcesWritePermissionsWrapper = ( child: React.ReactNode, permissionPath: string @@ -118,7 +122,7 @@ const StudioContainer: React.FunctionComponent = () => { { // remove the metadata from the payload, delta do full update // and not accept the metadata fields to be in the payload - ...omitBy(studioResource, (_, key) => key.trim().startsWith('_')), + ...resourceWithoutMetadata(studioResource), label, description, plugins, diff --git a/src/subapps/studioLegacy/containers/WorkspaceFormContainer.tsx b/src/subapps/studioLegacy/containers/WorkspaceFormContainer.tsx index 824c099e3..eb7c22fe3 100644 --- a/src/subapps/studioLegacy/containers/WorkspaceFormContainer.tsx +++ b/src/subapps/studioLegacy/containers/WorkspaceFormContainer.tsx @@ -19,6 +19,7 @@ import { } from 'antd'; import TextArea from 'antd/lib/input/TextArea'; import useNotification from '../../../shared/hooks/useNotification'; +import { resourceWithoutMetadata } from './StudioContainer'; type NexusSparqlError = { reason: string; @@ -123,7 +124,7 @@ const WorkspaceForm: React.FunctionComponent = ({ projectLabel, encodeURIComponent(workspace['@id']), workspace['_rev'], - newWorkspace + resourceWithoutMetadata(newWorkspace) ) .then(result => { if (onSuccess) { diff --git a/src/subapps/studioLegacy/containers/WorkspaceMenuContainer.tsx b/src/subapps/studioLegacy/containers/WorkspaceMenuContainer.tsx index 06f471955..489346073 100644 --- a/src/subapps/studioLegacy/containers/WorkspaceMenuContainer.tsx +++ b/src/subapps/studioLegacy/containers/WorkspaceMenuContainer.tsx @@ -11,7 +11,7 @@ import { import PromisePool from '@supercharge/promise-pool'; import { ItemType } from 'antd/lib/menu/hooks/useItems'; import { useQuery } from 'react-query'; -import { find, orderBy } from 'lodash'; +import { find, omitBy, orderBy } from 'lodash'; import useNotification from '../../../shared/hooks/useNotification'; import EditTableForm from '../../../shared/components/EditTableForm'; import DashboardEditorContainer from './DashBoardEditor/DashboardEditorContainer'; @@ -30,6 +30,7 @@ import STUDIO_CONTEXT from '../components/StudioContext'; import { createTableContext } from '../../../subapps/projects/utils/workFlowMetadataUtils'; import { ErrorComponent } from '../../../shared/components/ErrorComponent'; import '../studio.less'; +import { resourceWithoutMetadata } from './StudioContainer'; const DASHBOARD_TYPE = 'StudioDashboard'; @@ -484,18 +485,18 @@ const WorkspaceMenu: React.FC = ({ data: TableResource | UnsavedTableResource ) => { if (selectedDashboard) { - const resource = await nexus.Resource.get( + const resource = (await nexus.Resource.get( orgLabel, projectLabel, encodeURIComponent(selectedDashboard['@id']) - ); + )) as StudioResource; await nexus.Resource.update( orgLabel, projectLabel, encodeURIComponent(selectedDashboard['@id']), selectedDashboard._rev, { - ...resource, + ...resourceWithoutMetadata(resource), description: data.description, label: data['name'], }