Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Typing simplification #73

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,75 +3,80 @@ import { FLOOD, FloodSpecific } from '@wfp-dmp/interfaces';

import { getColumnSetup, getGroupSetup } from 'utils/tableFormatting';

export const NumAffected1Columns: GridColDef[] = [
getColumnSetup(FloodSpecific.NumVillAff, FLOOD),
getColumnSetup(FloodSpecific.NumPeoAff, FLOOD),
getColumnSetup(FloodSpecific.NumFamAff, FLOOD),
getColumnSetup(FloodSpecific.NumFeAff, FLOOD),
getColumnSetup(FloodSpecific.NumTDeath, FLOOD),
getColumnSetup(FloodSpecific.NumMeDeath, FLOOD),
getColumnSetup(FloodSpecific.NumFeDeath, FLOOD),
getColumnSetup(FloodSpecific.NumKidDeath, FLOOD),
getColumnSetup(FloodSpecific.NumOldDeath, FLOOD),
getColumnSetup(FloodSpecific.NumDisDeath, FLOOD),
getColumnSetup(FloodSpecific.NumTMissing, FLOOD),
getColumnSetup(FloodSpecific.NumMeMissing, FLOOD),
getColumnSetup(FloodSpecific.NumFeMissing, FLOOD),
getColumnSetup(FloodSpecific.NumKidMissing, FLOOD),
getColumnSetup(FloodSpecific.NumOldMissing, FLOOD),
getColumnSetup(FloodSpecific.NumDisMissing, FLOOD),
getColumnSetup(FloodSpecific.NumTInjure, FLOOD),
getColumnSetup(FloodSpecific.NumMeInjure, FLOOD),
getColumnSetup(FloodSpecific.NumFeInjure, FLOOD),
getColumnSetup(FloodSpecific.NumKidInjure, FLOOD),
getColumnSetup(FloodSpecific.NumOldInjure, FLOOD),
getColumnSetup(FloodSpecific.NumDisInjure, FLOOD),
// TODO - Finish reorganizing this file for typing
const NumAffected1ColumnsKeys: FloodSpecific[] = [
'NumVillAff',
'NumPeoAff',
'NumFamAff',
'NumFeAff',
'NumFeAff',
'NumTDeath',
'NumMeDeath',
'NumFeDeath',
'NumKidDeath',
'NumOldDeath',
'NumDisDeath',
'NumTMissing',
'NumMeMissing',
'NumFeMissing',
'NumKidMissing',
'NumOldMissing',
'NumDisMissing',
'NumTInjure',
'NumMeInjure',
'NumFeInjure',
'NumKidInjure',
'NumOldInjure',
'NumDisInjure',
];

export const NumAffected1Columns: GridColDef[] = NumAffected1ColumnsKeys.map(
key => getColumnSetup(key, FLOOD),
);

const keyAsField = (key: FloodSpecific) => ({ field: key });
const keysAsChildren = (keys: FloodSpecific[]) => keys.map(keyAsField);

export const NumAffected1ColumnGroup: GridColumnGroupingModel = [
{
...getGroupSetup('victimsAffected', FLOOD),
children: [
{ field: FloodSpecific.NumVillAff },
keyAsField('NumVillAff'),
{
...getGroupSetup('totalAffected', FLOOD),
children: [
{ field: FloodSpecific.NumPeoAff },
{ field: FloodSpecific.NumFamAff },
{ field: FloodSpecific.NumFeAff },
],
children: keysAsChildren(['NumPeoAff', 'NumFamAff', 'NumFeAff']),
},
{
...getGroupSetup('deathToll', FLOOD),
children: [
{ field: FloodSpecific.NumTDeath },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should continue to use the string Enum to avoid any typos

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This offers a check against typos as well. I proposed a few other option in the PR body. We can chat about it but it's not urgent anyway.

{ field: FloodSpecific.NumMeDeath },
{ field: FloodSpecific.NumFeDeath },
{ field: FloodSpecific.NumKidDeath },
{ field: FloodSpecific.NumOldDeath },
{ field: FloodSpecific.NumDisDeath },
{ field: 'NumTDeath' },
{ field: 'NumMeDeath' },
{ field: 'NumFeDeath' },
{ field: 'NumKidDeath' },
{ field: 'NumOldDeath' },
{ field: 'NumDisDeath' },
],
},
{
...getGroupSetup('missing', FLOOD),
children: [
{ field: FloodSpecific.NumTMissing },
{ field: FloodSpecific.NumMeMissing },
{ field: FloodSpecific.NumFeMissing },
{ field: FloodSpecific.NumKidMissing },
{ field: FloodSpecific.NumOldMissing },
{ field: FloodSpecific.NumDisMissing },
{ field: 'NumTMissing' },
{ field: 'NumMeMissing' },
{ field: 'NumFeMissing' },
{ field: 'NumKidMissing' },
{ field: 'NumOldMissing' },
{ field: 'NumDisMissing' },
],
},
{
...getGroupSetup('injured', FLOOD),
children: [
{ field: FloodSpecific.NumTInjure },
{ field: FloodSpecific.NumMeInjure },
{ field: FloodSpecific.NumFeInjure },
{ field: FloodSpecific.NumKidInjure },
{ field: FloodSpecific.NumOldInjure },
{ field: FloodSpecific.NumDisInjure },
{ field: 'NumTInjure' },
{ field: 'NumMeInjure' },
{ field: 'NumFeInjure' },
{ field: 'NumKidInjure' },
{ field: 'NumOldInjure' },
{ field: 'NumDisInjure' },
],
},
],
Expand Down
19 changes: 9 additions & 10 deletions apps/frontend/utils/aggregate/flood/generateFloodDetailedReport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { FloodSpecific, KoboCommonKeys } from '@wfp-dmp/interfaces';
import {
FloodSpecific,
floodSpecificKeysArray,
KoboCommonKeys,
} from '@wfp-dmp/interfaces';
import { omit } from 'lodash';

import { aggregate } from '../aggregate';
Expand All @@ -7,16 +11,11 @@ import { filterNFlood } from '../filterNFlood';
const firstKeys = [KoboCommonKeys.province, KoboCommonKeys.district];

const sumKeys = Object.values(
omit(FloodSpecific, [
FloodSpecific.floodN,
FloodSpecific.RicePrice,
FloodSpecific.threat,
FloodSpecific.other,
]),
omit(floodSpecificKeysArray, ['floodN', 'RicePrice', 'threat', 'other']),
);

const countCategoriesKeys = [FloodSpecific.RicePrice];
const countMultipleChoicesKeys = [FloodSpecific.threat];
const countCategoriesKeys: FloodSpecific[] = ['RicePrice'];
const countMultipleChoicesKeys: FloodSpecific[] = ['threat'];

export const generateFloodDetailedReport = (
data: Record<string, string | undefined>[],
Expand All @@ -25,7 +24,7 @@ export const generateFloodDetailedReport = (
data,
KoboCommonKeys.commune,
KoboCommonKeys.disasterDate,
FloodSpecific.floodN,
'floodN',
);

return aggregate({
Expand Down
Loading