From: Janicki Artur Date: Mon, 19 Nov 2018 09:52:47 +0000 (+0100) Subject: Merge branch 'master' of git.curoverse.com:arvados-workbench2 into 14433_properties_i... X-Git-Tag: 1.3.0~23^2 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/1a59e5dcc15a9a1aebfd15a08903fcb75efd2aac Merge branch 'master' of git.curoverse.com:arvados-workbench2 into 14433_properties_inside_projects refs #2 14433 Arvados-DCO-1.1-Signed-off-by: Janicki Artur --- 1a59e5dcc15a9a1aebfd15a08903fcb75efd2aac diff --cc src/store/details-panel/details-panel-action.ts index 6aebc050,0f132865..2c742a1f --- a/src/store/details-panel/details-panel-action.ts +++ b/src/store/details-panel/details-panel-action.ts @@@ -3,17 -3,10 +3,19 @@@ // SPDX-License-Identifier: AGPL-3.0 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 } from '~/store/snackbar/snackbar-actions'; + export const SLIDE_TIMEOUT = 500; + export const detailsPanelActions = unionize({ TOGGLE_DETAILS_PANEL: ofType<{}>(), LOAD_DETAILS_PANEL: ofType() @@@ -21,49 -14,13 +23,57 @@@ export type DetailsPanelAction = UnionOf; +export const PROJECT_PROPERTIES_FORM_NAME = 'projectPropertiesFormName'; +export const PROJECT_PROPERTIES_DIALOG_NAME = 'projectPropertiesDialogName'; + export const loadDetailsPanel = (uuid: string) => detailsPanelActions.LOAD_DETAILS_PANEL(uuid); +export const openProjectPropertiesDialog = () => + (dispatch: Dispatch) => { + dispatch(dialogActions.OPEN_DIALOG({ id: PROJECT_PROPERTIES_DIALOG_NAME, data: { } })); + }; + +export const deleteProjectProperty = (key: string) => + async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + const { detailsPanel, resources } = getState(); + const project = getResource(detailsPanel.resourceUuid)(resources) as ProjectResource; + try { + if (project) { + delete project.properties[key]; + const updatedProject = await services.projectService.update(project.uuid, project); + dispatch(resourcesActions.SET_RESOURCES([updatedProject])); + dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Property has been successfully deleted.", hideDuration: 2000 })); + } + } catch (e) { + dispatch(dialogActions.CLOSE_DIALOG({ id: PROJECT_PROPERTIES_FORM_NAME })); + throw new Error('Could not remove property from the project.'); + } + }; + +export const createProjectProperty = (data: TagProperty) => + async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + const { detailsPanel, resources } = getState(); + const project = getResource(detailsPanel.resourceUuid)(resources) as ProjectResource; + dispatch(startSubmit(PROJECT_PROPERTIES_FORM_NAME)); + try { + if (project) { + project.properties[data.key] = data.value; + const updatedProject = await services.projectService.update(project.uuid, project); + dispatch(resourcesActions.SET_RESOURCES([updatedProject])); + dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Property has been successfully added.", hideDuration: 2000 })); + dispatch(stopSubmit(PROJECT_PROPERTIES_FORM_NAME)); + } + return; + } catch (e) { + dispatch(dialogActions.CLOSE_DIALOG({ id: PROJECT_PROPERTIES_FORM_NAME })); + throw new Error('Could not add property to the project.'); + } - }; ++ }; + export const toggleDetailsPanel = () => (dispatch: Dispatch) => { + // because of material-ui issue resizing details panel breaks tabs. + // triggering window resize event fixes that. + setTimeout(() => { + window.dispatchEvent(new Event('resize')); + }, SLIDE_TIMEOUT); + dispatch(detailsPanelActions.TOGGLE_DETAILS_PANEL()); + }; diff --cc src/views/workbench/workbench.tsx index 19a2ef49,744526b1..8d1fb670 --- a/src/views/workbench/workbench.tsx +++ b/src/views/workbench/workbench.tsx @@@ -141,7 -141,7 +142,8 @@@ export const WorkbenchPanel + +