@craftercms/studio-ui
Version:
Services, components, models & utils to build CrafterCMS authoring extensions.
235 lines (233 loc) • 8.83 kB
JavaScript
/*
* 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 Table from '@mui/material/Table';
import TableHead from '@mui/material/TableHead';
import GlobalAppGridRow from '../GlobalAppGridRow';
import GlobalAppGridCell from '../GlobalAppGridCell';
import Typography from '@mui/material/Typography';
import { FormattedMessage } from 'react-intl';
import TableBody from '@mui/material/TableBody';
import TableContainer from '@mui/material/TableContainer';
import React from 'react';
import Checkbox from '@mui/material/Checkbox';
import ItemDisplay from '../ItemDisplay';
import useStyles from './styles';
import Pagination from '../Pagination';
export function ItemStatesGridUI(props) {
const {
itemStates,
onPageChange,
onRowsPerPageChange,
selectedItems,
onItemSelected,
onRowSelected,
onToggleSelectedItems,
allItemsSelected,
hasThisPageItemsChecked,
isThisPageIndeterminate
} = props;
const { classes, cx: clsx } = useStyles();
return React.createElement(
React.Fragment,
null,
React.createElement(
TableContainer,
{ className: classes.tableContainer },
React.createElement(
Table,
{ size: 'small' },
React.createElement(
TableHead,
null,
React.createElement(
GlobalAppGridRow,
{ className: 'hoverDisabled' },
React.createElement(
GlobalAppGridCell,
{ align: 'center' },
React.createElement(Checkbox, {
checked: allItemsSelected || hasThisPageItemsChecked,
indeterminate: hasThisPageItemsChecked ? isThisPageIndeterminate : false,
onClick: (e) => onToggleSelectedItems()
})
),
React.createElement(
GlobalAppGridCell,
{ className: 'width60 pl0' },
React.createElement(
Typography,
{ variant: 'subtitle2' },
React.createElement(FormattedMessage, { id: 'words.item', defaultMessage: 'Item' })
)
),
React.createElement(
GlobalAppGridCell,
{ className: 'width20' },
React.createElement(
Typography,
{ variant: 'subtitle2' },
React.createElement(FormattedMessage, { id: 'words.processing', defaultMessage: 'Processing' })
)
),
React.createElement(
GlobalAppGridCell,
{ className: 'width40' },
React.createElement(
Typography,
{ variant: 'subtitle2' },
React.createElement(FormattedMessage, { id: 'words.locked', defaultMessage: 'Locked' })
)
),
React.createElement(
GlobalAppGridCell,
{ className: 'width20' },
React.createElement(
Typography,
{ variant: 'subtitle2' },
React.createElement(FormattedMessage, { id: 'words.live', defaultMessage: 'Live' })
)
),
React.createElement(
GlobalAppGridCell,
{ className: 'width20' },
React.createElement(
Typography,
{ variant: 'subtitle2' },
React.createElement(FormattedMessage, { id: 'words.staged', defaultMessage: 'Staged' })
)
)
)
),
React.createElement(
TableBody,
null,
itemStates.map((item) =>
React.createElement(
GlobalAppGridRow,
{
key: item.id,
onClick: () => onRowSelected(item),
className: clsx((Boolean(selectedItems[item.path]) || allItemsSelected) && classes.rowSelected)
},
React.createElement(
GlobalAppGridCell,
{ align: 'center' },
React.createElement(Checkbox, {
checked: allItemsSelected || Boolean(selectedItems[item.path]),
onClick: (e) => {
e.stopPropagation();
},
onChange: (e) => {
onItemSelected(item, e.target.checked);
}
})
),
React.createElement(
GlobalAppGridCell,
{ className: 'ellipsis maxWidth300 pl0' },
React.createElement(ItemDisplay, { item: item }),
React.createElement(
Typography,
{
title: item.path,
variant: 'caption',
component: 'p',
className: clsx(classes.itemPath, classes.ellipsis)
},
item.path
)
),
React.createElement(
GlobalAppGridCell,
null,
React.createElement(
Typography,
{ variant: 'body2' },
item.stateMap.systemProcessing
? React.createElement(FormattedMessage, { id: 'words.yes', defaultMessage: 'Yes' })
: React.createElement(FormattedMessage, { id: 'words.no', defaultMessage: 'No' })
)
),
React.createElement(
GlobalAppGridCell,
null,
React.createElement(
Typography,
{ variant: 'body2', className: classes.ellipsis, title: item.lockOwner },
item.stateMap.locked
? React.createElement(FormattedMessage, {
id: 'itemStates.lockedBy',
defaultMessage: 'By {owner}',
values: {
owner: item.lockOwner
}
})
: React.createElement(FormattedMessage, { id: 'words.no', defaultMessage: 'No' })
)
),
React.createElement(
GlobalAppGridCell,
null,
React.createElement(
Typography,
{ variant: 'body2' },
item.stateMap.live
? React.createElement(FormattedMessage, { id: 'words.yes', defaultMessage: 'Yes' })
: React.createElement(FormattedMessage, { id: 'words.no', defaultMessage: 'No' })
)
),
React.createElement(
GlobalAppGridCell,
null,
React.createElement(
Typography,
{ variant: 'body2' },
item.stateMap.staged
? React.createElement(FormattedMessage, { id: 'words.yes', defaultMessage: 'Yes' })
: React.createElement(FormattedMessage, { id: 'words.no', defaultMessage: 'No' })
)
)
)
)
)
)
),
React.createElement(Pagination, {
mode: 'table',
count: itemStates.total,
rowsPerPage: itemStates.limit,
page: itemStates && Math.ceil(itemStates.offset / itemStates.limit),
onPageChange: (e, page) => onPageChange(page),
onRowsPerPageChange: onRowsPerPageChange
})
);
}
export default ItemStatesGridUI;