UNPKG

contentful-migration

Version:
81 lines 3.06 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const base_intent_1 = __importDefault(require("../base-intent")); const chalk_1 = __importDefault(require("chalk")); const editor_layout_move_field_1 = require("../../action/editor-layout/editor-layout-move-field"); class EditorLayoutMoveFieldIntent extends base_intent_1.default { isEditorInterfaceIntent() { return true; } isEditorLayoutUpdate() { return true; } requiresContentType() { // We need the fields to validate field IDs return true; } isGroupable() { return true; } groupsWith(other) { return other.isGroupable() && other.isEditorLayoutUpdate() && this.isSameContentType(other); } endsGroup() { return false; } shouldSave() { return true; } shouldPublish() { return false; } getPivotId() { return this.payload.movement.pivot; } getDirection() { return this.payload.movement.direction; } toActions() { return [ new editor_layout_move_field_1.EditorLayoutMoveFieldGroupAction(this.payload.contentTypeId, this.payload.fieldId, this.getDirection(), this.getPivotId()) ]; } toPlanMessage() { const direction = this.getDirection(); const pivot = this.getPivotId(); let humanizedMovement; if (direction === 'toTheTopOfFieldGroup') { humanizedMovement = (0, chalk_1.default) `to the first position ${pivot ? (0, chalk_1.default) `of group {yellow ${pivot}}` : 'of its group'}`; } if (direction === 'toTheBottomOfFieldGroup') { humanizedMovement = (0, chalk_1.default) `to the last position ${pivot ? (0, chalk_1.default) `of group {yellow ${pivot}}` : 'of its group'}`; } if (direction === 'afterField') { humanizedMovement = (0, chalk_1.default) `after field {yellow ${pivot}}`; } if (direction === 'beforeField') { humanizedMovement = (0, chalk_1.default) `before field {yellow ${pivot}}`; } if (direction === 'afterFieldGroup') { humanizedMovement = (0, chalk_1.default) `after field group {yellow ${pivot}}`; } if (direction === 'beforeFieldGroup') { humanizedMovement = (0, chalk_1.default) `before field group {yellow ${pivot}}`; } return { heading: (0, chalk_1.default) `Update editor layout for content type {bold.yellow ${this.getContentTypeId()}}`, sections: [{ heading: (0, chalk_1.default) `Move field {yellow ${this.payload.fieldId}} ${humanizedMovement}`, details: [] }], details: [] }; } } exports.default = EditorLayoutMoveFieldIntent; //# sourceMappingURL=editor-layout-move-field.js.map