Skip to content

Commit

Permalink
EES-5542 fix maps rendering with right boundary data
Browse files Browse the repository at this point in the history
  • Loading branch information
bennettstuart committed Dec 19, 2024
1 parent c0c6c08 commit 92835aa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import dataBlocksService, {
CreateReleaseDataBlock,
ReleaseDataBlock,
} from '@admin/services/dataBlockService';
import featuredTableService from '@admin/services/featuredTableService';
import LoadingSpinner from '@common/components/LoadingSpinner';
import Tabs from '@common/components/Tabs';
import TabsSection from '@common/components/TabsSection';
import WarningMessage from '@common/components/WarningMessage';
import useAsyncRetry from '@common/hooks/useAsyncRetry';
import getMapInitialBoundaryLevel from '@common/modules/charts/components/utils/getMapInitialBoundaryLevel';
import isOrphanedDataSet from '@common/modules/charts/util/isOrphanedDataSet';
import { InitialTableToolState } from '@common/modules/table-tool/components/TableToolWizard';
import getInitialStepSubjectMeta from '@common/modules/table-tool/components/utils/getInitialStepSubjectMeta';
Expand All @@ -29,7 +31,6 @@ import minDelay from '@common/utils/minDelay';
import { produce } from 'immer';
import omit from 'lodash/omit';
import React, { useCallback, useState } from 'react';
import featuredTableService from '@admin/services/featuredTableService';

export type SavedDataBlock = CreateReleaseDataBlock & {
id?: string;
Expand Down Expand Up @@ -78,14 +79,10 @@ const DataBlockPageTabs = ({
releaseId,
};

const boundaryLevel =
dataBlock.charts[0]?.type === 'map'
? dataBlock.charts[0].boundaryLevel
: undefined;
const tableData = await tableBuilderService.getTableData(
query,
releaseId,
boundaryLevel,
getMapInitialBoundaryLevel(dataBlock.charts[0]),
);

const { initialStep, subjectMeta } = await getInitialStepSubjectMeta(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Chart } from '@common/services/types/blocks';
import isEqual from 'lodash/isEqual';
import sortBy from 'lodash/sortBy';

export default function getMapInitialBoundaryLevel(
chart: Chart,
): number | undefined {
if (chart.type !== 'map') return undefined;

// data set options are ordered alphabetically based on their label text
const firstDataSet = sortBy(chart.legend.items, 'label')[0].dataSet;
const firstDataSetConfig = chart.map?.dataSetConfigs.find(({ dataSet }) => {
return isEqual(dataSet, firstDataSet);
});

return firstDataSetConfig?.boundaryLevel ?? chart.boundaryLevel;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import WarningMessage from '@common/components/WarningMessage';
import withLazyLoad from '@common/hocs/withLazyLoad';
import ChartRenderer from '@common/modules/charts/components/ChartRenderer';
import { GetInfographic } from '@common/modules/charts/components/InfographicBlock';
import getMapInitialBoundaryLevel from '@common/modules/charts/components/utils/getMapInitialBoundaryLevel';
import { AxesConfiguration } from '@common/modules/charts/types/chart';
import TimePeriodDataTable from '@common/modules/table-tool/components/TimePeriodDataTable';
import getDefaultTableHeaderConfig from '@common/modules/table-tool/utils/getDefaultTableHeadersConfig';
Expand Down Expand Up @@ -43,9 +44,7 @@ const DataBlockTabs = ({
onToggle,
}: DataBlockTabsProps) => {
const [selectedBoundaryLevel, setSelectedBoundaryLevel] = useState(
dataBlock.charts[0]?.type === 'map'
? dataBlock.charts[0].boundaryLevel
: undefined,
getMapInitialBoundaryLevel(dataBlock.charts[0]),
);

const {
Expand Down

0 comments on commit 92835aa

Please sign in to comment.