// Copyright (C) The Arvados Authors. All rights reserved. // // SPDX-License-Identifier: AGPL-3.0 import React from 'react'; import { CollectionIcon, RenameIcon } from 'components/icon/icon'; import { CollectionResource } from 'models/collection'; import { DetailsData } from "./details-data"; import { CollectionDetailsAttributes } from 'views/collection-panel/collection-panel'; import { RootState } from 'store/store'; import { filterResources, getResource, ResourcesState } from 'store/resources/resources'; import { connect } from 'react-redux'; import { CustomStyleRulesCallback } from 'common/custom-theme'; import { Button, Grid, ListItem, Typography } from '@mui/material'; import { WithStyles } from '@mui/styles'; import withStyles from '@mui/styles/withStyles'; import { formatDate, formatFileSize } from 'common/formatters'; import { UserNameFromID } from '../data-explorer/renderers'; import { Dispatch } from 'redux'; import { navigateTo } from 'store/navigation/navigation-action'; import { openContextMenu, resourceUuidToContextMenuKind } from 'store/context-menu/context-menu-actions'; import { openCollectionUpdateDialog } from 'store/collections/collection-update-actions'; import { resourceIsFrozen } from 'common/frozen-resources'; export type CssRules = 'versionBrowserHeader' | 'versionBrowserItem' | 'versionBrowserField' | 'editButton' | 'editIcon' | 'tag'; const styles: CustomStyleRulesCallback = theme => ({ versionBrowserHeader: { textAlign: 'center', fontWeight: 'bold', }, versionBrowserItem: { flexWrap: 'wrap', }, versionBrowserField: { textAlign: 'center', }, editIcon: { paddingRight: theme.spacing(0.5), fontSize: '1.125rem', }, editButton: { boxShadow: 'none', padding: '2px 10px 2px 5px', fontSize: '0.75rem' }, tag: { marginRight: theme.spacing(0.5), marginBottom: theme.spacing(0.5) }, }); export class CollectionDetails extends DetailsData { getIcon(className?: string) { return ; } getTabLabels() { return ['Details', 'Versions']; } getDetails({tabNr}) { switch (tabNr) { case 0: return this.getCollectionInfo(); case 1: return this.getVersionBrowser(); default: return
; } } private getCollectionInfo() { return ; } private getVersionBrowser() { return ; } } interface CollectionInfoDataProps { resources: ResourcesState; currentCollection: CollectionResource | undefined; } interface CollectionInfoDispatchProps { editCollection: (collection: CollectionResource | undefined) => void; } const ciMapStateToProps = (state: RootState): CollectionInfoDataProps => { return { resources: state.resources, currentCollection: getResource(state.detailsPanel.resourceUuid)(state.resources), }; }; const ciMapDispatchToProps = (dispatch: Dispatch): CollectionInfoDispatchProps => ({ editCollection: (collection: CollectionResource) => dispatch(openCollectionUpdateDialog({ uuid: collection.uuid, name: collection.name, description: collection.description, properties: collection.properties, storageClassesDesired: collection.storageClassesDesired, })), }); type CollectionInfoProps = CollectionInfoDataProps & CollectionInfoDispatchProps & WithStyles; const CollectionInfo = withStyles(styles)( connect(ciMapStateToProps, ciMapDispatchToProps)( ({ currentCollection, resources, editCollection, classes }: CollectionInfoProps) => currentCollection !== undefined ?
:
) ); interface CollectionVersionBrowserProps { currentCollection: CollectionResource | undefined; versions: CollectionResource[]; } interface CollectionVersionBrowserDispatchProps { showVersion: (c: CollectionResource) => void; handleContextMenu: (event: React.MouseEvent, collection: CollectionResource) => void; } const vbMapStateToProps = (state: RootState): CollectionVersionBrowserProps => { const currentCollection = getResource(state.detailsPanel.resourceUuid)(state.resources); const versions = (currentCollection && filterResources(rsc => (rsc as CollectionResource).currentVersionUuid === currentCollection.currentVersionUuid)(state.resources) .sort((a: CollectionResource, b: CollectionResource) => b.version - a.version) as CollectionResource[]) || []; return { currentCollection, versions }; }; const vbMapDispatchToProps = () => (dispatch: Dispatch): CollectionVersionBrowserDispatchProps => ({ showVersion: (collection) => dispatch(navigateTo(collection.uuid)), handleContextMenu: (event: React.MouseEvent, collection: CollectionResource) => { const menuKind = dispatch(resourceUuidToContextMenuKind(collection.uuid)); if (collection && menuKind) { dispatch(openContextMenu(event, { name: collection.name, uuid: collection.uuid, description: collection.description, storageClassesDesired: collection.storageClassesDesired, ownerUuid: collection.ownerUuid, isTrashed: collection.isTrashed, kind: collection.kind, menuKind })); } }, }); const CollectionVersionBrowser = withStyles(styles)( connect(vbMapStateToProps, vbMapDispatchToProps)( ({ currentCollection, versions, showVersion, handleContextMenu, classes }: CollectionVersionBrowserProps & CollectionVersionBrowserDispatchProps & WithStyles) => { return
Nr Size Date { versions.map(item => { const isSelectedVersion = !!(currentCollection && currentCollection.uuid === item.uuid); return ( showVersion(item)} onContextMenu={event => handleContextMenu(event, item)} selected={isSelectedVersion} className={classes.versionBrowserItem}> {item.version} {formatFileSize(item.fileSizeTotal)} {formatDate(item.modifiedAt)} Modified by: ); })}
; }));