1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Dispatch } from "redux";
6 import { RootState } from "store/store";
7 import { getUserUuid } from "common/getuser";
8 import { loadDetailsPanel } from "store/details-panel/details-panel-action";
9 import { snackbarActions, SnackbarKind } from "store/snackbar/snackbar-actions";
10 import { favoritePanelActions, loadFavoritePanel } from "store/favorite-panel/favorite-panel-action";
11 import { getProjectPanelCurrentUuid, setIsProjectPanelTrashed } from "store/project-panel/project-panel-action";
12 import { projectPanelActions } from "store/project-panel/project-panel-action-bind";
14 activateSidePanelTreeItem,
16 loadSidePanelTreeProjects,
17 SidePanelTreeCategory,
19 } from "store/side-panel-tree/side-panel-tree-actions";
20 import { updateResources } from "store/resources/resources-actions";
21 import { projectPanelColumns } from "views/project-panel/project-panel";
22 import { favoritePanelColumns } from "views/favorite-panel/favorite-panel";
23 import { matchRootRoute } from "routes/routes";
25 setGroupDetailsBreadcrumbs,
27 setProcessBreadcrumbs,
28 setSharedWithMeBreadcrumbs,
29 setSidePanelBreadcrumbs,
32 setMyAccountBreadcrumbs,
33 setUserProfileBreadcrumbs,
34 setInstanceTypesBreadcrumbs,
35 setVirtualMachinesBreadcrumbs,
36 setVirtualMachinesAdminBreadcrumbs,
37 setRepositoriesBreadcrumbs,
38 } from "store/breadcrumbs/breadcrumbs-actions";
39 import { navigateTo, navigateToRootProject } from "store/navigation/navigation-action";
40 import { MoveToFormDialogData } from "store/move-to-dialog/move-to-dialog";
41 import { ServiceRepository } from "services/services";
42 import { getResource } from "store/resources/resources";
43 import * as projectCreateActions from "store/projects/project-create-actions";
44 import * as projectMoveActions from "store/projects/project-move-actions";
45 import * as projectUpdateActions from "store/projects/project-update-actions";
46 import * as collectionCreateActions from "store/collections/collection-create-actions";
47 import * as collectionCopyActions from "store/collections/collection-copy-actions";
48 import * as collectionMoveActions from "store/collections/collection-move-actions";
49 import * as processesActions from "store/processes/processes-actions";
50 import * as processMoveActions from "store/processes/process-move-actions";
51 import * as processUpdateActions from "store/processes/process-update-actions";
52 import * as processCopyActions from "store/processes/process-copy-actions";
53 import { trashPanelColumns } from "views/trash-panel/trash-panel";
54 import { loadTrashPanel, trashPanelActions } from "store/trash-panel/trash-panel-action";
55 import { loadProcessPanel } from "store/process-panel/process-panel-actions";
56 import { loadSharedWithMePanel, sharedWithMePanelActions } from "store/shared-with-me-panel/shared-with-me-panel-actions";
57 import { sharedWithMePanelColumns } from "views/shared-with-me-panel/shared-with-me-panel";
58 import { CopyFormDialogData } from "store/copy-dialog/copy-dialog";
59 import { workflowPanelActions } from "store/workflow-panel/workflow-panel-actions";
60 import { loadSshKeysPanel } from "store/auth/auth-action-ssh";
61 import { loadLinkAccountPanel, linkAccountPanelActions } from "store/link-account-panel/link-account-panel-actions";
62 import { loadSiteManagerPanel } from "store/auth/auth-action-session";
63 import { workflowPanelColumns } from "views/workflow-panel/workflow-panel-view";
64 import { progressIndicatorActions } from "store/progress-indicator/progress-indicator-actions";
65 import { getProgressIndicator } from "store/progress-indicator/progress-indicator-reducer";
66 import { extractUuidKind, Resource, ResourceKind } from "models/resource";
67 import { FilterBuilder } from "services/api/filter-builder";
68 import { GroupContentsResource } from "services/groups-service/groups-service";
69 import { MatchCases, ofType, unionize, UnionOf } from "common/unionize";
70 import { loadRunProcessPanel } from "store/run-process-panel/run-process-panel-actions";
71 import { collectionPanelActions, loadCollectionPanel } from "store/collection-panel/collection-panel-action";
72 import { CollectionResource } from "models/collection";
73 import { WorkflowResource } from "models/workflow";
74 import { loadSearchResultsPanel, searchResultsPanelActions } from "store/search-results-panel/search-results-panel-actions";
75 import { searchResultsPanelColumns } from "views/search-results-panel/search-results-panel-view";
76 import { loadVirtualMachinesPanel } from "store/virtual-machines/virtual-machines-actions";
77 import { loadRepositoriesPanel } from "store/repositories/repositories-actions";
78 import { loadKeepServicesPanel } from "store/keep-services/keep-services-actions";
79 import { loadUsersPanel, userBindedActions } from "store/users/users-actions";
80 import * as userProfilePanelActions from "store/user-profile/user-profile-actions";
81 import { linkPanelActions, loadLinkPanel } from "store/link-panel/link-panel-actions";
82 import { linkPanelColumns } from "views/link-panel/link-panel-root";
83 import { userPanelColumns } from "views/user-panel/user-panel";
84 import { loadApiClientAuthorizationsPanel, apiClientAuthorizationsActions } from "store/api-client-authorizations/api-client-authorizations-actions";
85 import { apiClientAuthorizationPanelColumns } from "views/api-client-authorization-panel/api-client-authorization-panel-root";
86 import * as groupPanelActions from "store/groups-panel/groups-panel-actions";
87 import { groupsPanelColumns } from "views/groups-panel/groups-panel";
88 import * as groupDetailsPanelActions from "store/group-details-panel/group-details-panel-actions";
89 import { groupDetailsMembersPanelColumns, groupDetailsPermissionsPanelColumns } from "views/group-details-panel/group-details-panel";
90 import { DataTableFetchMode } from "components/data-table/data-table";
91 import { loadPublicFavoritePanel, publicFavoritePanelActions } from "store/public-favorites-panel/public-favorites-action";
92 import { publicFavoritePanelColumns } from "views/public-favorites-panel/public-favorites-panel";
94 loadCollectionsContentAddressPanel,
95 collectionsContentAddressActions,
96 } from "store/collections-content-address-panel/collections-content-address-panel-actions";
97 import { collectionContentAddressPanelColumns } from "views/collection-content-address-panel/collection-content-address-panel";
98 import { subprocessPanelActions } from "store/subprocess-panel/subprocess-panel-actions";
99 import { subprocessPanelColumns } from "views/subprocess-panel/subprocess-panel-root";
100 import { loadAllProcessesPanel, allProcessesPanelActions } from "../all-processes-panel/all-processes-panel-action";
101 import { allProcessesPanelColumns } from "views/all-processes-panel/all-processes-panel";
102 import { userProfileGroupsColumns } from "views/user-profile-panel/user-profile-panel-root";
103 import { selectedToArray, selectedToKindSet } from "components/multiselect-toolbar/MultiselectToolbar";
104 import { deselectOne } from "store/multiselect/multiselect-actions";
105 import { treePickerActions } from "store/tree-picker/tree-picker-actions";
106 import { workflowProcessesPanelColumns } from "views/workflow-panel/workflow-processes-panel-root";
107 import { workflowProcessesPanelActions } from "store/workflow-panel/workflow-panel-actions";
108 import { Breadcrumb } from "components/breadcrumbs/breadcrumbs";
110 export const WORKBENCH_LOADING_SCREEN = "workbenchLoadingScreen";
112 export const isWorkbenchLoading = (state: RootState) => {
113 const progress = getProgressIndicator(WORKBENCH_LOADING_SCREEN)(state.progressIndicator);
114 return progress ? progress.working : false;
117 export const handleFirstTimeLoad = (action: any) => async (dispatch: Dispatch<any>, getState: () => RootState) => {
119 await dispatch(action);
121 snackbarActions.OPEN_SNACKBAR({
122 message: "Error " + e,
124 kind: SnackbarKind.WARNING,
127 if (isWorkbenchLoading(getState())) {
128 dispatch(progressIndicatorActions.STOP_WORKING(WORKBENCH_LOADING_SCREEN));
133 export const loadWorkbench = () => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
134 dispatch(progressIndicatorActions.START_WORKING(WORKBENCH_LOADING_SCREEN));
135 const { auth, router } = getState();
136 const { user } = auth;
138 dispatch(projectPanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
139 dispatch(favoritePanelActions.SET_COLUMNS({ columns: favoritePanelColumns }));
141 allProcessesPanelActions.SET_COLUMNS({
142 columns: allProcessesPanelColumns,
146 publicFavoritePanelActions.SET_COLUMNS({
147 columns: publicFavoritePanelColumns,
150 dispatch(trashPanelActions.SET_COLUMNS({ columns: trashPanelColumns }));
151 dispatch(sharedWithMePanelActions.SET_COLUMNS({ columns: sharedWithMePanelColumns }));
152 dispatch(workflowPanelActions.SET_COLUMNS({ columns: workflowPanelColumns }));
154 searchResultsPanelActions.SET_FETCH_MODE({
155 fetchMode: DataTableFetchMode.INFINITE,
159 searchResultsPanelActions.SET_COLUMNS({
160 columns: searchResultsPanelColumns,
163 dispatch(userBindedActions.SET_COLUMNS({ columns: userPanelColumns }));
165 groupPanelActions.GroupsPanelActions.SET_COLUMNS({
166 columns: groupsPanelColumns,
170 groupDetailsPanelActions.GroupMembersPanelActions.SET_COLUMNS({
171 columns: groupDetailsMembersPanelColumns,
175 groupDetailsPanelActions.GroupPermissionsPanelActions.SET_COLUMNS({
176 columns: groupDetailsPermissionsPanelColumns,
180 userProfilePanelActions.UserProfileGroupsActions.SET_COLUMNS({
181 columns: userProfileGroupsColumns,
184 dispatch(linkPanelActions.SET_COLUMNS({ columns: linkPanelColumns }));
186 apiClientAuthorizationsActions.SET_COLUMNS({
187 columns: apiClientAuthorizationPanelColumns,
191 collectionsContentAddressActions.SET_COLUMNS({
192 columns: collectionContentAddressPanelColumns,
195 dispatch(subprocessPanelActions.SET_COLUMNS({ columns: subprocessPanelColumns }));
196 dispatch(workflowProcessesPanelActions.SET_COLUMNS({ columns: workflowProcessesPanelColumns }));
198 if (services.linkAccountService.getAccountToLink()) {
199 dispatch(linkAccountPanelActions.HAS_SESSION_DATA());
202 dispatch<any>(initSidePanelTree());
203 if (router.location) {
204 const match = matchRootRoute(router.location.pathname);
206 dispatch<any>(navigateToRootProject);
210 dispatch(userIsNotAuthenticated);
214 export const loadFavorites = () =>
215 handleFirstTimeLoad((dispatch: Dispatch) => {
216 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.FAVORITES));
217 dispatch<any>(loadFavoritePanel());
218 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.FAVORITES));
221 export const loadCollectionContentAddress = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
222 await dispatch(loadCollectionsContentAddressPanel());
225 export const loadTrash = () =>
226 handleFirstTimeLoad((dispatch: Dispatch) => {
227 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
228 dispatch<any>(loadTrashPanel());
229 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.TRASH));
232 export const loadAllProcesses = () =>
233 handleFirstTimeLoad((dispatch: Dispatch) => {
234 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.ALL_PROCESSES));
235 dispatch<any>(loadAllProcessesPanel());
236 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.ALL_PROCESSES));
239 export const loadProject = (uuid: string) =>
240 handleFirstTimeLoad(async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
241 const userUuid = getUserUuid(getState());
242 dispatch(setIsProjectPanelTrashed(false));
247 dispatch(progressIndicatorActions.START_WORKING(uuid));
248 if (extractUuidKind(uuid) === ResourceKind.USER && userUuid !== uuid) {
249 // Load another users home projects
250 dispatch(finishLoadingProject(uuid));
251 const prevBreadcrumbs = getState().properties.breadcrumbs as Breadcrumb[] || [];
252 if (prevBreadcrumbs.length === 0) {
253 dispatch<any>(setSidePanelBreadcrumbs(uuid));
255 } else if (userUuid !== uuid) {
256 await dispatch(finishLoadingProject(uuid));
257 const match = await loadGroupContentsResource({
264 await dispatch(activateSidePanelTreeItem(uuid));
265 dispatch<any>(setSidePanelBreadcrumbs(uuid));
267 SHARED: async () => {
268 await dispatch(activateSidePanelTreeItem(uuid));
269 dispatch<any>(setSharedWithMeBreadcrumbs(uuid));
271 TRASHED: async () => {
272 await dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
273 dispatch<any>(setTrashBreadcrumbs(uuid));
274 dispatch(setIsProjectPanelTrashed(true));
278 await dispatch(finishLoadingProject(userUuid));
279 await dispatch(activateSidePanelTreeItem(userUuid));
280 dispatch<any>(setSidePanelBreadcrumbs(userUuid));
283 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
287 export const createProject = (data: projectCreateActions.ProjectCreateFormDialogData) => async (dispatch: Dispatch) => {
288 const newProject = await dispatch<any>(projectCreateActions.createProject(data));
291 snackbarActions.OPEN_SNACKBAR({
292 message: "Project has been successfully created.",
294 kind: SnackbarKind.SUCCESS,
297 await dispatch<any>(loadSidePanelTreeProjects(newProject.ownerUuid));
298 dispatch<any>(navigateTo(newProject.uuid));
302 export const moveProject =
303 (data: MoveToFormDialogData, isSecondaryMove = false) =>
304 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
305 const checkedList = getState().multiselect.checkedList;
306 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
308 //if no items in checkedlist default to normal context menu behavior
309 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
311 const sourceUuid = getResource(data.uuid)(getState().resources)?.ownerUuid;
312 const destinationUuid = data.ownerUuid;
314 const projectsToMove: MoveableResource[] = uuidsToMove
315 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
316 .filter(resource => resource.kind === ResourceKind.PROJECT);
318 for (const project of projectsToMove) {
319 await moveSingleProject(project);
322 //omly propagate if this call is the original
323 if (!isSecondaryMove) {
324 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
325 kindsToMove.delete(ResourceKind.PROJECT);
327 kindsToMove.forEach(kind => {
328 secondaryMove[kind](data, true)(dispatch, getState, services);
332 async function moveSingleProject(project: MoveableResource) {
334 const oldProject: MoveToFormDialogData = { name: project.name, uuid: project.uuid, ownerUuid: data.ownerUuid };
335 const oldOwnerUuid = oldProject ? oldProject.ownerUuid : "";
336 const movedProject = await dispatch<any>(projectMoveActions.moveProject(oldProject));
339 snackbarActions.OPEN_SNACKBAR({
340 message: "Project has been moved",
342 kind: SnackbarKind.SUCCESS,
345 await dispatch<any>(reloadProjectMatchingUuid([oldOwnerUuid, movedProject.ownerUuid, movedProject.uuid]));
349 snackbarActions.OPEN_SNACKBAR({
350 message: !!(project as any).frozenByUuid ? 'Could not move frozen project.' : e.message,
352 kind: SnackbarKind.ERROR,
357 if (sourceUuid) await dispatch<any>(loadSidePanelTreeProjects(sourceUuid));
358 await dispatch<any>(loadSidePanelTreeProjects(destinationUuid));
361 export const updateProject = (data: projectUpdateActions.ProjectUpdateFormDialogData) => async (dispatch: Dispatch) => {
362 const updatedProject = await dispatch<any>(projectUpdateActions.updateProject(data));
363 if (updatedProject) {
365 snackbarActions.OPEN_SNACKBAR({
366 message: "Project has been successfully updated.",
368 kind: SnackbarKind.SUCCESS,
371 await dispatch<any>(loadSidePanelTreeProjects(updatedProject.ownerUuid));
372 dispatch<any>(reloadProjectMatchingUuid([updatedProject.ownerUuid, updatedProject.uuid]));
376 export const updateGroup = (data: projectUpdateActions.ProjectUpdateFormDialogData) => async (dispatch: Dispatch) => {
377 const updatedGroup = await dispatch<any>(groupPanelActions.updateGroup(data));
380 snackbarActions.OPEN_SNACKBAR({
381 message: "Group has been successfully updated.",
383 kind: SnackbarKind.SUCCESS,
386 await dispatch<any>(loadSidePanelTreeProjects(updatedGroup.ownerUuid));
387 dispatch<any>(reloadProjectMatchingUuid([updatedGroup.ownerUuid, updatedGroup.uuid]));
391 export const loadCollection = (uuid: string) =>
392 handleFirstTimeLoad(async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
393 const userUuid = getUserUuid(getState());
395 dispatch(progressIndicatorActions.START_WORKING(uuid));
397 const match = await loadGroupContentsResource({
402 let collection: CollectionResource | undefined;
404 | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
406 let sidepanel: string | undefined;
408 OWNED: thecollection => {
409 collection = thecollection as CollectionResource;
410 sidepanel = collection.ownerUuid;
411 breadcrumbfunc = setSidePanelBreadcrumbs;
413 SHARED: thecollection => {
414 collection = thecollection as CollectionResource;
415 sidepanel = collection.ownerUuid;
416 breadcrumbfunc = setSharedWithMeBreadcrumbs;
418 TRASHED: thecollection => {
419 collection = thecollection as CollectionResource;
420 sidepanel = SidePanelTreeCategory.TRASH;
421 breadcrumbfunc = () => setTrashBreadcrumbs("");
424 if (collection && breadcrumbfunc && sidepanel) {
425 dispatch(updateResources([collection]));
426 await dispatch<any>(finishLoadingProject(collection.ownerUuid));
427 dispatch(collectionPanelActions.SET_COLLECTION(collection));
428 await dispatch(activateSidePanelTreeItem(sidepanel));
429 dispatch(breadcrumbfunc(collection.ownerUuid));
430 dispatch(loadCollectionPanel(collection.uuid));
434 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
438 export const createCollection = (data: collectionCreateActions.CollectionCreateFormDialogData) => async (dispatch: Dispatch) => {
439 const collection = await dispatch<any>(collectionCreateActions.createCollection(data));
442 snackbarActions.OPEN_SNACKBAR({
443 message: "Collection has been successfully created.",
445 kind: SnackbarKind.SUCCESS,
448 dispatch<any>(updateResources([collection]));
449 dispatch<any>(navigateTo(collection.uuid));
453 export const copyCollection = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
454 const checkedList = getState().multiselect.checkedList;
455 const uuidsToCopy: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
457 //if no items in checkedlist && no items passed in, default to normal context menu behavior
458 if (!uuidsToCopy.length) uuidsToCopy.push(data.uuid);
460 const collectionsToCopy: CollectionCopyResource[] = uuidsToCopy
461 .map(uuid => getResource(uuid)(getState().resources) as CollectionCopyResource)
462 .filter(resource => resource.kind === ResourceKind.COLLECTION);
464 for (const collection of collectionsToCopy) {
465 await copySingleCollection({ ...collection, ownerUuid: data.ownerUuid } as CollectionCopyResource);
468 async function copySingleCollection(copyToProject: CollectionCopyResource) {
469 const newName = data.fromContextMenu || collectionsToCopy.length === 1 ? data.name : `Copy of: ${copyToProject.name}`;
471 const collection = await dispatch<any>(
472 collectionCopyActions.copyCollection({
475 fromContextMenu: collectionsToCopy.length === 1 ? true : data.fromContextMenu,
478 if (copyToProject && collection) {
479 await dispatch<any>(reloadProjectMatchingUuid([copyToProject.uuid]));
481 snackbarActions.OPEN_SNACKBAR({
482 message: "Collection has been copied.",
484 kind: SnackbarKind.SUCCESS,
485 link: collection.ownerUuid,
488 dispatch<any>(deselectOne(copyToProject.uuid));
492 snackbarActions.OPEN_SNACKBAR({
495 kind: SnackbarKind.ERROR,
500 dispatch(projectPanelActions.REQUEST_ITEMS());
503 export const moveCollection =
504 (data: MoveToFormDialogData, isSecondaryMove = false) =>
505 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
506 const checkedList = getState().multiselect.checkedList;
507 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
509 //if no items in checkedlist && no items passed in, default to normal context menu behavior
510 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
512 const collectionsToMove: MoveableResource[] = uuidsToMove
513 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
514 .filter(resource => resource.kind === ResourceKind.COLLECTION);
516 for (const collection of collectionsToMove) {
517 await moveSingleCollection(collection);
520 //omly propagate if this call is the original
521 if (!isSecondaryMove) {
522 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
523 kindsToMove.delete(ResourceKind.COLLECTION);
525 kindsToMove.forEach(kind => {
526 secondaryMove[kind](data, true)(dispatch, getState, services);
530 async function moveSingleCollection(collection: MoveableResource) {
532 const oldCollection: MoveToFormDialogData = { name: collection.name, uuid: collection.uuid, ownerUuid: data.ownerUuid };
533 const movedCollection = await dispatch<any>(collectionMoveActions.moveCollection(oldCollection));
534 dispatch<any>(updateResources([movedCollection]));
535 dispatch<any>(reloadProjectMatchingUuid([movedCollection.ownerUuid]));
537 snackbarActions.OPEN_SNACKBAR({
538 message: "Collection has been moved.",
540 kind: SnackbarKind.SUCCESS,
545 snackbarActions.OPEN_SNACKBAR({
548 kind: SnackbarKind.ERROR,
555 export const loadProcess = (uuid: string) =>
556 handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState) => {
558 dispatch(progressIndicatorActions.START_WORKING(uuid));
559 dispatch<any>(loadProcessPanel(uuid));
560 const process = await dispatch<any>(processesActions.loadProcess(uuid));
562 await dispatch<any>(finishLoadingProject(process.containerRequest.ownerUuid));
563 await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
564 dispatch<any>(setProcessBreadcrumbs(uuid));
565 dispatch<any>(loadDetailsPanel(uuid));
568 dispatch(progressIndicatorActions.STOP_WORKING(uuid));
572 export const loadRegisteredWorkflow = (uuid: string) =>
573 handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
574 const userUuid = getUserUuid(getState());
576 const match = await loadGroupContentsResource({
581 let workflow: WorkflowResource | undefined;
583 | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
586 OWNED: async theworkflow => {
587 workflow = theworkflow as WorkflowResource;
588 breadcrumbfunc = setSidePanelBreadcrumbs;
590 SHARED: async theworkflow => {
591 workflow = theworkflow as WorkflowResource;
592 breadcrumbfunc = setSharedWithMeBreadcrumbs;
596 if (workflow && breadcrumbfunc) {
597 dispatch(updateResources([workflow]));
598 await dispatch<any>(finishLoadingProject(workflow.ownerUuid));
599 await dispatch<any>(activateSidePanelTreeItem(workflow.ownerUuid));
600 dispatch<any>(breadcrumbfunc(workflow.ownerUuid));
601 dispatch(workflowProcessesPanelActions.REQUEST_ITEMS());
606 export const updateProcess = (data: processUpdateActions.ProcessUpdateFormDialogData) => async (dispatch: Dispatch) => {
608 const process = await dispatch<any>(processUpdateActions.updateProcess(data));
611 snackbarActions.OPEN_SNACKBAR({
612 message: "Process has been successfully updated.",
614 kind: SnackbarKind.SUCCESS,
617 dispatch<any>(updateResources([process]));
618 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
622 snackbarActions.OPEN_SNACKBAR({
625 kind: SnackbarKind.ERROR,
631 export const moveProcess =
632 (data: MoveToFormDialogData, isSecondaryMove = false) =>
633 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
634 const checkedList = getState().multiselect.checkedList;
635 const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
637 //if no items in checkedlist && no items passed in, default to normal context menu behavior
638 if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
640 const processesToMove: MoveableResource[] = uuidsToMove
641 .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
642 .filter(resource => resource.kind === ResourceKind.PROCESS);
644 for (const process of processesToMove) {
645 await moveSingleProcess(process);
648 //omly propagate if this call is the original
649 if (!isSecondaryMove) {
650 const kindsToMove: Set<string> = selectedToKindSet(checkedList);
651 kindsToMove.delete(ResourceKind.PROCESS);
653 kindsToMove.forEach(kind => {
654 secondaryMove[kind](data, true)(dispatch, getState, services);
658 async function moveSingleProcess(process: MoveableResource) {
660 const oldProcess: MoveToFormDialogData = { name: process.name, uuid: process.uuid, ownerUuid: data.ownerUuid };
661 const movedProcess = await dispatch<any>(processMoveActions.moveProcess(oldProcess));
662 dispatch<any>(updateResources([movedProcess]));
663 dispatch<any>(reloadProjectMatchingUuid([movedProcess.ownerUuid]));
665 snackbarActions.OPEN_SNACKBAR({
666 message: "Process has been moved.",
668 kind: SnackbarKind.SUCCESS,
673 snackbarActions.OPEN_SNACKBAR({
676 kind: SnackbarKind.ERROR,
683 export const copyProcess = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
685 const process = await dispatch<any>(processCopyActions.copyProcess(data));
686 dispatch<any>(updateResources([process]));
687 dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
689 snackbarActions.OPEN_SNACKBAR({
690 message: "Process has been copied.",
692 kind: SnackbarKind.SUCCESS,
695 dispatch<any>(navigateTo(process.uuid));
698 snackbarActions.OPEN_SNACKBAR({
701 kind: SnackbarKind.ERROR,
707 export const resourceIsNotLoaded = (uuid: string) =>
708 snackbarActions.OPEN_SNACKBAR({
709 message: `Resource identified by ${uuid} is not loaded.`,
710 kind: SnackbarKind.ERROR,
713 export const userIsNotAuthenticated = snackbarActions.OPEN_SNACKBAR({
714 message: "User is not authenticated",
715 kind: SnackbarKind.ERROR,
718 export const couldNotLoadUser = snackbarActions.OPEN_SNACKBAR({
719 message: "Could not load user",
720 kind: SnackbarKind.ERROR,
723 export const reloadProjectMatchingUuid =
724 (matchingUuids: string[]) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
725 const currentProjectPanelUuid = getProjectPanelCurrentUuid(getState());
726 if (currentProjectPanelUuid && matchingUuids.some(uuid => uuid === currentProjectPanelUuid)) {
727 dispatch<any>(loadProject(currentProjectPanelUuid));
731 export const loadSharedWithMe = handleFirstTimeLoad(async (dispatch: Dispatch) => {
732 dispatch<any>(loadSharedWithMePanel());
733 await dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.SHARED_WITH_ME));
734 await dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.SHARED_WITH_ME));
737 export const loadRunProcess = handleFirstTimeLoad(async (dispatch: Dispatch) => {
738 await dispatch<any>(loadRunProcessPanel());
741 export const loadPublicFavorites = () =>
742 handleFirstTimeLoad((dispatch: Dispatch) => {
743 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.PUBLIC_FAVORITES));
744 dispatch<any>(loadPublicFavoritePanel());
745 dispatch<any>(setSidePanelBreadcrumbs(SidePanelTreeCategory.PUBLIC_FAVORITES));
748 export const loadSearchResults = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
749 await dispatch(loadSearchResultsPanel());
752 export const loadLinks = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
753 await dispatch(loadLinkPanel());
756 export const loadVirtualMachines = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
757 await dispatch(loadVirtualMachinesPanel());
758 dispatch(setVirtualMachinesBreadcrumbs());
759 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.SHELL_ACCESS));
762 export const loadVirtualMachinesAdmin = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
763 await dispatch(loadVirtualMachinesPanel());
764 dispatch(setVirtualMachinesAdminBreadcrumbs());
765 dispatch(treePickerActions.DEACTIVATE_TREE_PICKER_NODE({ pickerId: SIDE_PANEL_TREE }))
768 export const loadRepositories = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
769 await dispatch(loadRepositoriesPanel());
770 dispatch(setRepositoriesBreadcrumbs());
773 export const loadSshKeys = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
774 await dispatch(loadSshKeysPanel());
777 export const loadInstanceTypes = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
778 dispatch<any>(activateSidePanelTreeItem(SidePanelTreeCategory.INSTANCE_TYPES));
779 dispatch(setInstanceTypesBreadcrumbs());
782 export const loadSiteManager = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
783 await dispatch(loadSiteManagerPanel());
786 export const loadUserProfile = (userUuid?: string) =>
787 handleFirstTimeLoad((dispatch: Dispatch<any>) => {
789 dispatch(setUserProfileBreadcrumbs(userUuid));
790 dispatch(userProfilePanelActions.loadUserProfilePanel(userUuid));
792 dispatch(setMyAccountBreadcrumbs());
793 dispatch(userProfilePanelActions.loadUserProfilePanel());
797 export const loadLinkAccount = handleFirstTimeLoad((dispatch: Dispatch<any>) => {
798 dispatch(loadLinkAccountPanel());
801 export const loadKeepServices = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
802 await dispatch(loadKeepServicesPanel());
805 export const loadUsers = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
806 await dispatch(loadUsersPanel());
807 dispatch(setUsersBreadcrumbs());
810 export const loadApiClientAuthorizations = handleFirstTimeLoad(async (dispatch: Dispatch<any>) => {
811 await dispatch(loadApiClientAuthorizationsPanel());
814 export const loadGroupsPanel = handleFirstTimeLoad((dispatch: Dispatch<any>) => {
815 dispatch(setGroupsBreadcrumbs());
816 dispatch(groupPanelActions.loadGroupsPanel());
819 export const loadGroupDetailsPanel = (groupUuid: string) =>
820 handleFirstTimeLoad((dispatch: Dispatch<any>) => {
821 dispatch(setGroupDetailsBreadcrumbs(groupUuid));
822 dispatch(groupDetailsPanelActions.loadGroupDetailsPanel(groupUuid));
825 const finishLoadingProject = (project: GroupContentsResource | string) => async (dispatch: Dispatch<any>) => {
826 const uuid = typeof project === "string" ? project : project.uuid;
827 dispatch(loadDetailsPanel(uuid));
828 if (typeof project !== "string") {
829 dispatch(updateResources([project]));
833 const loadGroupContentsResource = async (params: { uuid: string; userUuid: string; services: ServiceRepository }) => {
834 const filters = new FilterBuilder().addEqual("uuid", params.uuid).getFilters();
835 const { items } = await params.services.groupsService.contents(params.userUuid, {
840 const resource = items.shift();
841 let handler: GroupContentsHandler;
844 (resource.kind === ResourceKind.COLLECTION || resource.kind === ResourceKind.PROJECT) && resource.isTrashed
845 ? groupContentsHandlers.TRASHED(resource)
846 : groupContentsHandlers.OWNED(resource);
848 const kind = extractUuidKind(params.uuid);
849 let resource: GroupContentsResource;
850 if (kind === ResourceKind.COLLECTION) {
851 resource = await params.services.collectionService.get(params.uuid);
852 } else if (kind === ResourceKind.PROJECT) {
853 resource = await params.services.projectService.get(params.uuid);
854 } else if (kind === ResourceKind.WORKFLOW) {
855 resource = await params.services.workflowService.get(params.uuid);
856 } else if (kind === ResourceKind.CONTAINER_REQUEST) {
857 resource = await params.services.containerRequestService.get(params.uuid);
859 throw new Error("loadGroupContentsResource unsupported kind " + kind);
861 handler = groupContentsHandlers.SHARED(resource);
863 return (cases: MatchCases<typeof groupContentsHandlersRecord, GroupContentsHandler, void>) => groupContentsHandlers.match(handler, cases);
866 const groupContentsHandlersRecord = {
867 TRASHED: ofType<GroupContentsResource>(),
868 SHARED: ofType<GroupContentsResource>(),
869 OWNED: ofType<GroupContentsResource>(),
872 const groupContentsHandlers = unionize(groupContentsHandlersRecord);
874 type GroupContentsHandler = UnionOf<typeof groupContentsHandlers>;
876 type CollectionCopyResource = Resource & { name: string; fromContextMenu: boolean };
878 type MoveableResource = Resource & { name: string };
881 data: MoveToFormDialogData,
882 isSecondaryMove?: boolean
883 ) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>;
885 const secondaryMove: Record<string, MoveFunc> = {
886 [ResourceKind.PROJECT]: moveProject,
887 [ResourceKind.PROCESS]: moveProcess,
888 [ResourceKind.COLLECTION]: moveCollection,