From 4b1c1692edcee51ad80454e71cdb93d7e7c7f286 Mon Sep 17 00:00:00 2001 From: Johnathan Clementi Date: Wed, 8 Jan 2025 00:16:23 -0500 Subject: [PATCH] Handle value updates for all node types #147 --- .../components/generic/LabelEditor.vue | 84 +++++++++++++++---- 1 file changed, 68 insertions(+), 16 deletions(-) diff --git a/arches_lingo/src/arches_lingo/components/generic/LabelEditor.vue b/arches_lingo/src/arches_lingo/components/generic/LabelEditor.vue index bc03c9cd..da6f1e0f 100644 --- a/arches_lingo/src/arches_lingo/components/generic/LabelEditor.vue +++ b/arches_lingo/src/arches_lingo/components/generic/LabelEditor.vue @@ -63,14 +63,27 @@ const eventTypeOptions = ref([]); const groupAndPersonOptions = ref(); const textualWorkOptions = ref(); -function onUpdate( +function onUpdateString(node: keyof AppellativeStatus, val: string) { + (value.value[node] as unknown) = toRaw(val); +} + +function onUpdateReferenceDatatype( + node: keyof AppellativeStatus, + val: ControlledListItem[], +) { + (value.value[node] as unknown) = val.map((item) => toRaw(item)); +} + +function onUpdateResourceInstance( node: keyof AppellativeStatus, - val: ControlledListItem[] | ResourceInstanceReference[] | string, + val: string[], + options: ResourceInstanceReference[], ) { - if (Array.isArray(val)) { - (value.value[node] as unknown) = val.map((item) => toRaw(item)); - } else { - (value.value[node] as unknown) = toRaw(val); + if (val.length > 0) { + const selectedOptions = options.filter((option) => + val.includes(option.resourceId), + ); + (value.value[node] as unknown) = selectedOptions; } } @@ -156,7 +169,8 @@ onMounted(async () => { :value="value?.appellative_status_ascribed_name_content ?? ''" :mode="EDIT" @update=" - (val) => onUpdate('appellative_status_ascribed_name_content', val) + (val) => + onUpdateString('appellative_status_ascribed_name_content', val) " /> @@ -167,7 +181,11 @@ onMounted(async () => { :multi-value="false" :options="languageOptions" @update=" - (val) => onUpdate('appellative_status_ascribed_name_language', val) + (val) => + onUpdateReferenceDatatype( + 'appellative_status_ascribed_name_language', + val, + ) " /> @@ -177,7 +195,13 @@ onMounted(async () => { :mode="EDIT" :multi-value="false" :options="typeOptions" - @update="(val) => onUpdate('appellative_status_ascribed_relation', val)" + @update=" + (val) => + onUpdateReferenceDatatype( + 'appellative_status_ascribed_relation', + val, + ) + " /> @@ -186,7 +210,9 @@ onMounted(async () => { :mode="EDIT" :multi-value="false" :options="statusOptions" - @update="(val) => onUpdate('appellative_status_status', val)" + @update=" + (val) => onUpdateReferenceDatatype('appellative_status_status', val) + " /> @@ -195,7 +221,13 @@ onMounted(async () => { :mode="EDIT" :multi-value="false" :options="metatypeOptions" - @update="(val) => onUpdate('appellative_status_status_metatype', val)" + @update=" + (val) => + onUpdateReferenceDatatype( + 'appellative_status_status_metatype', + val, + ) + " /> @@ -205,7 +237,10 @@ onMounted(async () => { :mode="EDIT" @update=" (val) => - onUpdate('appellative_status_timespan_begin_of_the_begin', val) + onUpdateString( + 'appellative_status_timespan_begin_of_the_begin', + val, + ) " /> @@ -215,7 +250,11 @@ onMounted(async () => { :value="value?.appellative_status_timespan_end_of_the_end" :mode="EDIT" @update=" - (val) => onUpdate('appellative_status_timespan_end_of_the_end', val) + (val) => + onUpdateString( + 'appellative_status_timespan_end_of_the_end', + val, + ) " /> @@ -226,7 +265,12 @@ onMounted(async () => { :mode="EDIT" :options="groupAndPersonOptions" @update=" - (val) => onUpdate('appellative_status_data_assignment_actor', val) + (val) => + onUpdateResourceInstance( + 'appellative_status_data_assignment_actor', + val, + groupAndPersonOptions ?? [], + ) " /> @@ -237,7 +281,11 @@ onMounted(async () => { :options="textualWorkOptions" @update=" (val) => - onUpdate('appellative_status_data_assignment_object_used', val) + onUpdateResourceInstance( + 'appellative_status_data_assignment_object_used', + val, + textualWorkOptions ?? [], + ) " /> @@ -248,7 +296,11 @@ onMounted(async () => { :multi-value="false" :options="eventTypeOptions" @update=" - (val) => onUpdate('appellative_status_data_assignment_type', val) + (val) => + onUpdateReferenceDatatype( + 'appellative_status_data_assignment_type', + val, + ) " />