Skip to content

Commit

Permalink
fix: Added error for missing growth variables
Browse files Browse the repository at this point in the history
  • Loading branch information
edvinstava committed Apr 24, 2024
1 parent 007d927 commit c9ad75b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/Plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { useCustomReferences } from './utils/DataFetching/Hooks/useCustomReferen
import { chartData as chartDataWHO } from './DataSets/WhoStandardDataSets/ChartData';
import { CustomReferencesError } from './UI/GenericError/CustomReferencesError';
import { useFilterByMissingData } from './utils/DataFetching/Sorting';
import { MissingGrowthVariablesError } from './UI/GenericError/MissingGrowthVariablesError';

const queryClient = new QueryClient();

Expand All @@ -41,7 +42,7 @@ const PluginInner = (propsFromParent: EnrollmentOverviewProps) => {
isWeightInGrams: chartConfig?.settings.weightInGrams || false,
});

const { chartData } = useFilterByMissingData(
const { chartData, measurementDataExist } = useFilterByMissingData(
mappedGrowthVariables,
chartConfig?.settings.customReferences ? customReferences : chartDataWHO,
);
Expand All @@ -62,6 +63,10 @@ const PluginInner = (propsFromParent: EnrollmentOverviewProps) => {
return <CustomReferencesError />;
}

if (measurementDataExist.headCircumference === false && measurementDataExist.height === false && measurementDataExist.weight === false) {
return <MissingGrowthVariablesError />;
}

return (
<QueryClientProvider
client={queryClient}
Expand Down
33 changes: 33 additions & 0 deletions src/UI/GenericError/MissingGrowthVariablesError.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React, { useState } from 'react';
import i18n from '@dhis2/d2-i18n';
import { WidgetCollapsible } from '../../components/WidgetCollapsible';
import { Warning } from '../Icons';

export const MissingGrowthVariablesError = () => {
const [open, setOpen] = useState(true);
return (
<div style={{
width: '100vw',
margin: 0,
padding: 0,
}}
>
<WidgetCollapsible
header={i18n.t('Growth Chart')}
borderless={false}
open={open}
onOpen={() => setOpen(true)}
onClose={() => setOpen(false)}
>
<div className='flex justify-center'>
<Warning className='w-12 h-12' />
<p className='flex p-5 pt-2'>
{i18n.t('No growth variables were found.')}
<br />
{i18n.t('Please add growth variables and try again.')}
</p>
</div>
</WidgetCollapsible>
</div>
);
};
2 changes: 1 addition & 1 deletion src/utils/DataFetching/Sorting/useFilterByMissingData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ export const useFilterByMissingData = (measurementData: MeasurementData[], chart
return filteredData;
}, [chartData, measurementDataExist, requiredData]);

return { chartData: filteredChartData };
return { chartData: filteredChartData, measurementDataExist };
};

0 comments on commit c9ad75b

Please sign in to comment.