import type { Field } from '@wix/bex-core'; import type { FieldActionKey } from '../FieldActions'; const TEXT_TYPES = new Set(['SHORT_TEXT', 'LONG_TEXT']); /** * Per-action disabled tooltips for a schema-source field. Encodes the schema's * data-model rules — only a text field can be the primary/display field, system * fields are locked, the primary field can't be deleted — which used to live in * the shared * FieldActions registry. A key present ⇒ that action renders disabled with the * tooltip; an action with no handler ignores its entry. Tooltips match the * previous (untranslated) registry strings. */ export const schemaFieldDisabledTooltips = ( field: Field, perms: { canEdit: boolean; canAddFields: boolean }, ): Partial> => { const tooltips: Partial> = {}; if (!perms.canEdit) { tooltips.makePrimary = 'Editing fields is disabled.'; } else if (field.isPrimary) { tooltips.makePrimary = 'This is the primary field.'; } else if (field.isSystem) { tooltips.makePrimary = "System fields can't be modified."; } else if (!TEXT_TYPES.has(field.type)) { tooltips.makePrimary = 'Only text fields can be made primary.'; } if (!perms.canAddFields) { tooltips.duplicateField = 'Adding fields is disabled.'; tooltips.duplicateFieldWithContent = 'Adding fields is disabled.'; } else if (field.isSystem) { tooltips.duplicateField = "System fields can't be modified."; tooltips.duplicateFieldWithContent = "System fields can't be modified."; } if (field.isPrimary) { tooltips.delete = 'This is the primary field.'; } return tooltips; };