[ARVADOS-WORKBENCH2] created: 1.4.1-79-g9b64c487

Git user git at public.curoverse.com
Tue Oct 29 21:06:15 UTC 2019


        at  9b64c487d252309c9b9dae513f32d53f1a6c5cb6 (commit)


commit 9b64c487d252309c9b9dae513f32d53f1a6c5cb6
Author: Peter Amstutz <pamstutz at veritasgenetics.com>
Date:   Tue Oct 29 17:05:07 2019 -0400

    15728: Use case-insensitive regexp for autocomplete

diff --git a/src/common/regexp.ts b/src/common/regexp.ts
new file mode 100644
index 00000000..eca24c75
--- /dev/null
+++ b/src/common/regexp.ts
@@ -0,0 +1,6 @@
+// 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
diff --git a/src/views-components/resource-properties-form/property-key-field.tsx b/src/views-components/resource-properties-form/property-key-field.tsx
index 3fb2d377..686c858e 100644
--- a/src/views-components/resource-properties-form/property-key-field.tsx
+++ b/src/views-components/resource-properties-form/property-key-field.tsx
@@ -9,6 +9,7 @@ import { Autocomplete } from '~/components/autocomplete/autocomplete';
 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';
 
@@ -39,8 +40,10 @@ const matchTags = (vocabulary: Vocabulary) =>
             ? 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);
diff --git a/src/views-components/resource-properties-form/property-value-field.tsx b/src/views-components/resource-properties-form/property-value-field.tsx
index 13dcfeb5..c8634acf 100644
--- a/src/views-components/resource-properties-form/property-value-field.tsx
+++ b/src/views-components/resource-properties-form/property-value-field.tsx
@@ -10,6 +10,7 @@ import { Vocabulary } from '~/models/vocabulary';
 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;
@@ -48,8 +49,10 @@ const matchTagValues = ({ vocabulary, propertyKey }: PropertyValueFieldProps) =>
             ? 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];

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list