- {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