Skip to content

Commit

Permalink
Add collection criterion value formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloLec committed May 9, 2024
1 parent e359e16 commit b50a88d
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions test-frontend/src/lib/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ const formatCriteria = (criteria: SearchCriterion[]): SearchCriterion[] => {
criterion.value = criterion.value.toString();
}

if (criterion.op?.toLowerCase().includes('like')) {
if (["like", "notLike"].includes(criterion.op?.toLowerCase())) {
formatLikeCriterion(criterion);
} else if (["in", "notIn"].includes(criterion.op?.toLowerCase())) {
formatCollectionCriterion(criterion);
}

if (criterion.subQuery) {
Expand All @@ -99,4 +101,19 @@ const formatLikeCriterion = (criterion: SearchCriterion): SearchCriterion => {
criterion.value = `%${criterion.value}%`;
}
return criterion;
}
}

const formatCollectionCriterion = (criterion: SearchCriterion): SearchCriterion => {
const regex = /[\p{L}\p{N}\-.]+/gu;

if (criterion.value) {
const matches = criterion.value.match(regex);
if (matches && matches.length > 0) {
criterion.value = `[${matches.join(", ")}]`;
} else {
criterion.value = "[]";
}
}

return criterion;
}

0 comments on commit b50a88d

Please sign in to comment.