1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { StyleRulesCallback, WithStyles, withStyles, Grid, Button } from '@material-ui/core';
7 import { CollectionIcon } from '~/components/icon/icon';
8 import { ArvadosTheme } from '~/common/custom-theme';
9 import { BackIcon } from '~/components/icon/icon';
10 import { DataTableDefaultView } from '~/components/data-table-default-view/data-table-default-view';
11 import { COLLECTIONS_CONTENT_ADDRESS_PANEL_ID } from '~/store/collections-content-address-panel/collections-content-address-panel-actions';
12 import { DataExplorer } from "~/views-components/data-explorer/data-explorer";
13 import { Dispatch } from 'redux';
14 import { getIsAdmin } from '~/store/public-favorites/public-favorites-actions';
15 import { resourceKindToContextMenuKind, openContextMenu } from '~/store/context-menu/context-menu-actions';
16 import { ResourceKind } from '~/models/resource';
17 import { loadDetailsPanel } from '~/store/details-panel/details-panel-action';
18 import { connect } from 'react-redux';
19 import { navigateTo } from '~/store/navigation/navigation-action';
20 import { DataColumns } from '~/components/data-table/data-table';
21 import { SortDirection } from '~/components/data-table/data-column';
22 import { createTree } from '~/models/tree';
23 import { ResourceName, ResourceOwnerName, ResourceLastModifiedDate } from '~/views-components/data-explorer/renderers';
25 type CssRules = 'backLink' | 'backIcon' | 'card' | 'title' | 'iconHeader' | 'link';
27 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
33 padding: theme.spacing.unit,
34 marginBottom: theme.spacing.unit,
35 color: theme.palette.grey["700"],
38 marginRight: theme.spacing.unit
44 color: theme.palette.grey["700"]
48 color: theme.customs.colors.green700
52 color: theme.palette.primary.main,
60 enum CollectionContentAddressPanelColumnNames {
61 COLLECTION_WITH_THIS_ADDRESS = "Collection with this address",
62 LOCATION = "Location",
63 LAST_MODIFIED = "Last modified"
66 export const collectionContentAddressPanelColumns: DataColumns<string> = [
68 name: CollectionContentAddressPanelColumnNames.COLLECTION_WITH_THIS_ADDRESS,
71 sortDirection: SortDirection.NONE,
72 filters: createTree(),
73 render: uuid => <ResourceName uuid={uuid} />
76 name: CollectionContentAddressPanelColumnNames.LOCATION,
79 filters: createTree(),
80 render: uuid => <ResourceOwnerName uuid={uuid} />
83 name: CollectionContentAddressPanelColumnNames.LAST_MODIFIED,
86 sortDirection: SortDirection.DESC,
87 filters: createTree(),
88 render: uuid => <ResourceLastModifiedDate uuid={uuid} />
92 export interface CollectionContentAddressPanelActionProps {
93 onContextMenu: (event: React.MouseEvent<any>, uuid: string) => void;
94 onItemClick: (item: string) => void;
95 onItemDoubleClick: (item: string) => void;
98 const mapDispatchToProps = (dispatch: Dispatch): CollectionContentAddressPanelActionProps => ({
99 onContextMenu: (event, resourceUuid) => {
100 const isAdmin = dispatch<any>(getIsAdmin());
101 const kind = resourceKindToContextMenuKind(resourceUuid, isAdmin);
103 dispatch<any>(openContextMenu(event, {
107 kind: ResourceKind.NONE,
111 dispatch<any>(loadDetailsPanel(resourceUuid));
113 onItemClick: (uuid: string) => {
114 dispatch<any>(loadDetailsPanel(uuid));
116 onItemDoubleClick: uuid => {
117 dispatch<any>(navigateTo(uuid));
121 interface CollectionContentAddressDataProps {
123 params: { id: string }
127 export const CollectionsContentAddressPanel = withStyles(styles)(
128 connect(null, mapDispatchToProps)(
129 class extends React.Component<CollectionContentAddressPanelActionProps & CollectionContentAddressDataProps & WithStyles<CssRules>> {
131 return <Grid item xs={12}>
133 onClick={() => history.back()}
134 className={this.props.classes.backLink}>
135 <BackIcon className={this.props.classes.backIcon} />
139 id={COLLECTIONS_CONTENT_ADDRESS_PANEL_ID}
140 onRowClick={this.props.onItemClick}
141 onRowDoubleClick={this.props.onItemDoubleClick}
142 onContextMenu={this.props.onContextMenu}
143 contextMenuColumn={true}
144 title={`Content address: ${this.props.match.params.id}`}
145 dataTableDefaultView={
146 <DataTableDefaultView
147 icon={CollectionIcon}
148 messages={['Collections with this content address not found.']} />