From c29d365b290f84b79904d89d287563df3b167a74 Mon Sep 17 00:00:00 2001 From: SeanLeRoy Date: Thu, 1 Aug 2024 16:54:35 -0700 Subject: [PATCH] Fix reg ex to account for spaces --- .../DataSourcePrompt/DataSourcePrompt.module.css | 1 + .../components/DataSourcePrompt/FilePrompt.module.css | 3 +-- packages/core/entity/FileSet/index.ts | 8 +++++++- .../DatabaseAnnotationService/index.ts | 11 ++++++++--- .../services/FileService/DatabaseFileService/index.ts | 5 ++++- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/packages/core/components/DataSourcePrompt/DataSourcePrompt.module.css b/packages/core/components/DataSourcePrompt/DataSourcePrompt.module.css index e57a8fd5..95c13ede 100644 --- a/packages/core/components/DataSourcePrompt/DataSourcePrompt.module.css +++ b/packages/core/components/DataSourcePrompt/DataSourcePrompt.module.css @@ -36,6 +36,7 @@ .link-like-button span { font-weight: unset; + margin: 0; } .link-like-button:hover, .link-like-button:focus { diff --git a/packages/core/components/DataSourcePrompt/FilePrompt.module.css b/packages/core/components/DataSourcePrompt/FilePrompt.module.css index 50bf8f34..66311788 100644 --- a/packages/core/components/DataSourcePrompt/FilePrompt.module.css +++ b/packages/core/components/DataSourcePrompt/FilePrompt.module.css @@ -29,7 +29,7 @@ .selected-file-button { color: var(--primary-text-color); - margin-left: auto; + margin-left: 10px; } .selected-file-button:hover { @@ -39,7 +39,6 @@ .selected-file-container { display: flex; - justify-content: center; } .submit-icon { diff --git a/packages/core/entity/FileSet/index.ts b/packages/core/entity/FileSet/index.ts index ec554343..dd81c47a 100644 --- a/packages/core/entity/FileSet/index.ts +++ b/packages/core/entity/FileSet/index.ts @@ -197,7 +197,13 @@ export default class FileSet { } else { sqlBuilder.where( filterValues - .map((fv) => `REGEXP_MATCHES("${annotation}", '(\\b${fv}\\b)') = true`) + .map( + (fv) => + // Ex. This regex will match on a value + // that is at the start, middle, end, or only value in a comma separated list + // of values (,\s*Position,)|(^\s*Position\s*,)|(,\s*Position\s*$)|(^\s*Position\s*$) + `REGEXP_MATCHES("${annotation}", '(,\\s*${fv}\\s*,)|(^\\s*${fv}\\s*,)|(,\\s*${fv}\\s*$)|(^\\s*${fv}\\s*$)') = true` + ) .join(") OR (") ); } diff --git a/packages/core/services/AnnotationService/DatabaseAnnotationService/index.ts b/packages/core/services/AnnotationService/DatabaseAnnotationService/index.ts index 5a2cd3dc..f1219a1c 100644 --- a/packages/core/services/AnnotationService/DatabaseAnnotationService/index.ts +++ b/packages/core/services/AnnotationService/DatabaseAnnotationService/index.ts @@ -1,4 +1,4 @@ -import { uniq } from "lodash"; +import { isNil, uniq } from "lodash"; import AnnotationService, { AnnotationValue } from ".."; import DatabaseService from "../../DatabaseService"; @@ -96,7 +96,10 @@ export default class DatabaseAnnotationService implements AnnotationService { annotationValues .map( (value) => - `REGEXP_MATCHES("${annotationToFilter}", '(\\b${value}\\b)') = true` + // Ex. This regex will match on a value + // that is at the start, middle, end, or only value in a comma separated list + // of values (,\s*Position,)|(^\s*Position\s*,)|(,\s*Position\s*$)|(^\s*Position\s*$) + `REGEXP_MATCHES("${annotationToFilter}", '(,\\s*${value}\\s*,)|(^\\s*${value}\\s*,)|(,\\s*${value}\\s*$)|(^\\s*${value}\\s*$)') = true` ) .join(") OR (") ); @@ -105,7 +108,9 @@ export default class DatabaseAnnotationService implements AnnotationService { const rows = await this.databaseService.query(sqlBuilder.toSQL()); const rowsSplitByDelimiter = rows - .flatMap((row) => row[annotation].split(DatabaseService.LIST_DELIMITER)) + .flatMap((row) => + isNil(row[annotation]) ? [] : row[annotation].split(DatabaseService.LIST_DELIMITER) + ) .map((value) => value.trim()); return uniq(rowsSplitByDelimiter); } diff --git a/packages/core/services/FileService/DatabaseFileService/index.ts b/packages/core/services/FileService/DatabaseFileService/index.ts index c97f9518..67252154 100644 --- a/packages/core/services/FileService/DatabaseFileService/index.ts +++ b/packages/core/services/FileService/DatabaseFileService/index.ts @@ -148,7 +148,10 @@ export default class DatabaseFileService implements FileService { .flatMap(([column, values]) => values.map( (value) => - `REGEXP_MATCHES("${column}", '(\\b${value}\\b)') = true` + // Ex. This regex will match on a value + // that is at the start, middle, end, or only value in a comma separated list + // of values (,\s*Position,)|(^\s*Position\s*,)|(,\s*Position\s*$)|(^\s*Position\s*$) + `REGEXP_MATCHES("${column}", '(,\\s*${value}\\s*,)|(^\\s*${value}\\s*,)|(,\\s*${value}\\s*$)|(^\\s*${value}\\s*$)') = true` ) ) .join(") OR (")