Skip to content

Commit

Permalink
fix some condition on panel
Browse files Browse the repository at this point in the history
  • Loading branch information
jolevesq authored and jolevesq committed Dec 12, 2024
1 parent 12ed628 commit 79facef
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { UIEventProcessor } from './ui-event-processor';
import { TypeMapFeaturesConfig } from '@/core/types/global-types';
import { TypeClickMarker } from '@/core/components';
import { IMapState, TypeOrderedLayerInfo, TypeScaleInfo } from '@/core/stores/store-interface-and-intial-values/map-state';
import { TypeFeatureInfoResultSet, TypeHoverFeatureInfo } from '@/core/stores/store-interface-and-intial-values/feature-info-state';
import { TypeHoverFeatureInfo } from '@/core/stores/store-interface-and-intial-values/feature-info-state';
import { TypeBasemapProps } from '@/geo/layer/basemap/basemap-types';
import { LegendEventProcessor } from './legend-event-processor';
import { TypeLegendLayer } from '@/core/components/layers/types';
Expand Down Expand Up @@ -109,6 +109,20 @@ export class MapEventProcessor extends AbstractEventProcessor {
(removedFeatures[i].geometry as TypeGeometry).ol_uid
);
}
},
{
equalityFn: (prev, curr) => {
// Quick length checks first (prevents re-render) and calls to to removeHighlight
if (prev === curr) return true;
if (prev.length !== curr.length) return false;
if (prev.length === 0) return true;

// Use Set for O(1) lookup instead of array operations
const prevUids = new Set(prev.map((feature) => (feature.geometry as TypeGeometry).ol_uid));

// Single pass through current features
return curr.every((feature) => prevUids.has((feature.geometry as TypeGeometry).ol_uid));
},
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ export const Crosshair = memo(function Crosshair({ mapTargetElement }: Crosshair
logger.logTraceUseCallback('CROSSHAIR - simulateClick', pointerPosition);
if (event.key === 'Enter' && pointerPosition) {
// Update the store
setClickCoordinates(pointerPosition).catch((error) => {
// Log
logger.logPromiseFailed('Failed to setClickCoordinates in crosshair.simulateClick', error);
});
setClickCoordinates(pointerPosition);
}
},
[pointerPosition, setClickCoordinates]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,12 @@ export function DetailsPanel({ fullWidth = false }: DetailsPanelType): JSX.Eleme
* NOTE: Here we return null, so that in responsive grid layout, it can be used as flag to render the guide for details.
* @returns {JSX.Element | null} JSX.Element | null
*/
logger.logMarkerStart('DETAILS-MARKER');
const renderContent = (): JSX.Element | null => {
if (!memoIsAllLayersQueryStatusProcessed()) {
// If there is no layer, return null for the guide to show
if (memoLayersList && memoLayersList.length === 0) return null;

// Until process, return skeleton
if (!memoIsAllLayersQueryStatusProcessed() || !(memoSelectedLayerDataFeatures && memoSelectedLayerDataFeatures.length > 0)) {
return <DetailsSkeleton />;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const FeatureItem = memo(function FeatureItem({

return (
<Box key={generateId()} sx={sxClasses.featureInfoItemValue}>
<HtmlToReact htmlContent={sanitizeHtmlContent(linkifyHtml(stringify(item) as string, linkifyOptions))} />
<HtmlToReact htmlContent={sanitizeHtmlContent(linkifyHtml(item.toString(), linkifyOptions))} />
</Box>
);
});
Expand All @@ -97,18 +97,15 @@ export const FeatureRow = memo(function FeatureRow({ featureInfoItem, index, onI
const { alias, value } = featureInfoItem;

// Convert value to string, handling arrays and other types
const stringValue = useMemo((): string => {
const stringValue = useMemo((): string[] => {
if (Array.isArray(value)) {
return value.map((item) => stringify(item)).join(';');
return [value.map((item) => stringify(item)).join(';')] as string[];
}
return stringify(value) as string;
return [stringify(value)] as string[];
}, [value]);

// Split text but leave html intact
const valueArray = alias !== 'html' ? stringValue.split(';') : [stringValue];

// Generate stable IDs for each item when component mounts
const itemIds = useMemo(() => valueArray.map(() => generateId()), [valueArray]);
const itemIds = useMemo(() => stringValue.map(() => generateId()), [stringValue]);

return (
<Grid
Expand Down Expand Up @@ -141,7 +138,7 @@ export const FeatureRow = memo(function FeatureRow({ featureInfoItem, index, onI
flexGrow: 1,
}}
>
{valueArray.map((item: string, idx: number) => (
{stringValue.map((item: string, idx: number) => (
<FeatureItem
key={`${alias}_${itemIds[idx]}`}
item={item}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { MapEventProcessor } from '@/api/event-processors/event-processor-childr
import { TypeClickMarker } from '@/core/components/click-marker/click-marker';
import { TypeFeatureInfoEntry } from '@/geo/map/map-schema-types';
import { TypePointMarker } from '@/api/config/types/map-schema-types';
import { TypeFeatureInfoResultSet, TypeHoverFeatureInfo } from './feature-info-state';
import { TypeHoverFeatureInfo } from './feature-info-state';
import { CV_MAP_CENTER } from '@/api/config/types/config-constants';

// GV Important: See notes in header of MapEventProcessor file for information on the paradigm to apply when working with MapEventProcessor vs MapState
Expand Down Expand Up @@ -84,7 +84,7 @@ export interface IMapState {
zoomToGeoLocatorLocation: (coords: [number, number], bbox?: [number, number, number, number]) => Promise<void>;
zoomToMyLocation: (position: GeolocationPosition) => Promise<void>;
transformPoints: (coords: Coordinate[], outputProjection: number) => Coordinate[];
setClickCoordinates: (pointerPosition: TypeMapMouseInfo) => Promise<TypeFeatureInfoResultSet>;
setClickCoordinates: (pointerPosition: TypeMapMouseInfo) => void;
setCurrentBasemapOptions: (basemapOptions: TypeBasemapOptions) => void;
setFixNorth: (ifFix: boolean) => void;
setOverlayClickMarkerRef: (htmlRef: HTMLElement) => void;
Expand Down Expand Up @@ -459,7 +459,7 @@ export function initializeMapState(set: TypeSetStore, get: TypeGetStore): IMapSt
* @param {TypeMapMouseInfo} pointerPosition - The pointer position.
* @returns {Promise<TypeFeatureInfoResultSet>}
*/
setClickCoordinates: (pointerPosition: TypeMapMouseInfo): Promise<TypeFeatureInfoResultSet> => {
setClickCoordinates: (pointerPosition: TypeMapMouseInfo): void => {
// Redirect to processor
return MapEventProcessor.setClickCoordinates(get().mapId, pointerPosition);
},
Expand Down
8 changes: 4 additions & 4 deletions packages/geoview-core/src/geo/map/map-viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ export class MapViewer {
});
}
}
}, 250);
}, 1000);
}

/**
Expand Down Expand Up @@ -692,7 +692,7 @@ export class MapViewer {
this.#checkMapLayersLoaded();
}
}
}, 250);
}, 1000);
}

/**
Expand Down Expand Up @@ -726,7 +726,7 @@ export class MapViewer {
this.#emitMapLayersLoaded();
}
}
}, 250);
}, 1000);
}

/**
Expand Down Expand Up @@ -761,7 +761,7 @@ export class MapViewer {
resolve();
}
}
}, 250);
}, 1000);
});
}

Expand Down

0 comments on commit 79facef

Please sign in to comment.