21448: sorter sorts Arvados-DCO-1.1-Signed-off-by: Lisa Knox <lisa.knox@curii.com>
authorLisa Knox <lisaknox83@gmail.com>
Thu, 28 Mar 2024 18:51:28 +0000 (14:51 -0400)
committerLisa Knox <lisaknox83@gmail.com>
Thu, 28 Mar 2024 18:51:28 +0000 (14:51 -0400)
16 files changed:
services/workbench2/src/common/menu-item-sort.ts [deleted file]
services/workbench2/src/components/multiselect-toolbar/MultiselectToolbar.tsx
services/workbench2/src/components/multiselect-toolbar/ms-toolbar-action-filters.ts
services/workbench2/src/index.tsx
services/workbench2/src/store/context-menu/context-menu-actions.test.ts
services/workbench2/src/store/context-menu/context-menu-actions.ts
services/workbench2/src/views-components/collection-panel-files/collection-panel-files.ts
services/workbench2/src/views-components/context-menu/actions/collection-copy-to-clipboard-action.tsx
services/workbench2/src/views-components/context-menu/actions/collection-file-viewer-action.test.tsx
services/workbench2/src/views-components/context-menu/actions/collection-file-viewer-action.tsx
services/workbench2/src/views-components/context-menu/actions/download-collection-file-action.tsx
services/workbench2/src/views-components/context-menu/context-menu.tsx
services/workbench2/src/views-components/context-menu/menu-item-sort.ts [new file with mode: 0644]
services/workbench2/src/views/groups-panel/groups-panel.tsx
services/workbench2/src/views/process-panel/process-output-collection-files.ts
services/workbench2/src/views/trash-panel/trash-panel.tsx

diff --git a/services/workbench2/src/common/menu-item-sort.ts b/services/workbench2/src/common/menu-item-sort.ts
deleted file mode 100644 (file)
index 6cf8c9f..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-// Copyright (C) The Arvados Authors. All rights reserved.
-//
-// SPDX-License-Identifier: AGPL-3.0
-
-import { ContextMenuAction } from '../views-components/context-menu/context-menu-action-set';
-import { ContextMenuActionNames } from 'views-components/context-menu/context-menu-action-set';
-
-const {
-    ACCOUNT_SETTINGS,
-    ACTIVATE_USER,
-    ADD_TO_FAVORITES,
-    ADD_TO_PUBLIC_FAVORITES,
-    ATTRIBUTES,
-    API_DETAILS,
-    CANCEL,
-    COPY_AND_RERUN_PROCESS,
-    COPY_ITEM_INTO_EXISTING_COLLECTION,
-    COPY_ITEM_INTO_NEW_COLLECTION,
-    COPY_SELECTED_INTO_EXISTING_COLLECTION,
-    COPY_SELECTED_INTO_SEPARATE_COLLECTIONS,
-    COPY_SELECTED_INTO_NEW_COLLECTION,
-    COPY_TO_CLIPBOARD,
-    DEACTIVATE_USER,
-    DELETE_WORKFLOW,
-    DOWNLOAD,
-    EDIT_COLLECTION,
-    EDIT_PROCESS,
-    EDIT_PROJECT,
-    FREEZE_PROJECT,
-    HOME_PROJECT,
-    LOGIN_AS_USER,
-    MAKE_A_COPY,
-    MANAGE,
-    MOVE_ITEM_INTO_EXISTING_COLLECTION,
-    MOVE_ITEM_INTO_NEW_COLLECTION,
-    MOVE_SELECTED_INTO_EXISTING_COLLECTION,
-    MOVE_SELECTED_INTO_NEW_COLLECTION,
-    MOVE_SELECTED_INTO_SEPARATE_COLLECTIONS,
-    MOVE_TO,
-    MOVE_TO_TRASH,
-    NEW_COLLECTION,
-    NEW_PROJECT,
-    OPEN_IN_NEW_TAB,
-    OPEN_WITH_3RD_PARTY_CLIENT,
-    OUTPUTS,
-    PROVENANCE_GRAPH,
-    READ,
-    REMOVE,
-    REMOVE_SELECTED,
-    RENAME,
-    RESTORE,
-    RESTORE_VERSION,
-    RUN_WORKFLOW,
-    SELECT_ALL,
-    SETUP_USER,
-    SHARE,
-    UNSELECT_ALL,
-    VIEW_DETAILS,
-    WRITE,
-} = ContextMenuActionNames;
-
-const processOrder = [VIEW_DETAILS, OPEN_IN_NEW_TAB, OUTPUTS, API_DETAILS, EDIT_PROCESS, COPY_AND_RERUN_PROCESS, MOVE_TO, REMOVE, ADD_TO_FAVORITES, ADD_TO_PUBLIC_FAVORITES];
-
-const kindToOrder: Record<string, ContextMenuActionNames[]> = {
-    "ProcessResource": processOrder,
-};
-
-export const sortMenuItems = (menuKind:string, menuItems: ContextMenuAction[]) => {
-    const order = kindToOrder[menuKind] || [];
-    const bucketMap = new Map();
-    order.forEach((name) => bucketMap.set(name, null));
-    menuItems.forEach((item) => {if (bucketMap.has(item.name)) bucketMap.set(item.name, item)});
-    console.log(Array.from(bucketMap.values()));
-};
\ No newline at end of file
index ae22050f3337dad7d602b4067f25be5e6f6ef014..ff4e6072fba4bd193d02a0d64176f8e724c9537c 100644 (file)
@@ -34,7 +34,7 @@ import { Process } from "store/processes/process";
 import { PublicFavoritesState } from "store/public-favorites/public-favorites-reducer";
 import { isExactlyOneSelected } from "store/multiselect/multiselect-actions";
 import { IntersectionObserverWrapper } from "./ms-toolbar-overflow-wrapper";
-import { ContextMenuKind } from "views-components/context-menu/context-menu";
+import { ContextMenuKind } from 'views-components/context-menu/menu-item-sort';
 
 const WIDTH_TRANSITION = 150
 
index a5498e7a5357ccf22180badf17449618433fcba1..2b30525e56499c95216b24d9eb0176d560149f6a 100644 (file)
@@ -16,7 +16,7 @@ import {
 import { msProcessActionSet, msCommonProcessActionFilter, msAdminProcessActionFilter, msRunningProcessActionFilter } from 'views-components/multiselect-toolbar/ms-process-action-set';
 import { msWorkflowActionSet, msWorkflowActionFilter, msReadOnlyWorkflowActionFilter } from 'views-components/multiselect-toolbar/ms-workflow-action-set';
 import { ResourceKind } from 'models/resource';
-import { ContextMenuKind } from 'views-components/context-menu/context-menu';
+import { ContextMenuKind } from 'views-components/context-menu/menu-item-sort';
 
 const {
     COLLECTION,
index ef9ff9c98693576880141b679db8aff6f675d24c..400b975d4d7de73a47cc91f41db43fb367591aee 100644 (file)
@@ -20,7 +20,8 @@ import { MuiThemeProvider } from "@material-ui/core/styles";
 import { CustomTheme } from "common/custom-theme";
 import { fetchConfig } from "common/config";
 import servicesProvider from "common/service-provider";
-import { addMenuActionSet, ContextMenuKind } from "views-components/context-menu/context-menu";
+import { addMenuActionSet } from "views-components/context-menu/context-menu";
+import { ContextMenuKind } from "views-components/context-menu/menu-item-sort";
 import { rootProjectActionSet } from "views-components/context-menu/action-sets/root-project-action-set";
 import {
     filterGroupActionSet,
index 623c45088cc83922f137896effccf4969e19dc0b..a8b8e4089c622ab9f0a8aba7d86fbb072db39b24 100644 (file)
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { ContextMenuKind } from 'views-components/context-menu/context-menu';
+import { ContextMenuKind } from 'views-components/context-menu/menu-item-sort';
 import { resourceUuidToContextMenuKind } from './context-menu-actions';
 import configureStore from 'redux-mock-store';
 import thunk from 'redux-thunk';
index 464314877ff645328d838f2ddbbb1e4cd2a99ec7..4c31fa4e94b3878631ecadda72b0b832c3e97298 100644 (file)
@@ -4,7 +4,7 @@
 
 import { unionize, ofType, UnionOf } from "common/unionize";
 import { ContextMenuPosition } from "./context-menu-reducer";
-import { ContextMenuKind } from "views-components/context-menu/context-menu";
+import { ContextMenuKind } from "views-components/context-menu/menu-item-sort";
 import { Dispatch } from "redux";
 import { RootState } from "store/store";
 import { getResource, getResourceWithEditableStatus } from "../resources/resources";
index a26b9fe3ee0ad65ab2cc1d6b018de9b5783e90fb..c5bd1d737e8160494b9fe765ba32d79e2a814783 100644 (file)
@@ -10,7 +10,7 @@ import {
 import { RootState } from "store/store";
 import { Dispatch } from "redux";
 import { collectionPanelFilesAction } from "store/collection-panel/collection-panel-files/collection-panel-files-actions";
-import { ContextMenuKind } from "../context-menu/context-menu";
+import { ContextMenuKind } from 'views-components/context-menu/menu-item-sort';
 import { openContextMenu, openCollectionFilesContextMenu } from 'store/context-menu/context-menu-actions';
 import { openUploadCollectionFilesDialog } from 'store/collections/collection-upload-actions';
 import { ResourceKind } from "models/resource";
index c92f7bc88b861e28713c7d3ef5c70ad60601e075..dac3858fb31428d5f502e02c9ad07dd4e7445fa1 100644 (file)
@@ -5,7 +5,7 @@
 import { connect } from "react-redux";
 import { RootState } from "../../../store/store";
 import { getNodeValue } from "models/tree";
-import { ContextMenuKind } from 'views-components/context-menu/context-menu';
+import { ContextMenuKind } from 'views-components/context-menu/menu-item-sort';
 import { CopyToClipboardAction } from "./copy-to-clipboard-action";
 
 const mapStateToProps = (state: RootState) => {
index 8b90f588ffa49ec13e3971f13b6280897fcec6d1..9d8acad20cf3eedde293d5c4d5a0b6aabb377f81 100644 (file)
@@ -8,7 +8,7 @@ import Adapter from 'enzyme-adapter-react-16';
 import configureMockStore from 'redux-mock-store'
 import { Provider } from 'react-redux';
 import { CollectionFileViewerAction } from './collection-file-viewer-action';
-import { ContextMenuKind } from 'views-components/context-menu/context-menu';
+import { ContextMenuKind } from '../menu-item-sort';
 import { createTree, initTreeNode, setNode, getNodeValue } from "models/tree";
 import { getInlineFileUrl, sanitizeToken } from "./helpers";
 
index f736f0bf2705bf8d3481eb974cfdb93a3a1cc23f..06b79bda4d61008340c4c140cd2a78f68e9d2d2c 100644 (file)
@@ -6,7 +6,7 @@ import { connect } from "react-redux";
 import { RootState } from "../../../store/store";
 import { FileViewerAction } from 'views-components/context-menu/actions/file-viewer-action';
 import { getNodeValue } from "models/tree";
-import { ContextMenuKind } from 'views-components/context-menu/context-menu';
+import { ContextMenuKind } from 'views-components/context-menu/menu-item-sort';
 import { getInlineFileUrl, sanitizeToken, isInlineFileUrlSafe } from "./helpers";
 
 const mapStateToProps = (state: RootState) => {
index 3b1f770220a02a6f8faab446797ead523a5cfafe..3b04e29e735c1808d1699ca9d3c0f2125dab1966 100644 (file)
@@ -6,7 +6,7 @@ import { connect } from "react-redux";
 import { RootState } from "../../../store/store";
 import { DownloadAction } from "./download-action";
 import { getNodeValue } from "../../../models/tree";
-import { ContextMenuKind } from '../context-menu';
+import { ContextMenuKind } from 'views-components/context-menu/menu-item-sort';
 import { filterCollectionFilesBySelection } from "store/collection-panel/collection-panel-files/collection-panel-files-state";
 import { sanitizeToken } from "./helpers";
 
index 565785c11e2aa55462fa7e76f0baf6bb75beedfc..6314ba97ad984e716148fd4e75436f0afcef9ef3 100644 (file)
@@ -11,7 +11,7 @@ import { ContextMenuActionSet, ContextMenuAction } from "./context-menu-action-s
 import { Dispatch } from "redux";
 import { memoize } from "lodash";
 import { sortByProperty } from "common/array-utils";
-import { sortMenuItems } from "common/menu-item-sort";
+import { sortMenuItems, ContextMenuKind } from "./menu-item-sort";
 
 type DataProps = Pick<ContextMenuProps, "anchorEl" | "items" | "open"> & { resource?: ContextMenuResource };
 
@@ -66,59 +66,11 @@ export const ContextMenu = connect(mapStateToProps, mapDispatchToProps, mergePro
 
 const menuActionSets = new Map<string, ContextMenuActionSet>();
 
-export const addMenuActionSet = (name: string, itemSet: ContextMenuActionSet) => {
-    const sorted = itemSet.map(items => items.sort(sortByProperty("name")));
+export const addMenuActionSet = (name: ContextMenuKind, itemSet: ContextMenuActionSet) => {
+    const sorted = itemSet.map(items => sortMenuItems(name, items));
     menuActionSets.set(name, sorted);
 };
 
 const emptyActionSet: ContextMenuActionSet = [];
 const getMenuActionSet = (resource?: ContextMenuResource): ContextMenuActionSet =>
     resource ? menuActionSets.get(resource.menuKind) || emptyActionSet : emptyActionSet;
-
-export enum ContextMenuKind {
-    API_CLIENT_AUTHORIZATION = "ApiClientAuthorization",
-    ROOT_PROJECT = "RootProject",
-    PROJECT = "Project",
-    FILTER_GROUP = "FilterGroup",
-    READONLY_PROJECT = "ReadOnlyProject",
-    FROZEN_PROJECT = "FrozenProject",
-    FROZEN_PROJECT_ADMIN = "FrozenProjectAdmin",
-    PROJECT_ADMIN = "ProjectAdmin",
-    FILTER_GROUP_ADMIN = "FilterGroupAdmin",
-    RESOURCE = "Resource",
-    FAVORITE = "Favorite",
-    TRASH = "Trash",
-    COLLECTION_FILES = "CollectionFiles",
-    COLLECTION_FILES_MULTIPLE = "CollectionFilesMultiple",
-    READONLY_COLLECTION_FILES = "ReadOnlyCollectionFiles",
-    READONLY_COLLECTION_FILES_MULTIPLE = "ReadOnlyCollectionFilesMultiple",
-    COLLECTION_FILES_NOT_SELECTED = "CollectionFilesNotSelected",
-    COLLECTION_FILE_ITEM = "CollectionFileItem",
-    COLLECTION_DIRECTORY_ITEM = "CollectionDirectoryItem",
-    READONLY_COLLECTION_FILE_ITEM = "ReadOnlyCollectionFileItem",
-    READONLY_COLLECTION_DIRECTORY_ITEM = "ReadOnlyCollectionDirectoryItem",
-    COLLECTION = "Collection",
-    COLLECTION_ADMIN = "CollectionAdmin",
-    READONLY_COLLECTION = "ReadOnlyCollection",
-    OLD_VERSION_COLLECTION = "OldVersionCollection",
-    TRASHED_COLLECTION = "TrashedCollection",
-    PROCESS = "Process",
-    RUNNING_PROCESS_ADMIN = "RunningProcessAdmin",
-    PROCESS_ADMIN = "ProcessAdmin",
-    RUNNING_PROCESS_RESOURCE = "RunningProcessResource",
-    PROCESS_RESOURCE = "ProcessResource",
-    READONLY_PROCESS_RESOURCE = "ReadOnlyProcessResource",
-    PROCESS_LOGS = "ProcessLogs",
-    REPOSITORY = "Repository",
-    SSH_KEY = "SshKey",
-    VIRTUAL_MACHINE = "VirtualMachine",
-    KEEP_SERVICE = "KeepService",
-    USER = "User",
-    GROUPS = "Group",
-    GROUP_MEMBER = "GroupMember",
-    PERMISSION_EDIT = "PermissionEdit",
-    LINK = "Link",
-    WORKFLOW = "Workflow",
-    READONLY_WORKFLOW = "ReadOnlyWorkflow",
-    SEARCH_RESULTS = "SearchResults",
-}
diff --git a/services/workbench2/src/views-components/context-menu/menu-item-sort.ts b/services/workbench2/src/views-components/context-menu/menu-item-sort.ts
new file mode 100644 (file)
index 0000000..7e14fb6
--- /dev/null
@@ -0,0 +1,89 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { ContextMenuAction } from './context-menu-action-set';
+import { ContextMenuActionNames } from 'views-components/context-menu/context-menu-action-set';
+import { sortByProperty } from 'common/array-utils'; 
+
+export enum ContextMenuKind {
+    API_CLIENT_AUTHORIZATION = "ApiClientAuthorization",
+    ROOT_PROJECT = "RootProject",
+    PROJECT = "Project",
+    FILTER_GROUP = "FilterGroup",
+    READONLY_PROJECT = "ReadOnlyProject",
+    FROZEN_PROJECT = "FrozenProject",
+    FROZEN_PROJECT_ADMIN = "FrozenProjectAdmin",
+    PROJECT_ADMIN = "ProjectAdmin",
+    FILTER_GROUP_ADMIN = "FilterGroupAdmin",
+    RESOURCE = "Resource",
+    FAVORITE = "Favorite",
+    TRASH = "Trash",
+    COLLECTION_FILES = "CollectionFiles",
+    COLLECTION_FILES_MULTIPLE = "CollectionFilesMultiple",
+    READONLY_COLLECTION_FILES = "ReadOnlyCollectionFiles",
+    READONLY_COLLECTION_FILES_MULTIPLE = "ReadOnlyCollectionFilesMultiple",
+    COLLECTION_FILES_NOT_SELECTED = "CollectionFilesNotSelected",
+    COLLECTION_FILE_ITEM = "CollectionFileItem",
+    COLLECTION_DIRECTORY_ITEM = "CollectionDirectoryItem",
+    READONLY_COLLECTION_FILE_ITEM = "ReadOnlyCollectionFileItem",
+    READONLY_COLLECTION_DIRECTORY_ITEM = "ReadOnlyCollectionDirectoryItem",
+    COLLECTION = "Collection",
+    COLLECTION_ADMIN = "CollectionAdmin",
+    READONLY_COLLECTION = "ReadOnlyCollection",
+    OLD_VERSION_COLLECTION = "OldVersionCollection",
+    TRASHED_COLLECTION = "TrashedCollection",
+    PROCESS = "Process",
+    RUNNING_PROCESS_ADMIN = "RunningProcessAdmin",
+    PROCESS_ADMIN = "ProcessAdmin",
+    RUNNING_PROCESS_RESOURCE = "RunningProcessResource",
+    PROCESS_RESOURCE = "ProcessResource",
+    READONLY_PROCESS_RESOURCE = "ReadOnlyProcessResource",
+    PROCESS_LOGS = "ProcessLogs",
+    REPOSITORY = "Repository",
+    SSH_KEY = "SshKey",
+    VIRTUAL_MACHINE = "VirtualMachine",
+    KEEP_SERVICE = "KeepService",
+    USER = "User",
+    GROUPS = "Group",
+    GROUP_MEMBER = "GroupMember",
+    PERMISSION_EDIT = "PermissionEdit",
+    LINK = "Link",
+    WORKFLOW = "Workflow",
+    READONLY_WORKFLOW = "ReadOnlyWorkflow",
+    SEARCH_RESULTS = "SearchResults",
+}
+
+const processOrder = [
+    ContextMenuActionNames.VIEW_DETAILS,
+    ContextMenuActionNames.OPEN_IN_NEW_TAB,
+    ContextMenuActionNames.OUTPUTS,
+    ContextMenuActionNames.API_DETAILS,
+    ContextMenuActionNames.EDIT_PROCESS,
+    ContextMenuActionNames.COPY_AND_RERUN_PROCESS,
+    ContextMenuActionNames.MOVE_TO,
+    ContextMenuActionNames.REMOVE,
+    ContextMenuActionNames.ADD_TO_FAVORITES,
+    ContextMenuActionNames.ADD_TO_PUBLIC_FAVORITES,
+];
+
+const kindToOrder: Record<string, ContextMenuActionNames[]> = {
+    [ContextMenuKind.PROCESS_RESOURCE]: processOrder,
+};
+
+export const sortMenuItems = (menuKind: ContextMenuKind, menuItems: ContextMenuAction[]) => {
+    const order = kindToOrder[menuKind];
+    //if no specified order, sort by name
+    if (!order) return menuItems.sort(sortByProperty("name"));
+
+    const bucketMap = new Map();
+    const leftovers: ContextMenuAction[] = [];
+
+    order.forEach((name) => bucketMap.set(name, null));
+    menuItems.forEach((item) => {
+        if (bucketMap.has(item.name)) bucketMap.set(item.name, item);
+        else leftovers.push(item);
+    });
+    
+    return Array.from(bucketMap.values()).concat(leftovers).filter((item) => item !== null);
+};
index 86c85b5c97f4c909b0c7c8464f1a3dcc0af9180a..e7f682b052fefbb6c5cc7ee3aa4f73679e560c07 100644 (file)
@@ -14,7 +14,7 @@ import { ResourceName } from 'views-components/data-explorer/renderers';
 import { createTree } from 'models/tree';
 import { GROUPS_PANEL_ID, openCreateGroupDialog } from 'store/groups-panel/groups-panel-actions';
 import { noop } from 'lodash/fp';
-import { ContextMenuKind } from 'views-components/context-menu/context-menu';
+import { ContextMenuKind } from 'views-components/context-menu/menu-item-sort';
 import { getResource, ResourcesState } from 'store/resources/resources';
 import { GroupResource } from 'models/group';
 import { RootState } from 'store/store';
index d0b44cd1e6901f051dce7457c0b8d89264d432dd..c8165564bd1cf7a0b35fc15058c93d3bceb2e653 100644 (file)
@@ -9,7 +9,7 @@ import {
 } from "components/collection-panel-files/collection-panel-files";
 import { Dispatch } from "redux";
 import { collectionPanelFilesAction } from "store/collection-panel/collection-panel-files/collection-panel-files-actions";
-import { ContextMenuKind } from "views-components/context-menu/context-menu";
+import { ContextMenuKind } from 'views-components/context-menu/menu-item-sort';
 import { openContextMenu, openCollectionFilesContextMenu } from 'store/context-menu/context-menu-actions';
 import { openUploadCollectionFilesDialog } from 'store/collections/collection-upload-actions';
 import { ResourceKind } from "models/resource";
index ac11bb719535fe42e504a09758ce861f158679ec..31804fbdb8cdb468b758888f1204cb1246b70876 100644 (file)
@@ -28,7 +28,7 @@ import {
 import { navigateTo } from "store/navigation/navigation-action";
 import { loadDetailsPanel } from "store/details-panel/details-panel-action";
 import { toggleTrashed } from "store/trash/trash-actions";
-import { ContextMenuKind } from "views-components/context-menu/context-menu";
+import { ContextMenuKind } from 'views-components/context-menu/menu-item-sort';
 import { Dispatch } from "redux";
 import { createTree } from 'models/tree';
 import {