From 10750cf1b0d2dc032977c0e7d341f324c5959424 Mon Sep 17 00:00:00 2001 From: Tom Caiger Date: Mon, 4 Dec 2023 13:18:00 +1300 Subject: [PATCH 1/7] Update useMapOverlayMapData.ts (#5232) --- .../Map/utils/useMapOverlayMapData.ts | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/packages/tupaia-web/src/features/Map/utils/useMapOverlayMapData.ts b/packages/tupaia-web/src/features/Map/utils/useMapOverlayMapData.ts index 66e8b55e64..b042d65972 100644 --- a/packages/tupaia-web/src/features/Map/utils/useMapOverlayMapData.ts +++ b/packages/tupaia-web/src/features/Map/utils/useMapOverlayMapData.ts @@ -10,7 +10,7 @@ import { useEntityAncestors, useMapOverlays, } from '../../../api/queries'; -import { useMapOverlayTableData } from './useMapOverlayTableData.ts'; +import { useMapOverlayTableData } from './useMapOverlayTableData'; import { Entity } from '../../../types'; /* @@ -25,25 +25,44 @@ const useNavigationEntities = ( ) => { const rootEntityCode = activeEntity?.parentCode || activeEntity?.code; - const { data = [] } = useEntitiesWithLocation( + // Get siblings for the root entity + const { data: siblings = [] } = useEntitiesWithLocation( projectCode, rootEntityCode, { params: { includeRootEntity: false, filter: { - generational_distance: 2, + generational_distance: 1, }, }, }, { enabled: !!rootEntityCode }, ); - // if display on level is set, we don't want to show the sibling entities because this would cause slow load times, which displayOnLevel is aiming to fix + // Get immediate children for the selected entity + // If the root entity is the active entity, react-query will automatically de-dupe the requests + const { data: children = [] } = useEntitiesWithLocation( + projectCode, + activeEntity?.code, + { + params: { + includeRootEntity: false, + filter: { + generational_distance: 1, + }, + }, + }, + { enabled: !!activeEntity?.code }, + ); + + const entitiesData = [...siblings, ...children]; + + // If display on level is set, we don't want to show the sibling entities because this would cause slow load times, which displayOnLevel is aiming to fix if (displayOnLevel) return []; // Don't show nav entities for the selected measure level - const filteredData = data?.filter(entity => { + const filteredData = entitiesData?.filter(entity => { if (!measureLevel) return true; // handle edge cases of array measure levels if (Array.isArray(measureLevel)) From 3e4b3131154ac0d8a20393a2c6bdb89e92a1c32d Mon Sep 17 00:00:00 2001 From: acdunham <129009580+acdunham@users.noreply.github.com> Date: Mon, 4 Dec 2023 16:15:16 +1300 Subject: [PATCH 2/7] Fix issue with displayOnLevel (#5235) --- .../src/features/Map/MapOverlaysLayer/MapOverlaysLayer.tsx | 7 ++++++- .../src/features/Map/utils/useMapOverlayMapData.ts | 7 +++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/tupaia-web/src/features/Map/MapOverlaysLayer/MapOverlaysLayer.tsx b/packages/tupaia-web/src/features/Map/MapOverlaysLayer/MapOverlaysLayer.tsx index 9c451f0530..71ef331d12 100644 --- a/packages/tupaia-web/src/features/Map/MapOverlaysLayer/MapOverlaysLayer.tsx +++ b/packages/tupaia-web/src/features/Map/MapOverlaysLayer/MapOverlaysLayer.tsx @@ -21,11 +21,16 @@ const useZoomToEntity = () => { // This is a replacement for the map positioning being handled in the ui-map-components LeafletMap file. We are doing this because we need access to the user's current zoom level, and are also slowly moving away from class based components to use hooks instead. useEffect(() => { - if (!entity || !map || (!entity.point && !entity.bounds)) return; + if (!entity || !map || (!entity.point && !entity.bounds && !entity.region)) return; + if (entity.bounds) { map.flyToBounds(entity.bounds, { animate: false, // don't animate, as it can slow things down a bit }); + } else if (entity.region) { + map.flyToBounds(entity.region, { + animate: false, // don't animate, as it can slow things down a bit + }); } else { const currentZoom = map.getZoom(); // if already zoomed in beyond the POINT_ZOOM_LEVEL, don't zoom out diff --git a/packages/tupaia-web/src/features/Map/utils/useMapOverlayMapData.ts b/packages/tupaia-web/src/features/Map/utils/useMapOverlayMapData.ts index b042d65972..657a25feaa 100644 --- a/packages/tupaia-web/src/features/Map/utils/useMapOverlayMapData.ts +++ b/packages/tupaia-web/src/features/Map/utils/useMapOverlayMapData.ts @@ -58,8 +58,9 @@ const useNavigationEntities = ( const entitiesData = [...siblings, ...children]; - // If display on level is set, we don't want to show the sibling entities because this would cause slow load times, which displayOnLevel is aiming to fix - if (displayOnLevel) return []; + // If display on level is set, we don't want to show the sibling entities because this would cause slow load times, which displayOnLevel is aiming to fix. Also, don't show child entities if the current entity is the same as 'displayAtLevel', because we would end up with extra entities on the map + if (displayOnLevel) + return activeEntity?.type?.replace('_', '') === displayOnLevel.toLowerCase() ? [] : children; // Don't show nav entities for the selected measure level const filteredData = entitiesData?.filter(entity => { @@ -90,6 +91,7 @@ const useRootEntityCode = (entity, measureLevel, displayOnLevel) => { } const { parentCode, code, type } = entity; + // if displayAtLevel is set, look for the entity at that level if (displayOnLevel) { const measure = entityAncestors?.find( (entity: Entity) => entity.type.replace('_', '') === displayOnLevel?.toLowerCase(), @@ -136,6 +138,7 @@ export const useMapOverlayMapData = (hiddenValues = {}) => { // Get the main visual entities (descendants of root entity for the selected visual) and their data for displaying the visual const mapOverlayData = useMapOverlayTableData({ hiddenValues, rootEntityCode }); + // Get the relatives (siblings and immediate children) of the active entity for displaying navigation polygons const relativesMeasureData = entityRelatives ?.filter( From 1137f3154765c6e49981b3c656100bae5bba0f22 Mon Sep 17 00:00:00 2001 From: acdunham <129009580+acdunham@users.noreply.github.com> Date: Tue, 5 Dec 2023 13:00:45 +1300 Subject: [PATCH 3/7] Fix chart table overflow (#5238) --- packages/tupaia-web/src/features/Visuals/Chart.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/tupaia-web/src/features/Visuals/Chart.tsx b/packages/tupaia-web/src/features/Visuals/Chart.tsx index c120f0fb3f..63728d3ddf 100644 --- a/packages/tupaia-web/src/features/Visuals/Chart.tsx +++ b/packages/tupaia-web/src/features/Visuals/Chart.tsx @@ -17,6 +17,12 @@ const GREY_DE = '#DEDEE0'; const GREY_FB = '#FBF9F9'; const TEXT_DARKGREY = '#414D55'; +const ScreenChartTable = styled(ChartTable)` + table { + table-layout: unset; + } +`; + const ExportingStyledTable = styled(ChartTable)` padding: 1.8rem 0; border-bottom: none; @@ -142,7 +148,7 @@ const DISPLAY_TYPE_VIEWS = [ value: 'table', Icon: GridOn, label: 'View table', - display: ChartTable, + display: ScreenChartTable, }, ]; @@ -173,10 +179,10 @@ export const Chart = () => { const views = isExport ? EXPORT_DISPLAY_TYPE_VIEWS : DISPLAY_TYPE_VIEWS; let availableDisplayTypes = showTable ? views : [views[0]]; - const viewContent = ({ + const viewContent = { ...report, ...config, - } as unknown) as ViewContent; + } as unknown as ViewContent; return ( From 88fc20f99dd693a0ab34a9ab97d940b47d818e6a Mon Sep 17 00:00:00 2001 From: Tom Caiger Date: Thu, 7 Dec 2023 09:03:12 +1300 Subject: [PATCH 4/7] dedupe requests (#5244) --- .../src/features/Map/MapOverlaysLayer/PolygonLayer.tsx | 2 +- .../tupaia-web/src/features/Map/utils/useMapOverlayMapData.ts | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/tupaia-web/src/features/Map/MapOverlaysLayer/PolygonLayer.tsx b/packages/tupaia-web/src/features/Map/MapOverlaysLayer/PolygonLayer.tsx index b54b922e48..53cb626cd5 100644 --- a/packages/tupaia-web/src/features/Map/MapOverlaysLayer/PolygonLayer.tsx +++ b/packages/tupaia-web/src/features/Map/MapOverlaysLayer/PolygonLayer.tsx @@ -128,7 +128,7 @@ export const PolygonLayer = ({ measureData = [], serieses = [], isLoading }: Pol {polygons.map((measure: MeasureData) => { const { region, code, color, name, permanentTooltip = false } = measure; - const shade = BREWER_PALETTE[color as keyof typeof BREWER_PALETTE] || color; + const shade = BREWER_PALETTE[color as keyof typeof BREWER_PALETTE] || color || ''; const displayType = getDisplayType(measure); const PolygonComponent = POLYGON_COMPONENTS[displayType]; const showDataOnTooltip = displayType === DISPLAY_TYPES.shaded; diff --git a/packages/tupaia-web/src/features/Map/utils/useMapOverlayMapData.ts b/packages/tupaia-web/src/features/Map/utils/useMapOverlayMapData.ts index 657a25feaa..184f62fb18 100644 --- a/packages/tupaia-web/src/features/Map/utils/useMapOverlayMapData.ts +++ b/packages/tupaia-web/src/features/Map/utils/useMapOverlayMapData.ts @@ -41,7 +41,6 @@ const useNavigationEntities = ( ); // Get immediate children for the selected entity - // If the root entity is the active entity, react-query will automatically de-dupe the requests const { data: children = [] } = useEntitiesWithLocation( projectCode, activeEntity?.code, @@ -53,7 +52,7 @@ const useNavigationEntities = ( }, }, }, - { enabled: !!activeEntity?.code }, + { enabled: !!activeEntity?.code && activeEntity?.code !== rootEntityCode }, ); const entitiesData = [...siblings, ...children]; From abec630e937804008e3659076e12ede95c8c6901 Mon Sep 17 00:00:00 2001 From: acdunham <129009580+acdunham@users.noreply.github.com> Date: Thu, 7 Dec 2023 10:20:25 +1300 Subject: [PATCH 5/7] Fix display issues (#5245) --- packages/tupaia-web/src/api/api.ts | 2 +- .../src/features/Dashboard/ExportDashboard/Preview.tsx | 2 +- packages/tupaia-web/src/views/PDFExport.tsx | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/tupaia-web/src/api/api.ts b/packages/tupaia-web/src/api/api.ts index fa88608955..9fa67467f9 100644 --- a/packages/tupaia-web/src/api/api.ts +++ b/packages/tupaia-web/src/api/api.ts @@ -48,7 +48,7 @@ const getErrorMessage = (error: any) => { } // remove axios `api error ...:` prefix - return message?.includes(':') ? message?.split(': ')[1] : message; + return message?.includes(':') ? message?.split(': ').slice(1).join(': ') : message; }; // Todo: Move api request util to ui-components and allow for mapping to backend request type safety diff --git a/packages/tupaia-web/src/features/Dashboard/ExportDashboard/Preview.tsx b/packages/tupaia-web/src/features/Dashboard/ExportDashboard/Preview.tsx index b2d7ca17c5..1f6bcbf6d6 100644 --- a/packages/tupaia-web/src/features/Dashboard/ExportDashboard/Preview.tsx +++ b/packages/tupaia-web/src/features/Dashboard/ExportDashboard/Preview.tsx @@ -247,7 +247,7 @@ export const Preview = ({ onClose, selectedDashboardItems = [] }: ExportDashboar entityCode={entityCode} dashboardName={dashboardName} selectedDashboardItems={[visualisationToPreview]} - isPreview={!isLoading} + isPreview={true} /> diff --git a/packages/tupaia-web/src/views/PDFExport.tsx b/packages/tupaia-web/src/views/PDFExport.tsx index fbd0f279dd..56c4727553 100644 --- a/packages/tupaia-web/src/views/PDFExport.tsx +++ b/packages/tupaia-web/src/views/PDFExport.tsx @@ -36,8 +36,10 @@ export const PDFExport = ({ selectedDashboardItems: propsSelectedDashboardItems, isPreview = false, }: PDFExportProps) => { - // Hacky way to change default background color without touching root css. - document.body.style.backgroundColor = 'white'; + // Hacky way to change default background color without touching root css. Only apply when generating the pdf, not when in preview mode as it changes the display + if (!isPreview) { + document.body.style.backgroundColor = 'white'; + } const { projectCode: urlProjectCode, From be71542b1f622bc0969e26ecaeff0aab6f8b39bb Mon Sep 17 00:00:00 2001 From: acdunham Date: Thu, 7 Dec 2023 11:57:29 +1300 Subject: [PATCH 6/7] Loading container fix --- .../src/features/Dashboard/ExportDashboard/ExportDashboard.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/tupaia-web/src/features/Dashboard/ExportDashboard/ExportDashboard.tsx b/packages/tupaia-web/src/features/Dashboard/ExportDashboard/ExportDashboard.tsx index e88d9454c6..c5d4f24e59 100644 --- a/packages/tupaia-web/src/features/Dashboard/ExportDashboard/ExportDashboard.tsx +++ b/packages/tupaia-web/src/features/Dashboard/ExportDashboard/ExportDashboard.tsx @@ -46,6 +46,9 @@ const Container = styled.div` font-size: 1rem; } } + .loading-container { + width: 100%; + } `; const Title = styled(Typography).attrs({ From a6f269c2653b0a7fd6be526cf290dad5b939f433 Mon Sep 17 00:00:00 2001 From: Ethan McQuarrie <69437175+EMcQ-BES@users.noreply.github.com> Date: Thu, 7 Dec 2023 12:54:53 +1300 Subject: [PATCH 7/7] Hotfix: Update e2e for rewrite frontend (#5246) * Update cypress specs for rewrite * Remove dead projects from url lists * Update spec regex --- .../config/dashboardReportUrls/covidau.json | 72 ------------------- .../config/dashboardReportUrls/default.json | 52 -------------- .../config/mapOverlayUrls/default.json | 5 -- .../e2e/cypress/e2e/dashboardReports.spec.js | 2 +- packages/e2e/cypress/e2e/mapOverlays.spec.js | 5 +- 5 files changed, 5 insertions(+), 131 deletions(-) delete mode 100644 packages/e2e/cypress/config/dashboardReportUrls/covidau.json diff --git a/packages/e2e/cypress/config/dashboardReportUrls/covidau.json b/packages/e2e/cypress/config/dashboardReportUrls/covidau.json deleted file mode 100644 index e59b3ae452..0000000000 --- a/packages/e2e/cypress/config/dashboardReportUrls/covidau.json +++ /dev/null @@ -1,72 +0,0 @@ -[ - { - "code": "COVID_AU_Total_Cases_Each_State_Per_Day", - "project": "covidau", - "orgUnit": "AU", - "dashboard": "COVID-19" - }, - { - "code": "COVID_Compose_Cumulative_Deaths_Vs_Cases", - "project": "covidau", - "orgUnit": "AU", - "dashboard": "COVID-19" - }, - { - "code": "COVID_Compose_Daily_Deaths_Vs_Cases", - "project": "covidau", - "orgUnit": "AU", - "dashboard": "COVID-19" - }, - { - "code": "COVID_Daily_Cases_By_Type", - "project": "covidau", - "orgUnit": "AU_Victoria", - "dashboard": "COVID-19", - "startDate": "2020-07-17", - "endDate": "2020-07-17" - }, - { - "code": "COVID_Link_To_Sources", - "project": "covidau", - "orgUnit": "AU", - "dashboard": "COVID-19" - }, - { - "code": "COVID_New_Cases_By_Day", - "project": "covidau", - "orgUnit": "AU", - "dashboard": "COVID-19" - }, - { - "code": "COVID_New_Cases_By_State", - "project": "covidau", - "orgUnit": "AU", - "dashboard": "COVID-19", - "startDate": "2020-06-13", - "endDate": "2020-06-13" - }, - { - "code": "COVID_Tests_Per_Capita", - "project": "covidau", - "orgUnit": "AU", - "dashboard": "COVID-19" - }, - { - "code": "COVID_Total_Cases_By_State", - "project": "covidau", - "orgUnit": "AU", - "dashboard": "COVID-19" - }, - { - "code": "COVID_Total_Cases_By_Type", - "project": "covidau", - "orgUnit": "AU_Victoria", - "dashboard": "COVID-19" - }, - { - "code": "COVID_Total_Tests_Conducted", - "project": "covidau", - "orgUnit": "AU_Victoria", - "dashboard": "COVID-19" - } -] diff --git a/packages/e2e/cypress/config/dashboardReportUrls/default.json b/packages/e2e/cypress/config/dashboardReportUrls/default.json index d40b5d97be..5932e487b8 100644 --- a/packages/e2e/cypress/config/dashboardReportUrls/default.json +++ b/packages/e2e/cypress/config/dashboardReportUrls/default.json @@ -161,32 +161,6 @@ "orgUnit": "TO", "dashboard": "PEHS" }, - { - "code": "COVID_Compose_Daily_Deaths_Vs_Cases", - "project": "covidau", - "orgUnit": "AU", - "dashboard": "COVID-19" - }, - { - "code": "COVID_New_Cases_By_State", - "project": "covidau", - "orgUnit": "AU", - "dashboard": "COVID-19", - "startDate": "2021-05-30", - "endDate": "2021-05-30" - }, - { - "code": "COVID_Total_Cases_By_State", - "project": "covidau", - "orgUnit": "AU", - "dashboard": "COVID-19" - }, - { - "code": "COVID_Compose_Cumulative_Deaths_Vs_Cases", - "project": "covidau", - "orgUnit": "AU_Australian Capital Territory", - "dashboard": "COVID-19" - }, { "code": "FETP_PG_graduate_by_district", "project": "fetp", @@ -205,12 +179,6 @@ "orgUnit": "FETP-DYO3", "dashboard": "FETP" }, - { - "code": "LA_EOC_Total_Dengue_Cases_by_Week", - "project": "laos_eoc", - "orgUnit": "LA_Bokeo", - "dashboard": "Dengue" - }, { "code": "LA_Laos_Schools_Resources_Percentage_Primary", "project": "laos_schools", @@ -223,26 +191,6 @@ "orgUnit": "LA", "dashboard": "ICT Facilities" }, - { - "code": "Laos_EOC_Malaria_Critical_Item_Availability", - "project": "laos_eoc", - "orgUnit": "LA-BK AH Bokeo (Military)", - "dashboard": "Malaria" - }, - { - "code": "Laos_EOC_Malaria_Critical_Item_Availability_Single_Value", - "project": "laos_eoc", - "orgUnit": "LA-BK AH Bokeo (Military)", - "dashboard": "Malaria", - "startDate": "2020-06-01", - "endDate": "2020-06-30" - }, - { - "code": "Laos_EOC_Malaria_Stock_Availability_Facility", - "project": "laos_eoc", - "orgUnit": "LA-BK AH Bokeo (Military)", - "dashboard": "Malaria" - }, { "code": "Laos_Schools_Age_Of_Computers_By_School_Type", "project": "laos_schools", diff --git a/packages/e2e/cypress/config/mapOverlayUrls/default.json b/packages/e2e/cypress/config/mapOverlayUrls/default.json index dde7ea0f04..5c5104a030 100644 --- a/packages/e2e/cypress/config/mapOverlayUrls/default.json +++ b/packages/e2e/cypress/config/mapOverlayUrls/default.json @@ -44,11 +44,6 @@ "project": "explore", "orgUnit": "TO" }, - { - "id": "COVID_AU_State_Total_Number_Confirmed_Cases", - "project": "covidau", - "orgUnit": "AU" - }, { "id": "COVID_Facility_Commodities_Soap", "project": "explore", diff --git a/packages/e2e/cypress/e2e/dashboardReports.spec.js b/packages/e2e/cypress/e2e/dashboardReports.spec.js index ec760be6bb..3aa07b5fd6 100644 --- a/packages/e2e/cypress/e2e/dashboardReports.spec.js +++ b/packages/e2e/cypress/e2e/dashboardReports.spec.js @@ -36,7 +36,7 @@ const urlToRouteRegex = url => { throw new Error(`'${url}' is not a valid report url: it must contain a 'report' query param`); } - return new RegExp(`report/.*\\?(.*&|)isExpanded=true&(.*&|)itemCode=${itemCode}(&|$)`); + return new RegExp(`(legacyDashboardReport|report)/.*\\?(.*&|)itemCode=${itemCode}(&|$)`); }; describe('Dashboard reports', () => { diff --git a/packages/e2e/cypress/e2e/mapOverlays.spec.js b/packages/e2e/cypress/e2e/mapOverlays.spec.js index 865a4368ce..8ba1662f5b 100644 --- a/packages/e2e/cypress/e2e/mapOverlays.spec.js +++ b/packages/e2e/cypress/e2e/mapOverlays.spec.js @@ -35,7 +35,10 @@ const urlToRouteRegex = url => { throw new Error(`'${url}' is not a valid report url: it must contain a 'report' query param`); } - return new RegExp(`measureData\\?(.*&|)mapOverlayCode=${mapOverlayCode}(&|$)`); + // Allows responses for both versions of the frontend + return new RegExp( + `(measureData\\?(.*&|)mapOverlayCode=${mapOverlayCode}(&|$)|legacyMapOverlayReport/${mapOverlayCode})`, + ); }; describe('Map overlays', () => {