Skip to content

Commit

Permalink
place and pickup location filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
jlarsson committed Feb 19, 2025
1 parent 721dbd1 commit e1b9abc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export const SelectPickupLocation: FC<{
<FormControl fullWidth key="resolved">
<InputLabel id={labelId}>{label}</InputLabel>
<Select
multiple
labelId={labelId}
value={
filter.workflow?.pickupLocationTrackingNames || []
Expand All @@ -46,6 +45,9 @@ export const SelectPickupLocation: FC<{
})
}
>
<MenuItem value="">
{phrase('VALUE_EMPTY', '(inget värde)')}
</MenuItem>
{locations.map((l) => (
<MenuItem value={l.trackingName}>
{l.trackingName}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export const SelectPlace: FC<{
<FormControl fullWidth key="resolved">
<InputLabel id={labelId}>{label}</InputLabel>
<Select
multiple
labelId={labelId}
value={filter.workflow?.places || []}
label={label}
Expand All @@ -42,6 +41,9 @@ export const SelectPlace: FC<{
})
}
>
<MenuItem value="">
{phrase('VALUE_EMPTY', '(inget värde)')}
</MenuItem>
{places.map((p) => (
<MenuItem value={p}>{p}</MenuItem>
))}
Expand Down
1 change: 1 addition & 0 deletions src/phrases/defaults/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export default {
ACTION_CLOSE: 'Stäng',
ACTION_UPDATE: 'Uppdatera',
VALUE_CLEAR: '(rensa värde)',
VALUE_EMPTY: '(inget värde)',
}
42 changes: 24 additions & 18 deletions src/url-params/url-params-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,29 @@ const createUrlParamsContext = (
): boolean | undefined =>
// eslint-disable-next-line no-nested-ternary
params[name] === '1' ? true : params[name] === '0' ? false : d
const parseStringArray = (name: string): string[] | undefined =>
params[name]
?.split(',')
.map((s) => s.trim())
.map((s) => decodeURIComponent(s))
.filter((v) => v)

const search = params.s || ''
const categories = (params.c || '')
.split(',')
.map((s) => s.trim())
.map((s) => decodeURIComponent(s))
.filter((v) => v)
const tags = (params.tags || '')
.split(',')
.map((s) => s.trim())
.map((s) => decodeURIComponent(s))
.filter((v) => v)
const size = (params.size || '')
.split(',')
.map((s) => s.trim())
.map((s) => decodeURIComponent(s))
.filter((v) => v)
const categories = parseStringArray('c')
const tags = parseStringArray('tags')
const size = parseStringArray('size')
const sorting = params.sf || ''
const places = parseStringArray('places')
const pickupLocationTrackingNames = parseStringArray('pltn')
const page = parseInt(params.p, 10) || 0
return {
...filter,
search,
fields: {
...filter.fields,
category: categories.length ? { in: categories } : undefined,
tags: tags.length ? { in: tags } : undefined,
size: size.length ? { in: size } : undefined,
category: categories ? { in: categories } : undefined,
tags: tags ? { in: tags } : undefined,
size: size ? { in: size } : undefined,
},
sorting:
sortableFields.find((sf) => sf.key === sorting)?.sorting ||
Expand Down Expand Up @@ -72,6 +69,11 @@ const createUrlParamsContext = (
),
},
paging: { pageSize: 25, ...filter.paging, pageIndex: page },
workflow: {
...filter.workflow,
pickupLocationTrackingNames,
places,
},
}
},
updateUrlFromAdvertFilterInput: (prefix, filter, { sortableFields }) => {
Expand All @@ -94,6 +96,10 @@ const createUrlParamsContext = (
collects: mapRestriction(filter.restrictions?.hasCollects),
reservations: mapRestriction(filter.restrictions?.hasReservations),
reserveable: mapRestriction(filter.restrictions?.canBeReserved),
places: encode(filter.workflow?.places)?.join(','),
pltn: encode(filter.workflow?.pickupLocationTrackingNames)?.join(
','
),
})
},
makeAdvertSubscriptionUrl: (basePath, filter) =>
Expand Down

0 comments on commit e1b9abc

Please sign in to comment.