// Copyright (C) The Arvados Authors. All rights reserved. // // SPDX-License-Identifier: AGPL-3.0 import React from 'react'; import { CustomStyleRulesCallback } from 'common/custom-theme'; import { IconButton, Tooltip } from '@mui/material'; import { WithStyles } from '@mui/styles'; import withStyles from '@mui/styles/withStyles'; import { DataExplorer } from "views-components/data-explorer/data-explorer"; import { connect, DispatchProp } from 'react-redux'; import { DataColumns } from 'components/data-table/data-table'; import { RootState } from 'store/store'; import { DataTableFilterItem } from 'components/data-table-filters/data-table-filters'; import { SortDirection } from 'components/data-table/data-column'; import { ResourceKind, TrashableResource } from 'models/resource'; import { ArvadosTheme } from 'common/custom-theme'; import { RestoreFromTrashIcon, TrashIcon } from 'components/icon/icon'; import { TRASH_PANEL_ID } from "store/trash-panel/trash-panel-action"; import { getProperty } from "store/properties/properties"; import { PROJECT_PANEL_CURRENT_UUID } from "store/project-panel/project-panel-action"; import { openContextMenu } from "store/context-menu/context-menu-actions"; import { getResource, ResourcesState } from "store/resources/resources"; import { ResourceDeleteDate, ResourceFileSize, ResourceName, ResourceTrashDate, ResourceType } from "views-components/data-explorer/renderers"; import { navigateTo } from "store/navigation/navigation-action"; import { loadDetailsPanel } from "store/details-panel/details-panel-action"; import { toggleTrashed } from "store/trash/trash-actions"; import { ContextMenuKind } from 'views-components/context-menu/menu-item-sort'; import { Dispatch } from "redux"; import { createTree } from 'models/tree'; import { getTrashPanelTypeFilters } from 'store/resource-type-filters/resource-type-filters'; import { CollectionResource } from 'models/collection'; import { toggleOne, deselectAllOthers } from 'store/multiselect/multiselect-actions'; type CssRules = "toolbar" | "button" | "root"; const styles: CustomStyleRulesCallback = (theme: ArvadosTheme) => ({ toolbar: { paddingBottom: theme.spacing(3), textAlign: "right" }, button: { marginLeft: theme.spacing(1) }, root: { width: '100%', }, }); export enum TrashPanelColumnNames { NAME = "Name", TYPE = "Type", FILE_SIZE = "File size", TRASHED_DATE = "Trashed date", TO_BE_DELETED = "To be deleted" } export interface TrashPanelFilter extends DataTableFilterItem { type: ResourceKind; } export const ResourceRestore = connect((state: RootState, props: { uuid: string, dispatch?: Dispatch }) => { const resource = getResource(props.uuid)(state.resources); return { resource, dispatch: props.dispatch }; })((props: { resource?: TrashableResource, dispatch?: Dispatch }) => { if (props.resource && props.dispatch) { props.dispatch(toggleTrashed( props.resource.kind, props.resource.uuid, props.resource.ownerUuid, props.resource.isTrashed )); }}} size="large"> ); export const trashPanelColumns: DataColumns = [ { name: TrashPanelColumnNames.NAME, selected: true, configurable: true, sort: {direction: SortDirection.NONE, field: "name"}, filters: createTree(), render: uuid => }, { name: TrashPanelColumnNames.TYPE, selected: true, configurable: true, filters: getTrashPanelTypeFilters(), render: uuid => , }, { name: TrashPanelColumnNames.FILE_SIZE, selected: true, configurable: true, sort: {direction: SortDirection.NONE, field: "fileSizeTotal"}, filters: createTree(), render: uuid => }, { name: TrashPanelColumnNames.TRASHED_DATE, selected: true, configurable: true, sort: {direction: SortDirection.DESC, field: "trashAt"}, filters: createTree(), render: uuid => }, { name: TrashPanelColumnNames.TO_BE_DELETED, selected: true, configurable: true, sort: {direction: SortDirection.NONE, field: "deleteAt"}, filters: createTree(), render: uuid => }, { name: '', selected: true, configurable: false, filters: createTree(), render: uuid => } ]; interface TrashPanelDataProps { currentItemId: string; resources: ResourcesState; } type TrashPanelProps = TrashPanelDataProps & DispatchProp & WithStyles; export const TrashPanel = withStyles(styles)( connect((state: RootState) => ({ currentItemId: getProperty(PROJECT_PANEL_CURRENT_UUID)(state.properties), resources: state.resources }))( class extends React.Component { render() { return
; } handleContextMenu = (event: React.MouseEvent, resourceUuid: string) => { const resource = getResource(resourceUuid)(this.props.resources); if (resource) { this.props.dispatch(openContextMenu(event, { name: '', uuid: resource.uuid, ownerUuid: resource.ownerUuid, isTrashed: resource.isTrashed, kind: resource.kind, menuKind: ContextMenuKind.TRASH })); } this.props.dispatch(loadDetailsPanel(resourceUuid)); } handleRowDoubleClick = (uuid: string) => { this.props.dispatch(navigateTo(uuid)); } handleRowClick = (uuid: string) => { this.props.dispatch(toggleOne(uuid)) this.props.dispatch(deselectAllOthers(uuid)) this.props.dispatch(loadDetailsPanel(uuid)); } } ) );