X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/e7916d508b495a1fd2be51bd3da2125cc8eb7467..227ffcbd2efe8cccd4a9025344b09632630cff14:/src/models/vocabulary.ts diff --git a/src/models/vocabulary.ts b/src/models/vocabulary.ts index 158d8058..03f28c07 100644 --- a/src/models/vocabulary.ts +++ b/src/models/vocabulary.ts @@ -25,8 +25,8 @@ export interface Tag { } export interface PropFieldSuggestion { - "id": string; - "label": string; + id: string; + label: string; } const VOCABULARY_VALIDATORS = [ @@ -50,6 +50,14 @@ export const getTagValueID = (tagKeyID:string, tagValueLabel:string, vocabulary: l => l.label === tagValueLabel) !== undefined) || '' : ''; +export const getTagValueLabel = (tagKeyID:string, tagValueID:string, vocabulary: Vocabulary) => + vocabulary.tags[tagKeyID] && + vocabulary.tags[tagKeyID].values && + vocabulary.tags[tagKeyID].values![tagValueID] && + vocabulary.tags[tagKeyID].values![tagValueID].labels.length > 0 + ? vocabulary.tags[tagKeyID].values![tagValueID].labels[0].label + : tagValueID; + const compare = (a: PropFieldSuggestion, b: PropFieldSuggestion) => { if (a.label < b.label) {return -1;} if (a.label > b.label) {return 1;} @@ -60,7 +68,7 @@ export const getTagValues = (tagKeyID: string, vocabulary: Vocabulary) => { const tag = vocabulary.tags[tagKeyID]; const ret = tag && tag.values ? Object.keys(tag.values).map( - tagValueID => tag.values![tagValueID].labels + tagValueID => tag.values![tagValueID].labels && tag.values![tagValueID].labels.length > 0 ? tag.values![tagValueID].labels.map( lbl => Object.assign({}, {"id": tagValueID, "label": lbl.label})) : [{"id": tagValueID, "label": tagValueID}]) @@ -73,7 +81,7 @@ export const getTagValues = (tagKeyID: string, vocabulary: Vocabulary) => { export const getTags = ({ tags }: Vocabulary) => { const ret = tags && Object.keys(tags) ? Object.keys(tags).map( - tagID => tags[tagID].labels + tagID => tags[tagID].labels && tags[tagID].labels.length > 0 ? tags[tagID].labels.map( lbl => Object.assign({}, {"id": tagID, "label": lbl.label})) : [{"id": tagID, "label": tagID}]) @@ -86,4 +94,10 @@ export const getTags = ({ tags }: Vocabulary) => { export const getTagKeyID = (tagKeyLabel:string, vocabulary: Vocabulary) => Object.keys(vocabulary.tags).find( k => vocabulary.tags[k].labels.find( - l => l.label === tagKeyLabel) !== undefined) || ''; + l => l.label === tagKeyLabel) !== undefined + ) || ''; + +export const getTagKeyLabel = (tagKeyID:string, vocabulary: Vocabulary) => + vocabulary.tags[tagKeyID] && vocabulary.tags[tagKeyID].labels.length > 0 + ? vocabulary.tags[tagKeyID].labels[0].label + : tagKeyID;