UNPKG

@craftercms/studio-ui

Version:

Services, components, models & utils to build CrafterCMS authoring extensions.

306 lines (304 loc) 10.7 kB
/* * Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License version 3 as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* * Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import React, { useCallback, useMemo } from 'react'; import Table from '@mui/material/Table'; import TableHead from '@mui/material/TableHead'; import GlobalAppGridRow from '../../GlobalAppGridRow'; import GlobalAppGridCell from '../../GlobalAppGridCell'; import TableSortLabel from '@mui/material/TableSortLabel'; import TableBody from '@mui/material/TableBody'; import TableContainer from '@mui/material/TableContainer'; import useStyles from './styles'; import Checkbox from '@mui/material/Checkbox'; import { FormattedMessage } from 'react-intl'; import Typography from '@mui/material/Typography'; import ItemDisplay from '../../ItemDisplay'; import IconButton from '@mui/material/IconButton'; import MoreVertRounded from '@mui/icons-material/MoreVertRounded'; import { asLocalizedDateTime } from '../../../utils/datetime'; import Tooltip from '@mui/material/Tooltip'; import { getDatePublished, getDateScheduled } from '../../../utils/content'; export function RecentActivityDashletGridUI(props) { const { items, onOptionsButtonClick, selectedLookup, onItemChecked, isAllChecked, isIndeterminate, locale, sortType, sortBy, setSortBy, toggleSortType, onClickSelectAll } = props; const { classes, cx: clsx } = useStyles(); const comparator = useCallback( (fieldA, fieldB) => { if (sortType === 'asc') { return fieldA > fieldB ? 1 : -1; } else { return fieldA < fieldB ? 1 : -1; } }, [sortType] ); const sortItems = useCallback( (a, b) => { let fieldA, fieldB; switch (sortBy) { case 'label': fieldA = a.label; fieldB = b.label; break; case 'dateModified': fieldA = a.sandbox.dateModified; fieldB = b.sandbox.dateModified; break; case 'lastPublishedDate': fieldA = a.live.datePublished; fieldB = b.live.datePublished; break; } return comparator(fieldA, fieldB); }, [comparator, sortBy] ); const sortedItems = useMemo(() => { return [...items].sort(sortItems); }, [items, sortItems]); return React.createElement( TableContainer, null, React.createElement( Table, { size: 'small', className: classes.tableRoot }, React.createElement( TableHead, null, React.createElement( GlobalAppGridRow, { className: 'hoverDisabled' }, React.createElement( GlobalAppGridCell, { className: 'checkbox' }, React.createElement(Checkbox, { disabled: (sortedItems === null || sortedItems === void 0 ? void 0 : sortedItems.length) === 1 && sortedItems[0].stateMap.deleted, indeterminate: isIndeterminate, checked: isAllChecked, onChange: () => onClickSelectAll() }) ), React.createElement( GlobalAppGridCell, { className: 'width40 pl0' }, React.createElement( TableSortLabel, { active: sortBy === 'label', direction: sortType, onClick: () => { setSortBy('label'); toggleSortType(); } }, React.createElement( Typography, { variant: 'subtitle2' }, React.createElement(FormattedMessage, { id: 'words.item', defaultMessage: 'Item' }) ) ) ), React.createElement( GlobalAppGridCell, { className: 'width20 ellipsis' }, React.createElement( TableSortLabel, { active: sortBy === 'lastPublishedDate', direction: sortType, onClick: () => { setSortBy('lastPublishedDate'); toggleSortType(); } }, React.createElement( Typography, { variant: 'subtitle2' }, React.createElement(FormattedMessage, { id: 'recentActivity.publishDate', defaultMessage: 'Publish Date' }) ) ) ), React.createElement( GlobalAppGridCell, { className: 'width15 ellipsis' }, React.createElement( Typography, { variant: 'subtitle2' }, React.createElement(FormattedMessage, { id: 'recentActivity.lastEditedBy', defaultMessage: 'Last Edited By' }) ) ), React.createElement( GlobalAppGridCell, { className: 'width20 ellipsis' }, React.createElement( TableSortLabel, { active: sortBy === 'dateModified', direction: sortType, onClick: () => { setSortBy('dateModified'); toggleSortType(); } }, React.createElement( Typography, { variant: 'subtitle2' }, React.createElement(FormattedMessage, { id: 'recentlyPublished.myLastEdit', defaultMessage: 'My Last Edit' }) ) ) ), React.createElement(GlobalAppGridCell, { className: 'checkbox' }) ) ), React.createElement( TableBody, null, sortedItems.map((item) => React.createElement( GlobalAppGridRow, { key: item.id, onClick: item.stateMap.deleted ? null : () => { onItemChecked(item.path); } }, React.createElement( GlobalAppGridCell, { className: 'checkbox' }, React.createElement(Checkbox, { disabled: item.stateMap.deleted, checked: item.stateMap.deleted ? false : Boolean(selectedLookup[item.path]), onClick: (e) => { e.stopPropagation(); }, onChange: () => { onItemChecked(item.path); } }) ), React.createElement( GlobalAppGridCell, { className: 'ellipsis width40 pl0' }, React.createElement(ItemDisplay, { item: item, showNavigableAsLinks: false, showPublishingTarget: false }), React.createElement( Typography, { title: item.path, variant: 'caption', component: 'p', className: clsx(classes.itemPath, classes.ellipsis) }, item.path ) ), React.createElement( GlobalAppGridCell, { className: 'width20' }, getDateScheduled(item) ? asLocalizedDateTime(getDateScheduled(item), locale.localeCode, locale.dateTimeFormatOptions) : getDatePublished(item) ? asLocalizedDateTime(getDatePublished(item), locale.localeCode, locale.dateTimeFormatOptions) : React.createElement( Typography, { variant: 'caption', color: 'textSecondary' }, React.createElement(FormattedMessage, { id: 'words.unpublished', defaultMessage: 'Unpublished' }) ) ), React.createElement(GlobalAppGridCell, { className: 'width15' }, item.sandbox.modifier), React.createElement( GlobalAppGridCell, { className: 'width20' }, item.sandbox.dateModified && asLocalizedDateTime(item.sandbox.dateModified, locale.localeCode, locale.dateTimeFormatOptions) ), React.createElement( GlobalAppGridCell, { className: 'checkbox' }, item.stateMap.deleted ? React.createElement( IconButton, { disabled: true, size: 'large' }, React.createElement(MoreVertRounded, null) ) : React.createElement( Tooltip, { title: React.createElement(FormattedMessage, { id: 'words.options', defaultMessage: 'Options' }) }, React.createElement( IconButton, { onClick: (e) => { e.stopPropagation(); onOptionsButtonClick(e, item); }, size: 'large' }, React.createElement(MoreVertRounded, null) ) ) ) ) ) ) ) ); } export default RecentActivityDashletGridUI;