Skip to content

Commit

Permalink
feat: implement feature trim function to the search inputs on the sco…
Browse files Browse the repository at this point in the history
…re (#2384)

* feat: implement feature trim funtcion to the search inputs on the score

* fix: lint errors

* fix: add value check for type string[]

* fix: remove string type for filters on the score

* fix: add trim for query params

* fix: add string type for optionalQueryString

* fix: add returned value by string[]

* fix: returnd valeu

* fix: array serialization

* fix: add trim function for each element in array
  • Loading branch information
Zoro444 authored Dec 14, 2023
1 parent 0b48c5e commit 44264ea
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
8 changes: 4 additions & 4 deletions client/src/modules/Score/hooks/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export type ScoreTableFilters = {
githubId?: string;
name?: string;
'mentor.githubId'?: string;
cityName?: string;
githubId?: string[];
name?: string[];
'mentor.githubId'?: string[];
cityName?: string[];
activeOnly: boolean;
};

Expand Down
11 changes: 9 additions & 2 deletions client/src/utils/optionalQueryString.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
export function optionalQueryString(value: string | undefined) {
return value ? String(value) : undefined;
export function optionalQueryString(value: string | string[] | undefined) {
if (Array.isArray(value)) {
const trimmedElements = value.map(elem => elem.trim()).join(',');
if (trimmedElements !== '') {
return trimmedElements;
}
} else if (typeof value === 'string') {
return String(value).trim();
}
}
10 changes: 7 additions & 3 deletions client/src/utils/queryParams-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ export const getQueryParams = (
let params = { ...initialQueryParams };
for (const [key, value] of Object.entries(queryParams)) {
if (!isNil(value)) {
if (Array.isArray(value) && value[0] !== '') {
params = { ...params, [key]: value[0] };
if (Array.isArray(value)) {
const trimmedElements = value.map(elem => elem.trim()).join(',');
if (trimmedElements !== '') {
params = { ...params, [key]: trimmedElements };
}
} else if (typeof value === 'string' && value !== '') {
params = { ...params, [key]: value };
params = { ...params, [key]: value.trim() };
}
}
}

return params;
};

Expand Down

0 comments on commit 44264ea

Please sign in to comment.