Skip to content

Commit

Permalink
Handle value updates for all node types #147
Browse files Browse the repository at this point in the history
  • Loading branch information
johnatawnclementawn authored and jacobtylerwalls committed Jan 17, 2025
1 parent dd603b1 commit 4b1c169
Showing 1 changed file with 68 additions and 16 deletions.
84 changes: 68 additions & 16 deletions arches_lingo/src/arches_lingo/components/generic/LabelEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,27 @@ const eventTypeOptions = ref<ControlledListItem[]>([]);
const groupAndPersonOptions = ref<ResourceInstanceReference[]>();
const textualWorkOptions = ref<ResourceInstanceReference[]>();
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;
}
}
Expand Down Expand Up @@ -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)
"
/>
<!-- Label Language: reference datatype -->
Expand All @@ -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,
)
"
/>
<!-- Label Type: reference datatype -->
Expand All @@ -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,
)
"
/>
<!-- Label Status: reference datatype -->
<label for="">{{ $gettext("Label Status") }}</label>
Expand All @@ -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)
"
/>
<!-- Label Status Metatype: reference datatype -->
<label for="">{{ $gettext("Label Metatype") }}</label>
Expand All @@ -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,
)
"
/>

<!-- Label Temporal Validity Start: date -->
Expand All @@ -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,
)
"
/>

Expand All @@ -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,
)
"
/>

Expand All @@ -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 ?? [],
)
"
/>
<!-- Sources: resource instance -->
Expand All @@ -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 ?? [],
)
"
/>
<!-- Warrant Type: reference datatype -->
Expand All @@ -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,
)
"
/>
<Button
Expand Down

0 comments on commit 4b1c169

Please sign in to comment.