Skip to content

Commit

Permalink
feat: client-side filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
pjsier committed Sep 7, 2024
1 parent 788be4b commit d15db62
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
10 changes: 6 additions & 4 deletions client/src/components/Map/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import { createNewViewport } from "../../utils/map"
import {
capitalizeFirstLetter,
parseMBAddressString,
createLayerFilter,
createFilterFromParams,
createQueryStringFromParams,
} from "../../utils/helper"
import queryString from "query-string"
import { URLParamsToAPIQueryString } from "../../utils/parseURL"
import {
getMapStateAction,
Expand Down Expand Up @@ -318,8 +319,9 @@ class PraxisMap extends Component {
const { sliderValue, filter } = this.props.controller

Check failure on line 319 in client/src/components/Map/Map.jsx

View workflow job for this annotation

GitHub Actions / client

'filter' is assigned a value but never used
const { searchYear } = this.props.searchState.searchParams
const { lat, lng, bearing } = this.props.searchState.viewerCoords
const parcelLayerFilter = createLayerFilter(filter)
// TODO: replace parcelLayerFilter with something
const parcelLayerFilter = createFilterFromParams(
queryString.parse(window.location.search)
)

return (
<div className="map">
Expand Down Expand Up @@ -412,7 +414,7 @@ class PraxisMap extends Component {
<Layer
key="highlight-parcel-layer"
{...parcelHighlightLayer}
filter={["in", "id", ...highlightIds]} // hightlight can be an array or string
filter={["in", "id", ...(highlightIds || [])]} // hightlight can be an array or string
/>
</Source>

Expand Down
34 changes: 8 additions & 26 deletions client/src/components/Search/DetailedSearchResults.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function useSpeculationByCode(results, { code, year }) {
return { data, topCount, topPer }
}

function useCodesBySpeculator(results, { code, ownid, year }) {
function useCodesBySpeculator({ code, ownid, year }) {
const [speculatorData, setSpeculatorData] = useState(null)
const [propCount, setPropCount] = useState(null)
const [zipsBySpeculator, setZipsBySpeculator] = useState(null)
Expand All @@ -95,21 +95,6 @@ function useCodesBySpeculator(results, { code, ownid, year }) {
if (code) {
const route = `/api/detailed-search?type=codes-by-speculator&ownid=${ownid}&year=${year}`
const data = await APISearchQueryFromRoute(route)

//get feature ids based on speculator name
await data.map((item) => {
const ids = results
.map((record) => {
if (record.properties.propzip === item.propzip) {
return record.properties.prop_id
} else {
return null
}
})
.filter((id) => id !== null)
item.featureIds = ids
})

setSpeculatorData(data)

const { propCount, speculatorZips } = calulateSpeculatorTotals(data)
Expand Down Expand Up @@ -436,14 +421,11 @@ function SpeculatorParcels(props) {
)
const code = results[0].properties.propzip // need some error handling

const { speculatorData, propCount, zipsBySpeculator } = useCodesBySpeculator(
results,
{
code,
ownid,
year,
}
)
const { speculatorData, propCount, zipsBySpeculator } = useCodesBySpeculator({
code,
ownid,
year,
})

if (speculatorData && zipsBySpeculator) {
return (
Expand Down Expand Up @@ -746,7 +728,7 @@ function CodeSpeculatorParcels(props) {
const { drawerIsOpen, results } = useSelector(
(state) => state.searchState.detailedSearch
)
const { speculatorData, zipsBySpeculator } = useCodesBySpeculator(results, {
const { speculatorData, zipsBySpeculator } = useCodesBySpeculator({
code,
ownid,
year,
Expand Down Expand Up @@ -829,7 +811,7 @@ function SpeculatorCodeParcels(props) {
const { drawerIsOpen, results } = useSelector(
(state) => state.searchState.detailedSearch
)
const { speculatorData, zipsBySpeculator } = useCodesBySpeculator(results, {
const { speculatorData, zipsBySpeculator } = useCodesBySpeculator({
code,
ownid,
year,
Expand Down
16 changes: 16 additions & 0 deletions client/src/utils/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ export function parseMBAddressString(addressString) {
return strAddress[0].trim()
}

export function createFilterFromParams(params) {
let layerFilter = []

if (params.ownid) {
layerFilter = [...layerFilter, ["==", "own_id", params.ownid.toUpperCase()]]
}
if (params.code) {
layerFilter = [...layerFilter, ["==", "zipcode_sj", params.code]]
}
if (layerFilter.length > 0) {
return ["all", ...layerFilter]
} else {
return ["none"]
}
}

export function createLayerFilter(arr) {
let layerFilter = []

Expand Down
4 changes: 2 additions & 2 deletions server/routes/geojsonSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ router.get("/", async (req, res) => {
}))
.filter(
({ properties: { propno } }) =>
!place || +place.split(" ")[0] === propno // TODO: Is this good enough?
!!place || +place.split(" ")[0] === propno
)
let nearbyAddresses = []

Expand All @@ -61,7 +61,6 @@ router.get("/", async (req, res) => {
).data
}

// TODO: Change how this is displayed, pull single parcel on client?
if (targetAddress.length === 0 && nearbyAddresses.length === 0) {
// this is a default empty geojson
// where there is no features returned
Expand Down Expand Up @@ -96,6 +95,7 @@ router.get("/", async (req, res) => {
pgData = await queries.queryPGDB({
ownid,
year,
// TODO: Check
PGDBQueryType: queries.GEOJSON_PARCELS_OWNID,
})

Expand Down

0 comments on commit d15db62

Please sign in to comment.