Skip to content

Commit

Permalink
Replace hardcoded concept ids, #151
Browse files Browse the repository at this point in the history
  • Loading branch information
njkim committed Jan 22, 2025
1 parent 31a8dac commit adb4b91
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ import {
deleteSchemeRightStatement,
fetchPersonRdmSystemList,
fetchGroupRdmSystemList,
fetchControlledListOptions,
} from "@/arches_lingo/api.ts";
import { fetchLists } from "@/arches_references/api.ts";
import type {
ControlledListResult,
ControlledListItem,
ControlledListItemResult,
DataComponentMode,
Expand All @@ -37,10 +39,6 @@ import {
EDIT,
OPEN_EDITOR,
UPDATED,
RIGHT_TYPE_CONTROLLED_LIST,
METATYPES_CONTROLLED_LIST,
LANGUAGE_CONTROLLED_LIST,
NOTE_CONTROLLED_LIST,
} from "@/arches_lingo/constants.ts";
import ResourceInstanceRelationships from "@/arches_lingo/components/generic/ResourceInstanceRelationships.vue";
import ReferenceDatatype from "@/arches_lingo/components/generic/ReferenceDatatype.vue";
Expand Down Expand Up @@ -101,6 +99,29 @@ const metaStringLabel: MetaStringText = {
noRecords: $gettext("No scheme right statement were found."),
};
const referenceNodeConfig = [
{
nodeAlias: "appellative_status_status",
listRef: rightTypeOptions,
listName: "Right Types",
},
{
nodeAlias: "appellative_status_ascribed_name_language",
listRef: languageOptions,
listName: "Languages",
},
{
nodeAlias: "appellative_status_ascribed_relation",
listRef: noteOptions,
listName: "note",
},
{
nodeAlias: "appellative_status_status_metatype",
listRef: metatypesOptions,
listName: "Metatypes",
},
];
async function getActorOptions(): Promise<ResourceInstanceReference[]> {
const options_person = await fetchPersonRdmSystemList();
const options_group = await fetchGroupRdmSystemList();
Expand All @@ -117,16 +138,37 @@ async function getActorOptions(): Promise<ResourceInstanceReference[]> {
});
return results;
};
async function getControlledListOptions(listId: string): Promise<ControlledListItem[]> {
const parsed = await fetchControlledListOptions(listId);
const options = parsed.items.map(
(item: ControlledListItemResult): ControlledListItem => ({
list_id: item.list_id,
uri: item.uri,
labels: item.values
}),
);
return options;
async function getControlledLists() {
let parsed;
try {
parsed = await fetchLists(
referenceNodeConfig.map((node) => node.nodeAlias),
);
} catch (error) {
toast.add({
severity: ERROR,
summary: $gettext("Error"),
detail:
error instanceof Error
? error.message
: $gettext("Could not fetch the controlled list options"),
});
return [];
}
const controlledLists = parsed.controlled_lists;
referenceNodeConfig.forEach((node) => {
const matchingList = controlledLists.find(
(list: ControlledListResult) => list.name === node.listName,
);
const options = matchingList.items.map(
(item: ControlledListItemResult): ControlledListItem => ({
list_id: item.list_id,
uri: item.uri,
labels: item.values,
}),
);
node.listRef.value = options;
});
};
function onUpdateResourceInstance(
Expand Down Expand Up @@ -245,10 +287,7 @@ async function getSectionValue() {
return option;
}
});
rightTypeOptions.value = await getControlledListOptions(RIGHT_TYPE_CONTROLLED_LIST);
languageOptions.value = await getControlledListOptions(LANGUAGE_CONTROLLED_LIST);
noteOptions.value = await getControlledListOptions(NOTE_CONTROLLED_LIST);
metatypesOptions.value = await getControlledListOptions(METATYPES_CONTROLLED_LIST);
getControlledLists();
};
async function deleteStatementValue(tileId: string) {
Expand Down
12 changes: 1 addition & 11 deletions arches_lingo/src/arches_lingo/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,4 @@ export const ENGLISH = {
isdefault: true,
name: "English",
scope: "system",
};

export const LANGUAGE_CONTROLLED_LIST = "55ce793b-a51a-4b25-811d-d08ea797f8c3";
export const LABEL_CONTROLLED_LIST = "deb847fc-f4c3-4e82-be19-04641579f129";
export const STATUSES_CONTROLLED_LIST = "2cc0e054-ef9b-41ae-8e86-e0c3b4e7ca00";
export const METATYPES_CONTROLLED_LIST = "ef69e772-de53-45fe-98d4-bf3e7b10eb57";
export const EVENT_TYPES_CONTROLLED_LIST =
"6eaa2c6f-af83-464c-9200-051c4cfe7e8e";
export const RIGHT_TYPE_CONTROLLED_LIST = "1c950e16-3fcf-4f33-9e5e-ce5c6c992cca";
export const NOTE_CONTROLLED_LIST = "aba2a0b4-75a4-45ba-8b57-021f3ca92a6a";

};

0 comments on commit adb4b91

Please sign in to comment.