From 925a481e0df8f4ed51abb88d4acb3f257d98783a Mon Sep 17 00:00:00 2001 From: Philipp Otto Date: Tue, 6 Dec 2022 13:44:24 +0100 Subject: [PATCH] move details sidebar into own module --- .../dashboard/dataset_folder_view.tsx | 196 +----------------- .../dashboard/folders/details_sidebar.tsx | 195 +++++++++++++++++ 2 files changed, 198 insertions(+), 193 deletions(-) create mode 100644 frontend/javascripts/dashboard/folders/details_sidebar.tsx diff --git a/frontend/javascripts/dashboard/dataset_folder_view.tsx b/frontend/javascripts/dashboard/dataset_folder_view.tsx index 0869b2bd946..2078f0a01ce 100644 --- a/frontend/javascripts/dashboard/dataset_folder_view.tsx +++ b/frontend/javascripts/dashboard/dataset_folder_view.tsx @@ -1,23 +1,12 @@ -import { - FileOutlined, - FolderOpenOutlined, - SearchOutlined, - SettingOutlined, -} from "@ant-design/icons"; -import { Result, Spin, Tag, Tooltip } from "antd"; -import { stringToColor } from "libs/format_utils"; -import { filterNullValues, pluralize } from "libs/utils"; -import _ from "lodash"; -import { DatasetExtentRow } from "oxalis/view/right-border-tabs/dataset_info_tab_view"; +import { filterNullValues } from "libs/utils"; import React, { useEffect, useState } from "react"; -import { APIMaybeUnimportedDataset, APIUser, Folder } from "types/api_flow_types"; -import { DatasetLayerTags, DatasetTags, TeamTags } from "./advanced_dataset/dataset_table"; +import { APIMaybeUnimportedDataset, APIUser } from "types/api_flow_types"; import DatasetCollectionContextProvider, { useDatasetCollectionContext, } from "./dataset/dataset_collection_context"; -import { SEARCH_RESULTS_LIMIT, useFolderQuery } from "./dataset/queries"; import DatasetView from "./dataset_view"; +import { DetailsSidebar } from "./folders/details_sidebar"; import { EditFolderModal } from "./folders/edit_folder_modal"; import { FolderTreeSidebar } from "./folders/folder_tree"; @@ -133,182 +122,3 @@ function DatasetFolderViewInner(props: Props) { ); } - -function DetailsSidebar({ - selectedDatasets, - setSelectedDataset, - datasetCount, - searchQuery, - activeFolderId, - setFolderIdForEditModal, -}: { - selectedDatasets: APIMaybeUnimportedDataset[]; - setSelectedDataset: (ds: APIMaybeUnimportedDataset | null) => void; - datasetCount: number; - searchQuery: string | null; - activeFolderId: string | null; - setFolderIdForEditModal: (value: string | null) => void; -}) { - const context = useDatasetCollectionContext(); - const { data: folder, error } = useFolderQuery(activeFolderId); - - const selectedDataset = selectedDatasets.length > 0 ? selectedDatasets[0] : null; - - useEffect(() => { - if (selectedDataset == null || !("folderId" in selectedDataset)) { - return; - } - if (selectedDataset.folderId !== context.activeFolderId && context.activeFolderId != null) { - // Ensure that the selected dataset is in the active folder. If not, - // clear the sidebar. When there is no active folder, a search page is shown. In that case, - // clearing the selection should not happen. - setSelectedDataset(null); - } - }, [selectedDataset, context.activeFolderId]); - - const maybeSelectMsg = datasetCount > 0 ? "Select one to see details." : ""; - - return ( -
- {selectedDataset != null ? ( - <> -

- {" "} - {selectedDataset.displayName || selectedDataset.name} -

- {selectedDataset.isActive && ( -
- Voxel Size & Extent -
- - - - -
-
-
- )} - {selectedDataset.description && ( -
- Description -
{selectedDataset.description}
-
- )} -
- Access Permissions -
- -
-
- Layers -
-
- {selectedDataset.isActive ? ( -
- Tags - -
- ) : null} - - ) : ( -
- {searchQuery ? ( - } - subTitle={ - datasetCount !== SEARCH_RESULTS_LIMIT ? ( - <> - {datasetCount} {pluralize("dataset", datasetCount)} were found. {maybeSelectMsg} - - ) : ( - <> - At least {SEARCH_RESULTS_LIMIT} datasets match your search criteria.{" "} - {maybeSelectMsg} - - ) - } - /> - ) : ( - <> - {folder ? ( -
-

- - setFolderIdForEditModal(folder.id)} /> - - - {folder.name} -

-

- This folder contains{" "} - - {datasetCount} {pluralize("dataset", datasetCount)}* - - . {maybeSelectMsg} -

- Access Permissions -
- -
- ) : error ? ( - "Could not load folder." - ) : activeFolderId != null ? ( - - ) : null} - - )} -
- )} -
- ); -} - -function FolderTeamTags({ folder }: { folder: Folder }) { - if (folder.allowedTeamsCumulative.length === 0) { - return Administrators & Dataset Managers; - } - const allowedTeamsById = _.keyBy(folder.allowedTeams, "id"); - - return ( - <> - {folder.allowedTeamsCumulative.map((team) => { - const isCumulative = !allowedTeamsById[team.id]; - return ( - - - {team.name} - {isCumulative ? "*" : ""} - - - ); - })} - - ); -} diff --git a/frontend/javascripts/dashboard/folders/details_sidebar.tsx b/frontend/javascripts/dashboard/folders/details_sidebar.tsx new file mode 100644 index 00000000000..d812449d2bf --- /dev/null +++ b/frontend/javascripts/dashboard/folders/details_sidebar.tsx @@ -0,0 +1,195 @@ +import { + FileOutlined, + FolderOpenOutlined, + SearchOutlined, + SettingOutlined, +} from "@ant-design/icons"; +import { Result, Spin, Tag, Tooltip } from "antd"; +import { stringToColor } from "libs/format_utils"; +import { pluralize } from "libs/utils"; +import _ from "lodash"; +import { DatasetExtentRow } from "oxalis/view/right-border-tabs/dataset_info_tab_view"; +import React, { useEffect } from "react"; +import { APIMaybeUnimportedDataset, Folder } from "types/api_flow_types"; +import { DatasetLayerTags, DatasetTags, TeamTags } from "../advanced_dataset/dataset_table"; +import { useDatasetCollectionContext } from "../dataset/dataset_collection_context"; +import { SEARCH_RESULTS_LIMIT, useFolderQuery } from "../dataset/queries"; + +export function DetailsSidebar({ + selectedDatasets, + setSelectedDataset, + datasetCount, + searchQuery, + activeFolderId, + setFolderIdForEditModal, +}: { + selectedDatasets: APIMaybeUnimportedDataset[]; + setSelectedDataset: (ds: APIMaybeUnimportedDataset | null) => void; + datasetCount: number; + searchQuery: string | null; + activeFolderId: string | null; + setFolderIdForEditModal: (value: string | null) => void; +}) { + const context = useDatasetCollectionContext(); + const { data: folder, error } = useFolderQuery(activeFolderId); + + const selectedDataset = selectedDatasets.length > 0 ? selectedDatasets[0] : null; + + useEffect(() => { + if (selectedDataset == null || !("folderId" in selectedDataset)) { + return; + } + if (selectedDataset.folderId !== context.activeFolderId && context.activeFolderId != null) { + // Ensure that the selected dataset is in the active folder. If not, + // clear the sidebar. When there is no active folder, a search page is shown. In that case, + // clearing the selection should not happen. + setSelectedDataset(null); + } + }, [selectedDataset, context.activeFolderId]); + + const maybeSelectMsg = datasetCount > 0 ? "Select one to see details." : ""; + + return ( +
+ {selectedDataset != null ? ( + <> +

+ {" "} + {selectedDataset.displayName || selectedDataset.name} +

+ {selectedDataset.isActive && ( +
+ Voxel Size & Extent +
+ + + + +
+
+
+ )} + {selectedDataset.description && ( +
+ Description +
{selectedDataset.description}
+
+ )} +
+ Access Permissions +
+ +
+
+ Layers +
+
+ {selectedDataset.isActive ? ( +
+ Tags + +
+ ) : null} + + ) : ( +
+ {searchQuery ? ( + } + subTitle={ + datasetCount !== SEARCH_RESULTS_LIMIT ? ( + <> + {datasetCount} {pluralize("dataset", datasetCount)} were found. {maybeSelectMsg} + + ) : ( + <> + At least {SEARCH_RESULTS_LIMIT} datasets match your search criteria.{" "} + {maybeSelectMsg} + + ) + } + /> + ) : ( + <> + {folder ? ( +
+

+ + setFolderIdForEditModal(folder.id)} /> + + + {folder.name} +

+

+ This folder contains{" "} + + {datasetCount} {pluralize("dataset", datasetCount)}* + + . {maybeSelectMsg} +

+ Access Permissions +
+ +
+ ) : error ? ( + "Could not load folder." + ) : activeFolderId != null ? ( + + ) : null} + + )} +
+ )} +
+ ); +} + +function FolderTeamTags({ folder }: { folder: Folder }) { + if (folder.allowedTeamsCumulative.length === 0) { + return Administrators & Dataset Managers; + } + const allowedTeamsById = _.keyBy(folder.allowedTeams, "id"); + + return ( + <> + {folder.allowedTeamsCumulative.map((team) => { + const isCumulative = !allowedTeamsById[team.id]; + return ( + + + {team.name} + {isCumulative ? "*" : ""} + + + ); + })} + + ); +}