Skip to content

Commit

Permalink
Merge branch 'feat/Vendor-page' of https://github.com/TrackER-Corpora…
Browse files Browse the repository at this point in the history
…tion/TrackER-UI into feat/Vendor-page
  • Loading branch information
Piccio98 committed May 15, 2023
2 parents a016b3d + f0d3697 commit 0316255
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
48 changes: 38 additions & 10 deletions src/Vendor/Pages/RenewableDetailsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { PageHeader } from "@ant-design/pro-components"
import { ApexOptions } from "apexcharts"
import { RenewableDetailsModal } from "../../types"
import { sortDate } from "../../Consumer/utils"
import IconFont from "../../Iconfont"
const optionsBar = {
chart: {
type: 'bar',
Expand Down Expand Up @@ -111,7 +112,9 @@ const optionsLine = {
const RenewableDetailsModal = ({ filter, data, setVisible, visible }: RenewableDetailsModal) => {
const [dataRenewable, setData] = useState<any>({})
const [dataEarning, setDataEarning] = useState(0)
const [totalProduction, setTotalProduction] = useState(0)
const [metric, setMetric] = useState(false)

const getData = () => {
if (data.buildings === undefined) {
return
Expand All @@ -122,15 +125,31 @@ const RenewableDetailsModal = ({ filter, data, setVisible, visible }: RenewableD
res.renewable.map((el: any) => {
el.resources.map((resource: any) => {
if (Object.keys(resource).includes(filter))
tmp.push([el.date, Number(Object.values(resource)).toFixed(2)])
tmp.push({ x: el.date, y: Number(Object.values(resource)).toFixed(2) })
})
sortDate(tmp)
setData(tmp)
})
filter === "Solar" && setDataEarning(res.totalSolar / 1000 * data.organization / 100)
filter === "Wind" && setDataEarning(res.totalWind / 1000 * data.organization / 100)
filter === "Hydro" && setDataEarning(res.totalHydro / 1000 * data.organization / 100)
filter === "Geo" && setDataEarning(res.totalGeo / 1000 * data.organization / 100)
sortDate(tmp)
setData(tmp)
switch (filter) {
case "Solar":
setDataEarning(res.totalSolar / 1000 * data.organization / 100)
setTotalProduction(res.totalSolar)
break;
case "Wind":
setDataEarning(res.totalWind / 1000 * data.organization / 100)
setTotalProduction(res.totalSolar)
break;
case "Hydro":
setDataEarning(res.totalHydro / 1000 * data.organization / 100)
setTotalProduction(res.totalHydro)
break;
case "Geo":
setDataEarning(res.totalGeo / 1000 * data.organization / 100)
setTotalProduction(res.totalGeo)
break;
default:
break;
}
}).catch(() => { return })
})
}
Expand Down Expand Up @@ -178,14 +197,23 @@ const RenewableDetailsModal = ({ filter, data, setVisible, visible }: RenewableD
<Card style={{ borderRadius: 20, boxShadow: "0 2px 4px rgba(0,0,0,0.2)", }}>
<Row align="top" gutter={[32, 32]} >
<Col span={12}>
<Statistic title="Total Electric Usage" value={0} suffix={metric ? "Kilowatt (kW)" : "Watt"} precision={2} />
<Statistic title="Total Electric Usage"
value={!metric ? totalProduction : totalProduction / 1000}
suffix={metric ? "Kilowatt (kW)" : "Watt"}
precision={2} />
<Row align="middle">
<span onClick={() => setMetric(!metric)} style={{ color: "blue", marginRight: 6, cursor: "pointer" }} className="anticon iconfont">&#xe615;</span>
<IconFont type="i-arrow_up_down_circle"
onClick={() => setMetric(!metric)}
style={{ color: "blue", marginRight: 6, cursor: "pointer" }}
className="anticon iconfont" />
<p style={{ color: "grey", fontSize: "18px", fontWeight: "lighter", margin: 0 }}>{!metric ? "Kilowatt (kWh)" : "Watt"}</p>
</Row>
</Col>
<Col span={12}>
<Statistic title="Total Earnings" value={0} suffix={metric ? "Kilowatt (kW)" : "Watt"} precision={2} />
<Statistic title="Total Earnings"
value={dataEarning}
suffix={"€"}
precision={2} />
</Col>
</Row>
<Divider />
Expand Down
2 changes: 1 addition & 1 deletion test/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ describe('renewable', () => {
const result = await api.renewable.createResources(testBody);

expect(axios.post).toHaveBeenCalledTimes(1);
expect(axios.post).toHaveBeenCalledWith(`${API_URL}/renewable`, testBody);
expect(axios.post).toHaveBeenCalledWith(`${API_URL}/renewable/renewable`, testBody);
expect(result).toEqual(expectedData);
});
});
Expand Down

0 comments on commit 0316255

Please sign in to comment.