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 d2d3bbe
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import tableBuilderService, {
ReleaseTableDataQuery,
} from '@common/services/tableBuilderService';
import minDelay from '@common/utils/minDelay';
import getMapInitialBoundaryLevel from '@common/components/util/getMapInitialBoundaryLevel';
import { produce } from 'immer';
import omit from 'lodash/omit';
import React, { useCallback, useState } from 'react';
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 @@ -12,6 +12,7 @@ import getDefaultTableHeaderConfig from '@common/modules/table-tool/utils/getDef
import mapFullTable from '@common/modules/table-tool/utils/mapFullTable';
import mapTableHeadersConfig from '@common/modules/table-tool/utils/mapTableHeadersConfig';
import { DataBlock } from '@common/services/types/blocks';
import getMapInitialBoundaryLevel from '@common/components/util/getMapInitialBoundaryLevel';
import { useQuery } from '@tanstack/react-query';
import { isAxiosError } from 'axios';
import React, { ReactNode, useMemo, useState } from 'react';
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 d2d3bbe

Please sign in to comment.