-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add a switch in the map table filters to hide filtered records on the map #331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,13 +16,15 @@ export function DataSourceMarkers({ | |
| dataSourceMarkers, | ||
| isMembers, | ||
| mapConfig, | ||
| hideFilteredMarkers = false, | ||
| }: { | ||
| dataSourceMarkers: { dataSourceId: string; markers: MarkerFeature[] }; | ||
| isMembers: boolean; | ||
| mapConfig: { | ||
| markerDisplayModes?: Record<string, MarkerDisplayMode>; | ||
| markerColors?: Record<string, string>; | ||
| }; | ||
| hideFilteredMarkers?: boolean; | ||
| }) { | ||
| const { filteredRecords, publicFilters } = useContext( | ||
| PublicFiltersContext, | ||
|
|
@@ -40,27 +42,44 @@ export function DataSourceMarkers({ | |
| MarkerDisplayMode.Clusters; | ||
|
|
||
| const safeMarkers = useMemo<FeatureCollection>(() => { | ||
| if (Object.keys(publicFilters).length === 0) { | ||
| const hasClientFilters = Object.keys(publicFilters).length > 0; | ||
|
|
||
| let features = dataSourceMarkers.markers; | ||
|
|
||
| // When hideFilteredMarkers is true, remove server-side unmatched markers | ||
| if (hideFilteredMarkers) { | ||
| features = features.filter((f) => f.properties.matched !== false); | ||
| } | ||
|
|
||
| if (!hasClientFilters) { | ||
| return { | ||
| type: "FeatureCollection", | ||
| features: dataSourceMarkers.markers, | ||
| features, | ||
| }; | ||
| } | ||
|
|
||
| const recordIds = (filteredRecords || []) | ||
| .map((r: { id: string | number }) => r.id) | ||
| .filter(Boolean); | ||
|
|
||
| const mappedFeatures = features.map((f) => ({ | ||
| ...f, | ||
| properties: { | ||
| ...f.properties, | ||
| [MARKER_CLIENT_EXCLUDED_KEY]: !recordIds.includes(f.properties.id), | ||
| }, | ||
| })); | ||
|
|
||
| return { | ||
| type: "FeatureCollection", | ||
| features: dataSourceMarkers.markers.map((f) => ({ | ||
| ...f, | ||
| properties: { | ||
| ...f.properties, | ||
| [MARKER_CLIENT_EXCLUDED_KEY]: !recordIds.includes(f.properties.id), | ||
| }, | ||
| })), | ||
| features: mappedFeatures, | ||
| }; | ||
|
Comment on lines
+65
to
76
|
||
| }, [dataSourceMarkers.markers, filteredRecords, publicFilters]); | ||
| }, [ | ||
| dataSourceMarkers.markers, | ||
| filteredRecords, | ||
| publicFilters, | ||
| hideFilteredMarkers, | ||
| ]); | ||
|
|
||
| const sourceId = `${dataSourceMarkers.dataSourceId}-markers`; | ||
| const publicMapColor = | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,7 @@ export default function Markers() { | |
| dataSourceMarkers={memberMarkers} | ||
| isMembers | ||
| mapConfig={mapConfig} | ||
| hideFilteredMarkers={viewConfig.hideFilteredMarkers} | ||
|
||
| /> | ||
| )} | ||
| {otherMarkers.map((markers) => { | ||
|
|
@@ -52,6 +53,7 @@ export default function Markers() { | |
| dataSourceMarkers={markers} | ||
| isMembers={false} | ||
| mapConfig={mapConfig} | ||
| hideFilteredMarkers={viewConfig.hideFilteredMarkers} | ||
|
||
| /> | ||
| ); | ||
| })} | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,7 @@ import { ListFilter, XIcon } from "lucide-react"; | |||||
| import { useCallback, useEffect, useMemo, useRef, useState } from "react"; | ||||||
| import { useDataSources } from "@/app/map/[id]/hooks/useDataSources"; | ||||||
| import { useMapConfig } from "@/app/map/[id]/hooks/useMapConfig"; | ||||||
| import { useMapViews } from "@/app/map/[id]/hooks/useMapViews"; | ||||||
| import { usePlacedMarkersQuery } from "@/app/map/[id]/hooks/usePlacedMarkers"; | ||||||
| import { useTable } from "@/app/map/[id]/hooks/useTable"; | ||||||
| import { useTurfsQuery } from "@/app/map/[id]/hooks/useTurfsQuery"; | ||||||
|
|
@@ -19,6 +20,8 @@ import { | |||||
| CommandList, | ||||||
| } from "@/shadcn/ui/command"; | ||||||
| import { Input } from "@/shadcn/ui/input"; | ||||||
| import { Label } from "@/shadcn/ui/label"; | ||||||
| import { Switch } from "@/shadcn/ui/switch"; | ||||||
| import { Toggle } from "@/shadcn/ui/toggle"; | ||||||
| import { buildName } from "@/utils/dataRecord"; | ||||||
| import { mapColors } from "../../styles"; | ||||||
|
|
@@ -52,6 +55,7 @@ export default function MapTableFilter({ | |||||
|
|
||||||
| function MultiFilter({ filter, setFilter: _setFilter }: TableFilterProps) { | ||||||
| const { mapConfig } = useMapConfig(); | ||||||
| const { viewConfig, updateViewConfig } = useMapViews(); | ||||||
| const { data: turfs = [] } = useTurfsQuery(); | ||||||
| const { data: placedMarkers = [] } = usePlacedMarkersQuery(); | ||||||
| const { getDataSourceById } = useDataSources(); | ||||||
|
|
@@ -215,6 +219,25 @@ function MultiFilter({ filter, setFilter: _setFilter }: TableFilterProps) { | |||||
| onOperatorChange={updateOperator} | ||||||
| /> | ||||||
| ) : null} | ||||||
|
|
||||||
| {/* Show filtered markers toggle */} | ||||||
| {children.length > 0 ? ( | ||||||
| <div className="flex items-center gap-1.5"> | ||||||
| <Switch | ||||||
| id="hide-filtered-markers" | ||||||
| checked={Boolean(viewConfig.hideFilteredMarkers)} | ||||||
| onCheckedChange={(checked) => | ||||||
| updateViewConfig({ hideFilteredMarkers: checked }) | ||||||
| } | ||||||
| /> | ||||||
| <Label | ||||||
| htmlFor="hide-filtered-markers" | ||||||
| className="text-xs text-muted-foreground whitespace-nowrap cursor-pointer" | ||||||
| > | ||||||
| Remove filtered from map | ||||||
|
||||||
| Remove filtered from map | |
| Hide filtered records from map |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The filter condition
f.properties.matched !== falsewill keep markers wherematchedistrue,undefined, ornull. However, when hiding filtered markers, you likely want to only show markers that explicitly match the filter (i.e.,matched === true). Consider changing this tof.properties.matched === trueto be more precise, unless there's a specific reason to keep markers with undefined/null matched values.