From: Janicki Artur Date: Thu, 9 Aug 2018 10:20:17 +0000 (+0200) Subject: Merge branch '13898-edit-collection-from-data-explorer' X-Git-Tag: 1.2.0~8 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/a40f50b97895044b2e6879109fe430844b027ad6?hp=5a4e3e7f2efcd6c3a291adcd3ec6fa154b3a9151 Merge branch '13898-edit-collection-from-data-explorer' refs #13898 Arvados-DCO-1.1-Signed-off-by: Janicki Artur --- diff --git a/src/index.tsx b/src/index.tsx index aac275f9..dd272233 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -26,6 +26,7 @@ import { favoriteActionSet } from "./views-components/context-menu/action-sets/f import { collectionFilesActionSet } from './views-components/context-menu/action-sets/collection-files-action-set'; import { collectionFilesItemActionSet } from './views-components/context-menu/action-sets/collection-files-item-action-set'; import { collectionActionSet } from './views-components/context-menu/action-sets/collection-action-set'; +import { collectionResourceActionSet } from './views-components/context-menu/action-sets/collection-resource-action-set'; addMenuActionSet(ContextMenuKind.ROOT_PROJECT, rootProjectActionSet); addMenuActionSet(ContextMenuKind.PROJECT, projectActionSet); @@ -34,6 +35,7 @@ addMenuActionSet(ContextMenuKind.FAVORITE, favoriteActionSet); addMenuActionSet(ContextMenuKind.COLLECTION_FILES, collectionFilesActionSet); addMenuActionSet(ContextMenuKind.COLLECTION_FILES_ITEM, collectionFilesItemActionSet); addMenuActionSet(ContextMenuKind.COLLECTION, collectionActionSet); +addMenuActionSet(ContextMenuKind.COLLECTION_RESOURCE, collectionResourceActionSet); fetchConfig() .then(config => { diff --git a/src/store/collections/updater/collection-updater-action.ts b/src/store/collections/updater/collection-updater-action.ts index a7a354ad..bb9f4d30 100644 --- a/src/store/collections/updater/collection-updater-action.ts +++ b/src/store/collections/updater/collection-updater-action.ts @@ -10,6 +10,7 @@ import { ServiceRepository } from "../../../services/services"; import { CollectionResource } from '../../../models/collection'; import { initialize } from 'redux-form'; import { collectionPanelActions } from "../../collection-panel/collection-panel-action"; +import { ContextMenuResource } from "../../context-menu/context-menu-reducer"; export const collectionUpdaterActions = unionize({ OPEN_COLLECTION_UPDATER: ofType<{ uuid: string }>(), @@ -23,11 +24,10 @@ export const collectionUpdaterActions = unionize({ export const COLLECTION_FORM_NAME = 'collectionEditDialog'; -export const openUpdater = (uuid: string) => +export const openUpdater = (item: ContextMenuResource) => (dispatch: Dispatch, getState: () => RootState) => { - dispatch(collectionUpdaterActions.OPEN_COLLECTION_UPDATER({ uuid })); - const item = getState().collectionPanel.item; - if(item) { + if (item) { + dispatch(collectionUpdaterActions.OPEN_COLLECTION_UPDATER({ uuid: item.uuid })); dispatch(initialize(COLLECTION_FORM_NAME, { name: item.name, description: item.description })); } }; diff --git a/src/store/collections/updater/collection-updater-reducer.ts b/src/store/collections/updater/collection-updater-reducer.ts index 432aa270..97d010fc 100644 --- a/src/store/collections/updater/collection-updater-reducer.ts +++ b/src/store/collections/updater/collection-updater-reducer.ts @@ -22,7 +22,7 @@ const initialState: CollectionUpdaterState = { export const collectionUpdaterReducer = (state: CollectionUpdaterState = initialState, action: CollectionUpdaterAction) => { return collectionUpdaterActions.match(action, { OPEN_COLLECTION_UPDATER: ({ uuid }) => updateCollection(state, { uuid, opened: true }), - CLOSE_COLLECTION_UPDATER: () => updateCollection(state, { opened: false }), + CLOSE_COLLECTION_UPDATER: () => updateCollection(state, { opened: false, uuid: "" }), UPDATE_COLLECTION_SUCCESS: () => updateCollection(state, { opened: false, uuid: "" }), default: () => state }); diff --git a/src/store/context-menu/context-menu-reducer.ts b/src/store/context-menu/context-menu-reducer.ts index 8b51478d..ac14c355 100644 --- a/src/store/context-menu/context-menu-reducer.ts +++ b/src/store/context-menu/context-menu-reducer.ts @@ -19,6 +19,7 @@ export interface ContextMenuResource { uuid: string; kind: string; name: string; + description?: string; } const initialState = { diff --git a/src/views-components/context-menu/action-sets/collection-action-set.ts b/src/views-components/context-menu/action-sets/collection-action-set.ts index 513cb5fc..10da9ef1 100644 --- a/src/views-components/context-menu/action-sets/collection-action-set.ts +++ b/src/views-components/context-menu/action-sets/collection-action-set.ts @@ -14,7 +14,7 @@ export const collectionActionSet: ContextMenuActionSet = [[ icon: RenameIcon, name: "Edit collection", execute: (dispatch, resource) => { - dispatch(openUpdater(resource.uuid)); + dispatch(openUpdater(resource)); } }, { diff --git a/src/views-components/context-menu/action-sets/collection-resource-action-set.ts b/src/views-components/context-menu/action-sets/collection-resource-action-set.ts new file mode 100644 index 00000000..e6356bbc --- /dev/null +++ b/src/views-components/context-menu/action-sets/collection-resource-action-set.ts @@ -0,0 +1,63 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +import { ContextMenuActionSet } from "../context-menu-action-set"; +import { ToggleFavoriteAction } from "../actions/favorite-action"; +import { toggleFavorite } from "../../../store/favorites/favorites-actions"; +import { RenameIcon, ShareIcon, MoveToIcon, CopyIcon, DetailsIcon, RemoveIcon } from "../../../components/icon/icon"; +import { openUpdater } from "../../../store/collections/updater/collection-updater-action"; +import { favoritePanelActions } from "../../../store/favorite-panel/favorite-panel-action"; + +export const collectionResourceActionSet: ContextMenuActionSet = [[ + { + icon: RenameIcon, + name: "Edit collection", + execute: (dispatch, resource) => { + dispatch(openUpdater(resource)); + } + }, + { + icon: ShareIcon, + name: "Share", + execute: (dispatch, resource) => { + // add code + } + }, + { + icon: MoveToIcon, + name: "Move to", + execute: (dispatch, resource) => { + // add code + } + }, + { + component: ToggleFavoriteAction, + execute: (dispatch, resource) => { + dispatch(toggleFavorite(resource)).then(() => { + dispatch(favoritePanelActions.REQUEST_ITEMS()); + }); + } + }, + { + icon: CopyIcon, + name: "Copy to project", + execute: (dispatch, resource) => { + // add code + } + }, + { + icon: DetailsIcon, + name: "View details", + execute: (dispatch, resource) => { + // add code + } + }, + { + icon: RemoveIcon, + name: "Remove", + execute: (dispatch, resource) => { + // add code + } + } +]]; diff --git a/src/views-components/context-menu/context-menu.tsx b/src/views-components/context-menu/context-menu.tsx index 8b008937..0a629b2e 100644 --- a/src/views-components/context-menu/context-menu.tsx +++ b/src/views-components/context-menu/context-menu.tsx @@ -62,5 +62,6 @@ export enum ContextMenuKind { FAVORITE = "Favorite", COLLECTION_FILES = "CollectionFiles", COLLECTION_FILES_ITEM = "CollectionFilesItem", - COLLECTION = 'Collection' + COLLECTION = 'Collection', + COLLECTION_RESOURCE = 'CollectionResource' } diff --git a/src/views-components/rename-file-dialog/rename-file-dialog.tsx b/src/views-components/rename-file-dialog/rename-file-dialog.tsx index 6c880cc8..5e2f7c44 100644 --- a/src/views-components/rename-file-dialog/rename-file-dialog.tsx +++ b/src/views-components/rename-file-dialog/rename-file-dialog.tsx @@ -10,7 +10,7 @@ import { RenameDialog } from "../../components/rename-dialog/rename-dialog"; export const RENAME_FILE_DIALOG = 'renameFileDialog'; -export const openRenameFileDialog = (originalName: string, ) => +export const openRenameFileDialog = (originalName: string) => (dispatch: Dispatch) => { dispatch(reset(RENAME_FILE_DIALOG)); dispatch(dialogActions.OPEN_DIALOG({ id: RENAME_FILE_DIALOG, data: originalName })); diff --git a/src/views/project-panel/project-panel-item.ts b/src/views/project-panel/project-panel-item.ts index d0609d6d..d81ef502 100644 --- a/src/views/project-panel/project-panel-item.ts +++ b/src/views/project-panel/project-panel-item.ts @@ -8,6 +8,7 @@ import { ResourceKind } from "../../models/resource"; export interface ProjectPanelItem { uuid: string; name: string; + description?: string; kind: string; url: string; owner: string; @@ -21,6 +22,7 @@ export function resourceToDataItem(r: GroupContentsResource): ProjectPanelItem { return { uuid: r.uuid, name: r.name, + description: r.description, kind: r.kind, url: "", owner: r.ownerUuid, diff --git a/src/views/workbench/workbench.tsx b/src/views/workbench/workbench.tsx index a8552eef..8377744c 100644 --- a/src/views/workbench/workbench.tsx +++ b/src/views/workbench/workbench.tsx @@ -257,6 +257,7 @@ export const Workbench = withStyles(styles)( this.openContextMenu(event, { uuid: item.uuid, name: item.name, + description: item.description, kind: ContextMenuKind.COLLECTION }); }} @@ -265,11 +266,20 @@ export const Workbench = withStyles(styles)( renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => this.props.dispatch(setProjectItem(itemId, ItemMode.ACTIVE))} onContextMenu={(event, item) => { + let kind: ContextMenuKind; - const kind = item.kind === ResourceKind.PROJECT ? ContextMenuKind.PROJECT : ContextMenuKind.RESOURCE; + if (item.kind === ResourceKind.PROJECT) { + kind = ContextMenuKind.PROJECT; + } else if (item.kind === ResourceKind.COLLECTION) { + kind = ContextMenuKind.COLLECTION_RESOURCE; + } else { + kind = ContextMenuKind.RESOURCE; + } + this.openContextMenu(event, { uuid: item.uuid, name: item.name, + description: item.description, kind }); }} @@ -362,7 +372,7 @@ export const Workbench = withStyles(styles)( this.props.dispatch(collectionCreateActions.OPEN_COLLECTION_CREATOR({ ownerUuid: itemUuid })); } - openContextMenu = (event: React.MouseEvent, resource: { name: string; uuid: string; kind: ContextMenuKind; }) => { + openContextMenu = (event: React.MouseEvent, resource: { name: string; uuid: string; description?: string; kind: ContextMenuKind; }) => { event.preventDefault(); this.props.dispatch( contextMenuActions.OPEN_CONTEXT_MENU({