• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

liqd / adhocracy4 / 17695931325

13 Sep 2025 11:31AM UTC coverage: 75.635% (-0.2%) from 75.856%
17695931325

push

github

web-flow
[ST620] apps/maps: Make adjustments for new address api (#1815)

273 of 888 branches covered (30.74%)

Branch coverage included in aggregate %.

3 of 23 new or added lines in 2 files covered. (13.04%)

1 existing line in 1 file now uncovered.

6134 of 7583 relevant lines covered (80.89%)

1.25 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/adhocracy4/maps_react/static/a4maps_react/AddressSearch.jsx
1
import React, { useEffect, useState } from 'react'
2
import django from 'django'
3

4
import useDebounce from '../../../static/useDebounce'
5
import { AutoComplete } from '../../../static/forms/AutoComplete'
6

7
const addressSearchCapStr = django.gettext('Address Search')
×
8

9
function fetchSuggestions (address, apiUrl) {
NEW
10
  return fetch(apiUrl + '?search=' + address)
×
11
    .then((response) => response.json())
×
12
}
13

14
export function getSearchResultText (feature) {
15
  const {
16
    strasse = '',
×
17
    haus = '',
×
18
    plz = '',
×
19
    ortsteil = ''
×
NEW
20
  } = feature?.properties || {}
×
21

22
  // eslint-disable-next-line no-restricted-syntax
NEW
23
  return `${strasse} ${haus} in ${plz} ${ortsteil}`.trim()
×
24
}
25

26
const AddressSearch = ({
×
27
  onSelectAddress,
28
  onChangeInput,
29
  apiUrl
30
}) => {
NEW
31
  const [suggestions, setSuggestions] = useState([])
×
NEW
32
  const [rawFeatures, setRawFeatures] = useState([])
×
UNCOV
33
  const [searchString, setSearchString] = useState('')
×
34

35
  const debouncedOnChange = useDebounce(async () => {
×
NEW
36
    if (!searchString.trim()) {
×
NEW
37
      setSuggestions([])
×
NEW
38
      setRawFeatures([])
×
NEW
39
      return
×
40
    }
41

NEW
42
    const data = await fetchSuggestions(searchString, apiUrl)
×
NEW
43
    const features = data.results?.features || []
×
NEW
44
    setRawFeatures(features)
×
45

NEW
46
    const newSuggestions = features.map((feature, index) => ({
×
47
      name: getSearchResultText(feature),
48
      value: index.toString()
49
    }))
NEW
50
    setSuggestions(newSuggestions)
×
51
  })
52

53
  useEffect(() => {
×
54
    debouncedOnChange()
×
55
  }, [searchString, debouncedOnChange])
56

57
  return (
×
58
    <div className="a4-address-search">
59
      <div className="a4-address-search__search-form">
60
        <div className="form-group">
61
          <AutoComplete
62
            choices={suggestions}
63
            // filtering is happening on the server
64
            filterFn={() => true}
×
65
            hideLabel
66
            label={addressSearchCapStr}
67
            placeholder={addressSearchCapStr}
68
            onChangeInput={(val) => {
69
              setSearchString(val)
×
70
              onChangeInput?.(val)
×
71
            }}
72
            onChange={(val) => {
NEW
73
              if (val.length > 0 && rawFeatures.length > 0) {
×
NEW
74
                const selectedIndex = parseInt(val[0])
×
NEW
75
                const selectedAddress = rawFeatures[selectedIndex]
×
NEW
76
                const newSearchString = getSearchResultText(selectedAddress)
×
NEW
77
                setSearchString(newSearchString)
×
NEW
78
                onSelectAddress(selectedAddress)
×
79
              }
80
            }}
81
            inputValue={searchString}
82
            before={
83
              <i className="fa fa-search" aria-hidden="true" />
84
            }
85
          />
86
        </div>
87
      </div>
88
    </div>
89
  )
90
}
91

92
export default AddressSearch
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc