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

Conversation

jacobtylerwalls
Copy link
Member

@jacobtylerwalls jacobtylerwalls commented Nov 21, 2024

Discovered in archesproject/arches-lingo#135 that if you have incomplete data, like using the resource editor to create an incomplete scheme, the concept tree would break. The backend is hardened against this in lingo, but to harden the frontend, we need to update this util to not throw.

Copy link
Member

@johnatawnclementawn johnatawnclementawn left a comment

Choose a reason for hiding this comment

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

Small question about whether to provide empty string or "None", but other than that, lgtm 👍🏼

@@ -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

@@ -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?

Copy link
Member Author

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

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

I like this idea, but the problem is that we'd need to localize it, and we don't currently have a way to use gettext in js/ts files. The recommendation is to expose the result of createGettext in its own file, but we create it dynamically after making a call to the backend to get available languages.

We might want to make the languages a little more static following the lead of archesproject/arches#11571. I'll open a core issue to discuss it with @chrabyrd.

@jacobtylerwalls
Copy link
Member Author

(If we leave it as is, the caller can check if the result is truthy and then replace it with a localized placeholder.)

@jacobtylerwalls jacobtylerwalls merged commit e325729 into main Nov 27, 2024
2 of 5 checks passed
@jacobtylerwalls jacobtylerwalls deleted the jtw/dont-raise-error-for-no-labels branch November 27, 2024 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants