Skip to content

Commit

Permalink
[Tech] don't create all features
Browse files Browse the repository at this point in the history
  • Loading branch information
claire2212 committed Nov 12, 2024
1 parent cead17b commit 948bf5d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
15 changes: 12 additions & 3 deletions frontend/src/features/layersSelector/search/ResultsList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,30 @@ export function ResultList({ searchedText }: ResultListProps) {
groupBy(regulatoryLayersSearchResult ?? regulatoryLayers?.ids, r => regulatoryLayers?.entities[r]?.layer_name),
[regulatoryLayersSearchResult, regulatoryLayers]
)
const totalRegulatoryAreas = regulatoryLayersSearchResult?.length ?? regulatoryLayers?.ids?.length ?? 0
const totalRegulatoryAreas = useMemo(
() => regulatoryLayersSearchResult?.length ?? regulatoryLayers?.ids?.length ?? 0,
[regulatoryLayersSearchResult?.length, regulatoryLayers?.ids?.length]
)

const { data: amps } = useGetAMPsQuery()
const ampResulstsByAMPName = useMemo(
() => groupBy(ampsSearchResult ?? amps?.ids, a => amps?.entities[a]?.name),
[ampsSearchResult, amps]
)
const totalAmps = ampsSearchResult?.length ?? amps?.ids?.length ?? 0
const totalAmps = useMemo(
() => ampsSearchResult?.length ?? amps?.ids?.length ?? 0,
[ampsSearchResult?.length, amps?.ids?.length]
)

const { vigilanceAreas } = useGetFilteredVigilanceAreasQuery()
const vigilanceAreasIds = useMemo(
() => vigilanceAreaSearchResult ?? vigilanceAreas?.ids,
[vigilanceAreaSearchResult, vigilanceAreas]
)
const totalVigilanceAreas = vigilanceAreaSearchResult?.length ?? vigilanceAreas?.ids.length ?? 0
const totalVigilanceAreas = useMemo(
() => vigilanceAreaSearchResult?.length ?? vigilanceAreas?.ids.length ?? 0,
[vigilanceAreaSearchResult?.length, vigilanceAreas?.ids?.length]
)

const toggleRegulatory = () => {
if (!isRegulatorySearchResultsVisible) {
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/features/map/layers/AMP/AMPPreviewLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export function AMPPreviewLayer({ map }: BaseMapChildrenProps) {
const ampLayersFeatures = useMemo(() => {
let ampFeatures: Feature[] = []

if ((ampsSearchResult || ampLayers?.entities) && isLayerVisible) {
const ampsToDisplay = ampsSearchResult ?? ampLayers?.ids ?? []
if (ampsSearchResult) {
const ampsToDisplay = ampsSearchResult ?? []

ampFeatures = ampsToDisplay.reduce((amplayers, id) => {
if (showedAmpLayerIds.includes(id)) {
Expand All @@ -67,7 +67,7 @@ export function AMPPreviewLayer({ map }: BaseMapChildrenProps) {
}

return ampFeatures
}, [ampLayers?.entities, ampLayers?.ids, ampMetadataLayerId, ampsSearchResult, showedAmpLayerIds, isLayerVisible])
}, [ampLayers?.entities, ampMetadataLayerId, ampsSearchResult, showedAmpLayerIds])

useEffect(() => {
ampPreviewVectorSourceRef.current?.clear(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export function RegulatoryPreviewLayer({ map }: BaseMapChildrenProps) {

const regulatoryLayersFeatures = useMemo(() => {
let regulatoryFeatures: Feature[] = []
if ((regulatoryLayersSearchResult || regulatoryLayers?.ids) && isLayerVisible) {
const regulatoryAreasToDisplay = regulatoryLayersSearchResult ?? regulatoryLayers?.ids ?? []
if (regulatoryLayersSearchResult) {
const regulatoryAreasToDisplay = regulatoryLayersSearchResult ?? []
regulatoryFeatures = regulatoryAreasToDisplay?.reduce((regulatorylayers, id) => {
const layer = regulatoryLayers?.entities[id]

Expand All @@ -63,7 +63,7 @@ export function RegulatoryPreviewLayer({ map }: BaseMapChildrenProps) {
}

return regulatoryFeatures
}, [regulatoryLayers, regulatoryMetadataLayerId, regulatoryLayersSearchResult, isLayerVisible])
}, [regulatoryLayers, regulatoryMetadataLayerId, regulatoryLayersSearchResult])

useEffect(() => {
regulatoryPreviewVectorSourceRef.current?.clear(true)
Expand Down

0 comments on commit 948bf5d

Please sign in to comment.