Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
48 changes: 36 additions & 12 deletions backend/source/config/reports.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
{
"title": "Count by service level",
"children": true,
"children_path": "data.sanitation service level"
"children_path": "data.sanitation service level",
"show_percent": true,
"percent_path": "total"
}
],
"span": 24
Expand All @@ -69,7 +71,9 @@
{
"title": "Count by service level",
"children": true,
"children_path": "data.hygiene service level"
"children_path": "data.hygiene service level",
"show_percent": true,
"percent_path": "total"
}
],
"span": 24
Expand All @@ -93,7 +97,9 @@
{
"title": "Count by service level",
"children": true,
"children_path": "data.menstrual hygiene service level"
"children_path": "data.menstrual hygiene service level",
"show_percent": true,
"percent_path": "total"
}
],
"span": 24
Expand Down Expand Up @@ -162,7 +168,9 @@
{
"title": "Count by service level",
"children": true,
"children_path": "data.sanitation service level"
"children_path": "data.sanitation service level",
"show_percent": true,
"percent_path": "total"
}
],
"span": 24
Expand All @@ -186,7 +194,9 @@
{
"title": "Count by service level",
"children": true,
"children_path": "data.hygiene (hand washing) service level"
"children_path": "data.hygiene (hand washing) service level",
"show_percent": true,
"percent_path": "total"
}
],
"span": 24
Expand All @@ -210,7 +220,9 @@
{
"title": "Count by service level",
"children": true,
"children_path": "data.health care waste management service level"
"children_path": "data.health care waste management service level",
"show_percent": true,
"percent_path": "total"
}
],
"span": 24
Expand All @@ -234,7 +246,9 @@
{
"title": "Count by service level",
"children": true,
"children_path": "data.environmental cleaning service level"
"children_path": "data.environmental cleaning service level",
"show_percent": true,
"percent_path": "total"
}
],
"span": 24
Expand Down Expand Up @@ -290,7 +304,9 @@
{
"title": "Count by service level",
"children": true,
"children_path": "data.sanitation service level"
"children_path": "data.sanitation service level",
"show_percent": true,
"percent_path": "total"
}
],
"span": 24
Expand All @@ -314,7 +330,9 @@
{
"title": "Count by service level",
"children": true,
"children_path": "data.hygiene (handwashing) service level"
"children_path": "data.hygiene (handwashing) service level",
"show_percent": true,
"percent_path": "total"
}
],
"span": 24
Expand All @@ -338,7 +356,9 @@
{
"title": "Count by service level",
"children": true,
"children_path": "data.drinking water service level"
"children_path": "data.drinking water service level",
"show_percent": true,
"percent_path": "total"
}
],
"span": 24
Expand All @@ -362,7 +382,9 @@
{
"title": "Count by service level",
"children": true,
"children_path": "data.enviromental cleaning service level"
"children_path": "data.enviromental cleaning service level",
"show_percent": true,
"percent_path": "total"
}
],
"span": 24
Expand All @@ -386,7 +408,9 @@
{
"title": "Count by service level",
"children": true,
"children_path": "data.hygiene (mhm) service level"
"children_path": "data.hygiene (mhm) service level",
"show_percent": true,
"percent_path": "total"
}
],
"span": 24
Expand Down
43 changes: 33 additions & 10 deletions frontend/src/pages/dashboard/components/TableVisual.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import React, { useMemo } from "react";
import { useParams } from "react-router-dom";
import { Col, Table, Button } from "antd";
import { get, capitalize, sumBy } from "lodash";
import { get, capitalize, sumBy, orderBy } from "lodash";
import { DownloadOutlined } from "@ant-design/icons";
import { Excel } from "antd-table-saveas-excel";
import { jmpColorScore } from "../../../lib";

const fontSize = 12;

const TableVisual = ({ tableConfig, loading }) => {
const { formId } = useParams();
const { title, type, columns, span, data, index, admLevelName } = tableConfig;

const jmpConfig = jmpColorScore?.[formId];

const tableColumns = useMemo(() => {
return columns.map((c) => {
const showPercent = c?.show_percent;
const percentPath = c?.percent_path;
if (c?.children) {
const obj = get(data?.[0], c.children_path);
if (!obj) {
Expand All @@ -19,16 +26,32 @@ const TableVisual = ({ tableConfig, loading }) => {
children: [],
};
}
const child = Object.keys(obj).map((key) => ({
title: capitalize(key),
dataIndex: key,
key: key,
width: key.length * fontSize,
align: "center",
}));
const jmpType = c.children_path.split(".")[1];
const child = Object.keys(obj).map((key) => {
const jmpOrder = Object.keys(jmpConfig[jmpType]);
let col = {
title: capitalize(key),
dataIndex: key,
key: key,
width: key.length * fontSize,
align: "center",
order: jmpOrder.indexOf(key) + 1,
};
if (showPercent && percentPath) {
col = {
...col,
render: (val, record) => {
const percentDivider = Number(get(record, percentPath));
const percent = (val / percentDivider) * 100;
return `${val} (${percent.toFixed()}%)`;
},
};
}
return col;
});
return {
title: c.title,
children: child,
children: orderBy(child, "order"),
};
}
let tmp = {
Expand All @@ -47,7 +70,7 @@ const TableVisual = ({ tableConfig, loading }) => {
}
return tmp;
});
}, [columns, data]);
}, [columns, data, jmpConfig]);

const tableDataSource = useMemo(() => {
const paths = columns.map((x) => {
Expand Down