Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Refactor user group related functions:
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
d-rita committed Jul 5, 2022
1 parent 2b787bc commit 87537ec
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/components/tests/footer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Footer } from "../footer";
afterEach(cleanup);

it("Footer component", () => {
const { getByText, debug } = render(
const { getByText } = render(
<IntlProviders>
<Footer />
</IntlProviders>
Expand Down
14 changes: 7 additions & 7 deletions src/components/userGroup/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ export const UserGroupColumnHeadings = [
},
},
{
accessor: "createdBuildings",
accessor: "addedBuildings",
Header: <FormattedMessage {...messages.CreatedBuildings} />,
},
{
accessor: "modifiedBuildings",
Header: <FormattedMessage {...messages.ModifiedBuildings} />,
},
{
accessor: "createdHighways",
accessor: "addedHighway",
Header: <FormattedMessage {...messages.CreatedHighways} />,
},
{
accessor: "modifiedHighways",
accessor: "modifiedHighway",
Header: <FormattedMessage {...messages.ModifiedHighways} />,
},
{
Expand All @@ -53,19 +53,19 @@ export const UserGroupReportCSVHeaders = [
label: "Mapper",
},
{
key: "createdBuildings",
key: "addedBuildings",
label: "Created Buildings",
},
{
key: "modifiedBuildings",
label: "Modified Buildings",
},
{
key: "createdHighways",
label: "Added Highways",
key: "addedHighway",
label: "Created Highways",
},
{
key: "modifiedHighways",
key: "modifiedHighway",
label: "Modified Highways",
},
];
6 changes: 3 additions & 3 deletions src/components/userGroup/tests/testData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
17 changes: 17 additions & 0 deletions src/utils/tests/testData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
],
},
];
13 changes: 0 additions & 13 deletions src/utils/userGroupUtils.js

This file was deleted.

5 changes: 2 additions & 3 deletions src/views/UserGroupReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -44,7 +43,7 @@ export const UserGroupReport = () => {
.then((res) => {
setUsers((oldUsersArray) => [
...oldUsersArray,
{ ...i, stats: res },
{ ...i, ...res[0] },
]);
})
.catch((error) => {
Expand Down Expand Up @@ -85,7 +84,7 @@ export const UserGroupReport = () => {
{data && (
<UserGroupResultsTable
columns={UserGroupColumnHeadings}
data={aggregateUserGroupData(users)}
data={users}
userDataCheck={userIds && userIds.length > 0}
loading={userIds.length !== users.length}
/>
Expand Down

0 comments on commit 87537ec

Please sign in to comment.