-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,
+ })
+ );
+ }
+ }
+ };