From c4b35e715ff5c6840aabfb76b540e2fad341b0ec Mon Sep 17 00:00:00 2001 From: Michal Klobukowski Date: Wed, 5 Sep 2018 13:02:58 +0200 Subject: [PATCH] Move default views to corresponding panels Feature #14160 Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski --- .../data-explorer/data-explorer.tsx | 4 +-- src/views/favorite-panel/favorite-panel.tsx | 34 +++++++++++++------ src/views/project-panel/project-panel.tsx | 33 +++++++++++++----- src/views/trash-panel/trash-panel.tsx | 34 ++++++++++++------- 4 files changed, 70 insertions(+), 35 deletions(-) diff --git a/src/components/data-explorer/data-explorer.tsx b/src/components/data-explorer/data-explorer.tsx index 2ff4e7fe..0147937f 100644 --- a/src/components/data-explorer/data-explorer.tsx +++ b/src/components/data-explorer/data-explorer.tsx @@ -45,8 +45,6 @@ interface DataExplorerDataProps { rowsPerPage: number; rowsPerPageOptions: number[]; page: number; - defaultIcon: IconType; - defaultMessages: string[]; contextMenuColumn: boolean; noItemsPlaceholder?: React.ReactNode; } @@ -78,7 +76,7 @@ export const DataExplorer = withStyles(styles)( const { columns, onContextMenu, onFiltersChange, onSortToggle, extractKey, rowsPerPage, rowsPerPageOptions, onColumnToggle, searchValue, onSearch, - items, itemsAvailable, onRowClick, onRowDoubleClick, defaultIcon, defaultMessages, classes, + items, itemsAvailable, onRowClick, onRowDoubleClick, classes, noItemsPlaceholder } = this.props; return diff --git a/src/views/favorite-panel/favorite-panel.tsx b/src/views/favorite-panel/favorite-panel.tsx index 803d8002..ce86adf9 100644 --- a/src/views/favorite-panel/favorite-panel.tsx +++ b/src/views/favorite-panel/favorite-panel.tsx @@ -28,6 +28,9 @@ import { openContextMenu, resourceKindToContextMenuKind } from '~/store/context- import { loadDetailsPanel } from '~/store/details-panel/details-panel-action'; import { navigateTo } from '~/store/navigation/navigation-action'; import { ContainerRequestState } from "~/models/container-request"; +import { DefaultView } from '~/components/default-view/default-view'; +import { FavoritesState } from '../../store/favorites/favorites-reducer'; +import { RootState } from '~/store/store'; type CssRules = "toolbar" | "button"; @@ -124,7 +127,7 @@ export const favoritePanelColumns: DataColumns = [ ]; interface FavoritePanelDataProps { - currentItemId: string; + favorites: FavoritesState; } interface FavoritePanelActionProps { @@ -133,6 +136,9 @@ interface FavoritePanelActionProps { onDialogOpen: (ownerUuid: string) => void; onItemDoubleClick: (item: string) => void; } +const mapStateToProps = ({ favorites }: RootState): FavoritePanelDataProps => ({ + favorites +}); const mapDispatchToProps = (dispatch: Dispatch): FavoritePanelActionProps => ({ onContextMenu: (event, resourceUuid) => { @@ -160,17 +166,25 @@ type FavoritePanelProps = FavoritePanelDataProps & FavoritePanelActionProps & Di & WithStyles & RouteComponentProps<{ id: string }>; export const FavoritePanel = withStyles(styles)( - connect(undefined, mapDispatchToProps)( + connect(mapStateToProps, mapDispatchToProps)( class extends React.Component { render() { - return ; + return this.hasAnyFavorites() + ? + : ; + } + + hasAnyFavorites = () => { + return Object + .keys(this.props.favorites) + .find(uuid => this.props.favorites[uuid]); } } ) diff --git a/src/views/project-panel/project-panel.tsx b/src/views/project-panel/project-panel.tsx index 2573f818..19d4ee1c 100644 --- a/src/views/project-panel/project-panel.tsx +++ b/src/views/project-panel/project-panel.tsx @@ -12,7 +12,7 @@ import { RootState } from '~/store/store'; import { DataTableFilterItem } from '~/components/data-table-filters/data-table-filters'; import { ContainerRequestState } from '~/models/container-request'; import { SortDirection } from '~/components/data-table/data-column'; -import { ResourceKind } from '~/models/resource'; +import { ResourceKind, Resource } from '~/models/resource'; import { resourceLabel } from '~/common/labels'; import { ArvadosTheme } from '~/common/custom-theme'; import { ResourceFileSize, ResourceLastModifiedDate, ProcessStatus, ResourceType, ResourceOwner } from '~/views-components/data-explorer/renderers'; @@ -27,6 +27,8 @@ import { getProperty } from '~/store/properties/properties'; import { PROJECT_PANEL_CURRENT_UUID } from '~/store/project-panel/project-panel-action'; import { openCollectionCreateDialog } from '../../store/collections/collection-create-actions'; import { openProjectCreateDialog } from '~/store/projects/project-create-actions'; +import { filterResources } from '../../store/resources/resources'; +import { DefaultView } from '~/components/default-view/default-view'; type CssRules = 'root' | "toolbar" | "button"; @@ -157,17 +159,30 @@ export const ProjectPanel = withStyles(styles)( New project - + {this.hasAnyItems() + ? + : + } + ; } + hasAnyItems = () => { + const resources = filterResources(this.isCurrentItemChild)(this.props.resources); + return resources.length > 0; + } + + isCurrentItemChild = (resource: Resource) => { + return resource.ownerUuid === this.props.currentItemId; + } + handleNewProjectClick = () => { this.props.dispatch(openProjectCreateDialog(this.props.currentItemId)); } diff --git a/src/views/trash-panel/trash-panel.tsx b/src/views/trash-panel/trash-panel.tsx index 08df05c2..2c9d61e7 100644 --- a/src/views/trash-panel/trash-panel.tsx +++ b/src/views/trash-panel/trash-panel.tsx @@ -31,6 +31,7 @@ import { loadDetailsPanel } from "~/store/details-panel/details-panel-action"; import { toggleCollectionTrashed, toggleProjectTrashed, toggleTrashed } from "~/store/trash/trash-actions"; import { ContextMenuKind } from "~/views-components/context-menu/context-menu"; import { Dispatch } from "redux"; +import { DefaultView } from '~/components/default-view/default-view'; type CssRules = "toolbar" | "button"; @@ -71,7 +72,7 @@ export const ResourceRestore = )); } }}> - + ); @@ -82,7 +83,7 @@ export const trashPanelColumns: DataColumns = [ configurable: true, sortDirection: SortDirection.ASC, filters: [], - render: uuid => , + render: uuid => , width: "450px" }, { @@ -107,7 +108,7 @@ export const trashPanelColumns: DataColumns = [ type: ResourceKind.PROJECT } ], - render: uuid => , + render: uuid => , width: "125px" }, { @@ -143,7 +144,7 @@ export const trashPanelColumns: DataColumns = [ configurable: false, sortDirection: SortDirection.NONE, filters: [], - render: uuid => , + render: uuid => , width: "50px" } ]; @@ -162,15 +163,22 @@ export const TrashPanel = withStyles(styles)( }))( class extends React.Component { render() { - return - ; + return this.hasAnyTrashedResources() + ? + : ; + } + + hasAnyTrashedResources = () => { + // TODO: implement check if there is anything in the trash, + // without taking pagination into the account + return true; } handleContextMenu = (event: React.MouseEvent, resourceUuid: string) => { -- 2.30.2