Skip to content

Commit

Permalink
Merge pull request #2059 from Signalen/feature/pdok-municipality-filter
Browse files Browse the repository at this point in the history
Allow a negative term for municipality
  • Loading branch information
Jan Jaap van Deursen authored Mar 7, 2022
2 parents bddf57f + 1d4ca8e commit 8ed1242
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app.amsterdam.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"smallHeight": "29px"
},
"map": {
"municipality": ["amsterdam", "ouder-amstel"],
"municipality": "amsterdam \"ouder-amstel\"",
"options": {
"center": [
52.3731081,
Expand Down
1 change: 1 addition & 0 deletions internals/schemas/app.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@
"additionalProperties": false,
"properties": {
"municipality": {
"description": "Allows to filter address lookup by municipality. For example a value of 'amsterdam' will be used in the following format: `fq=gemeentenaam:(amsterdam)`. Separate multiple municipalities with a space. If a municipality has spaces, surround it by quotes, which in the config will look like `\"boxtel \\\"den bosch\\\"\"`. For more information see https://www.pdok.nl/restful-api/-/article/pdok-locatieserver#/paths/~1suggest/get",
"type": [
"string",
"array"
Expand Down
28 changes: 24 additions & 4 deletions src/components/PDOKAutoSuggest/PDOKAutoSuggest.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,35 @@ describe('components/PDOKAutoSuggest', () => {
it('should call fetch with municipality', async () => {
await renderAndSearch('Dam', { municipality: 'amsterdam' })
expect(fetch).toHaveBeenCalledWith(
expect.stringContaining(`${municipalityQs}("amsterdam")`),
expect.stringContaining(`${municipalityQs}(amsterdam)`),
expect.objectContaining({ method: 'GET' })
)
})

it('should work with an array for municipality', async () => {
await renderAndSearch('Dam', { municipality: ['utrecht', 'amsterdam'] })
it('should work with multiple municipalities', async () => {
await renderAndSearch('Dam', { municipality: 'utrecht amsterdam' })
expect(fetch).toHaveBeenCalledWith(
expect.stringContaining(`${municipalityQs}("utrecht" "amsterdam")`),
expect.stringContaining(`${municipalityQs}(utrecht amsterdam)`),
expect.objectContaining({ method: 'GET' })
)
})

it('should work with quotes and negations', async () => {
await renderAndSearch('Dam', {
municipality: '"den bosch" -amsterdam',
})
expect(fetch).toHaveBeenCalledWith(
expect.stringContaining(`${municipalityQs}("den bosch" -amsterdam)`),
expect.objectContaining({ method: 'GET' })
)
})

it('should ignore an empty string', async () => {
await renderAndSearch('Dam', {
municipality: '',
})
expect(fetch).toHaveBeenCalledWith(
expect.not.stringContaining(municipalityQs),
expect.objectContaining({ method: 'GET' })
)
})
Expand Down
8 changes: 1 addition & 7 deletions src/components/PDOKAutoSuggest/PDOKAutoSuggest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,8 @@ const PDOKAutoSuggest: FC<PDOKAutoSuggestProps> = ({
municipality = configuration.map.municipality,
...rest
}) => {
const municipalityArray = Array.isArray(municipality)
? municipality
: [municipality].filter(Boolean)
const municipalityString = municipalityArray
.map((item) => `"${item}"`)
.join(' ')
const fq = municipality
? [['fq', `${municipalityFilterName}:(${municipalityString})`]]
? [['fq', `${municipalityFilterName}:(${municipality})`]]
: []
// ['fl', '*'], // undocumented; requests all available field values from the API
const fl = [
Expand Down

0 comments on commit 8ed1242

Please sign in to comment.