- Make sure subscription and initial query only grab jobs that have statuses that are on the board
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
@@ -37,7 +37,7 @@ const mapDispatchToProps = (dispatch) => ({
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
function ProductionBoardKanbanComponent({ data, bodyshop, refetch, insertAuditTrail, associationSettings }) {
|
function ProductionBoardKanbanComponent({ data, bodyshop, refetch, insertAuditTrail, associationSettings, statuses }) {
|
||||||
const [boardLanes, setBoardLanes] = useState({ lanes: [] });
|
const [boardLanes, setBoardLanes] = useState({ lanes: [] });
|
||||||
const [filter, setFilter] = useState({ search: "", employeeId: null });
|
const [filter, setFilter] = useState({ search: "", employeeId: null });
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
@@ -57,11 +57,7 @@ function ProductionBoardKanbanComponent({ data, bodyshop, refetch, insertAuditTr
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setIsMoving(true);
|
setIsMoving(true);
|
||||||
const newBoardData = createBoardData(
|
const newBoardData = createBoardData(statuses, data, filter);
|
||||||
[...bodyshop.md_ro_statuses.production_statuses, ...(bodyshop.md_ro_statuses.additional_board_statuses || [])],
|
|
||||||
data,
|
|
||||||
filter
|
|
||||||
);
|
|
||||||
|
|
||||||
newBoardData.lanes = newBoardData.lanes.map((lane) => ({
|
newBoardData.lanes = newBoardData.lanes.map((lane) => ({
|
||||||
...lane,
|
...lane,
|
||||||
@@ -140,17 +136,6 @@ function ProductionBoardKanbanComponent({ data, bodyshop, refetch, insertAuditTr
|
|||||||
|
|
||||||
const newChildCardNewParent = newChildCard ? draggableId : null;
|
const newChildCardNewParent = newChildCard ? draggableId : null;
|
||||||
|
|
||||||
console.log({
|
|
||||||
oldChildCard,
|
|
||||||
newChildCard,
|
|
||||||
oldChildCardNewParent,
|
|
||||||
newChildCardNewParent,
|
|
||||||
movedCardNewKanbanParent,
|
|
||||||
sameColumnTransfer,
|
|
||||||
movedCardWillBeFirst,
|
|
||||||
movedCardWillBeLast
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const update = await client.mutate({
|
const update = await client.mutate({
|
||||||
mutation: generate_UPDATE_JOB_KANBAN(
|
mutation: generate_UPDATE_JOB_KANBAN(
|
||||||
@@ -164,6 +149,8 @@ function ProductionBoardKanbanComponent({ data, bodyshop, refetch, insertAuditTr
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TODO (Note): This is causing the subscription to fire
|
||||||
|
|
||||||
insertAuditTrail({
|
insertAuditTrail({
|
||||||
jobid: draggableId,
|
jobid: draggableId,
|
||||||
operation: AuditTrailMapping.jobstatuschange(targetLane.id),
|
operation: AuditTrailMapping.jobstatuschange(targetLane.id),
|
||||||
@@ -187,7 +174,7 @@ function ProductionBoardKanbanComponent({ data, bodyshop, refetch, insertAuditTr
|
|||||||
setIsMoving(false);
|
setIsMoving(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[boardLanes, client, getCardByID, insertAuditTrail, isMoving, t]
|
[boardLanes, client, getCardByID, isMoving, t]
|
||||||
);
|
);
|
||||||
|
|
||||||
const totalHrs = useMemo(
|
const totalHrs = useMemo(
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
import { useQuery, useSubscription } from "@apollo/client";
|
|
||||||
import React, { useEffect, useMemo } from "react";
|
import React, { useEffect, useMemo } from "react";
|
||||||
|
import { useQuery, useSubscription } from "@apollo/client";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
import { QUERY_JOBS_IN_PRODUCTION, SUBSCRIPTION_JOBS_IN_PRODUCTION } from "../../graphql/jobs.queries";
|
import {
|
||||||
|
QUERY_JOBS_IN_PRODUCTION_WITH_STATUSES,
|
||||||
|
SUBSCRIPTION_JOBS_IN_PRODUCTION_WITH_STATUSES
|
||||||
|
} from "../../graphql/jobs.queries";
|
||||||
import { QUERY_KANBAN_SETTINGS } from "../../graphql/user.queries";
|
import { QUERY_KANBAN_SETTINGS } from "../../graphql/user.queries";
|
||||||
import { selectBodyshop, selectCurrentUser } from "../../redux/user/user.selectors";
|
import { selectBodyshop, selectCurrentUser } from "../../redux/user/user.selectors";
|
||||||
import ProductionBoardKanbanComponent from "./production-board-kanban.component";
|
import ProductionBoardKanbanComponent from "./production-board-kanban.component";
|
||||||
@@ -13,14 +16,26 @@ const mapStateToProps = createStructuredSelector({
|
|||||||
});
|
});
|
||||||
|
|
||||||
function ProductionBoardKanbanContainer({ bodyshop, currentUser }) {
|
function ProductionBoardKanbanContainer({ bodyshop, currentUser }) {
|
||||||
const { refetch, loading, data } = useQuery(QUERY_JOBS_IN_PRODUCTION, {
|
const combinedStatuses = useMemo(
|
||||||
|
() => [
|
||||||
|
...bodyshop.md_ro_statuses.production_statuses,
|
||||||
|
...(bodyshop.md_ro_statuses.additional_board_statuses || [])
|
||||||
|
],
|
||||||
|
[bodyshop.md_ro_statuses.production_statuses, bodyshop.md_ro_statuses.additional_board_statuses]
|
||||||
|
);
|
||||||
|
|
||||||
|
const { refetch, loading, data } = useQuery(QUERY_JOBS_IN_PRODUCTION_WITH_STATUSES, {
|
||||||
|
variables: { statuses: combinedStatuses },
|
||||||
pollInterval: 3600000,
|
pollInterval: 3600000,
|
||||||
fetchPolicy: "network-only",
|
fetchPolicy: "network-only",
|
||||||
nextFetchPolicy: "network-only",
|
nextFetchPolicy: "network-only",
|
||||||
onError: (error) => console.error(`Error fetching jobs in production: ${error.message}`)
|
onError: (error) => console.error(`Error fetching jobs in production: ${error.message}`)
|
||||||
});
|
});
|
||||||
|
|
||||||
const { data: updatedJobs } = useSubscription(SUBSCRIPTION_JOBS_IN_PRODUCTION);
|
const { data: updatedJobs } = useSubscription(SUBSCRIPTION_JOBS_IN_PRODUCTION_WITH_STATUSES, {
|
||||||
|
variables: { statuses: combinedStatuses },
|
||||||
|
onError: (error) => console.error(`Error subscribing to jobs in production: ${error.message}`)
|
||||||
|
});
|
||||||
|
|
||||||
const { loading: associationSettingsLoading, data: associationSettings } = useQuery(QUERY_KANBAN_SETTINGS, {
|
const { loading: associationSettingsLoading, data: associationSettings } = useQuery(QUERY_KANBAN_SETTINGS, {
|
||||||
variables: { email: currentUser.email },
|
variables: { email: currentUser.email },
|
||||||
@@ -28,10 +43,10 @@ function ProductionBoardKanbanContainer({ bodyshop, currentUser }) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (updatedJobs) {
|
if (updatedJobs && data) {
|
||||||
refetch().catch((err) => console.error(`Error re-fetching jobs in production: ${err.message}`));
|
refetch().catch((err) => console.error(`Error re-fetching jobs in production: ${err.message}`));
|
||||||
}
|
}
|
||||||
}, [updatedJobs, refetch]);
|
}, [updatedJobs, data, refetch]);
|
||||||
|
|
||||||
const filteredAssociationSettings = useMemo(() => {
|
const filteredAssociationSettings = useMemo(() => {
|
||||||
return associationSettings?.associations[0] || null;
|
return associationSettings?.associations[0] || null;
|
||||||
@@ -43,6 +58,8 @@ function ProductionBoardKanbanContainer({ bodyshop, currentUser }) {
|
|||||||
data={data ? data.jobs : []}
|
data={data ? data.jobs : []}
|
||||||
refetch={refetch}
|
refetch={refetch}
|
||||||
associationSettings={filteredAssociationSettings}
|
associationSettings={filteredAssociationSettings}
|
||||||
|
bodyshop={bodyshop}
|
||||||
|
statuses={combinedStatuses}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,9 +28,10 @@ const sortByParentId = (arr) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Function to create board data based on statuses and jobs, with optional filtering
|
// Function to create board data based on statuses and jobs, with optional filtering
|
||||||
export const createBoardData = (AllStatuses, Jobs, filter) => {
|
export const createBoardData = (statuses, Jobs, filter) => {
|
||||||
const { search, employeeId } = filter;
|
const { search, employeeId } = filter;
|
||||||
const lanes = AllStatuses.map((status) => ({
|
|
||||||
|
const lanes = statuses.map((status) => ({
|
||||||
id: status,
|
id: status,
|
||||||
title: status,
|
title: status,
|
||||||
cards: []
|
cards: []
|
||||||
|
|||||||
@@ -151,14 +151,6 @@ export const QUERY_PARTS_QUEUE = gql`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
export const SUBSCRIPTION_JOBS_IN_PRODUCTION = gql`
|
|
||||||
subscription SUBSCRIPTION_JOBS_IN_PRODUCTION {
|
|
||||||
jobs(where: { inproduction: { _eq: true } }) {
|
|
||||||
id
|
|
||||||
updated_at
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
export const QUERY_EXACT_JOB_IN_PRODUCTION = gql`
|
export const QUERY_EXACT_JOB_IN_PRODUCTION = gql`
|
||||||
query QUERY_EXACT_JOB_IN_PRODUCTION($id: uuid!) {
|
query QUERY_EXACT_JOB_IN_PRODUCTION($id: uuid!) {
|
||||||
@@ -904,10 +896,7 @@ export const QUERY_JOB_CARD_DETAILS = gql`
|
|||||||
status
|
status
|
||||||
}
|
}
|
||||||
|
|
||||||
joblines(
|
joblines(where: { removed: { _eq: false } }, order_by: { line_no: asc }) {
|
||||||
where: { removed: { _eq: false } }
|
|
||||||
order_by: { line_no: asc }
|
|
||||||
) {
|
|
||||||
id
|
id
|
||||||
alt_partm
|
alt_partm
|
||||||
line_no
|
line_no
|
||||||
@@ -2028,10 +2017,6 @@ export const generate_UPDATE_JOB_KANBAN = (
|
|||||||
newChildId,
|
newChildId,
|
||||||
newChildParent
|
newChildParent
|
||||||
) => {
|
) => {
|
||||||
// console.log("oldChildId", oldChildId, "oldChildNewParent", oldChildNewParent);
|
|
||||||
// console.log("Moved", movedId, movedNewParent, movedNewStatus);
|
|
||||||
// console.log("new", newChildId, newChildParent);
|
|
||||||
|
|
||||||
const oldChildQuery = `
|
const oldChildQuery = `
|
||||||
updateOldChild: update_jobs(where: { id: { _eq: "${oldChildId}" } },
|
updateOldChild: update_jobs(where: { id: { _eq: "${oldChildId}" } },
|
||||||
_set: {kanbanparent: ${oldChildNewParent ? `"${oldChildNewParent}"` : null}}) {
|
_set: {kanbanparent: ${oldChildNewParent ? `"${oldChildNewParent}"` : null}}) {
|
||||||
@@ -2542,3 +2527,97 @@ export const QUERY_PARTS_QUEUE_CARD_DETAILS = gql`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
export const QUERY_JOBS_IN_PRODUCTION_WITH_STATUSES = gql`
|
||||||
|
query QUERY_JOBS_IN_PRODUCTION($statuses: [String!]) {
|
||||||
|
jobs(where: { inproduction: { _eq: true }, status: { _in: $statuses } }) {
|
||||||
|
id
|
||||||
|
updated_at
|
||||||
|
comment
|
||||||
|
status
|
||||||
|
category
|
||||||
|
iouparent
|
||||||
|
ro_number
|
||||||
|
ownerid
|
||||||
|
ownr_fn
|
||||||
|
ownr_ln
|
||||||
|
ownr_co_nm
|
||||||
|
v_model_yr
|
||||||
|
v_model_desc
|
||||||
|
clm_no
|
||||||
|
v_make_desc
|
||||||
|
v_color
|
||||||
|
vehicleid
|
||||||
|
plate_no
|
||||||
|
actual_in
|
||||||
|
scheduled_completion
|
||||||
|
scheduled_delivery
|
||||||
|
date_last_contacted
|
||||||
|
date_next_contact
|
||||||
|
ins_co_nm
|
||||||
|
clm_total
|
||||||
|
ownr_ph1
|
||||||
|
ownr_ph2
|
||||||
|
special_coverage_policy
|
||||||
|
owner_owing
|
||||||
|
production_vars
|
||||||
|
kanbanparent
|
||||||
|
alt_transport
|
||||||
|
employee_body
|
||||||
|
employee_refinish
|
||||||
|
employee_prep
|
||||||
|
employee_csr
|
||||||
|
est_ct_fn
|
||||||
|
est_ct_ln
|
||||||
|
suspended
|
||||||
|
date_repairstarted
|
||||||
|
joblines_status {
|
||||||
|
part_type
|
||||||
|
status
|
||||||
|
count
|
||||||
|
}
|
||||||
|
labhrs: joblines_aggregate(where: { _and: [{ mod_lbr_ty: { _neq: "LAR" } }, { removed: { _eq: false } }] }) {
|
||||||
|
aggregate {
|
||||||
|
sum {
|
||||||
|
mod_lb_hrs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
larhrs: joblines_aggregate(where: { _and: [{ mod_lbr_ty: { _eq: "LAR" } }, { removed: { _eq: false } }] }) {
|
||||||
|
aggregate {
|
||||||
|
sum {
|
||||||
|
mod_lb_hrs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
subletLines: joblines(
|
||||||
|
where: { _and: { part_type: { _in: ["PAS", "PASL"] }, removed: { _eq: false } } }
|
||||||
|
order_by: { line_no: asc }
|
||||||
|
) {
|
||||||
|
id
|
||||||
|
line_desc
|
||||||
|
sublet_ignored
|
||||||
|
sublet_completed
|
||||||
|
jobid
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const SUBSCRIPTION_JOBS_IN_PRODUCTION_WITH_STATUSES = gql`
|
||||||
|
subscription SUBSCRIPTION_JOBS_IN_PRODUCTION($statuses: [String!]) {
|
||||||
|
jobs(where: { inproduction: { _eq: true }, status: { _in: $statuses } }) {
|
||||||
|
id
|
||||||
|
updated_at
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const SUBSCRIPTION_JOBS_IN_PRODUCTION = gql`
|
||||||
|
subscription SUBSCRIPTION_JOBS_IN_PRODUCTION {
|
||||||
|
jobs(where: { inproduction: { _eq: true } }) {
|
||||||
|
id
|
||||||
|
updated_at
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|||||||
Reference in New Issue
Block a user