From: Janicki Artur Date: Tue, 10 Jul 2018 11:17:30 +0000 (+0200) Subject: load item to panelDetails and display data X-Git-Tag: 1.2.0~54^2~1 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/0e3c4c507b9d3ec37b808b7a38cf111722659403 load item to panelDetails and display data Feature #13765 Arvados-DCO-1.1-Signed-off-by: Janicki Artur --- diff --git a/src/store/details-panel/details-panel-action.ts b/src/store/details-panel/details-panel-action.ts index e2d2479b..ffa66b69 100644 --- a/src/store/details-panel/details-panel-action.ts +++ b/src/store/details-panel/details-panel-action.ts @@ -3,10 +3,11 @@ // SPDX-License-Identifier: AGPL-3.0 import { unionize, ofType, UnionOf } from "unionize"; -import { Resource } from "../../common/api/common-resource-service"; +import CommonResourceService, { Resource } from "../../common/api/common-resource-service"; import { ResourceKind } from "../../models/kinds"; import { Dispatch } from "redux"; import { groupsService } from "../../services/services"; +import { serverApi } from "../../common/api/server-api"; const actions = unionize({ TOGGLE_DETAILS_PANEL: ofType<{}>(), @@ -21,15 +22,23 @@ export type DetailsPanelAction = UnionOf; export const loadDetails = (uuid: string, kind: ResourceKind) => (dispatch: Dispatch) => { dispatch(actions.LOAD_DETAILS({ uuid, kind })); - if (kind === ResourceKind.Project) { - groupsService - .get(uuid) - .then(project => { - dispatch(actions.LOAD_DETAILS_SUCCESS({ item: project })); - }); - } - + getService(kind) + .get(uuid) + .then(project => { + dispatch(actions.LOAD_DETAILS_SUCCESS({ item: project })); + }); }; +const getService = (kind: ResourceKind) => { + switch (kind) { + case ResourceKind.Project: + return new CommonResourceService(serverApi, "groups"); + case ResourceKind.Collection: + return new CommonResourceService(serverApi, "collections"); + default: + return new CommonResourceService(serverApi, ""); + } +}; + diff --git a/src/store/navigation/navigation-action.ts b/src/store/navigation/navigation-action.ts index 034cdacc..1cab7349 100644 --- a/src/store/navigation/navigation-action.ts +++ b/src/store/navigation/navigation-action.ts @@ -36,8 +36,6 @@ export const setProjectItem = (itemId: string, itemMode: ItemMode) => const treeItem = findTreeItem(projects.items, itemId); if (treeItem) { - // TODO: Get correct resource kind - dispatch(loadDetails(treeItem.data.uuid, ResourceKind.Project)); dispatch(sidePanelActions.RESET_SIDE_PANEL_ACTIVITY()); const projectsItem = sidePanelData[0]; diff --git a/src/views-components/details-panel/details-panel.tsx b/src/views-components/details-panel/details-panel.tsx index b29e1902..138c91a5 100644 --- a/src/views-components/details-panel/details-panel.tsx +++ b/src/views-components/details-panel/details-panel.tsx @@ -22,13 +22,14 @@ import { ResourceKind } from '../../models/kinds'; import { ProjectResource } from '../../models/project'; import { CollectionResource } from '../../models/collection'; import IconBase, { IconTypes } from '../../components/icon/icon'; +import { ProcessResource } from '../../models/process'; export interface DetailsPanelDataProps { onCloseDrawer: () => void; isOpened: boolean; - header: React.ReactElement; - renderDetails?: React.ComponentType<{}>; - renderActivity?: React.ComponentType<{}>; + icon: IconTypes; + title: string; + details: React.ReactElement; } type DetailsPanelProps = DetailsPanelDataProps & WithStyles; @@ -48,14 +49,17 @@ class DetailsPanel extends React.Component { render() { - const { classes, onCloseDrawer, isOpened, header, renderDetails, renderActivity } = this.props; + const { classes, onCloseDrawer, isOpened, icon, title, details } = this.props; const { tabsValue } = this.state; return ( - {header} + + + {title} + @@ -67,24 +71,11 @@ class DetailsPanel extends React.Component { {tabsValue === 0 && this.renderTabContainer( - {renderDetails} - - - - - - Projects - - - + {details} )} {tabsValue === 1 && this.renderTabContainer( - - {renderActivity} - - + )} @@ -93,7 +84,7 @@ class DetailsPanel extends React.Component { } -type CssRules = 'drawerPaper' | 'container' | 'opened' | 'headerContainer' | 'tabContainer'; +type CssRules = 'drawerPaper' | 'container' | 'opened' | 'headerContainer' | 'headerIcon' | 'tabContainer'; const drawerWidth = 320; const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ @@ -113,48 +104,102 @@ const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ }, headerContainer: { color: theme.palette.grey["600"], - margin: `${theme.spacing.unit}px 0`, - '& .fa-cogs': { - fontSize: "24px", - color: theme.customs.colors.green700 - } + margin: `${theme.spacing.unit}px 0` + }, + headerIcon: { + fontSize: "34px" }, tabContainer: { padding: theme.spacing.unit * 3 } }); -const renderCollectionHeader = (collection: CollectionResource) => - <> - - - {collection.name} - - ; +type DetailsPanelResource = ProjectResource | CollectionResource | ProcessResource; -const renderProjectHeader = (project: ProjectResource) => - <> - - - {project.name} - - ; +const getIcon = (res: DetailsPanelResource) => { + switch (res.kind) { + case ResourceKind.Project: + return IconTypes.FOLDER; + case ResourceKind.Collection: + return IconTypes.COLLECTION; + case ResourceKind.Process: + return IconTypes.PROCESS; + default: + return IconTypes.FOLDER; + } +}; -const renderHeader = (resource: Resource) => { - switch(resource.kind) { +const getDetails = (res: DetailsPanelResource) => { + switch (res.kind) { case ResourceKind.Project: - return renderProjectHeader(resource as ProjectResource); + return
+ + + + + Projects + + + + + +
; case ResourceKind.Collection: - return renderCollectionHeader(resource as CollectionResource); - default: - return null; + return
+ + + + + Projects + + + + + + + + + + +
; + case ResourceKind.Process: + return
+ + + + + Projects + + + + + + + + + + + +
; + default: + return getEmptyState(); } }; -const mapStateToProps = ({detailsPanel}: RootState) => ({ - isOpened: detailsPanel.isOpened, - header: detailsPanel.item ? renderHeader(detailsPanel.item) : null -}); +const getEmptyState = () => { + return ; +}; + +const mapStateToProps = ({ detailsPanel }: RootState) => { + const { isOpened, item } = detailsPanel; + return { + isOpened, + title: item ? (item as DetailsPanelResource).name : 'Projects', + icon: item ? getIcon(item as DetailsPanelResource) : IconTypes.FOLDER, + details: item ? getDetails(item as DetailsPanelResource) : getEmptyState() + }; +}; const mapDispatchToProps = (dispatch: Dispatch) => ({ onCloseDrawer: () => { diff --git a/src/views/workbench/workbench.tsx b/src/views/workbench/workbench.tsx index e8487845..11f36948 100644 --- a/src/views/workbench/workbench.tsx +++ b/src/views/workbench/workbench.tsx @@ -27,7 +27,8 @@ import projectActions from "../../store/project/project-action"; import ProjectPanel from "../project-panel/project-panel"; import DetailsPanel from '../../views-components/details-panel/details-panel'; import { ArvadosTheme } from '../../common/custom-theme'; -import detailsPanelActions from "../../store/details-panel/details-panel-action"; +import detailsPanelActions, { loadDetails } from "../../store/details-panel/details-panel-action"; +import { ResourceKind } from '../../models/kinds'; const drawerWidth = 240; const appBarHeight = 100; @@ -207,7 +208,10 @@ class Workbench extends React.Component { renderProjectPanel = (props: RouteComponentProps<{ id: string }>) => this.props.dispatch(setProjectItem(itemId, ItemMode.ACTIVE))} - onItemClick={item => this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE))} + onItemClick={item => { + this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE)); + this.props.dispatch(loadDetails(item.uuid, item.kind as ResourceKind)); + }} {...props} /> }