Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HKISD-224: search groups and projects with same name #319

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/components/Search/FreeSearchForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ const FreeSearchForm = ({
const handleSetSearchWord = useCallback(
(value: string) =>
setSearchState((current) => {
// TODO: here user must be notified if selected value is duplicate
// TODO: searchWordDuplicates contains duplicates
return { ...current, searchWord: value };
}),
[],
Expand Down
17 changes: 14 additions & 3 deletions src/utils/buildSearchParams.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { FreeSearchFormObject, IOption } from '@/interfaces/common';
import { FreeSearchFormItem, FreeSearchFormObject, IOption } from '@/interfaces/common';
import { ISearchForm } from '@/interfaces/formInterfaces';

// Build a search parameter with all the choices from the search form
const buildSearchParams = (form: ISearchForm) => {
const typeToParam: {[key in FreeSearchFormItem['type']]?: string} = {
projects: 'projectName',
groups: 'group',
hashtags: 'hashtag'
};
const searchParams = [];
for (const [key, value] of Object.entries(form)) {
switch (key) {
Expand All @@ -29,8 +34,14 @@ const buildSearchParams = (form: ISearchForm) => {
break;
case 'freeSearchParams':
for (const [_, v] of Object.entries(value as FreeSearchFormObject)) {
const paramType = v.type.substring(0, v.type.length - 1);
searchParams.push(`${paramType}=${v.value}`);
const paramType = typeToParam[v.type];
const paramValue = v.type === 'hashtags' ? v.value : v.label;
if (paramType === "hashtag") {
searchParams.push(`${paramType}=${paramValue}`);
} else {
searchParams.push(`projectName=${paramValue}`);
searchParams.push(`group=${paramValue}`);
}
}
break;
default:
Expand Down