From 13a555be7208304484b4d994e0b9942b7db7cd8e Mon Sep 17 00:00:00 2001 From: Johann Levesque Date: Fri, 1 Nov 2024 16:35:11 -0400 Subject: [PATCH] =?UTF-8?q?fix(bugs):=20wrong=20basemap=20when=20switch=20?= =?UTF-8?q?proj/lang,=20long=20field=20name=20BC=20WM=E2=80=A6=20(#2575)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(bugs): wrong basemap when switch proj/lang, long field name BC WMS, delete not working when switching action Closes #2571, #2538, #2573 * fix typo --- .../map-event-processor.ts | 2 +- .../data-table/data-table-modal.tsx | 36 ++++++++++--------- .../details/feature-detail-modal.tsx | 7 +++- .../components/details/feature-info-new.tsx | 11 +++++- .../layers/left-panel/delete-undo-button.tsx | 10 ++++++ .../geoview-core/src/core/utils/date-mgt.ts | 3 +- 6 files changed, 48 insertions(+), 21 deletions(-) diff --git a/packages/geoview-core/src/api/event-processors/event-processor-children/map-event-processor.ts b/packages/geoview-core/src/api/event-processors/event-processor-children/map-event-processor.ts index f41ede70bf0..dc81147326a 100644 --- a/packages/geoview-core/src/api/event-processors/event-processor-children/map-event-processor.ts +++ b/packages/geoview-core/src/api/event-processors/event-processor-children/map-event-processor.ts @@ -298,7 +298,7 @@ export class MapEventProcessor extends AbstractEventProcessor { } static getBasemapOptions(mapId: string): TypeBasemapOptions { - return this.getMapStateProtected(mapId).basemapOptions; + return this.getMapStateProtected(mapId).currentBasemapOptions || this.getMapStateProtected(mapId).basemapOptions; } static getCurrentBasemapOptions(mapId: string): TypeBasemapOptions { diff --git a/packages/geoview-core/src/core/components/data-table/data-table-modal.tsx b/packages/geoview-core/src/core/components/data-table/data-table-modal.tsx index 2b44bd40acf..76300b28e0e 100644 --- a/packages/geoview-core/src/core/components/data-table/data-table-modal.tsx +++ b/packages/geoview-core/src/core/components/data-table/data-table-modal.tsx @@ -103,23 +103,25 @@ export default function DataTableModal(): JSX.Element { const columnList = [] as MRTColumnDef[]; entries.forEach(([key, value]) => { - columnList.push({ - id: key, - accessorFn: (row) => { - // check if row is valid react element. - if (isValidElement(row[key])) { - return row[key]; - } - if (typeof row[key]?.value === 'string' || typeof row[key]?.value === 'number') { - return row[key]?.value ?? ''; - } - return ''; - }, - header: value?.alias ?? '', - Cell: ({ cell }) => getCellValue(cell.getValue() as string), - Header: ({ column }) => getTableHeader(column.columnDef.header), - maxSize: 120, - }); + // Do not show internal geoviewID field + if (value?.alias !== 'geoviewID') + columnList.push({ + id: key, + accessorFn: (row) => { + // check if row is valid react element. + if (isValidElement(row[key])) { + return row[key]; + } + if (typeof row[key]?.value === 'string' || typeof row[key]?.value === 'number') { + return row[key]?.value ?? ''; + } + return ''; + }, + header: value?.alias ?? '', + Cell: ({ cell }) => getCellValue(cell.getValue() as string), + Header: ({ column }) => getTableHeader(column.columnDef.header), + maxSize: 120, + }); }); return columnList; diff --git a/packages/geoview-core/src/core/components/details/feature-detail-modal.tsx b/packages/geoview-core/src/core/components/details/feature-detail-modal.tsx index f4d995fcbdc..41735820567 100644 --- a/packages/geoview-core/src/core/components/details/feature-detail-modal.tsx +++ b/packages/geoview-core/src/core/components/details/feature-detail-modal.tsx @@ -40,7 +40,7 @@ export default function FeatureDetailModal(): JSX.Element { const nameFieldValueTmp = feature.fieldInfo[feature.nameField !== null ? feature.nameField : 0]; setNameFieldValue(nameFieldValueTmp !== undefined ? (nameFieldValueTmp.value as string) : ''); - return Object.keys(feature?.fieldInfo ?? {}).map((fieldName) => { + const featureInfo = Object.keys(feature?.fieldInfo ?? {}).map((fieldName) => { return { fieldKey: feature.fieldInfo[fieldName]!.fieldKey, value: feature.fieldInfo[fieldName]!.value, @@ -49,6 +49,11 @@ export default function FeatureDetailModal(): JSX.Element { domain: null, }; }); + + // Remove last item who is the geoviewID + featureInfo.pop(); + + return featureInfo; }, [feature]); return ( diff --git a/packages/geoview-core/src/core/components/details/feature-info-new.tsx b/packages/geoview-core/src/core/components/details/feature-info-new.tsx index 09f699220b3..6e8ddcbbe41 100644 --- a/packages/geoview-core/src/core/components/details/feature-info-new.tsx +++ b/packages/geoview-core/src/core/components/details/feature-info-new.tsx @@ -55,11 +55,20 @@ export function FeatureInfo({ features, currentFeatureIndex }: TypeFeatureInfoPr logger.logTraceUseMemo('DETAILS PANEL - Feature Info new - featureInfoList'); const featureInfo = Object.keys(feature?.fieldInfo ?? {}).map((fieldName) => { + // We have few service WMS from BC where fields name are extremely long and separated by . + // for WMS and WFS we should only keep the last item. If we see this with other type of services, + // we may need to remove the check and apply all the time. + // TODO: should we do this at the root when sourceinfo is define? + const alias = + feature.geoviewLayerType !== 'ogcWms' && feature.geoviewLayerType !== 'ogcWfs' + ? feature.fieldInfo[fieldName]?.alias || fieldName + : (feature.fieldInfo[fieldName]?.alias || fieldName).split('.').pop() || ''; + return { fieldKey: feature.fieldInfo[fieldName]!.fieldKey, value: feature.fieldInfo[fieldName]!.value, dataType: feature.fieldInfo[fieldName]!.dataType, - alias: feature.fieldInfo[fieldName]!.alias ? feature.fieldInfo[fieldName]!.alias : fieldName, + alias, domain: null, }; }); diff --git a/packages/geoview-core/src/core/components/layers/left-panel/delete-undo-button.tsx b/packages/geoview-core/src/core/components/layers/left-panel/delete-undo-button.tsx index a8bdd56ef0b..50d22fc9b2d 100644 --- a/packages/geoview-core/src/core/components/layers/left-panel/delete-undo-button.tsx +++ b/packages/geoview-core/src/core/components/layers/left-panel/delete-undo-button.tsx @@ -86,6 +86,16 @@ export function DeleteUndoButton(props: DeleteUndoButtonProps): JSX.Element { } }; + // Make sure there is no pending state on unmount. If not, it can stay in progress forever... + // If user switch panel when action is in progress + useEffect(() => { + return () => { + setInUndoState(false); + setLayerDeleteInProgress(false); + }; + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + useEffect(() => { if (progress === 100) { deleteLayer(layer.layerPath); diff --git a/packages/geoview-core/src/core/utils/date-mgt.ts b/packages/geoview-core/src/core/utils/date-mgt.ts index 8c79552e29c..8f6355fcdd7 100644 --- a/packages/geoview-core/src/core/utils/date-mgt.ts +++ b/packages/geoview-core/src/core/utils/date-mgt.ts @@ -718,7 +718,8 @@ export abstract class DateMgt { * @returns {string} The date format. */ static deduceDateFormat(dateString: string): string { - let dateFormat = dateString !== null ? dateString.toUpperCase().replaceAll('/', '-').replaceAll(' ', 'T') : 'YYYY-MM-DD'; + let dateFormat = + dateString !== null && dateString !== undefined ? dateString.toUpperCase().replaceAll('/', '-').replaceAll(' ', 'T') : 'YYYY-MM-DD'; dateFormat = dateFormat .replace(/\d{4}/, 'YYYY') .replace(/^\d{1,2}(?=-\d{1,2}-YYYY)|((?<=^YYYY-\d-)|(?<=^YYYY-\d\d-))\d{1,2}/, 'DD')