Ability to delete manually entered job lines IO-568
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import { FilterFilled, SyncOutlined } from "@ant-design/icons";
|
||||
import { useQuery } from "@apollo/react-hooks";
|
||||
import { Button, Dropdown, Input, Menu, Table } from "antd";
|
||||
import { DeleteFilled, FilterFilled, SyncOutlined } from "@ant-design/icons";
|
||||
import { useMutation, useQuery } from "@apollo/react-hooks";
|
||||
import { Button, Dropdown, Input, Menu, Space, Table } from "antd";
|
||||
import React, { useMemo, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { QUERY_BILLS_BY_JOB_REF } from "../../graphql/bill-lines.queries";
|
||||
import { DELETE_JOB_LINE_BY_PK } from "../../graphql/jobs-lines.queries";
|
||||
import { selectJobReadOnly } from "../../redux/application/application.selectors";
|
||||
import { setModalContext } from "../../redux/modals/modals.actions";
|
||||
import { onlyUnique } from "../../utils/arrayHelper";
|
||||
@@ -18,7 +19,6 @@ import JobLinesBillRefernece from "../job-lines-bill-reference/job-lines-bill-re
|
||||
// import AllocationsBulkAssignmentContainer from "../allocations-bulk-assignment/allocations-bulk-assignment.container";
|
||||
// import AllocationsEmployeeLabelContainer from "../allocations-employee-label/allocations-employee-label.container";
|
||||
import PartsOrderModalContainer from "../parts-order-modal/parts-order-modal.container";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
//currentUser: selectCurrentUser
|
||||
jobRO: selectJobReadOnly,
|
||||
@@ -44,6 +44,7 @@ export function JobLinesComponent({
|
||||
setJobLineEditContext,
|
||||
form,
|
||||
}) {
|
||||
const [deleteJobLine] = useMutation(DELETE_JOB_LINE_BY_PK);
|
||||
const {
|
||||
loading: billLinesLoading,
|
||||
error: billLinesError,
|
||||
@@ -53,9 +54,7 @@ export function JobLinesComponent({
|
||||
skip: loading,
|
||||
});
|
||||
|
||||
console.log("billLinesLoading :>> ", billLinesLoading);
|
||||
const billLinesDataObj = useMemo(() => {
|
||||
console.log("Memoized object called");
|
||||
if (!billLinesData) return {};
|
||||
const ret = {};
|
||||
billLinesData.billlines.map((b) => {
|
||||
@@ -292,7 +291,7 @@ export function JobLinesComponent({
|
||||
dataIndex: "actions",
|
||||
key: "actions",
|
||||
render: (text, record) => (
|
||||
<div>
|
||||
<Space>
|
||||
<Button
|
||||
disabled={jobRO}
|
||||
onClick={() => {
|
||||
@@ -304,6 +303,29 @@ export function JobLinesComponent({
|
||||
>
|
||||
{t("general.actions.edit")}
|
||||
</Button>
|
||||
{record.manual_line && (
|
||||
<Button
|
||||
onClick={() =>
|
||||
deleteJobLine({
|
||||
variables: { joblineId: record.id },
|
||||
update(cache) {
|
||||
cache.modify({
|
||||
id: cache.identify(job),
|
||||
fields: {
|
||||
joblines(existingJobLines, { readField }) {
|
||||
return existingJobLines.filter(
|
||||
(jlRef) => record.id !== readField("id", jlRef)
|
||||
);
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
})
|
||||
}
|
||||
>
|
||||
<DeleteFilled />
|
||||
</Button>
|
||||
)}
|
||||
{
|
||||
// <AllocationsAssignmentContainer
|
||||
// key={record.id}
|
||||
@@ -312,7 +334,7 @@ export function JobLinesComponent({
|
||||
// hours={record.mod_lb_hrs}
|
||||
// />
|
||||
}
|
||||
</div>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
@@ -33,7 +33,15 @@ function JobLinesUpsertModalContainer({
|
||||
if (!jobLineEditModal.context.id) {
|
||||
insertJobLine({
|
||||
variables: {
|
||||
lineInput: [{ jobid: jobLineEditModal.context.jobid, ...values }],
|
||||
lineInput: [
|
||||
{
|
||||
jobid: jobLineEditModal.context.jobid,
|
||||
manual_line: !(
|
||||
jobLineEditModal.context && jobLineEditModal.context.id
|
||||
),
|
||||
...values,
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
.then((r) => {
|
||||
|
||||
@@ -30,6 +30,7 @@ export default function DuplicateJob(
|
||||
_tempLines.forEach((line) => {
|
||||
delete line.id;
|
||||
delete line.__typename;
|
||||
line.manual_line = true;
|
||||
});
|
||||
|
||||
delete newJob.joblines;
|
||||
|
||||
Reference in New Issue
Block a user