From: Tom Clegg Date: Wed, 16 Mar 2022 20:26:27 +0000 (-0400) Subject: Merge branch '18848-upgrade-yarn3'. Closes #18848 X-Git-Tag: 2.4.0~5 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/ac317fdfc6cc1bfdee257580a03a6054edac05a2?hp=ebb5bf6fc93912af4013cb74b751e877c292eee7 Merge branch '18848-upgrade-yarn3'. Closes #18848 Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- diff --git a/src/models/vocabulary.test.ts b/src/models/vocabulary.test.ts index 761c785b..f4ba64e5 100644 --- a/src/models/vocabulary.test.ts +++ b/src/models/vocabulary.test.ts @@ -52,6 +52,14 @@ describe('Vocabulary', () => { labels: [] } } + }, + automation: { + strict: true, + labels: [], + values: { + upload: { labels: [] }, + results: { labels: [] }, + } } } } @@ -66,6 +74,7 @@ describe('Vocabulary', () => { {id: "IDKEYANIMALS", label: "Creature"}, {id: "IDKEYCOMMENT", label: "IDKEYCOMMENT"}, {id: "IDKEYSIZES", label: "Sizes"}, + {id: "automation", label: "automation"}, ]); }); @@ -76,6 +85,7 @@ describe('Vocabulary', () => { {id: "IDKEYANIMALS", label: "Animal", synonyms: []}, {id: "IDKEYCOMMENT", label: "IDKEYCOMMENT", synonyms: []}, {id: "IDKEYSIZES", label: "Sizes", synonyms: []}, + {id: "automation", label: "automation", synonyms: []}, ]); }); @@ -86,6 +96,7 @@ describe('Vocabulary', () => { {id: "IDKEYANIMALS", label: "Animal", synonyms: ["Creature"]}, {id: "IDKEYCOMMENT", label: "IDKEYCOMMENT", synonyms: []}, {id: "IDKEYSIZES", label: "Sizes", synonyms: []}, + {id: "automation", label: "automation", synonyms: []}, ]); }); @@ -101,7 +112,13 @@ describe('Vocabulary', () => { {id: "IDVALSIZES2", label: "Medium"}, {id: "IDVALSIZES1", label: "S"}, {id: "IDVALSIZES1", label: "Small"}, - ]) + ]); + // Let's try a key that doesn't have any labels + const tagValues2 = Vocabulary.getTagValues('automation', vocabulary); + expect(tagValues2).toEqual([ + {id: "results", label: "results"}, + {id: "upload", label: "upload"}, + ]); }); it('returns the preferred tag values for a given key', () => { @@ -112,7 +129,13 @@ describe('Vocabulary', () => { {id: "IDVALSIZES3", label: "Large", synonyms: []}, {id: "IDVALSIZES2", label: "Medium", synonyms: []}, {id: "IDVALSIZES1", label: "Small", synonyms: []}, - ]) + ]); + // Let's try a key that doesn't have any labels + const preferredTagValues2 = Vocabulary.getPreferredTagValues('automation', vocabulary); + expect(preferredTagValues2).toEqual([ + {id: "results", label: "results", synonyms: []}, + {id: "upload", label: "upload", synonyms: []}, + ]); }); it('returns the preferred tag values with matching synonyms for a given key', () => { @@ -138,6 +161,8 @@ describe('Vocabulary', () => { {keyLabel: 'Creature', expected: 'IDKEYANIMALS'}, // Non-existent label returns empty string {keyLabel: 'ThisKeyLabelDoesntExist', expected: ''}, + // Key with no labels still returns the key ID + {keyLabel: 'automation', expected: 'automation'}, ] testCases.forEach(tc => { const tagValueID = Vocabulary.getTagKeyID(tc.keyLabel, vocabulary); @@ -169,6 +194,8 @@ describe('Vocabulary', () => { {keyID: 'IDKEYANIMALS', valueLabel: 'Dinosaur', expected: ''}, // Key ID unknown {keyID: 'IDNONSENSE', valueLabel: 'Does not matter', expected: ''}, + // Value with no labels still returns the value ID + {keyID: 'automation', valueLabel: 'results', expected: 'results'}, ] testCases.forEach(tc => { const tagValueID = Vocabulary.getTagValueID(tc.keyID, tc.valueLabel, vocabulary); diff --git a/src/models/vocabulary.ts b/src/models/vocabulary.ts index 6c629059..c913bd65 100644 --- a/src/models/vocabulary.ts +++ b/src/models/vocabulary.ts @@ -45,12 +45,17 @@ export const isStrictTag = (tagKeyID: string, vocabulary: Vocabulary) => { return tag ? tag.strict : false; }; -export const getTagValueID = (tagKeyID:string, tagValueLabel:string, vocabulary: Vocabulary) => - (tagKeyID && vocabulary.tags[tagKeyID] && vocabulary.tags[tagKeyID].values) - ? Object.keys(vocabulary.tags[tagKeyID].values!).find( - k => vocabulary.tags[tagKeyID].values![k].labels.find( - l => l.label.toLowerCase() === tagValueLabel.toLowerCase()) !== undefined) || '' - : ''; +export const getTagValueID = (tagKeyID:string, tagValueLabel:string, vocabulary: Vocabulary) => { + if (tagKeyID && vocabulary.tags[tagKeyID] && vocabulary.tags[tagKeyID].values) { + const values = vocabulary.tags[tagKeyID].values!; + return Object.keys(values).find(k => + (k.toLowerCase() === tagValueLabel.toLowerCase()) + || values[k].labels.find( + l => l.label.toLowerCase() === tagValueLabel.toLowerCase()) !== undefined) + || ''; + }; + return ''; +}; export const getTagValueLabel = (tagKeyID:string, tagValueID:string, vocabulary: Vocabulary) => vocabulary.tags[tagKeyID] && @@ -130,11 +135,11 @@ export const getPreferredTags = ({ tags }: Vocabulary, withMatch?: string): Prop : []; }; -export const getTagKeyID = (tagKeyLabel:string, vocabulary: Vocabulary) => - Object.keys(vocabulary.tags).find( - k => vocabulary.tags[k].labels.find( - l => l.label.toLowerCase() === tagKeyLabel.toLowerCase()) !== undefined - ) || ''; +export const getTagKeyID = (tagKeyLabel: string, vocabulary: Vocabulary) => + Object.keys(vocabulary.tags).find(k => (k.toLowerCase() === tagKeyLabel.toLowerCase()) + || vocabulary.tags[k].labels.find( + l => l.label.toLowerCase() === tagKeyLabel.toLowerCase()) !== undefined) + || ''; export const getTagKeyLabel = (tagKeyID:string, vocabulary: Vocabulary) => vocabulary.tags[tagKeyID] && vocabulary.tags[tagKeyID].labels.length > 0