UNPKG

@sanity/desk-tool

Version:

Tool for managing all sorts of content in a structured manner

104 lines (103 loc) 5.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConfirmDeleteDialog = ConfirmDeleteDialog; exports.LoadingContainer = exports.DialogBody = void 0; var _react = _interopRequireWildcard(require("react")); var _styledComponents = _interopRequireDefault(require("styled-components")); var _ui = require("@sanity/ui"); var _autoId = require("@reach/auto-id"); var _DocTitle = require("../DocTitle"); var _useReferringDocuments = require("./useReferringDocuments"); var _ConfirmDeleteDialogBody = require("./ConfirmDeleteDialogBody"); var _templateObject, _templateObject2; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); } var DialogBody = (0, _styledComponents.default)(_ui.Flex).attrs({ padding: 4, direction: 'column', height: 'fill' })(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n box-sizing: border-box;\n"]))); exports.DialogBody = DialogBody; var LoadingContainer = (0, _styledComponents.default)(_ui.Flex).attrs({ align: 'center', direction: 'column', justify: 'center' })(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n height: 300px;\n"]))); exports.LoadingContainer = LoadingContainer; /** * A confirmation dialog used to prevent unwanted document deletes. Loads all * the referencing internal and cross-data references prior to showing the * delete button. */ function ConfirmDeleteDialog(_ref) { var id = _ref.id, type = _ref.type, _ref$action = _ref.action, action = _ref$action === void 0 ? 'delete' : _ref$action, onCancel = _ref.onCancel, onConfirm = _ref.onConfirm; var dialogId = "deletion-confirmation-".concat((0, _autoId.useId)()); var _useReferringDocument = (0, _useReferringDocuments.useReferringDocuments)(id), internalReferences = _useReferringDocument.internalReferences, crossDatasetReferences = _useReferringDocument.crossDatasetReferences, isLoading = _useReferringDocument.isLoading, totalCount = _useReferringDocument.totalCount, projectIds = _useReferringDocument.projectIds, datasetNames = _useReferringDocument.datasetNames, hasUnknownDatasetNames = _useReferringDocument.hasUnknownDatasetNames; var capitalizedAction = "".concat(action.substring(0, 1).toUpperCase()).concat(action.substring(1)); var documentTitle = /*#__PURE__*/_react.default.createElement(_DocTitle.DocTitle, { document: (0, _react.useMemo)(() => ({ _id: id, _type: type }), [id, type]) }); var showConfirmButton = !isLoading; return /*#__PURE__*/_react.default.createElement(_ui.Dialog, { width: 1, id: dialogId, header: "".concat(capitalizedAction, " document?"), footer: /*#__PURE__*/_react.default.createElement(_ui.Grid, { columns: showConfirmButton ? 2 : 1, gap: 2, paddingX: 4, paddingY: 3 }, /*#__PURE__*/_react.default.createElement(_ui.Button, { mode: "ghost", onClick: onCancel, text: "Cancel" }), showConfirmButton && /*#__PURE__*/_react.default.createElement(_ui.Button, { "data-testid": "confirm-delete-button", text: totalCount > 0 ? "".concat(capitalizedAction, " anyway") : "".concat(capitalizedAction, " now"), tone: "critical", onClick: onConfirm })), onClose: onCancel, onClickOutside: onCancel }, /*#__PURE__*/_react.default.createElement(DialogBody, null, crossDatasetReferences && internalReferences && !isLoading ? /*#__PURE__*/_react.default.createElement(_ConfirmDeleteDialogBody.ConfirmDeleteDialogBody, { crossDatasetReferences: crossDatasetReferences, internalReferences: internalReferences, documentTitle: documentTitle, isLoading: isLoading, totalCount: totalCount, action: action, projectIds: projectIds, datasetNames: datasetNames, hasUnknownDatasetNames: hasUnknownDatasetNames, onReferenceLinkClick: onCancel }) : /*#__PURE__*/_react.default.createElement(LoadingContainer, { "data-testid": "loading-container" }, /*#__PURE__*/_react.default.createElement(_ui.Spinner, { muted: true }), /*#__PURE__*/_react.default.createElement(_ui.Box, { marginTop: 3 }, /*#__PURE__*/_react.default.createElement(_ui.Text, { align: "center", muted: true, size: 1 }, "Looking for referring documents\u2026"))))); }