--- /dev/null
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+export const escapeRegExp = (st: string) =>
+ st.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
import { Vocabulary } from '~/models/vocabulary';
import { connectVocabulary, VocabularyProp, buildProps } from '~/views-components/resource-properties-form/property-field-common';
import { TAG_KEY_VALIDATION } from '~/validators/validators';
+import { escapeRegExp } from '~/common/regexp.ts';
export const PROPERTY_KEY_FIELD_NAME = 'key';
? undefined
: 'Incorrect key';
-const getSuggestions = (value: string, vocabulary: Vocabulary) =>
- getTagsList(vocabulary).filter(tag => tag.includes(value) && tag !== value);
+const getSuggestions = (value: string, vocabulary: Vocabulary) => {
+ const re = new RegExp(escapeRegExp(value), "i");
+ return getTagsList(vocabulary).filter(tag => re.test(tag) && tag !== value);
+};
const getTagsList = ({ tags }: Vocabulary) =>
Object.keys(tags);
import { PROPERTY_KEY_FIELD_NAME } from '~/views-components/resource-properties-form/property-key-field';
import { VocabularyProp, connectVocabulary, buildProps } from '~/views-components/resource-properties-form/property-field-common';
import { TAG_VALUE_VALIDATION } from '~/validators/validators';
+import { escapeRegExp } from '~/common/regexp.ts';
interface PropertyKeyProp {
propertyKey: string;
? undefined
: 'Incorrect value';
-const getSuggestions = (value: string, tagName: string, vocabulary: Vocabulary) =>
- getTagValues(tagName, vocabulary).filter(v => v.includes(value) && v !== value);
+const getSuggestions = (value: string, tagName: string, vocabulary: Vocabulary) => {
+ const re = new RegExp(escapeRegExp(value), "i");
+ return getTagValues(tagName, vocabulary).filter(v => re.test(v) && v !== value);
+};
const isStrictTag = (tagName: string, vocabulary: Vocabulary) => {
const tag = vocabulary.tags[tagName];