-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 getPreferredTags = ({ tags }: Vocabulary, withMatch?: string): PropFieldSuggestion[] => {
+ const regex = !!withMatch ? new RegExp(escapeRegExp(withMatch), 'i') : undefined;
+ return tags && Object.keys(tags)
+ ? Object.keys(tags).map(
+ tagID => tags[tagID].labels && tags[tagID].labels.length > 0
+ ? {
+ "id": tagID,
+ "label": tags[tagID].labels[0].label,
+ "synonyms": !!withMatch && tags[tagID].labels.length > 1
+ ? tags[tagID].labels.slice(1)
+ .filter(l => !!regex ? regex.test(l.label) : true)
+ .map(lbl => lbl.label)
+ : []
+ }
+ : {"id": tagID, "label": tagID, "synonyms": []})
+ .sort(compare)
+ : [];
+};
+
+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)
+ || '';