Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't raise errors for missing labels #5

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions arches_vue_utils/src/arches_vue_utils/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ function asLabel(valuetype_id: string, language_id: string): Label {
}

const systemLanguageCode = "en-ZA"; // arbitrary
const emptyLabel = {
value: "",
Copy link
Member

@johnatawnclementawn johnatawnclementawn Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elsewhere in Arches, we have "None" as a placeholder for no data (e.g. resource report page). What do you think of returning that instead of empty string to maintain the pattern and signal the absence of data?

language_id: "",
valuetype_id: "",
};

describe("rankLabel() util", () => {
const rank = (
Expand Down Expand Up @@ -59,21 +64,21 @@ describe("rankLabel() util", () => {
});

describe("getItemLabel() util", () => {
it("Errors if no labels", () => {
expect(() =>
it("Returns empty label if no labels to search", () => {
expect(
getItemLabel(
{ labels: [] },
systemLanguageCode,
systemLanguageCode,
),
).toThrow();
expect(() =>
).toEqual(emptyLabel);
expect(
getItemLabel(
{ values: [] },
systemLanguageCode,
systemLanguageCode,
),
).toThrow();
).toEqual(emptyLabel);
});
it("Falls back to system language", () => {
expect(
Expand Down
6 changes: 5 additions & 1 deletion arches_vue_utils/src/arches_vue_utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ export const getItemLabel = (
): Label => {
const labels = (item as WithLabels).labels ?? (item as WithValues).values;
if (!labels.length) {
throw new Error();
return {
value: "",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

language_id: "",
valuetype_id: "",
};
}
return labels.sort(
(a, b) =>
Expand Down
Loading