From cc2947c7a22912c46713e6173d4e3d607b411168 Mon Sep 17 00:00:00 2001 From: Patrick Fic <> Date: Thu, 27 Aug 2020 15:56:01 -0700 Subject: [PATCH] Updated parts status graph and formatting. BOD-328 --- bodyshop_translations.babel | 21 +++ .../job-detail-cards.component.jsx | 4 +- .../job-detail-cards.parts.component.jsx | 130 +----------------- .../job-detail-cards.totals.component.jsx | 13 +- .../parts-status-pie.component.jsx | 108 ++++++++++++--- client/src/translations/en_us/common.json | 3 +- client/src/translations/es/common.json | 3 +- client/src/translations/fr/common.json | 3 +- .../1598568175188_run_sql_migration/down.yaml | 1 + .../1598568175188_run_sql_migration/up.yaml | 8 ++ .../1598568298727_run_sql_migration/down.yaml | 1 + .../1598568298727_run_sql_migration/up.yaml | 8 ++ .../1598568331134_run_sql_migration/down.yaml | 1 + .../1598568331134_run_sql_migration/up.yaml | 8 ++ 14 files changed, 150 insertions(+), 162 deletions(-) create mode 100644 hasura/migrations/1598568175188_run_sql_migration/down.yaml create mode 100644 hasura/migrations/1598568175188_run_sql_migration/up.yaml create mode 100644 hasura/migrations/1598568298727_run_sql_migration/down.yaml create mode 100644 hasura/migrations/1598568298727_run_sql_migration/up.yaml create mode 100644 hasura/migrations/1598568331134_run_sql_migration/down.yaml create mode 100644 hasura/migrations/1598568331134_run_sql_migration/up.yaml diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel index 388cccfec..9d85f2a45 100644 --- a/bodyshop_translations.babel +++ b/bodyshop_translations.babel @@ -9860,6 +9860,27 @@ + + nostatus + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + diff --git a/client/src/components/job-detail-cards/job-detail-cards.component.jsx b/client/src/components/job-detail-cards/job-detail-cards.component.jsx index d7442d2dd..6a5fdee95 100644 --- a/client/src/components/job-detail-cards/job-detail-cards.component.jsx +++ b/client/src/components/job-detail-cards/job-detail-cards.component.jsx @@ -145,7 +145,7 @@ export function JobDetailCards({ setPrintCenterContext }) { data={data ? data.jobs_by_pk : null} /> - + - + joblines_stats", - // joblines_status - // ); - - const memoizedData = useMemo(() => Calculatedata(joblines_status), [ - joblines_status, - ]); - - const [state, setState] = useState({ activeIndex: 0 }); - - const onPieEnter = (data, index) => { - setState({ - activeIndex: index, - }); - }; return (
- - - +
); } - -const Calculatedata = (data) => { - if (data.length > 0) { - const statusMapping = {}; - data.map((i) => { - if (!statusMapping[i.status]) - statusMapping[i.status] = { name: i.status || "No Status*", value: 0 }; - statusMapping[i.status].value = statusMapping[i.status].value + i.count; - return null; - }); - return Object.keys(statusMapping).map((key) => { - return statusMapping[key]; - }); - } else { - return [ - { name: "Group A", value: 400 }, - { name: "Group B", value: 300 }, - { name: "Group C", value: 300 }, - { name: "Group D", value: 200 }, - ]; - } -}; - -const renderActiveShape = (props) => { - const RADIAN = Math.PI / 180; - const { - cx, - cy, - midAngle, - innerRadius, - outerRadius, - startAngle, - endAngle, - fill, - payload, - percent, - value, - } = props; - const sin = Math.sin(-RADIAN * midAngle); - const cos = Math.cos(-RADIAN * midAngle); - const sx = cx + (outerRadius + 10) * cos; - const sy = cy + (outerRadius + 10) * sin; - const mx = cx + (outerRadius + 30) * cos; - const my = cy + (outerRadius + 30) * sin; - const ex = mx + (cos >= 0 ? 1 : -1) * 22; - const ey = my; - const textAnchor = cos >= 0 ? "start" : "end"; - - return ( - - - {payload.name} - - - - - - = 0 ? 1 : -1) * 12} - y={ey} - textAnchor={textAnchor} - fill="#333" - >{`Count: ${value}`} - = 0 ? 1 : -1) * 12} - y={ey} - dy={18} - textAnchor={textAnchor} - fill="#999" - > - {`(${(percent * 100).toFixed(2)}%)`} - - - ); -}; diff --git a/client/src/components/job-detail-cards/job-detail-cards.totals.component.jsx b/client/src/components/job-detail-cards/job-detail-cards.totals.component.jsx index ad5a7f787..31236a9e4 100644 --- a/client/src/components/job-detail-cards/job-detail-cards.totals.component.jsx +++ b/client/src/components/job-detail-cards/job-detail-cards.totals.component.jsx @@ -6,22 +6,15 @@ import CardTemplate from "./job-detail-cards.template.component"; export default function JobDetailCardsTotalsComponent({ loading, data }) { const { t } = useTranslation(); - let totals; - - try { - totals = JSON.parse(data.job_totals); - } catch (error) { - console.log("Error in CardsTotal component", error); - } return ( - {totals ? ( + {data.job_totals ? (
) : ( diff --git a/client/src/components/parts-status-pie/parts-status-pie.component.jsx b/client/src/components/parts-status-pie/parts-status-pie.component.jsx index 1afe6abc6..ee574c527 100644 --- a/client/src/components/parts-status-pie/parts-status-pie.component.jsx +++ b/client/src/components/parts-status-pie/parts-status-pie.component.jsx @@ -1,25 +1,93 @@ -import React from "react"; +import React, { useCallback, useMemo } from "react"; +import { connect } from "react-redux"; +import { Cell, Pie, PieChart, ResponsiveContainer } from "recharts"; +import { createStructuredSelector } from "reselect"; +import { selectBodyshop } from "../../redux/user/user.selectors"; +import { useTranslation } from "react-i18next"; +const mapStateToProps = createStructuredSelector({ + bodyshop: selectBodyshop, +}); -export default function PartsStatusPie({ partsList }) { - return
Parts Pie
; - //const [pieData, setPieData] = useState([]); +export function PartsStatusPie({ bodyshop, joblines_status }) { + const { t } = useTranslation(); + const pieColor = useCallback( + (status) => { + if (status === bodyshop.md_order_statuses.default_ordered) + return "lightgreen"; + if (status === bodyshop.md_order_statuses.default_bo) return "crimson"; - // const result = partsList - // ? partsList.reduce((names, name) => { - // const val = name || "?"; - // const count = names[val] || 0; - // names[val] = count + 1; - // return names; - // }, {}) - // : {}; + if (status === bodyshop.md_order_statuses.default_canceled) + return "dodgerblue"; - // const pieData = Object.keys(result).map((i) => { - // return { - // id: i, - // label: i, - // value: result[i], - // }; - // }); + if (status === bodyshop.md_order_statuses.default_returned) + return "powderblue"; + if (status === bodyshop.md_order_statuses.default_received) + return "seagreen"; - // return
{JSON.stringify(pieData)}
; + return "slategray"; + }, + [ + bodyshop.md_order_statuses.default_ordered, + bodyshop.md_order_statuses.default_bo, + bodyshop.md_order_statuses.default_canceled, + bodyshop.md_order_statuses.default_returned, + bodyshop.md_order_statuses.default_received, + ] + ); + + const Calculatedata = useCallback( + (data) => { + if (data.length > 0) { + const statusMapping = {}; + data.map((i) => { + if (!statusMapping[i.status]) + statusMapping[i.status] = { + name: i.status || t("joblines.labels.nostatus"), + value: 0, + color: pieColor(i.status), + }; + statusMapping[i.status].value = + statusMapping[i.status].value + i.count; + return null; + }); + return Object.keys(statusMapping).map((key) => { + return statusMapping[key]; + }); + } else { + return []; + } + }, + [pieColor, t] + ); + + const memoizedData = useMemo(() => Calculatedata(joblines_status), [ + joblines_status, + Calculatedata, + ]); + + console.log("PartsStatusPie -> memoizedData", memoizedData); + + return ( +
+ + + `${entry.name} - ${entry.value}`} + labelLine + > + {memoizedData.map((entry, index) => ( + + ))} + + + +
+ ); } +export default connect(mapStateToProps, null)(PartsStatusPie); diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index 8fb636e64..625ce00c1 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -635,7 +635,8 @@ }, "labels": { "edit": "Edit Line", - "new": "New Line" + "new": "New Line", + "nostatus": "No Status" }, "successes": { "created": "Job line created successfully.", diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json index 905f9116b..b21708348 100644 --- a/client/src/translations/es/common.json +++ b/client/src/translations/es/common.json @@ -635,7 +635,8 @@ }, "labels": { "edit": "Línea de edición", - "new": "Nueva línea" + "new": "Nueva línea", + "nostatus": "" }, "successes": { "created": "", diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json index 8e0efd463..2630ee048 100644 --- a/client/src/translations/fr/common.json +++ b/client/src/translations/fr/common.json @@ -635,7 +635,8 @@ }, "labels": { "edit": "Ligne d'édition", - "new": "Nouvelle ligne" + "new": "Nouvelle ligne", + "nostatus": "" }, "successes": { "created": "", diff --git a/hasura/migrations/1598568175188_run_sql_migration/down.yaml b/hasura/migrations/1598568175188_run_sql_migration/down.yaml new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/hasura/migrations/1598568175188_run_sql_migration/down.yaml @@ -0,0 +1 @@ +[] diff --git a/hasura/migrations/1598568175188_run_sql_migration/up.yaml b/hasura/migrations/1598568175188_run_sql_migration/up.yaml new file mode 100644 index 000000000..7f90cb120 --- /dev/null +++ b/hasura/migrations/1598568175188_run_sql_migration/up.yaml @@ -0,0 +1,8 @@ +- args: + cascade: true + read_only: false + sql: "CREATE OR REPLACE VIEW \"public\".\"joblines_status\" AS \n SELECT j.jobid,\n + \ j.status,\n count(1) AS count,\n j.part_type\n FROM joblines j\n + \ where j.part_type is not null\n GROUP BY j.jobid, j.status, j.part_type\n + \ ;" + type: run_sql diff --git a/hasura/migrations/1598568298727_run_sql_migration/down.yaml b/hasura/migrations/1598568298727_run_sql_migration/down.yaml new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/hasura/migrations/1598568298727_run_sql_migration/down.yaml @@ -0,0 +1 @@ +[] diff --git a/hasura/migrations/1598568298727_run_sql_migration/up.yaml b/hasura/migrations/1598568298727_run_sql_migration/up.yaml new file mode 100644 index 000000000..7f90cb120 --- /dev/null +++ b/hasura/migrations/1598568298727_run_sql_migration/up.yaml @@ -0,0 +1,8 @@ +- args: + cascade: true + read_only: false + sql: "CREATE OR REPLACE VIEW \"public\".\"joblines_status\" AS \n SELECT j.jobid,\n + \ j.status,\n count(1) AS count,\n j.part_type\n FROM joblines j\n + \ where j.part_type is not null\n GROUP BY j.jobid, j.status, j.part_type\n + \ ;" + type: run_sql diff --git a/hasura/migrations/1598568331134_run_sql_migration/down.yaml b/hasura/migrations/1598568331134_run_sql_migration/down.yaml new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/hasura/migrations/1598568331134_run_sql_migration/down.yaml @@ -0,0 +1 @@ +[] diff --git a/hasura/migrations/1598568331134_run_sql_migration/up.yaml b/hasura/migrations/1598568331134_run_sql_migration/up.yaml new file mode 100644 index 000000000..0ed3a7e15 --- /dev/null +++ b/hasura/migrations/1598568331134_run_sql_migration/up.yaml @@ -0,0 +1,8 @@ +- args: + cascade: true + read_only: false + sql: "CREATE OR REPLACE VIEW \"public\".\"joblines_status\" AS \n SELECT j.jobid,\n + \ j.status,\n count(1) AS count,\n j.part_type\n FROM joblines j\n + \ where j.part_type is not null and j.part_type <> 'PAE'\n GROUP BY j.jobid, + j.status, j.part_type\n ;" + type: run_sql