Skip to content

Commit

Permalink
feat: add no-field case spec to Dynamic Layout item type
Browse files Browse the repository at this point in the history
- Add computed property to check if fields are empty
- Add computed property to check if root data is empty
- Update fields computation based on new properties

Signed-off-by: sulmo <[email protected]>
  • Loading branch information
sulmoJ committed Dec 17, 2024
1 parent ea582e9 commit 0d1fdc4
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,16 @@ const props = withDefaults(defineProps<Props>(), {
const state = reactive({
layoutName: computed(() => (props.options.translation_id ? I18nConnector.i18n.t(props.options.translation_id) : props.name)),
isFieldEmpty: computed<boolean>(() => !props.options.fields || props.options.fields.length === 0),
isRootDataEmpty: computed<boolean>(() => !state.rootData || Object.keys(state.rootData).length === 0),
fields: computed<DefinitionField[]>(() => {
if (!props.options.fields) return [];
if (state.isFieldEmpty) {
if (state.isRootDataEmpty) return [];
return Object.keys(state.rootData).map((key) => ({
label: key,
name: key,
}));
}
const locale = I18nConnector.i18n.locale;
return props.options.fields.map((d) => ({
label: d.options?.translation_id ? I18nConnector.i18n.t(d.options.translation_id as string, locale) : d.name,
Expand Down

0 comments on commit 0d1fdc4

Please sign in to comment.