UNPKG

@craftercms/studio-ui

Version:

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

106 lines (104 loc) 4.3 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 * as React from 'react'; import PublishingStatusWidget from '../PublishingStatusWidget'; import Grid from '@mui/material/Grid'; import { PublishingQueueWidget } from '../PublishingQueue'; import PublishOnDemandWidget from '../PublishOnDemandWidget'; import GlobalAppToolbar from '../GlobalAppToolbar'; import { FormattedMessage } from 'react-intl'; import { useActiveSiteId } from '../../hooks/useActiveSiteId'; import Box from '@mui/material/Box'; import { useTheme } from '@mui/material/styles'; import useActiveUser from '../../hooks/useActiveUser'; export function PublishingDashboard(props) { const { embedded, showAppsButton, onSubmittingAndOrPendingChange } = props; const user = useActiveUser(); const site = useActiveSiteId(); const userPermissions = user?.permissionsBySite[site] ?? []; // TODO: These permission checks should be on the PublishOnDemand widget itself. Dashboard should only check for `publish` permission to render the widget or not. const hasPublishPermission = userPermissions?.includes('publish'); const hasPublishByCommitPermission = userPermissions?.includes('publish_by_commits'); const allowedPublishOnDemandModes = []; if (hasPublishPermission) allowedPublishOnDemandModes.push('everything', 'studio'); if (hasPublishByCommitPermission) allowedPublishOnDemandModes.push('git'); const { spacing, palette: { mode } } = useTheme(); return React.createElement( Box, { component: 'section', sx: { bgcolor: `grey.${mode === 'light' ? 100 : 800}`, height: '100%', pb: 3 } }, !embedded && React.createElement(GlobalAppToolbar, { title: React.createElement(FormattedMessage, { id: 'publishingDashboard.title', defaultMessage: 'Publishing Dashboard' }), showAppsButton: showAppsButton }), React.createElement( Grid, { gap: 2, container: true, sx: { padding: spacing(2), pb: 4, ...(embedded ? {} : { height: 'calc(100% - 65px)', // full viewport height - toolbar height overflowY: 'auto' }) } }, React.createElement(Grid, { item: true, xs: 12 }, React.createElement(PublishingStatusWidget, { siteId: site })), userPermissions.includes('get_publishing_queue') && React.createElement( Grid, { item: true, xs: 12 }, React.createElement(PublishingQueueWidget, { siteId: site, readOnly: !hasPublishPermission }) ), hasPublishPermission && React.createElement( Grid, { item: true, xs: 12 }, React.createElement(PublishOnDemandWidget, { siteId: site, mode: allowedPublishOnDemandModes, onSubmittingAndOrPendingChange: onSubmittingAndOrPendingChange }) ) ) ); } export default PublishingDashboard;