18219: Replaces edit props dialog with full editor on details panel.
[arvados-workbench2.git] / src / store / details-panel / details-panel-action.ts
index bda35441a83fda894d80338dbabe48dd33fd5943..b708ad622c8ccfa141a7118c516d8cef33fcc8b7 100644 (file)
@@ -5,15 +5,10 @@
 import { unionize, ofType, UnionOf } from 'common/unionize';
 import { RootState } from 'store/store';
 import { Dispatch } from 'redux';
-import { dialogActions } from 'store/dialog/dialog-actions';
 import { getResource } from 'store/resources/resources';
-import { ProjectResource } from "models/project";
 import { ServiceRepository } from 'services/services';
-import { TagProperty } from 'models/tag';
-import { startSubmit, stopSubmit } from 'redux-form';
 import { resourcesActions } from 'store/resources/resources-actions';
-import {snackbarActions, SnackbarKind} from 'store/snackbar/snackbar-actions';
-import { addProperty, deleteProperty } from 'lib/resource-properties';
+import { snackbarActions, SnackbarKind } from 'store/snackbar/snackbar-actions';
 import { FilterBuilder } from 'services/api/filter-builder';
 import { OrderBuilder } from 'services/api/order-builder';
 import { CollectionResource } from 'models/collection';
@@ -29,9 +24,6 @@ export const detailsPanelActions = unionize({
 
 export type DetailsPanelAction = UnionOf<typeof detailsPanelActions>;
 
-export const PROJECT_PROPERTIES_FORM_NAME = 'projectPropertiesFormName';
-export const PROJECT_PROPERTIES_DIALOG_NAME = 'projectPropertiesDialogName';
-
 export const loadDetailsPanel = (uuid: string) =>
     (dispatch: Dispatch, getState: () => RootState) => {
         if (getState().detailsPanel.isOpened) {
@@ -55,11 +47,6 @@ export const openDetailsPanel = (uuid?: string, tabNr: number = 0) =>
         }
     };
 
-export const openProjectPropertiesDialog = () =>
-    (dispatch: Dispatch) => {
-        dispatch<any>(dialogActions.OPEN_DIALOG({ id: PROJECT_PROPERTIES_DIALOG_NAME, data: { } }));
-    };
-
 export const refreshCollectionVersionsList = (uuid: string) =>
     (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
         services.collectionService.list({
@@ -76,49 +63,6 @@ export const refreshCollectionVersionsList = (uuid: string) =>
         );
     };
 
-export const deleteProjectProperty = (key: string, value: string) =>
-    async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
-        const { detailsPanel, resources } = getState();
-        const project = getResource(detailsPanel.resourceUuid)(resources) as ProjectResource;
-        if (!project) { return; }
-
-        const properties = Object.assign({}, project.properties);
-
-        try {
-            const updatedProject = await services.projectService.update(
-                project.uuid, {
-                    properties: deleteProperty(properties, key, value),
-                });
-            dispatch(resourcesActions.SET_RESOURCES([updatedProject]));
-            dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Property has been successfully deleted.", hideDuration: 2000, kind: SnackbarKind.SUCCESS }));
-        } catch (e) {
-            dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.errors[0], hideDuration: 2000, kind: SnackbarKind.ERROR }));
-        }
-    };
-
-export const createProjectProperty = (data: TagProperty) =>
-    async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
-        const { detailsPanel, resources } = getState();
-        const project = getResource(detailsPanel.resourceUuid)(resources) as ProjectResource;
-        if (!project) { return; }
-
-        dispatch(startSubmit(PROJECT_PROPERTIES_FORM_NAME));
-        try {
-            const key = data.keyID || data.key;
-            const value = data.valueID || data.value;
-            const properties = Object.assign({}, project.properties);
-            const updatedProject = await services.projectService.update(
-                project.uuid, {
-                    properties: addProperty(properties, key, value),
-                }
-            );
-            dispatch(resourcesActions.SET_RESOURCES([updatedProject]));
-            dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Property has been successfully added.", hideDuration: 2000, kind: SnackbarKind.SUCCESS }));
-            dispatch(stopSubmit(PROJECT_PROPERTIES_FORM_NAME));
-        } catch (e) {
-            dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.errors[0], hideDuration: 2000, kind: SnackbarKind.ERROR }));
-        }
-    };
 export const toggleDetailsPanel = () => (dispatch: Dispatch, getState: () => RootState) => {
     // because of material-ui issue resizing details panel breaks tabs.
     // triggering window resize event fixes that.