Skip to content

Commit

Permalink
Merge pull request #886 from City-of-Helsinki/UHF-9563_area_filter_mu…
Browse files Browse the repository at this point in the history
…ltiselect

UHF-9563: add multiselect for job search area filter
  • Loading branch information
j-mys authored Jan 22, 2024
2 parents a8a6523 + a2e558c commit bb86e37
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dist/js/job-search.min.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/js/react/apps/job-search/containers/FormContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const FormContainer = () => {
// Set form control values from url parameters on load
useEffect(() => {
setKeyword(urlParams?.keyword?.toString() || '');
setAreaFilter(getInitialAreaFilter(urlParams?.area_filter, areaFilterOptions));
setAreaFilter(transformDropdownsValues(urlParams?.area_filter, areaFilterOptions));
setTaskAreaFilter(transformDropdownsValues(urlParams?.task_areas, taskAreasOptions));
setEmploymentFilter(transformDropdownsValues(urlParams?.employment, employmentOptions));
setContinuous(!!urlParams?.continuous);
Expand All @@ -69,7 +69,7 @@ const FormContainer = () => {

event.preventDefault();
setUrlParams({
area_filter: areaFilterSelection?.value,
area_filter: areaFilterSelection.map((selection: OptionType) => selection.value),
employment: employmentSelection.reduce((acc: any, curr: any) => {
const target = curr.additionalValue
? [curr.additionalValue.toString(), curr.value.toString()]
Expand Down Expand Up @@ -222,6 +222,7 @@ const FormContainer = () => {
clearButtonAriaLabel={Drupal.t('Clear @label selection', {'@label': areaFilterLabel}, { context: 'React search clear selection label' })}
className='job-search-form__dropdown'
clearable
multiselect
selectedItemRemoveButtonAriaLabel={Drupal.t(
'Remove item',
{},
Expand Down
12 changes: 7 additions & 5 deletions src/js/react/apps/job-search/containers/SelectionsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import SearchComponents from '../enum/SearchComponents';
import { getLanguageLabel } from '../helpers/Language';
import transformDropdownsValues from '../helpers/Params';
import {
areaFilterAtom,
areaFilterSelectionAtom,
continuousAtom,
employmentAtom,
Expand All @@ -21,7 +22,6 @@ import {
youthSummerJobsAtom,
} from '../store';
import OptionType from '../types/OptionType';
import { getAreaInfo } from '../helpers/Areas';

const SelectionsContainer = () => {
const urlParams = useAtomValue(urlAtom);
Expand All @@ -30,9 +30,11 @@ const SelectionsContainer = () => {
const updateTaskAreas = useSetAtom(taskAreasSelectionAtom);
const employmentOptions = useAtomValue(employmentAtom);
const updateEmploymentOptions = useSetAtom(employmentSelectionAtom);
const updateAreaFilter = useSetAtom(areaFilterSelectionAtom);
const areaFilterOptions = useAtomValue(areaFilterAtom);

const showClearButton =
urlParams?.area_filter ||
urlParams?.area_filter?.length ||
urlParams?.task_areas?.length ||
urlParams?.continuous ||
urlParams?.internship ||
Expand Down Expand Up @@ -68,10 +70,10 @@ const SelectionsContainer = () => {
/>
)}
{urlParams.area_filter && (
<SingleFilter
label={getAreaInfo.find(area => area.key === urlParams.area_filter?.toString())?.label}
atom={areaFilterSelectionAtom}
<ListFilter
updater={updateAreaFilter}
valueKey={SearchComponents.AREA_FILTER}
values={transformDropdownsValues(urlParams.area_filter, areaFilterOptions)}
/>
)}
{urlParams.continuous && (
Expand Down
9 changes: 7 additions & 2 deletions src/js/react/apps/job-search/hooks/useQueryString.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,15 @@ const useQueryString = (urlParams: URLParams): string => {
});
}

if (urlParams.area_filter) {
if (urlParams?.area_filter?.length) {
const postalCodes: string[] = [];
urlParams.area_filter.forEach(areaCode => {
postalCodes.push(...getAreaInfo.find(area => area.key === areaCode)?.postalCodes || []);
});

query.bool.filter.push({
terms: {
[IndexFields.POSTAL_CODE]: getAreaInfo.find(area => area.key === urlParams.area_filter?.toString())?.postalCodes,
[IndexFields.POSTAL_CODE]: postalCodes
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/js/react/apps/job-search/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export const summerJobsAtom = atom<boolean>(false);
export const youthSummerJobsAtom = atom<boolean>(false);

export const resetFormAtom = atom(null, (get, set) => {
set(areaFilterSelectionAtom, null);
set(areaFilterSelectionAtom, []);
set(taskAreasSelectionAtom, []);
set(keywordAtom, '');
set(continuousAtom, false);
Expand All @@ -311,4 +311,4 @@ export const areaFilterAtom = atom(
)
));

export const areaFilterSelectionAtom = atom<OptionType | null>(null);
export const areaFilterSelectionAtom = atom<OptionType[]>([] as OptionType[]);
2 changes: 1 addition & 1 deletion src/js/react/apps/job-search/types/URLParams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type URLParams = {
area_filter?: string;
area_filter?: string[];
continuous?: boolean;
employment?: string[];
internship?: boolean;
Expand Down

0 comments on commit bb86e37

Please sign in to comment.