Skip to content

Commit

Permalink
fix: Alterations after review
Browse files Browse the repository at this point in the history
  • Loading branch information
edvinstava committed Aug 6, 2024
1 parent c029012 commit 266a385
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ const PluginInner = (propsFromParent: EnrollmentOverviewProps) => {
} = useCustomReferences();

const {
teiId,
programId,
orgUnitId,
teiId = 'oJGqqqazdje',
programId = 'Ewe20zBQxw4',
orgUnitId = 'RaTwtPm4gBX',
} = propsFromParent;

const {
Expand Down
12 changes: 12 additions & 0 deletions src/utils/Hooks/Calculations/useAppropriateChartData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ export const useAppropriateChartData = (
const isMonthsInRange = (xAxis: string, range: { start: number, end: number }) =>
xAxis === TimeUnitCodes.months && childAgeInMonths >= range.start && childAgeInMonths < range.end;

const getMaxRangeDataset = (datasets: ChartData[0]['datasets']) =>
Object.entries(datasets)
.reduce((max, [key, value]) =>
((!max || value.metadata.range.end > max[1].metadata.range.end) ? [key, value] : max));

const isAboveRange = (xAxis: string, range: { start: number, end: number }) =>
xAxis === TimeUnitCodes.months && childAgeInMonths >= range.end;
Object.entries(datasets)
.some(([key, value]) => {
const { range } = value.metadata;
Expand All @@ -36,6 +43,11 @@ export const useAppropriateChartData = (
return true;
}

if (isAboveRange(xAxis, range)) {
const [newDatasetKey] = getMaxRangeDataset(datasets);
setSelectedDataset(newDatasetKey);
return true;
}
return false;
});
};
Expand Down

0 comments on commit 266a385

Please sign in to comment.