Aded joblines status view and updated graph to use the view. BOD-110
This commit is contained in:
@@ -145,7 +145,7 @@ export function JobDetailCards({ setPrintCenterContext }) {
|
||||
data={data ? data.jobs_by_pk : null}
|
||||
/>
|
||||
</Col>
|
||||
<Col {...colBreakPoints}>
|
||||
<Col span={24}>
|
||||
<JobDetailCardsPartsComponent
|
||||
loading={loading}
|
||||
data={data ? data.jobs_by_pk : null}
|
||||
|
||||
@@ -1,14 +1,144 @@
|
||||
import React from "react";
|
||||
import React, { useState, useMemo } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import CardTemplate from "./job-detail-cards.template.component";
|
||||
import { PieChart, Pie, Sector, ResponsiveContainer } from "recharts";
|
||||
|
||||
export default function JobDetailCardsPartsComponent({ loading, data }) {
|
||||
const { t } = useTranslation();
|
||||
const { joblines_status } = data;
|
||||
// console.log(
|
||||
// "JobDetailCardsPartsComponent -> joblines_stats",
|
||||
// joblines_status
|
||||
// );
|
||||
|
||||
const memoizedData = useMemo(() => Calculatedata(joblines_status), [
|
||||
joblines_status,
|
||||
]);
|
||||
|
||||
console.log("memoizedData :>> ", memoizedData);
|
||||
const [state, setState] = useState({ activeIndex: 0 });
|
||||
|
||||
const onPieEnter = (data, index) => {
|
||||
setState({
|
||||
activeIndex: index,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<CardTemplate loading={loading} title={t("jobs.labels.cards.parts")}>
|
||||
Placeholder piechart.
|
||||
<PieChart width={400} height={400}>
|
||||
<Pie
|
||||
activeIndex={state.activeIndex}
|
||||
activeShape={renderActiveShape}
|
||||
data={memoizedData}
|
||||
cx={200}
|
||||
cy={200}
|
||||
innerRadius={60}
|
||||
outerRadius={80}
|
||||
fill="#8884d8"
|
||||
dataKey="value"
|
||||
onMouseEnter={onPieEnter}
|
||||
/>
|
||||
</PieChart>
|
||||
</CardTemplate>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const Calculatedata = (data) => {
|
||||
console.log("calculating data", 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 (
|
||||
<g>
|
||||
<text x={cx} y={cy} dy={8} textAnchor="middle" fill={fill}>
|
||||
{payload.name}
|
||||
</text>
|
||||
<Sector
|
||||
cx={cx}
|
||||
cy={cy}
|
||||
innerRadius={innerRadius}
|
||||
outerRadius={outerRadius}
|
||||
startAngle={startAngle}
|
||||
endAngle={endAngle}
|
||||
fill={fill}
|
||||
/>
|
||||
<Sector
|
||||
cx={cx}
|
||||
cy={cy}
|
||||
startAngle={startAngle}
|
||||
endAngle={endAngle}
|
||||
innerRadius={outerRadius + 6}
|
||||
outerRadius={outerRadius + 10}
|
||||
fill={fill}
|
||||
/>
|
||||
<path
|
||||
d={`M${sx},${sy}L${mx},${my}L${ex},${ey}`}
|
||||
stroke={fill}
|
||||
fill="none"
|
||||
/>
|
||||
<circle cx={ex} cy={ey} r={2} fill={fill} stroke="none" />
|
||||
<text
|
||||
x={ex + (cos >= 0 ? 1 : -1) * 12}
|
||||
y={ey}
|
||||
textAnchor={textAnchor}
|
||||
fill="#333"
|
||||
>{`Count: ${value}`}</text>
|
||||
<text
|
||||
x={ex + (cos >= 0 ? 1 : -1) * 12}
|
||||
y={ey}
|
||||
dy={18}
|
||||
textAnchor={textAnchor}
|
||||
fill="#999"
|
||||
>
|
||||
{`(${(percent * 100).toFixed(2)}%)`}
|
||||
</text>
|
||||
</g>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -4,26 +4,14 @@ import { connect } from "react-redux";
|
||||
import {
|
||||
Area,
|
||||
Bar,
|
||||
|
||||
|
||||
CartesianGrid, ComposedChart,
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Legend, Line,
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ResponsiveContainer, Tooltip, XAxis,
|
||||
YAxis
|
||||
CartesianGrid,
|
||||
ComposedChart,
|
||||
Legend,
|
||||
Line,
|
||||
ResponsiveContainer,
|
||||
Tooltip,
|
||||
XAxis,
|
||||
YAxis,
|
||||
} from "recharts";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
|
||||
@@ -415,6 +415,11 @@ export const QUERY_JOB_CARD_DETAILS = gql`
|
||||
ownr_ln
|
||||
ownr_ph1
|
||||
ownr_ea
|
||||
joblines_status {
|
||||
part_type
|
||||
count
|
||||
status
|
||||
}
|
||||
owner {
|
||||
id
|
||||
allow_text_message
|
||||
@@ -463,6 +468,7 @@ export const QUERY_JOB_CARD_DETAILS = gql`
|
||||
date_closed
|
||||
date_scheduled
|
||||
date_estimated
|
||||
|
||||
notes {
|
||||
id
|
||||
text
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
14
hasura/migrations/1596730747611_run_sql_migration/up.yaml
Normal file
14
hasura/migrations/1596730747611_run_sql_migration/up.yaml
Normal file
@@ -0,0 +1,14 @@
|
||||
- args:
|
||||
cascade: true
|
||||
read_only: false
|
||||
sql: "CREATE OR REPLACE FUNCTION public.parts_status_by_job_id(jobid uuid)\n RETURNS
|
||||
SETOF joblines\n LANGUAGE plpgsql\n STABLE\nAS $function$\n\nBEGIN\n if jobid
|
||||
= '' then\n return query select status ,count(1), part_type from joblines
|
||||
j group by status, part_type ;\n else \n return query select status ,count(1),
|
||||
part_type from joblines j where j.jobid =jobid group by status, part_type;\n
|
||||
\ end if;\n\n\tEND\n$function$;"
|
||||
type: run_sql
|
||||
- args:
|
||||
name: parts_status_by_job_id
|
||||
schema: public
|
||||
type: track_function
|
||||
@@ -0,0 +1,10 @@
|
||||
- args:
|
||||
cascade: false
|
||||
read_only: false
|
||||
sql: "CREATE OR REPLACE FUNCTION public.parts_status_by_job_id(jobid uuid)\n RETURNS
|
||||
SETOF joblines\n LANGUAGE plpgsql\n STABLE\nAS $function$\n\nBEGIN\n if jobid
|
||||
= '' then\n return query select status ,count(1), part_type from joblines
|
||||
j group by status, part_type ;\n else \n return query select status ,count(1),
|
||||
part_type from joblines j where j.jobid =jobid group by status, part_type;\n
|
||||
\ end if;\n\n\tEND\n$function$;"
|
||||
type: run_sql
|
||||
@@ -0,0 +1,5 @@
|
||||
- args:
|
||||
cascade: false
|
||||
read_only: false
|
||||
sql: DROP FUNCTION "public"."parts_status_by_job_id"("pg_catalog"."uuid");
|
||||
type: run_sql
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
14
hasura/migrations/1596731045755_run_sql_migration/up.yaml
Normal file
14
hasura/migrations/1596731045755_run_sql_migration/up.yaml
Normal file
@@ -0,0 +1,14 @@
|
||||
- args:
|
||||
cascade: true
|
||||
read_only: false
|
||||
sql: "CREATE OR REPLACE FUNCTION public.parts_status_by_job_id(jobid text)\n RETURNS
|
||||
SETOF joblines\n LANGUAGE plpgsql\n STABLE\nAS $function$\n\nBEGIN\n if jobid
|
||||
= '' then\n return query select status ,count(1), part_type from joblines
|
||||
j group by status, part_type ;\n else \n return query select status ,count(1),
|
||||
part_type from joblines j where j.jobid =jobid group by status, part_type;\n
|
||||
\ end if;\n\n\tEND\n$function$;"
|
||||
type: run_sql
|
||||
- args:
|
||||
name: parts_status_by_job_id
|
||||
schema: public
|
||||
type: track_function
|
||||
@@ -0,0 +1,10 @@
|
||||
- args:
|
||||
cascade: false
|
||||
read_only: false
|
||||
sql: "CREATE OR REPLACE FUNCTION public.parts_status_by_job_id(jobid text)\n RETURNS
|
||||
SETOF joblines\n LANGUAGE plpgsql\n STABLE\nAS $function$\n\nBEGIN\n if jobid
|
||||
= '' then\n return query select status ,count(1), part_type from joblines
|
||||
j group by status, part_type ;\n else \n return query select status ,count(1),
|
||||
part_type from joblines j where j.jobid =jobid group by status, part_type;\n
|
||||
\ end if;\n\n\tEND\n$function$;"
|
||||
type: run_sql
|
||||
@@ -0,0 +1,5 @@
|
||||
- args:
|
||||
cascade: false
|
||||
read_only: false
|
||||
sql: DROP FUNCTION "public"."parts_status_by_job_id"("pg_catalog"."text");
|
||||
type: run_sql
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
14
hasura/migrations/1596731097672_run_sql_migration/up.yaml
Normal file
14
hasura/migrations/1596731097672_run_sql_migration/up.yaml
Normal file
@@ -0,0 +1,14 @@
|
||||
- args:
|
||||
cascade: true
|
||||
read_only: false
|
||||
sql: "CREATE OR REPLACE FUNCTION public.parts_status_by_job_id(jobIdVar text)\n
|
||||
RETURNS SETOF joblines\n LANGUAGE plpgsql\n STABLE\nAS $function$\n\nBEGIN\n
|
||||
\ if jobIdVar = '' then\n return query select status ,count(1), part_type
|
||||
from joblines j group by status, part_type ;\n else \n return query select
|
||||
status ,count(1), part_type from joblines j where j.jobid =jobIdVar group by
|
||||
status, part_type;\n end if;\n\n\tEND\n$function$;"
|
||||
type: run_sql
|
||||
- args:
|
||||
name: parts_status_by_job_id
|
||||
schema: public
|
||||
type: track_function
|
||||
@@ -0,0 +1,10 @@
|
||||
- args:
|
||||
cascade: false
|
||||
read_only: false
|
||||
sql: "CREATE OR REPLACE FUNCTION public.parts_status_by_job_id(jobidvar text)\n
|
||||
RETURNS SETOF joblines\n LANGUAGE plpgsql\n STABLE\nAS $function$\n\nBEGIN\n
|
||||
\ if jobIdVar = '' then\n return query select status ,count(1), part_type
|
||||
from joblines j group by status, part_type ;\n else \n return query select
|
||||
status ,count(1), part_type from joblines j where j.jobid =jobIdVar group by
|
||||
status, part_type;\n end if;\n\n\tEND\n$function$;"
|
||||
type: run_sql
|
||||
@@ -0,0 +1,5 @@
|
||||
- args:
|
||||
cascade: false
|
||||
read_only: false
|
||||
sql: DROP FUNCTION "public"."parts_status_by_job_id"("pg_catalog"."text");
|
||||
type: run_sql
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
14
hasura/migrations/1596731190786_run_sql_migration/up.yaml
Normal file
14
hasura/migrations/1596731190786_run_sql_migration/up.yaml
Normal file
@@ -0,0 +1,14 @@
|
||||
- args:
|
||||
cascade: true
|
||||
read_only: false
|
||||
sql: "CREATE OR REPLACE FUNCTION public.parts_status_by_job_id(jobIdVar uuid)\n
|
||||
RETURNS SETOF joblines\n LANGUAGE plpgsql\n STABLE\nAS $function$\n\nBEGIN\n
|
||||
\ if jobIdVar = '' then\n return query select status ,count(1), part_type
|
||||
from joblines j group by status, part_type ;\n else \n return query select
|
||||
status ,count(1), part_type from joblines j where j.jobid =jobIdVar group by
|
||||
status, part_type;\n end if;\n\n\tEND\n$function$;"
|
||||
type: run_sql
|
||||
- args:
|
||||
name: parts_status_by_job_id
|
||||
schema: public
|
||||
type: track_function
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
@@ -0,0 +1,8 @@
|
||||
- args:
|
||||
cascade: true
|
||||
read_only: false
|
||||
sql: "CREATE OR REPLACE FUNCTION public.parts_status_by_job_id(jobidvar uuid)\n
|
||||
RETURNS SETOF joblines\n LANGUAGE plpgsql\n STABLE\nAS $function$\n\nBEGIN\n
|
||||
\ \n return query select status ,count(1), part_type from joblines j where
|
||||
j.jobid =jobIdVar group by status, part_type;\n\n\n\tEND\n$function$;"
|
||||
type: run_sql
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
@@ -0,0 +1,8 @@
|
||||
- args:
|
||||
cascade: true
|
||||
read_only: false
|
||||
sql: "CREATE OR REPLACE FUNCTION public.parts_status_by_job_id(jobidvar uuid)\n
|
||||
RETURNS SETOF joblines\n LANGUAGE plpgsql\n STABLE\nAS $function$\n\nBEGIN\n
|
||||
\ \n return query select status ,count(1), part_type from joblines j where
|
||||
j.jobid =jobidvar group by status, part_type;\n\n\n\tEND\n$function$;"
|
||||
type: run_sql
|
||||
@@ -0,0 +1,8 @@
|
||||
- args:
|
||||
cascade: false
|
||||
read_only: false
|
||||
sql: "CREATE OR REPLACE FUNCTION public.parts_status_by_job_id(jobidvar uuid)\n
|
||||
RETURNS SETOF joblines\n LANGUAGE plpgsql\n STABLE\nAS $function$\n\nBEGIN\n
|
||||
\ \n return query select status ,count(1), part_type from joblines j where
|
||||
j.jobid =jobidvar group by status, part_type;\n\n\n\tEND\n$function$;"
|
||||
type: run_sql
|
||||
@@ -0,0 +1,5 @@
|
||||
- args:
|
||||
cascade: false
|
||||
read_only: false
|
||||
sql: DROP FUNCTION "public"."parts_status_by_job_id"("pg_catalog"."uuid");
|
||||
type: run_sql
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
10
hasura/migrations/1596731602565_run_sql_migration/up.yaml
Normal file
10
hasura/migrations/1596731602565_run_sql_migration/up.yaml
Normal file
@@ -0,0 +1,10 @@
|
||||
- args:
|
||||
cascade: true
|
||||
read_only: false
|
||||
sql: create view joblines_stats as select jobid, status ,count(1), part_type
|
||||
from joblines j group by jobid, status, part_type ;
|
||||
type: run_sql
|
||||
- args:
|
||||
name: joblines_stats
|
||||
schema: public
|
||||
type: add_existing_table_or_view
|
||||
@@ -0,0 +1,5 @@
|
||||
- args:
|
||||
cascade: false
|
||||
read_only: false
|
||||
sql: alter view "public"."joblines_status" rename to "joblines_stats";
|
||||
type: run_sql
|
||||
@@ -0,0 +1,5 @@
|
||||
- args:
|
||||
cascade: false
|
||||
read_only: false
|
||||
sql: alter view "public"."joblines_stats" rename to "joblines_status";
|
||||
type: run_sql
|
||||
@@ -0,0 +1,6 @@
|
||||
- args:
|
||||
relationship: job
|
||||
table:
|
||||
name: joblines_status
|
||||
schema: public
|
||||
type: drop_relationship
|
||||
@@ -0,0 +1,13 @@
|
||||
- args:
|
||||
name: job
|
||||
table:
|
||||
name: joblines_status
|
||||
schema: public
|
||||
using:
|
||||
manual_configuration:
|
||||
column_mapping:
|
||||
jobid: id
|
||||
remote_table:
|
||||
name: jobs
|
||||
schema: public
|
||||
type: create_object_relationship
|
||||
@@ -0,0 +1,6 @@
|
||||
- args:
|
||||
relationship: joblines_status
|
||||
table:
|
||||
name: jobs
|
||||
schema: public
|
||||
type: drop_relationship
|
||||
@@ -0,0 +1,13 @@
|
||||
- args:
|
||||
name: joblines_status
|
||||
table:
|
||||
name: jobs
|
||||
schema: public
|
||||
using:
|
||||
manual_configuration:
|
||||
column_mapping:
|
||||
id: jobid
|
||||
remote_table:
|
||||
name: joblines_status
|
||||
schema: public
|
||||
type: create_array_relationship
|
||||
@@ -0,0 +1,6 @@
|
||||
- args:
|
||||
role: user
|
||||
table:
|
||||
name: joblines_status
|
||||
schema: public
|
||||
type: drop_select_permission
|
||||
@@ -0,0 +1,26 @@
|
||||
- args:
|
||||
permission:
|
||||
allow_aggregations: false
|
||||
backend_only: false
|
||||
columns:
|
||||
- jobid
|
||||
- status
|
||||
- count
|
||||
- part_type
|
||||
computed_fields: []
|
||||
filter:
|
||||
job:
|
||||
bodyshop:
|
||||
associations:
|
||||
_and:
|
||||
- user:
|
||||
authid:
|
||||
_eq: X-Hasura-User-Id
|
||||
- active:
|
||||
_eq: true
|
||||
limit: null
|
||||
role: user
|
||||
table:
|
||||
name: joblines_status
|
||||
schema: public
|
||||
type: create_select_permission
|
||||
@@ -1891,6 +1891,36 @@ tables:
|
||||
_eq: X-Hasura-User-Id
|
||||
- active:
|
||||
_eq: true
|
||||
- table:
|
||||
schema: public
|
||||
name: joblines_status
|
||||
object_relationships:
|
||||
- name: job
|
||||
using:
|
||||
manual_configuration:
|
||||
remote_table:
|
||||
schema: public
|
||||
name: jobs
|
||||
column_mapping:
|
||||
jobid: id
|
||||
select_permissions:
|
||||
- role: user
|
||||
permission:
|
||||
columns:
|
||||
- jobid
|
||||
- status
|
||||
- count
|
||||
- part_type
|
||||
filter:
|
||||
job:
|
||||
bodyshop:
|
||||
associations:
|
||||
_and:
|
||||
- user:
|
||||
authid:
|
||||
_eq: X-Hasura-User-Id
|
||||
- active:
|
||||
_eq: true
|
||||
- table:
|
||||
schema: public
|
||||
name: jobs
|
||||
@@ -1978,6 +2008,14 @@ tables:
|
||||
table:
|
||||
schema: public
|
||||
name: joblines
|
||||
- name: joblines_status
|
||||
using:
|
||||
manual_configuration:
|
||||
remote_table:
|
||||
schema: public
|
||||
name: joblines_status
|
||||
column_mapping:
|
||||
id: jobid
|
||||
- name: notes
|
||||
using:
|
||||
foreign_key_constraint_on:
|
||||
|
||||
Reference in New Issue
Block a user