Added pagingation to courtesy car detail contracts list BOD-374
This commit is contained in:
@@ -61,8 +61,11 @@ export default function ContractsList({ loading, contracts, refetch, total }) {
|
|||||||
//sorter: (a, b) => alphaSort(a.status, b.status),
|
//sorter: (a, b) => alphaSort(a.status, b.status),
|
||||||
//sortOrder:
|
//sortOrder:
|
||||||
// state.sortedInfo.columnKey === "status" && state.sortedInfo.order,
|
// state.sortedInfo.columnKey === "status" && state.sortedInfo.order,
|
||||||
render: (text, record) =>
|
render: (text, record) => (
|
||||||
`${record.courtesycar.fleetnumber} - ${record.courtesycar.year} ${record.courtesycar.make} ${record.courtesycar.model}`,
|
<Link
|
||||||
|
to={`/manage/courtesycars/${record.courtesycar.id}`}
|
||||||
|
>{`${record.courtesycar.fleetnumber} - ${record.courtesycar.year} ${record.courtesycar.make} ${record.courtesycar.model}`}</Link>
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: t("contracts.fields.status"),
|
title: t("contracts.fields.status"),
|
||||||
|
|||||||
@@ -1,15 +1,18 @@
|
|||||||
import { Table } from "antd";
|
import { Table } from "antd";
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Link } from "react-router-dom";
|
import { Link, useHistory, useLocation } from "react-router-dom";
|
||||||
import { alphaSort } from "../../utils/sorters";
|
import { alphaSort } from "../../utils/sorters";
|
||||||
import { DateFormatter } from "../../utils/DateFormatter";
|
import { DateFormatter } from "../../utils/DateFormatter";
|
||||||
|
import queryString from "query-string";
|
||||||
|
|
||||||
export default function CourtesyCarContractListComponent({ contracts }) {
|
export default function CourtesyCarContractListComponent({
|
||||||
const [state, setState] = useState({
|
contracts,
|
||||||
sortedInfo: {},
|
totalContracts,
|
||||||
filteredInfo: { text: "" },
|
}) {
|
||||||
});
|
const search = queryString.parse(useLocation().search);
|
||||||
|
const { page, sortcolumn, sortorder } = search;
|
||||||
|
const history = useHistory();
|
||||||
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
@@ -19,9 +22,7 @@ export default function CourtesyCarContractListComponent({ contracts }) {
|
|||||||
dataIndex: "agreementnumber",
|
dataIndex: "agreementnumber",
|
||||||
key: "agreementnumber",
|
key: "agreementnumber",
|
||||||
sorter: (a, b) => a.agreementnumber - b.agreementnumber,
|
sorter: (a, b) => a.agreementnumber - b.agreementnumber,
|
||||||
sortOrder:
|
sortOrder: sortcolumn === "agreementnumber" && sortorder,
|
||||||
state.sortedInfo.columnKey === "agreementnumber" &&
|
|
||||||
state.sortedInfo.order,
|
|
||||||
render: (text, record) => (
|
render: (text, record) => (
|
||||||
<Link to={`/manage/courtesycars/contracts/${record.id}`}>
|
<Link to={`/manage/courtesycars/contracts/${record.id}`}>
|
||||||
{record.agreementnumber || ""}
|
{record.agreementnumber || ""}
|
||||||
@@ -32,10 +33,7 @@ export default function CourtesyCarContractListComponent({ contracts }) {
|
|||||||
title: t("jobs.fields.ro_number"),
|
title: t("jobs.fields.ro_number"),
|
||||||
dataIndex: "job.ro_number",
|
dataIndex: "job.ro_number",
|
||||||
key: "job.ro_number",
|
key: "job.ro_number",
|
||||||
sorter: (a, b) => alphaSort(a.job.ro_number, b.job.ro_number),
|
|
||||||
sortOrder:
|
|
||||||
state.sortedInfo.columnKey === "job.ro_number" &&
|
|
||||||
state.sortedInfo.order,
|
|
||||||
render: (text, record) => (
|
render: (text, record) => (
|
||||||
<Link to={`/manage/jobs/${record.job.id}`}>
|
<Link to={`/manage/jobs/${record.job.id}`}>
|
||||||
{record.job.ro_number || ""}
|
{record.job.ro_number || ""}
|
||||||
@@ -46,9 +44,7 @@ export default function CourtesyCarContractListComponent({ contracts }) {
|
|||||||
title: t("contracts.fields.driver"),
|
title: t("contracts.fields.driver"),
|
||||||
dataIndex: "driver_ln",
|
dataIndex: "driver_ln",
|
||||||
key: "driver_ln",
|
key: "driver_ln",
|
||||||
sorter: (a, b) => alphaSort(a.driver_ln, b.driver_ln),
|
|
||||||
sortOrder:
|
|
||||||
state.sortedInfo.columnKey === "driver_ln" && state.sortedInfo.order,
|
|
||||||
render: (text, record) =>
|
render: (text, record) =>
|
||||||
`${record.driver_fn || ""} ${record.driver_ln || ""}`,
|
`${record.driver_fn || ""} ${record.driver_ln || ""}`,
|
||||||
},
|
},
|
||||||
@@ -57,8 +53,7 @@ export default function CourtesyCarContractListComponent({ contracts }) {
|
|||||||
dataIndex: "status",
|
dataIndex: "status",
|
||||||
key: "status",
|
key: "status",
|
||||||
sorter: (a, b) => alphaSort(a.status, b.status),
|
sorter: (a, b) => alphaSort(a.status, b.status),
|
||||||
sortOrder:
|
sortOrder: sortcolumn === "status" && sortorder,
|
||||||
state.sortedInfo.columnKey === "status" && state.sortedInfo.order,
|
|
||||||
render: (text, record) => t(record.status),
|
render: (text, record) => t(record.status),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -66,8 +61,7 @@ export default function CourtesyCarContractListComponent({ contracts }) {
|
|||||||
dataIndex: "start",
|
dataIndex: "start",
|
||||||
key: "start",
|
key: "start",
|
||||||
sorter: (a, b) => alphaSort(a.start, b.start),
|
sorter: (a, b) => alphaSort(a.start, b.start),
|
||||||
sortOrder:
|
sortOrder: sortcolumn === "start" && sortorder,
|
||||||
state.sortedInfo.columnKey === "start" && state.sortedInfo.order,
|
|
||||||
render: (text, record) => <DateFormatter>{record.start}</DateFormatter>,
|
render: (text, record) => <DateFormatter>{record.start}</DateFormatter>,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -75,9 +69,7 @@ export default function CourtesyCarContractListComponent({ contracts }) {
|
|||||||
dataIndex: "scheduledreturn",
|
dataIndex: "scheduledreturn",
|
||||||
key: "scheduledreturn",
|
key: "scheduledreturn",
|
||||||
sorter: (a, b) => a.scheduledreturn - b.scheduledreturn,
|
sorter: (a, b) => a.scheduledreturn - b.scheduledreturn,
|
||||||
sortOrder:
|
sortOrder: sortcolumn === "scheduledreturn" && sortorder,
|
||||||
state.sortedInfo.columnKey === "scheduledreturn" &&
|
|
||||||
state.sortedInfo.order,
|
|
||||||
render: (text, record) => (
|
render: (text, record) => (
|
||||||
<DateFormatter>{record.scheduledreturn}</DateFormatter>
|
<DateFormatter>{record.scheduledreturn}</DateFormatter>
|
||||||
),
|
),
|
||||||
@@ -85,12 +77,22 @@ export default function CourtesyCarContractListComponent({ contracts }) {
|
|||||||
];
|
];
|
||||||
|
|
||||||
const handleTableChange = (pagination, filters, sorter) => {
|
const handleTableChange = (pagination, filters, sorter) => {
|
||||||
setState({ ...state, filteredInfo: filters, sortedInfo: sorter });
|
search.page = pagination.current;
|
||||||
|
search.sortcolumn = sorter.columnKey;
|
||||||
|
search.sortorder = sorter.order;
|
||||||
|
history.push({ search: queryString.stringify(search) });
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Table
|
<Table
|
||||||
size="small"
|
size="small"
|
||||||
pagination={{ position: "top" }}
|
scroll={{ x: true }}
|
||||||
|
pagination={{
|
||||||
|
position: "top",
|
||||||
|
pageSize: 25,
|
||||||
|
current: parseInt(page || 1),
|
||||||
|
total: totalContracts,
|
||||||
|
}}
|
||||||
columns={columns.map((item) => ({ ...item }))}
|
columns={columns.map((item) => ({ ...item }))}
|
||||||
rowKey="id"
|
rowKey="id"
|
||||||
dataSource={contracts}
|
dataSource={contracts}
|
||||||
|
|||||||
@@ -13,10 +13,7 @@ export default function JobsList({ refetch, loading, jobs, total }) {
|
|||||||
const search = queryString.parse(useLocation().search);
|
const search = queryString.parse(useLocation().search);
|
||||||
const { page, sortcolumn, sortorder } = search;
|
const { page, sortcolumn, sortorder } = search;
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const [state, setState] = useState({
|
|
||||||
sortedInfo: {},
|
|
||||||
filteredInfo: { text: "" },
|
|
||||||
});
|
|
||||||
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const columns = [
|
const columns = [
|
||||||
@@ -169,7 +166,6 @@ export default function JobsList({ refetch, loading, jobs, total }) {
|
|||||||
];
|
];
|
||||||
|
|
||||||
const handleTableChange = (pagination, filters, sorter) => {
|
const handleTableChange = (pagination, filters, sorter) => {
|
||||||
setState({ ...state, filteredInfo: filters, sortedInfo: sorter });
|
|
||||||
search.page = pagination.current;
|
search.page = pagination.current;
|
||||||
search.sortcolumn = sorter.columnKey;
|
search.sortcolumn = sorter.columnKey;
|
||||||
search.sortorder = sorter.order;
|
search.sortorder = sorter.order;
|
||||||
|
|||||||
@@ -78,7 +78,12 @@ export const QUERY_ALL_CC = gql`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
export const QUERY_CC_BY_PK = gql`
|
export const QUERY_CC_BY_PK = gql`
|
||||||
query QUERY_CC_BY_PK($id: uuid!) {
|
query QUERY_CC_BY_PK(
|
||||||
|
$id: uuid!
|
||||||
|
$offset: Int
|
||||||
|
$limit: Int
|
||||||
|
$order: [cccontracts_order_by!]!
|
||||||
|
) {
|
||||||
courtesycars_by_pk(id: $id) {
|
courtesycars_by_pk(id: $id) {
|
||||||
bodyshopid
|
bodyshopid
|
||||||
color
|
color
|
||||||
@@ -104,7 +109,12 @@ export const QUERY_CC_BY_PK = gql`
|
|||||||
vin
|
vin
|
||||||
year
|
year
|
||||||
mileage
|
mileage
|
||||||
cccontracts {
|
cccontracts_aggregate {
|
||||||
|
aggregate {
|
||||||
|
count(distinct: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cccontracts(offset: $offset, limit: $limit, order_by: $order) {
|
||||||
agreementnumber
|
agreementnumber
|
||||||
id
|
id
|
||||||
status
|
status
|
||||||
|
|||||||
@@ -6,11 +6,15 @@ export default function CourtesyCarDetailPageComponent({
|
|||||||
contracts,
|
contracts,
|
||||||
form,
|
form,
|
||||||
saveLoading,
|
saveLoading,
|
||||||
|
totalContracts,
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<CourtesyCarCreateFormComponent form={form} saveLoading={saveLoading} />
|
<CourtesyCarCreateFormComponent form={form} saveLoading={saveLoading} />
|
||||||
<CourtesyCarContractListComponent contracts={contracts} />
|
<CourtesyCarContractListComponent
|
||||||
|
contracts={contracts}
|
||||||
|
totalContracts={totalContracts}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ import { CreateRecentItem } from "../../utils/create-recent-item";
|
|||||||
import CourtesyCarDetailPageComponent from "./courtesy-car-detail.page.component";
|
import CourtesyCarDetailPageComponent from "./courtesy-car-detail.page.component";
|
||||||
import NotFound from "../../components/not-found/not-found.component";
|
import NotFound from "../../components/not-found/not-found.component";
|
||||||
import LoadingSpinner from "../../components/loading-spinner/loading-spinner.component";
|
import LoadingSpinner from "../../components/loading-spinner/loading-spinner.component";
|
||||||
|
import queryString from "query-string";
|
||||||
|
import { useLocation } from "react-router-dom";
|
||||||
|
|
||||||
const mapDispatchToProps = (dispatch) => ({
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
setBreadcrumbs: (breadcrumbs) => dispatch(setBreadcrumbs(breadcrumbs)),
|
setBreadcrumbs: (breadcrumbs) => dispatch(setBreadcrumbs(breadcrumbs)),
|
||||||
@@ -25,13 +27,29 @@ export function CourtesyCarDetailPageContainer({
|
|||||||
setBreadcrumbs,
|
setBreadcrumbs,
|
||||||
addRecentItem,
|
addRecentItem,
|
||||||
}) {
|
}) {
|
||||||
|
const searchParams = queryString.parse(useLocation().search);
|
||||||
|
const { page, sortcolumn, sortorder } = searchParams;
|
||||||
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [insertCourtesyCar] = useMutation(UPDATE_CC);
|
const [insertCourtesyCar] = useMutation(UPDATE_CC);
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const { ccId } = useParams();
|
const { ccId } = useParams();
|
||||||
const [saveLoading, setSaveLoading] = useState(false);
|
const [saveLoading, setSaveLoading] = useState(false);
|
||||||
const { loading, error, data } = useQuery(QUERY_CC_BY_PK, {
|
const { loading, error, data } = useQuery(QUERY_CC_BY_PK, {
|
||||||
variables: { id: ccId },
|
variables: {
|
||||||
|
id: ccId,
|
||||||
|
offset: page ? (page - 1) * 25 : 0,
|
||||||
|
limit: 25,
|
||||||
|
order: [
|
||||||
|
{
|
||||||
|
[sortcolumn || "start"]: sortorder
|
||||||
|
? sortorder === "descend"
|
||||||
|
? "desc"
|
||||||
|
: "asc"
|
||||||
|
: "desc",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -142,6 +160,11 @@ export function CourtesyCarDetailPageContainer({
|
|||||||
contracts={data ? data.courtesycars_by_pk.cccontracts : []}
|
contracts={data ? data.courtesycars_by_pk.cccontracts : []}
|
||||||
form={form}
|
form={form}
|
||||||
saveLoading={saveLoading}
|
saveLoading={saveLoading}
|
||||||
|
totalContracts={
|
||||||
|
data
|
||||||
|
? data.courtesycars_by_pk.cccontracts_aggregate.aggregate.count
|
||||||
|
: 0
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</Form>
|
</Form>
|
||||||
</RbacWrapper>
|
</RbacWrapper>
|
||||||
|
|||||||
Reference in New Issue
Block a user