From 29aaf32b8931380b339e57b8cf348e3b7f1781d3 Mon Sep 17 00:00:00 2001 From: Johnathan Clementi Date: Thu, 21 Nov 2024 16:19:33 -0500 Subject: [PATCH 1/3] Add util for retrieving i18n'd resource descriptor --- arches_vue_utils/src/arches_vue_utils/types.ts | 7 +++++++ arches_vue_utils/src/arches_vue_utils/utils.ts | 12 ++++++++++++ 2 files changed, 19 insertions(+) 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..02ad322 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,14 @@ export const getItemLabel = ( rankLabel(a, preferredLanguageCode, systemLanguageCode), )[0]; }; + +export const getDescriptors = ( + data: Descriptors, + systemLanguageCode: string, + ): [string, string] => { + if (!data) { + return ["None", "None"]; + } + const descriptors = data[systemLanguageCode]; + return [descriptors.name, descriptors.description]; +}; From 917ff3dbec3f031a83f8aa91d45a7b980dde02b8 Mon Sep 17 00:00:00 2001 From: Johnathan Clementi Date: Tue, 3 Dec 2024 17:29:40 -0500 Subject: [PATCH 2/3] make consistent with getItemLabel --- arches_vue_utils/src/arches_vue_utils/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arches_vue_utils/src/arches_vue_utils/utils.ts b/arches_vue_utils/src/arches_vue_utils/utils.ts index 02ad322..fa1361c 100644 --- a/arches_vue_utils/src/arches_vue_utils/utils.ts +++ b/arches_vue_utils/src/arches_vue_utils/utils.ts @@ -73,7 +73,7 @@ export const getDescriptors = ( systemLanguageCode: string, ): [string, string] => { if (!data) { - return ["None", "None"]; + return ["", ""]; } const descriptors = data[systemLanguageCode]; return [descriptors.name, descriptors.description]; From 18795cad7eb4c9f42cbf23b996e8f9d4fcb0eaf6 Mon Sep 17 00:00:00 2001 From: Johnathan Clementi Date: Wed, 4 Dec 2024 12:19:10 -0500 Subject: [PATCH 3/3] Return dict, null guard individual vals, and have fall back val if no val for system lang --- arches_vue_utils/src/arches_vue_utils/utils.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/arches_vue_utils/src/arches_vue_utils/utils.ts b/arches_vue_utils/src/arches_vue_utils/utils.ts index fa1361c..50e53aa 100644 --- a/arches_vue_utils/src/arches_vue_utils/utils.ts +++ b/arches_vue_utils/src/arches_vue_utils/utils.ts @@ -71,10 +71,16 @@ export const getItemLabel = ( export const getDescriptors = ( data: Descriptors, systemLanguageCode: string, - ): [string, string] => { + ): Descriptors => { if (!data) { - return ["", ""]; + return { + name: "", + description: "", + }; } - const descriptors = data[systemLanguageCode]; - return [descriptors.name, descriptors.description]; + const descriptors = data[systemLanguageCode] ?? data[Object.keys(data)[0]]; + return { + name: descriptors.name ?? "", + description: descriptors.description ?? "", + }; };