UNPKG

@craftercms/studio-ui

Version:

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

170 lines (168 loc) 6.59 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 { FormattedMessage } from 'react-intl'; import * as React from 'react'; export function getItemPublishingTargetText(stateMap) { return stateMap.live ? React.createElement(FormattedMessage, { id: 'words.live', defaultMessage: 'Live' }) : stateMap.staged ? React.createElement(FormattedMessage, { id: 'words.staged', defaultMessage: 'Staged' }) : React.createElement(FormattedMessage, { id: 'words.unpublished', defaultMessage: 'Unpublished' }); } export function getItemStateText(stateMap, values) { var _a, _b; let map; map = { new: () => React.createElement(FormattedMessage, { id: 'itemState.new', defaultMessage: 'New' }), modified: () => React.createElement(FormattedMessage, { id: 'itemState.modified', defaultMessage: 'Modified' }), deleted: () => React.createElement(FormattedMessage, { id: 'itemState.deleted', defaultMessage: 'Deleted' }), locked: () => (values === null || values === void 0 ? void 0 : values.user) ? React.createElement(FormattedMessage, { id: 'itemState.lockedBy', defaultMessage: 'Locked by {user}', values: values }) : React.createElement(FormattedMessage, { id: 'itemState.locked', defaultMessage: 'Locked' }), systemProcessing: () => React.createElement(FormattedMessage, { id: 'itemState.systemProcessing', defaultMessage: 'System Processing' }), submitted: () => React.createElement(FormattedMessage, { id: 'itemState.submitted', defaultMessage: 'Submitted' }), scheduled: () => React.createElement(FormattedMessage, { id: 'itemState.scheduled', defaultMessage: 'Scheduled' }), publishing: () => React.createElement(FormattedMessage, { id: 'itemState.publishing', defaultMessage: 'Publishing' }), submittedToStaging: () => stateMap.submitted ? React.createElement(FormattedMessage, { id: 'itemState.submittedToStaging', defaultMessage: 'Submitted to staging' }) : React.createElement(FormattedMessage, { id: 'itemState.scheduledToStaging', defaultMessage: 'Scheduled to staging' }), submittedToLive: () => stateMap.submitted ? React.createElement(FormattedMessage, { id: 'itemState.submittedToLive', defaultMessage: 'Submitted to live' }) : React.createElement(FormattedMessage, { id: 'itemState.scheduledToGoLive', defaultMessage: 'Scheduled to live' }), staged: () => void 0, live: () => void 0, disabled: () => React.createElement(FormattedMessage, { id: 'itemState.disabled', defaultMessage: 'Disabled' }), translationUpToDate: null, translationPending: null, translationInProgress: null }; return (_b = (_a = map[getItemStateId(stateMap)]) === null || _a === void 0 ? void 0 : _a.call(map)) !== null && _b !== void 0 ? _b : React.createElement(FormattedMessage, { id: 'itemState.notInWorkflow', defaultMessage: 'Not in workflow' }); } export function getItemStateId(stateMap) { switch (true) { case stateMap.deleted: return 'deleted'; case stateMap.disabled: return 'disabled'; case stateMap.systemProcessing: return 'systemProcessing'; case stateMap.locked: return 'locked'; case stateMap.submittedToLive: return 'submittedToLive'; case stateMap.submittedToStaging: return 'submittedToStaging'; case stateMap.submitted: return 'submitted'; case stateMap.scheduled: return 'scheduled'; case stateMap.new: return 'new'; case stateMap.modified: return 'modified'; case stateMap.publishing: return 'publishing'; case stateMap.staged: return 'staged'; case stateMap.live: return 'live'; case stateMap.translationUpToDate: return 'translationUpToDate'; case stateMap.translationPending: return 'translationPending'; case stateMap.translationInProgress: return 'translationInProgress'; default: return null; } // region Compiler hints // This var below is simply means for typescript to complain if we ever add/remove states; so the compiler // complains and we can come edit the above `switch` to make sure all states are covered. // eslint-disable-next-line no-unreachable,@typescript-eslint/no-unused-vars const control = { new: false, modified: false, deleted: false, locked: false, systemProcessing: false, submitted: false, scheduled: false, publishing: false, submittedToStaging: false, submittedToLive: false, staged: false, live: false, disabled: false, translationUpToDate: false, translationPending: false, translationInProgress: false }; // endregion } export function isInWorkflow(stateMap) { return stateMap ? stateMap.deleted || stateMap.disabled || stateMap.systemProcessing || stateMap.locked || stateMap.submittedToLive || stateMap.submittedToStaging || stateMap.submitted || stateMap.scheduled || stateMap.new || stateMap.modified || stateMap.publishing : false; }