diff --git a/arches_vue_utils/src/arches_vue_utils/types.ts b/arches_vue_utils/src/arches_vue_utils/types.ts index 77fbde1..9a49008 100644 --- a/arches_vue_utils/src/arches_vue_utils/types.ts +++ b/arches_vue_utils/src/arches_vue_utils/types.ts @@ -22,3 +22,10 @@ export interface WithValues { } export type Labellable = WithLabels | WithValues; + +export interface Descriptors { + [key: string]: { + name: string; + description: string; + }; +} diff --git a/arches_vue_utils/src/arches_vue_utils/utils.ts b/arches_vue_utils/src/arches_vue_utils/utils.ts index f063c27..50e53aa 100644 --- a/arches_vue_utils/src/arches_vue_utils/utils.ts +++ b/arches_vue_utils/src/arches_vue_utils/utils.ts @@ -1,6 +1,7 @@ import { ALT_LABEL, PREF_LABEL } from "@/arches_vue_utils/constants.ts"; import type { + Descriptors, Label, Labellable, WithLabels, @@ -66,3 +67,20 @@ export const getItemLabel = ( rankLabel(a, preferredLanguageCode, systemLanguageCode), )[0]; }; + +export const getDescriptors = ( + data: Descriptors, + systemLanguageCode: string, + ): Descriptors => { + if (!data) { + return { + name: "", + description: "", + }; + } + const descriptors = data[systemLanguageCode] ?? data[Object.keys(data)[0]]; + return { + name: descriptors.name ?? "", + description: descriptors.description ?? "", + }; +};