Skip to content

Commit

Permalink
Fix reg ex to account for spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanLeRoy committed Aug 1, 2024
1 parent 666f6fb commit c29d365
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

.link-like-button span {
font-weight: unset;
margin: 0;
}

.link-like-button:hover, .link-like-button:focus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

.selected-file-button {
color: var(--primary-text-color);
margin-left: auto;
margin-left: 10px;
}

.selected-file-button:hover {
Expand All @@ -39,7 +39,6 @@

.selected-file-container {
display: flex;
justify-content: center;
}

.submit-icon {
Expand Down
8 changes: 7 additions & 1 deletion packages/core/entity/FileSet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (")
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { uniq } from "lodash";
import { isNil, uniq } from "lodash";

import AnnotationService, { AnnotationValue } from "..";
import DatabaseService from "../../DatabaseService";
Expand Down Expand Up @@ -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 (")
);
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (")
Expand Down

0 comments on commit c29d365

Please sign in to comment.