Skip to content

Commit

Permalink
Merge pull request #1500 from BlueBrain/fix-studio-and-workspace-edits
Browse files Browse the repository at this point in the history
Remove metadata when updating studios or workspaces
  • Loading branch information
Dinika authored Feb 21, 2024
2 parents c7e4c8c + 71ea84b commit f0bd16c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/shared/containers/DataTableContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -290,7 +291,7 @@ const DataTableContainer: React.FC<DataTableProps> = ({
projectLabel,
encodeURIComponent(data['@id']),
latest._rev,
{ ...latest, ...data }
{ ...resourceWithoutMetadata(latest), ...resourceWithoutMetadata(data) }
);
}
const resource = await nexus.Resource.create(orgLabel, projectLabel, data);
Expand Down
6 changes: 5 additions & 1 deletion src/subapps/studioLegacy/containers/StudioContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -123,7 +124,7 @@ const WorkspaceForm: React.FunctionComponent<WorkspaceFormProps> = ({
projectLabel,
encodeURIComponent(workspace['@id']),
workspace['_rev'],
newWorkspace
resourceWithoutMetadata(newWorkspace)
)
.then(result => {
if (onSuccess) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';

Expand Down Expand Up @@ -484,18 +485,18 @@ const WorkspaceMenu: React.FC<WorkspaceMenuProps> = ({
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'],
}
Expand Down

0 comments on commit f0bd16c

Please sign in to comment.