From 87537eca5a3a222b17ccf6d2f7c1a3dab09b75d7 Mon Sep 17 00:00:00 2001
From: Diana Rita Nanyanzi <31903212+d-rita@users.noreply.github.com>
Date: Tue, 5 Jul 2022 14:48:15 +0300
Subject: [PATCH] Refactor user group related functions:
- Eliminate redundant user group utils function and test
- Pass users array directly to the results component
- Modify user group csv headers
- Modify user group test data
---
src/components/tests/footer.test.js | 2 +-
src/components/userGroup/constants.js | 14 +++++++-------
src/components/userGroup/tests/testData.js | 6 +++---
src/utils/tests/testData.js | 17 +++++++++++++++++
src/utils/userGroupUtils.js | 13 -------------
src/views/UserGroupReport.js | 5 ++---
6 files changed, 30 insertions(+), 27 deletions(-)
delete mode 100644 src/utils/userGroupUtils.js
diff --git a/src/components/tests/footer.test.js b/src/components/tests/footer.test.js
index 71a59cd..345aa96 100644
--- a/src/components/tests/footer.test.js
+++ b/src/components/tests/footer.test.js
@@ -6,7 +6,7 @@ import { Footer } from "../footer";
afterEach(cleanup);
it("Footer component", () => {
- const { getByText, debug } = render(
+ const { getByText } = render(
diff --git a/src/components/userGroup/constants.js b/src/components/userGroup/constants.js
index 146efc4..007c2db 100644
--- a/src/components/userGroup/constants.js
+++ b/src/components/userGroup/constants.js
@@ -20,7 +20,7 @@ export const UserGroupColumnHeadings = [
},
},
{
- accessor: "createdBuildings",
+ accessor: "addedBuildings",
Header: ,
},
{
@@ -28,11 +28,11 @@ export const UserGroupColumnHeadings = [
Header: ,
},
{
- accessor: "createdHighways",
+ accessor: "addedHighway",
Header: ,
},
{
- accessor: "modifiedHighways",
+ accessor: "modifiedHighway",
Header: ,
},
{
@@ -53,7 +53,7 @@ export const UserGroupReportCSVHeaders = [
label: "Mapper",
},
{
- key: "createdBuildings",
+ key: "addedBuildings",
label: "Created Buildings",
},
{
@@ -61,11 +61,11 @@ export const UserGroupReportCSVHeaders = [
label: "Modified Buildings",
},
{
- key: "createdHighways",
- label: "Added Highways",
+ key: "addedHighway",
+ label: "Created Highways",
},
{
- key: "modifiedHighways",
+ key: "modifiedHighway",
label: "Modified Highways",
},
];
diff --git a/src/components/userGroup/tests/testData.js b/src/components/userGroup/tests/testData.js
index 2691e41..a180723 100644
--- a/src/components/userGroup/tests/testData.js
+++ b/src/components/userGroup/tests/testData.js
@@ -2,10 +2,10 @@ export const userGroupTestResults = [
{
userId: 1001,
userName: "user1",
- createdBuildings: 10281,
+ addedBuildings: 10281,
modifiedBuildings: 8,
- createdHighways: 19,
- modifiedHighways: 50,
+ addedHighway: 19,
+ modifiedHighway: 50,
addedHighwayMeters: 1056.8384445134818,
modifiedHighwayMeters: 86412.81413059866,
},
diff --git a/src/utils/tests/testData.js b/src/utils/tests/testData.js
index 31216e9..a7ac18a 100644
--- a/src/utils/tests/testData.js
+++ b/src/utils/tests/testData.js
@@ -83,3 +83,20 @@ export const validMapathonDetailResponse2 = {
},
],
};
+
+export const validUserGroupData1 = [
+ {
+ userId: 1001,
+ username: "user1",
+ stats: [
+ {
+ addedBuildings: 1180,
+ modifiedBuildings: 0,
+ addedHighway: 16,
+ modifiedHighway: 11,
+ addedHighwayMeters: 35955.05053289406,
+ modifiedHighwayMeters: 42539.38543911992,
+ },
+ ],
+ },
+];
diff --git a/src/utils/userGroupUtils.js b/src/utils/userGroupUtils.js
deleted file mode 100644
index eb982dc..0000000
--- a/src/utils/userGroupUtils.js
+++ /dev/null
@@ -1,13 +0,0 @@
-export const aggregateUserGroupData = (obj) => {
- const arr = [];
- obj.forEach((i) => {
- arr.push({
- ...i,
- createdBuildings: i["stats"][0]["addedBuildings"],
- modifiedBuildings: i["stats"][0]["modifiedBuildings"],
- createdHighways: i["stats"][0]["addedHighway"],
- modifiedHighways: i["stats"][0]["modifiedHighway"],
- });
- });
- return arr;
-};
diff --git a/src/views/UserGroupReport.js b/src/views/UserGroupReport.js
index b6f8360..06a63a9 100644
--- a/src/views/UserGroupReport.js
+++ b/src/views/UserGroupReport.js
@@ -8,7 +8,6 @@ import { FormContext } from "../context/formContext";
import { getUserIds, getUserStats } from "../queries/getUserStats";
import { MiniNavBar } from "../components/nav/navbar";
import { UserGroupColumnHeadings } from "../components/userGroup/constants";
-import { aggregateUserGroupData } from "../utils/userGroupUtils";
import { SpinnerIcon } from "../assets/svgIcons";
const userGroupPage = [
@@ -44,7 +43,7 @@ export const UserGroupReport = () => {
.then((res) => {
setUsers((oldUsersArray) => [
...oldUsersArray,
- { ...i, stats: res },
+ { ...i, ...res[0] },
]);
})
.catch((error) => {
@@ -85,7 +84,7 @@ export const UserGroupReport = () => {
{data && (
0}
loading={userIds.length !== users.length}
/>