import { loadDetailsPanel } from "store/details-panel/details-panel-action";
import { snackbarActions, SnackbarKind } from "store/snackbar/snackbar-actions";
import { favoritePanelActions, loadFavoritePanel } from "store/favorite-panel/favorite-panel-action";
-import {
- getProjectPanelCurrentUuid,
- openProjectPanel,
- projectPanelActions,
- setIsProjectPanelTrashed,
-} from "store/project-panel/project-panel-action";
+import { getProjectPanelCurrentUuid, setIsProjectPanelTrashed } from "store/project-panel/project-panel-action";
+import { projectPanelActions } from "store/project-panel/project-panel-action-bind";
import {
activateSidePanelTreeItem,
initSidePanelTree,
import { allProcessesPanelColumns } from "views/all-processes-panel/all-processes-panel";
import { AdminMenuIcon } from "components/icon/icon";
import { userProfileGroupsColumns } from "views/user-profile-panel/user-profile-panel-root";
-import { selectedToArray } from "components/multiselectToolbar/MultiselectToolbar";
+import { selectedToArray, selectedToKindSet } from "components/multiselect-toolbar/MultiselectToolbar";
+import { multiselectActions } from "store/multiselect/multiselect-actions";
export const WORKBENCH_LOADING_SCREEN = "workbenchLoadingScreen";
export const handleFirstTimeLoad = (action: any) => async (dispatch: Dispatch<any>, getState: () => RootState) => {
try {
await dispatch(action);
+ } catch (e) {
+ snackbarActions.OPEN_SNACKBAR({
+ message: "Error " + e,
+ hideDuration: 8000,
+ kind: SnackbarKind.WARNING,
+ })
} finally {
if (isWorkbenchLoading(getState())) {
dispatch(progressIndicatorActions.STOP_WORKING(WORKBENCH_LOADING_SCREEN));
if (!userUuid) {
return;
}
- if (extractUuidKind(uuid) === ResourceKind.USER && userUuid !== uuid) {
- // Load another users home projects
- dispatch(finishLoadingProject(uuid));
- } else if (userUuid !== uuid) {
- await dispatch(finishLoadingProject(uuid));
- const match = await loadGroupContentsResource({
- uuid,
- userUuid,
- services,
- });
- match({
- OWNED: async () => {
- await dispatch(activateSidePanelTreeItem(uuid));
- dispatch<any>(setSidePanelBreadcrumbs(uuid));
- },
- SHARED: async () => {
- await dispatch(activateSidePanelTreeItem(uuid));
- dispatch<any>(setSharedWithMeBreadcrumbs(uuid));
- },
- TRASHED: async () => {
- await dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
- dispatch<any>(setTrashBreadcrumbs(uuid));
- dispatch(setIsProjectPanelTrashed(true));
- },
- });
- } else {
- await dispatch(finishLoadingProject(userUuid));
- await dispatch(activateSidePanelTreeItem(userUuid));
- dispatch<any>(setSidePanelBreadcrumbs(userUuid));
+ try {
+ dispatch(progressIndicatorActions.START_WORKING(uuid));
+ if (extractUuidKind(uuid) === ResourceKind.USER && userUuid !== uuid) {
+ // Load another users home projects
+ dispatch(finishLoadingProject(uuid));
+ } else if (userUuid !== uuid) {
+ await dispatch(finishLoadingProject(uuid));
+ const match = await loadGroupContentsResource({
+ uuid,
+ userUuid,
+ services,
+ });
+ match({
+ OWNED: async () => {
+ await dispatch(activateSidePanelTreeItem(uuid));
+ dispatch<any>(setSidePanelBreadcrumbs(uuid));
+ },
+ SHARED: async () => {
+ await dispatch(activateSidePanelTreeItem(uuid));
+ dispatch<any>(setSharedWithMeBreadcrumbs(uuid));
+ },
+ TRASHED: async () => {
+ await dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH));
+ dispatch<any>(setTrashBreadcrumbs(uuid));
+ dispatch(setIsProjectPanelTrashed(true));
+ },
+ });
+ } else {
+ await dispatch(finishLoadingProject(userUuid));
+ await dispatch(activateSidePanelTreeItem(userUuid));
+ dispatch<any>(setSidePanelBreadcrumbs(userUuid));
+ }
+ } finally {
+ dispatch(progressIndicatorActions.STOP_WORKING(uuid));
}
});
}
};
-export const moveProject = (data: MoveToFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
- const projectsToMove: string[] = selectedToArray(getState().multiselect.checkedList);
- //if no items in checkedlist, default to normal context menu behavior
- if (!projectsToMove.length) projectsToMove.push(data.uuid);
- const sourceUuid = getResource(data.uuid)(getState().resources)?.ownerUuid;
- const destinationUuid = data.ownerUuid;
+export const moveProject =
+ (data: MoveToFormDialogData, isSecondaryMove = false) =>
+ async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+ const checkedList = getState().multiselect.checkedList;
+ const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
- for (const projectUuid of projectsToMove) {
- await moveSingleProject(projectUuid);
- }
+ //if no items in checkedlist default to normal context menu behavior
+ if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
+
+ const sourceUuid = getResource(data.uuid)(getState().resources)?.ownerUuid;
+ const destinationUuid = data.ownerUuid;
+
+ const projectsToMove: MoveableResource[] = uuidsToMove
+ .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
+ .filter(resource => resource.kind === ResourceKind.PROJECT);
+
+ for (const project of projectsToMove) {
+ await moveSingleProject(project);
+ }
+
+ //omly propagate if this call is the original
+ if (!isSecondaryMove) {
+ const kindsToMove: Set<string> = selectedToKindSet(checkedList);
+ kindsToMove.delete(ResourceKind.PROJECT);
- async function moveSingleProject(projectUuid) {
- const originalProject = getResource(projectUuid)(getState().resources) as Resource & { name: string };
- if (originalProject.kind === ResourceKind.PROJECT) {
- try {
- const oldProject: MoveToFormDialogData = { name: originalProject.name, uuid: originalProject.uuid, ownerUuid: data.ownerUuid };
- const oldOwnerUuid = oldProject ? oldProject.ownerUuid : "";
- const movedProject = await dispatch<any>(projectMoveActions.moveProject(oldProject));
- if (movedProject) {
+ kindsToMove.forEach(kind => {
+ secondaryMove[kind](data, true)(dispatch, getState, services);
+ });
+ }
+
+ async function moveSingleProject(project: MoveableResource) {
+ try {
+ const oldProject: MoveToFormDialogData = { name: project.name, uuid: project.uuid, ownerUuid: data.ownerUuid };
+ const oldOwnerUuid = oldProject ? oldProject.ownerUuid : "";
+ const movedProject = await dispatch<any>(projectMoveActions.moveProject(oldProject));
+ if (movedProject) {
+ dispatch(
+ snackbarActions.OPEN_SNACKBAR({
+ message: "Project has been moved",
+ hideDuration: 2000,
+ kind: SnackbarKind.SUCCESS,
+ })
+ );
+ await dispatch<any>(reloadProjectMatchingUuid([oldOwnerUuid, movedProject.ownerUuid, movedProject.uuid]));
+ }
+ } catch (e) {
dispatch(
snackbarActions.OPEN_SNACKBAR({
- message: "Project has been moved",
+ message: e.message,
hideDuration: 2000,
- kind: SnackbarKind.SUCCESS,
+ kind: SnackbarKind.ERROR,
})
);
- await dispatch<any>(reloadProjectMatchingUuid([oldOwnerUuid, movedProject.ownerUuid, movedProject.uuid]));
}
- } catch (e) {
- dispatch(
- snackbarActions.OPEN_SNACKBAR({
- message: e.message,
- hideDuration: 2000,
- kind: SnackbarKind.ERROR,
- })
- );
}
- }
- }
- if (sourceUuid) await dispatch<any>(loadSidePanelTreeProjects(sourceUuid));
- await dispatch<any>(loadSidePanelTreeProjects(destinationUuid));
-};
+ if (sourceUuid) await dispatch<any>(loadSidePanelTreeProjects(sourceUuid));
+ await dispatch<any>(loadSidePanelTreeProjects(destinationUuid));
+ };
export const updateProject = (data: projectUpdateActions.ProjectUpdateFormDialogData) => async (dispatch: Dispatch) => {
const updatedProject = await dispatch<any>(projectUpdateActions.updateProject(data));
export const loadCollection = (uuid: string) =>
handleFirstTimeLoad(async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
const userUuid = getUserUuid(getState());
- if (userUuid) {
- const match = await loadGroupContentsResource({
- uuid,
- userUuid,
- services,
- });
- let collection: CollectionResource | undefined;
- let breadcrumbfunc:
- | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
- | undefined;
- let sidepanel: string | undefined;
- match({
- OWNED: thecollection => {
- collection = thecollection as CollectionResource;
- sidepanel = collection.ownerUuid;
- breadcrumbfunc = setSidePanelBreadcrumbs;
- },
- SHARED: thecollection => {
- collection = thecollection as CollectionResource;
- sidepanel = collection.ownerUuid;
- breadcrumbfunc = setSharedWithMeBreadcrumbs;
- },
- TRASHED: thecollection => {
- collection = thecollection as CollectionResource;
- sidepanel = SidePanelTreeCategory.TRASH;
- breadcrumbfunc = () => setTrashBreadcrumbs("");
- },
- });
- if (collection && breadcrumbfunc && sidepanel) {
- dispatch(updateResources([collection]));
- await dispatch<any>(finishLoadingProject(collection.ownerUuid));
- dispatch(collectionPanelActions.SET_COLLECTION(collection));
- await dispatch(activateSidePanelTreeItem(sidepanel));
- dispatch(breadcrumbfunc(collection.ownerUuid));
- dispatch(loadCollectionPanel(collection.uuid));
+ try {
+ dispatch(progressIndicatorActions.START_WORKING(uuid));
+ if (userUuid) {
+ const match = await loadGroupContentsResource({
+ uuid,
+ userUuid,
+ services,
+ });
+ let collection: CollectionResource | undefined;
+ let breadcrumbfunc:
+ | ((uuid: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>)
+ | undefined;
+ let sidepanel: string | undefined;
+ match({
+ OWNED: thecollection => {
+ collection = thecollection as CollectionResource;
+ sidepanel = collection.ownerUuid;
+ breadcrumbfunc = setSidePanelBreadcrumbs;
+ },
+ SHARED: thecollection => {
+ collection = thecollection as CollectionResource;
+ sidepanel = collection.ownerUuid;
+ breadcrumbfunc = setSharedWithMeBreadcrumbs;
+ },
+ TRASHED: thecollection => {
+ collection = thecollection as CollectionResource;
+ sidepanel = SidePanelTreeCategory.TRASH;
+ breadcrumbfunc = () => setTrashBreadcrumbs("");
+ },
+ });
+ if (collection && breadcrumbfunc && sidepanel) {
+ dispatch(updateResources([collection]));
+ await dispatch<any>(finishLoadingProject(collection.ownerUuid));
+ dispatch(collectionPanelActions.SET_COLLECTION(collection));
+ await dispatch(activateSidePanelTreeItem(sidepanel));
+ dispatch(breadcrumbfunc(collection.ownerUuid));
+ dispatch(loadCollectionPanel(collection.uuid));
+ }
}
+ } finally {
+ dispatch(progressIndicatorActions.STOP_WORKING(uuid));
}
});
};
export const copyCollection = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
- try {
- const copyToProject = getResource(data.ownerUuid)(getState().resources);
- const collection = await dispatch<any>(collectionCopyActions.copyCollection(data));
- if (copyToProject && collection) {
- dispatch<any>(reloadProjectMatchingUuid([copyToProject.uuid]));
+ const checkedList = getState().multiselect.checkedList;
+ const uuidsToCopy: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
+
+ //if no items in checkedlist && no items passed in, default to normal context menu behavior
+ if (!uuidsToCopy.length) uuidsToCopy.push(data.uuid);
+
+ const collectionsToCopy: CollectionCopyResource[] = uuidsToCopy
+ .map(uuid => getResource(uuid)(getState().resources) as CollectionCopyResource)
+ .filter(resource => resource.kind === ResourceKind.COLLECTION);
+
+ for (const collection of collectionsToCopy) {
+ await copySingleCollection({ ...collection, ownerUuid: data.ownerUuid } as CollectionCopyResource);
+ }
+
+ async function copySingleCollection(copyToProject: CollectionCopyResource) {
+ const newName = data.fromContextMenu || collectionsToCopy.length === 1 ? data.name : `Copy of: ${copyToProject.name}`;
+ try {
+ const collection = await dispatch<any>(
+ collectionCopyActions.copyCollection({
+ ...copyToProject,
+ name: newName,
+ fromContextMenu: collectionsToCopy.length === 1 ? true : data.fromContextMenu,
+ })
+ );
+ if (copyToProject && collection) {
+ await dispatch<any>(reloadProjectMatchingUuid([copyToProject.uuid]));
+ dispatch(
+ snackbarActions.OPEN_SNACKBAR({
+ message: "Collection has been copied.",
+ hideDuration: 3000,
+ kind: SnackbarKind.SUCCESS,
+ link: collection.ownerUuid,
+ })
+ );
+ dispatch<any>(multiselectActions.deselectOne(copyToProject.uuid));
+ }
+ } catch (e) {
dispatch(
snackbarActions.OPEN_SNACKBAR({
- message: "Collection has been copied.",
- hideDuration: 3000,
- kind: SnackbarKind.SUCCESS,
- link: collection.ownerUuid,
+ message: e.message,
+ hideDuration: 2000,
+ kind: SnackbarKind.ERROR,
})
);
}
- } catch (e) {
- dispatch(
- snackbarActions.OPEN_SNACKBAR({
- message: e.message,
- hideDuration: 2000,
- kind: SnackbarKind.ERROR,
- })
- );
}
+ dispatch(projectPanelActions.REQUEST_ITEMS());
};
-export const moveCollection = (data: MoveToFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
- try {
- const collection = await dispatch<any>(collectionMoveActions.moveCollection(data));
- dispatch<any>(updateResources([collection]));
- dispatch<any>(reloadProjectMatchingUuid([collection.ownerUuid]));
- dispatch(
- snackbarActions.OPEN_SNACKBAR({
- message: "Collection has been moved.",
- hideDuration: 2000,
- kind: SnackbarKind.SUCCESS,
- })
- );
- } catch (e) {
- dispatch(
- snackbarActions.OPEN_SNACKBAR({
- message: e.message,
- hideDuration: 2000,
- kind: SnackbarKind.ERROR,
- })
- );
- }
-};
+export const moveCollection =
+ (data: MoveToFormDialogData, isSecondaryMove = false) =>
+ async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+ const checkedList = getState().multiselect.checkedList;
+ const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
+
+ //if no items in checkedlist && no items passed in, default to normal context menu behavior
+ if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
+
+ const collectionsToMove: MoveableResource[] = uuidsToMove
+ .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
+ .filter(resource => resource.kind === ResourceKind.COLLECTION);
+
+ for (const collection of collectionsToMove) {
+ await moveSingleCollection(collection);
+ }
+
+ //omly propagate if this call is the original
+ if (!isSecondaryMove) {
+ const kindsToMove: Set<string> = selectedToKindSet(checkedList);
+ kindsToMove.delete(ResourceKind.COLLECTION);
+
+ kindsToMove.forEach(kind => {
+ secondaryMove[kind](data, true)(dispatch, getState, services);
+ });
+ }
+
+ async function moveSingleCollection(collection: MoveableResource) {
+ try {
+ const oldCollection: MoveToFormDialogData = { name: collection.name, uuid: collection.uuid, ownerUuid: data.ownerUuid };
+ const movedCollection = await dispatch<any>(collectionMoveActions.moveCollection(oldCollection));
+ dispatch<any>(updateResources([movedCollection]));
+ dispatch<any>(reloadProjectMatchingUuid([movedCollection.ownerUuid]));
+ dispatch(
+ snackbarActions.OPEN_SNACKBAR({
+ message: "Collection has been moved.",
+ hideDuration: 2000,
+ kind: SnackbarKind.SUCCESS,
+ })
+ );
+ } catch (e) {
+ dispatch(
+ snackbarActions.OPEN_SNACKBAR({
+ message: e.message,
+ hideDuration: 2000,
+ kind: SnackbarKind.ERROR,
+ })
+ );
+ }
+ }
+ };
export const loadProcess = (uuid: string) =>
handleFirstTimeLoad(async (dispatch: Dispatch, getState: () => RootState) => {
- dispatch<any>(loadProcessPanel(uuid));
- const process = await dispatch<any>(processesActions.loadProcess(uuid));
- if (process) {
- await dispatch<any>(finishLoadingProject(process.containerRequest.ownerUuid));
- await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
- dispatch<any>(setProcessBreadcrumbs(uuid));
- dispatch<any>(loadDetailsPanel(uuid));
+ try {
+ dispatch(progressIndicatorActions.START_WORKING(uuid));
+ dispatch<any>(loadProcessPanel(uuid));
+ const process = await dispatch<any>(processesActions.loadProcess(uuid));
+ if (process) {
+ await dispatch<any>(finishLoadingProject(process.containerRequest.ownerUuid));
+ await dispatch<any>(activateSidePanelTreeItem(process.containerRequest.ownerUuid));
+ dispatch<any>(setProcessBreadcrumbs(uuid));
+ dispatch<any>(loadDetailsPanel(uuid));
+ }
+ } finally {
+ dispatch(progressIndicatorActions.STOP_WORKING(uuid));
}
});
workflow = theworkflow as WorkflowResource;
breadcrumbfunc = setSharedWithMeBreadcrumbs;
},
- TRASHED: () => {},
+ TRASHED: () => { },
});
if (workflow && breadcrumbfunc) {
dispatch(updateResources([workflow]));
}
};
-export const moveProcess = (data: MoveToFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
- console.log("PROCESSS_DATA: ", data);
- try {
- const process = await dispatch<any>(processMoveActions.moveProcess(data));
- dispatch<any>(updateResources([process]));
- dispatch<any>(reloadProjectMatchingUuid([process.ownerUuid]));
- dispatch(
- snackbarActions.OPEN_SNACKBAR({
- message: "Process has been moved.",
- hideDuration: 2000,
- kind: SnackbarKind.SUCCESS,
- })
- );
- } catch (e) {
- dispatch(
- snackbarActions.OPEN_SNACKBAR({
- message: e.message,
- hideDuration: 2000,
- kind: SnackbarKind.ERROR,
- })
- );
- }
-};
+export const moveProcess =
+ (data: MoveToFormDialogData, isSecondaryMove = false) =>
+ async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+ const checkedList = getState().multiselect.checkedList;
+ const uuidsToMove: string[] = data.fromContextMenu ? [data.uuid] : selectedToArray(checkedList);
+
+ //if no items in checkedlist && no items passed in, default to normal context menu behavior
+ if (!isSecondaryMove && !uuidsToMove.length) uuidsToMove.push(data.uuid);
+
+ const processesToMove: MoveableResource[] = uuidsToMove
+ .map(uuid => getResource(uuid)(getState().resources) as MoveableResource)
+ .filter(resource => resource.kind === ResourceKind.PROCESS);
+
+ for (const process of processesToMove) {
+ await moveSingleProcess(process);
+ }
+
+ //omly propagate if this call is the original
+ if (!isSecondaryMove) {
+ const kindsToMove: Set<string> = selectedToKindSet(checkedList);
+ kindsToMove.delete(ResourceKind.PROCESS);
+
+ kindsToMove.forEach(kind => {
+ secondaryMove[kind](data, true)(dispatch, getState, services);
+ });
+ }
+
+ async function moveSingleProcess(process: MoveableResource) {
+ try {
+ const oldProcess: MoveToFormDialogData = { name: process.name, uuid: process.uuid, ownerUuid: data.ownerUuid };
+ const movedProcess = await dispatch<any>(processMoveActions.moveProcess(oldProcess));
+ dispatch<any>(updateResources([movedProcess]));
+ dispatch<any>(reloadProjectMatchingUuid([movedProcess.ownerUuid]));
+ dispatch(
+ snackbarActions.OPEN_SNACKBAR({
+ message: "Process has been moved.",
+ hideDuration: 2000,
+ kind: SnackbarKind.SUCCESS,
+ })
+ );
+ } catch (e) {
+ dispatch(
+ snackbarActions.OPEN_SNACKBAR({
+ message: e.message,
+ hideDuration: 2000,
+ kind: SnackbarKind.ERROR,
+ })
+ );
+ }
+ }
+ };
export const copyProcess = (data: CopyFormDialogData) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
try {
const finishLoadingProject = (project: GroupContentsResource | string) => async (dispatch: Dispatch<any>) => {
const uuid = typeof project === "string" ? project : project.uuid;
- dispatch(openProjectPanel(uuid));
dispatch(loadDetailsPanel(uuid));
if (typeof project !== "string") {
dispatch(updateResources([project]));
const groupContentsHandlers = unionize(groupContentsHandlersRecord);
type GroupContentsHandler = UnionOf<typeof groupContentsHandlers>;
+
+type CollectionCopyResource = Resource & { name: string; fromContextMenu: boolean };
+
+type MoveableResource = Resource & { name: string };
+
+type MoveFunc = (
+ data: MoveToFormDialogData,
+ isSecondaryMove?: boolean
+) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => Promise<void>;
+
+const secondaryMove: Record<string, MoveFunc> = {
+ [ResourceKind.PROJECT]: moveProject,
+ [ResourceKind.PROCESS]: moveProcess,
+ [ResourceKind.COLLECTION]: moveCollection,
+};