-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#391] Fix EnterIncomeData value & dashboardData calculation
- Loading branch information
1 parent
2a2107b
commit 8ca1e80
Showing
11 changed files
with
254 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
frontend/src/pages/cases/components/IncomeDriversDropdown.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import React, { useMemo } from "react"; | ||
import { Select } from "antd"; | ||
import { selectProps } from "../../../lib"; | ||
import { uniqBy, capitalize } from "lodash"; | ||
|
||
const otherCommodities = ["secondary", "tertiary"]; | ||
|
||
const IncomeDriversDropdown = ({ | ||
selectedSegmentData, | ||
options = [], | ||
value, | ||
onChange, | ||
}) => { | ||
const driverOptionsDropdown = useMemo(() => { | ||
if (!selectedSegmentData) { | ||
return []; | ||
} | ||
const focusCommodityAnswers = selectedSegmentData.answers.filter( | ||
(a) => a.commodityFocus && a.question.question_type !== "diversified" | ||
); | ||
const driverQuestions = | ||
uniqBy( | ||
focusCommodityAnswers.map((a) => a.question), | ||
"id" | ||
).find((q) => !q.parent)?.childrens || []; | ||
const focusRes = driverQuestions | ||
.map((q) => ({ | ||
label: q.text, | ||
type: "focus", | ||
value: q.id, | ||
childrens: q.childrens.map((q) => ({ ...q, type: "focus" })), | ||
})) | ||
.filter((x) => x.value !== 2); // remove land driver from dropdown | ||
// add secondary - tertiary value | ||
const additonalCommodities = otherCommodities | ||
.map((x) => { | ||
const commodity = selectedSegmentData.answers.find( | ||
(a) => | ||
a.commodityType === x && a.question.question_type !== "diversified" | ||
); | ||
if (!commodity) { | ||
return false; | ||
} | ||
return { | ||
text: `Total ${capitalize(x)} / Non Primary - ${ | ||
commodity.commodityName | ||
}`, | ||
type: x, | ||
id: x, | ||
}; | ||
}) | ||
.filter((x) => x); | ||
// add diversified questions | ||
let diversifiedQuestions = selectedSegmentData.answers | ||
.filter( | ||
(a) => | ||
a.commodityType === "diversified" && | ||
a.question.question_type === "diversified" | ||
) | ||
.flatMap((a) => a.question); | ||
diversifiedQuestions = uniqBy(diversifiedQuestions, "id").map((q) => ({ | ||
...q, | ||
type: "diversified", | ||
})); | ||
const diversifiedRes = [ | ||
{ | ||
label: "Diversified Income", | ||
type: "diversified", | ||
value: "diversified", | ||
childrens: [...additonalCommodities, ...diversifiedQuestions], | ||
}, | ||
]; | ||
return [...focusRes, ...diversifiedRes]; | ||
}, [selectedSegmentData]); | ||
|
||
return ( | ||
<Select | ||
options={driverOptionsDropdown} | ||
placeholder="Select Driver" | ||
value={value} | ||
onChange={onChange} | ||
{...selectProps} | ||
allowClear={false} | ||
/> | ||
); | ||
}; | ||
|
||
export default IncomeDriversDropdown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React, { useEffect } from "react"; | ||
import { Radio } from "antd"; | ||
import { CaseVisualState } from "../store"; | ||
|
||
const SegmentSelector = ({ selectedSegment, setSelectedSegment }) => { | ||
const dashboardData = CaseVisualState.useState((s) => s.dashboardData); | ||
|
||
useEffect(() => { | ||
if (!selectedSegment && dashboardData?.length > 0) { | ||
setSelectedSegment(dashboardData[0].id); | ||
} | ||
}, [selectedSegment, dashboardData]); | ||
|
||
const handleChangeSegmentSelector = (e) => { | ||
const value = e.target.value; | ||
setSelectedSegment(value); | ||
}; | ||
|
||
return ( | ||
<Radio.Group value={selectedSegment} onChange={handleChangeSegmentSelector}> | ||
{dashboardData.map((d) => ( | ||
<Radio.Button key={d.id} value={d.id}> | ||
{d.name} | ||
</Radio.Button> | ||
))} | ||
</Radio.Group> | ||
); | ||
}; | ||
|
||
export default SegmentSelector; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
frontend/src/pages/cases/visualizations/ChartExploreIncomeDriverBreakdown.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import React, { useState } from "react"; | ||
import { Card, Col, Row, Space } from "antd"; | ||
import { VisualCardWrapper } from "../components"; | ||
import { CaseVisualState, CurrentCaseState } from "../store"; | ||
|
||
const otherCommodities = ["secondary", "tertiary"]; | ||
const currentColors = [ | ||
"#1b726f", // Dark Cyan | ||
"#81e4ab", // Pale Green | ||
"#fecb21", // Maximum Yellow Red | ||
"#4eb8ff", // Dodger Blue | ||
"#ff8f4e", // Atomic Tangerine | ||
"#725b1b", // Olive Brown | ||
"#ad1b72", // Rose Red | ||
"#214b72", // Prussian Blue | ||
"#724a1b", // Raw Sienna | ||
"#1b7272", // Skobeloff | ||
"#721b49", // Plum Purple | ||
"#1b724a", // Jungle Green | ||
"#721b1b", // Persian Red | ||
"#4a721b", // Olive Drab | ||
"#1b4a72", // Dark Slate Blue | ||
"#1b7261", // Tropical Rain Forest | ||
]; | ||
|
||
const feasibleColors = [ | ||
"#9cc2c1", // Silver Sand (Lighter Version of #1b726f) | ||
"#ddf8e9", // Honeydew (Lighter Version of #81e4ab) | ||
"#ffeeb8", // Moccasin (Lighter Version of #fecb21) | ||
"#d0ecff", // Lavender Blue (Lighter Version of #4eb8ff) | ||
"#ffe1d0", // Peach Yellow (Lighter Version of #ff8f4e) | ||
"#9e8a4d", // Shadow (Lighter Version of #725b1b) | ||
"#d44a94", // Blush (Lighter Version of #ad1b72) | ||
"#41799d", // Steel Blue (Lighter Version of #214b72) | ||
"#ad8a4d", // Café Au Lait (Lighter Version of #724a1b) | ||
"#4d9e9e", // Viridian Green (Lighter Version of #1b7272) | ||
"#94486e", // Mulberry (Lighter Version of #721b49) | ||
"#4d944a", // Turtle Green (Lighter Version of #1b724a) | ||
"#944848", // Chestnut Rose (Lighter Version of #721b1b) | ||
"#6e9448", // La Palma (Lighter Version of #4a721b) | ||
"#486e94", // Jelly Bean (Lighter Version of #1b4a72) | ||
"#487e6e", // Jaguar (Lighter Version of #1b7261) | ||
]; | ||
|
||
const ChartExploreIncomeDriverBreakdown = () => { | ||
const dashboardData = CaseVisualState.useState((s) => s.dashboardData); | ||
const currentCase = CurrentCaseState.useState((s) => s); | ||
|
||
const [axisTitle, setAxisTitle] = useState(currentCase.currency); | ||
const [loading, setLoading] = useState(false); | ||
|
||
return ( | ||
<Card className="card-visual-wrapper"> | ||
<Row gutter={[20, 20]} align="middle"> | ||
<Col span={16}> | ||
<VisualCardWrapper | ||
title="Explore income driver breakdown" | ||
showIncomeDriversDropdown={true} | ||
showSegmentSelector={true} | ||
bordered | ||
> | ||
Chart | ||
</VisualCardWrapper> | ||
</Col> | ||
<Col span={8}> | ||
<Space direction="vertical"> | ||
<div className="section-title">Explore income driver breakdown</div> | ||
<div className="section-description"> | ||
This graph lets you dive into a specific income driver and see how | ||
its sub-components contribute. Use it to identify the largest and | ||
smallest contributors and spot variations across segments | ||
</div> | ||
</Space> | ||
</Col> | ||
</Row> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default ChartExploreIncomeDriverBreakdown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters