import { computed, defineComponent, onMounted, type PropType } from 'vue'; import type { BCMSProp, BCMSPropEntryPointerData, BCMSPropGroupPointerData, } from '@becomes/cms-sdk/types'; import { BCMSPropType } from '@becomes/cms-sdk/types'; import BCMSButton from '../button'; import BCMSIcon from '../icon'; import BCMSLink from '../link'; import { BCMSOverflowMenu, BCMSOverflowMenuItem } from '../overflow'; import { useTranslation } from '../../translations'; const component = defineComponent({ props: { name: { type: String, required: true, }, props: { type: Array as PropType, required: true }, whereIsItUsedAvailable: Boolean, }, emits: { add: () => { return true; }, deleteEntity: () => { return true; }, whereIsItUsed: () => { return true; }, propMove: (_data: { direction: -1 | 1; index: number }) => { return true; }, propEdit: (_index: number) => { return true; }, propDelete: (_index: number) => { return true; }, }, setup(props, ctx) { const translations = computed(() => { return useTranslation(); }); const throwable = window.bcms.util.throwable; const stringUtil = window.bcms.util.string; const store = window.bcms.vue.store; const groups = computed(() => { return store.getters.group_items; }); const templates = computed(() => { return store.getters.template_items; }); const logic = { getGroupLabel(prop: BCMSProp): string { const group = groups.value.find( (e) => e._id === (prop.defaultData as BCMSPropGroupPointerData)._id, ); return group ? `${group.label}${ prop.array ? ' ' + translations.value.prop.viewer.array : '' }` : translations.value.prop.viewer.loading; }, getTemplateLabel(prop: BCMSProp): string { const template = templates.value.find((e) => (prop.defaultData as BCMSPropEntryPointerData[]).find( (d) => d.templateId === e._id, ), ); return template ? `${template.label}${ prop.array ? ' ' + translations.value.prop.viewer.array : '' }` : translations.value.prop.viewer.loading; }, getTemplateLabelById(id: string): string { const template = templates.value.find((e) => e._id === id); return template ? `${template.label}` : 'Loading ...'; }, }; onMounted(async () => { await throwable(async () => { return await window.bcms.sdk.group.getAll(); }); await throwable(async () => { return await window.bcms.sdk.template.getAll(); }); }); return () => (
{ ctx.emit('add'); }} > {translations.value.prop.viewer.actions.add} { ctx.emit('deleteEntity'); }} > {translations.value.prop.viewer.actions.delete} {props.whereIsItUsedAvailable ? ( { ctx.emit('whereIsItUsed'); }} > {translations.value.prop.viewer.actions.whereIsItUsed} ) : ( '' )}

{translations.value.prop.viewer.propertiesCount({ count: props.props.length || 'No', label: props.name, })}

{props.props.length > 0 ? ( ) : (
{translations.value.prop.viewer.emptyText({ label: props.name, })}
)}
); }, }); export default component;