X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/8360ba81b48f6883b453f13756432a3d599c3042..1bde07ef5884a55bbb47aaf30a90b122a4810617:/src/components/multiselectToolbar/MultiselectToolbar.tsx diff --git a/src/components/multiselectToolbar/MultiselectToolbar.tsx b/src/components/multiselectToolbar/MultiselectToolbar.tsx index bd01b361..2d6b1889 100644 --- a/src/components/multiselectToolbar/MultiselectToolbar.tsx +++ b/src/components/multiselectToolbar/MultiselectToolbar.tsx @@ -13,10 +13,17 @@ import { TCheckedList } from 'components/data-table/data-table'; import { openRemoveProcessDialog, openRemoveManyProcessesDialog } from 'store/processes/processes-actions'; import { processResourceActionSet } from '../../views-components/context-menu/action-sets/process-resource-action-set'; import { ContextMenuResource } from 'store/context-menu/context-menu-actions'; -import { toggleTrashed } from 'store/trash/trash-actions'; import { ResourceKind, extractUuidKind } from 'models/resource'; +import { openMoveProcessDialog } from 'store/processes/process-move-actions'; +import { openCopyProcessDialog } from 'store/processes/process-copy-actions'; +import { getResource } from 'store/resources/resources'; +import { ResourceName } from 'views-components/data-explorer/renderers'; +import { ProcessResource } from 'models/process'; +import { ResourcesState } from 'store/resources/resources'; +import { Resource } from 'models/resource'; +import { getProcess } from 'store/processes/process'; -type CssRules = 'root' | 'expanded' | 'button'; +type CssRules = 'root' | 'button'; const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ root: { @@ -26,8 +33,6 @@ const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ padding: 0, margin: '1rem auto auto 0.5rem', overflow: 'hidden', - }, - expanded: { transition: 'width 150ms', }, button: { @@ -42,30 +47,31 @@ const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ type MultiselectToolbarAction = { name: string; - action: string; - relevantKinds: Array; + funcName: string; + relevantKinds: Set; }; +//gleaned from src/views-components/context-menu/action-sets export const defaultActions: Array = [ { - name: 'copy', - action: 'copySelected', - relevantKinds: [ResourceKind.COLLECTION], + name: 'copy and re-run', + funcName: 'copySelected', + relevantKinds: new Set([ResourceKind.PROCESS]), }, { name: 'move', - action: 'moveSelected', - relevantKinds: [ResourceKind.COLLECTION, ResourceKind.PROCESS], + funcName: 'moveSelected', + relevantKinds: new Set([ResourceKind.PROCESS, ResourceKind.PROJECT]), }, { name: 'remove', - action: 'removeSelected', - relevantKinds: [ResourceKind.COLLECTION, ResourceKind.PROCESS, ResourceKind.PROJECT], + funcName: 'removeSelected', + relevantKinds: new Set([ResourceKind.PROCESS, ResourceKind.COLLECTION]), }, { - name: 'foo', - action: 'barSelected', - relevantKinds: [ResourceKind.COLLECTION, ResourceKind.PROJECT], + name: 'favorite', + funcName: 'favoriteSelected', + relevantKinds: new Set([ResourceKind.PROCESS, ResourceKind.PROJECT, ResourceKind.COLLECTION]), }, ]; @@ -73,10 +79,11 @@ export type MultiselectToolbarProps = { actions: Array; isVisible: boolean; checkedList: TCheckedList; - copySelected: () => void; - moveSelected: () => void; + resources: ResourcesState; + copySelected: (checkedList: TCheckedList, resources: ResourcesState) => void; + moveSelected: (resource) => void; barSelected: () => void; - removeSelected: (selectedList: TCheckedList) => void; + removeSelected: (checkedList: TCheckedList) => void; }; export const MultiselectToolbar = connect( @@ -85,19 +92,16 @@ export const MultiselectToolbar = connect( )( withStyles(styles)((props: MultiselectToolbarProps & WithStyles) => { // console.log(props); - const { classes, actions, isVisible, checkedList } = props; - - const currentResourceKinds = selectedToArray(checkedList).map((element) => extractUuidKind(element)); + const { classes, actions, isVisible, checkedList, resources } = props; - const buttons = actions.filter( - (action) => currentResourceKinds.length && currentResourceKinds.every((kind) => action.relevantKinds.includes(kind as ResourceKind)) - ); + const currentResourceKinds = Array.from(selectedToKindSet(checkedList)); + const buttons = actions.filter((action) => currentResourceKinds.length && currentResourceKinds.every((kind) => action.relevantKinds.has(kind as ResourceKind))); return ( - + {buttons.length ? ( buttons.map((btn) => ( - )) @@ -109,44 +113,70 @@ export const MultiselectToolbar = connect( }) ); -function selectedToString(checkedList: TCheckedList) { - let stringifiedSelectedList: string = ''; +function selectedToArray(checkedList: TCheckedList): Array { + const arrayifiedSelectedList: Array = []; for (const [key, value] of Object.entries(checkedList)) { if (value === true) { - stringifiedSelectedList += key + ','; + arrayifiedSelectedList.push(key); } } - return stringifiedSelectedList.slice(0, -1); + return arrayifiedSelectedList; } -function selectedToArray(checkedList: TCheckedList): Array { - const arrayifiedSelectedList: Array = []; +function selectedToKindSet(checkedList: TCheckedList): Set { + const setifiedList = new Set(); for (const [key, value] of Object.entries(checkedList)) { if (value === true) { - arrayifiedSelectedList.push(key); + setifiedList.add(extractUuidKind(key) as string); } } - return arrayifiedSelectedList; + return setifiedList; } function mapStateToProps(state: RootState) { + // console.log(state); + // console.log(getResource('tordo-dz642-0p7xefqdr4nw4pw')(state.resources)); const { isVisible, checkedList } = state.multiselect; return { isVisible: isVisible, checkedList: checkedList as TCheckedList, + resources: state.resources, }; } function mapDispatchToProps(dispatch: Dispatch) { return { - copySelected: () => {}, - moveSelected: () => {}, + copySelected: (checkedList: TCheckedList, resources: ResourcesState) => copyMoveMulti(dispatch, checkedList, resources), + moveSelected: (checkedList: TCheckedList) => {}, barSelected: () => {}, - removeSelected: (checkedList: TCheckedList) => removeMulti(dispatch, checkedList), + removeSelected: (checkedList: TCheckedList) => removeMultiProcesses(dispatch, checkedList), }; } -function removeMulti(dispatch: Dispatch, checkedList: TCheckedList): void { - const list: Array = selectedToArray(checkedList); - dispatch(list.length === 1 ? openRemoveProcessDialog(list[0]) : openRemoveManyProcessesDialog(list)); +function copyMoveMulti(dispatch: Dispatch, checkedList: TCheckedList, resources: ResourcesState) { + const selectedList: Array = selectedToArray(checkedList); + const single = getProcess(selectedList[0])(resources)?.containerRequest; + console.log(single); + const { name, uuid } = single as any; + console.log(name, uuid); + dispatch(openCopyProcessDialog({ name, uuid })); +} + +function moveMultiProcesses(dispatch: Dispatch, checkedList: TCheckedList): void { + const selectedList: Array = selectedToArray(checkedList); + // if (selectedList.length === 1) dispatch(openMoveProcessDialog(selectedList[0])); +} + +const RemoveFunctions = { + ONE_PROCESS: (uuid: string) => openRemoveProcessDialog(uuid), + MANY_PROCESSES: (list: Array) => openRemoveManyProcessesDialog(list), +}; + +function removeMultiProcesses(dispatch: Dispatch, checkedList: TCheckedList): void { + const selectedList: Array = selectedToArray(checkedList); + dispatch(selectedList.length === 1 ? RemoveFunctions.ONE_PROCESS(selectedList[0]) : RemoveFunctions.MANY_PROCESSES(selectedList)); } + +//onRemove +//go through the array of selected and choose the appropriate removal function +//have a constant with [ResourceKind]: different removal methods