Reformat all project files to use the prettier config file.
This commit is contained in:
@@ -1,159 +1,150 @@
|
||||
import {DownloadOutlined, SyncOutlined} from "@ant-design/icons";
|
||||
import {Button, Card, Input, notification, Space, Table} from "antd";
|
||||
import { DownloadOutlined, SyncOutlined } from "@ant-design/icons";
|
||||
import { Button, Card, Input, notification, Space, Table } from "antd";
|
||||
import axios from "axios";
|
||||
import React, {useState} from "react";
|
||||
import {useTranslation} from "react-i18next";
|
||||
import {connect} from "react-redux";
|
||||
import {createStructuredSelector} from "reselect";
|
||||
import {selectPartnerVersion} from "../../redux/application/application.selectors";
|
||||
import {alphaSort} from "../../utils/sorters";
|
||||
import React, { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { selectPartnerVersion } from "../../redux/application/application.selectors";
|
||||
import { alphaSort } from "../../utils/sorters";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
//currentUser: selectCurrentUser
|
||||
partnerVersion: selectPartnerVersion,
|
||||
//currentUser: selectCurrentUser
|
||||
partnerVersion: selectPartnerVersion
|
||||
});
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
//setUserLanguage: language => dispatch(setUserLanguage(language))
|
||||
//setUserLanguage: language => dispatch(setUserLanguage(language))
|
||||
});
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(JobsAvailableScan);
|
||||
|
||||
export function JobsAvailableScan({partnerVersion, refetch}) {
|
||||
const [estimatesOnDisk, setEstimatesOnDisk] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [searchText, setSearchText] = useState("");
|
||||
const [state, setState] = useState({
|
||||
sortedInfo: {},
|
||||
filteredInfo: {text: ""},
|
||||
export function JobsAvailableScan({ partnerVersion, refetch }) {
|
||||
const [estimatesOnDisk, setEstimatesOnDisk] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [searchText, setSearchText] = useState("");
|
||||
const [state, setState] = useState({
|
||||
sortedInfo: {},
|
||||
filteredInfo: { text: "" }
|
||||
});
|
||||
const { t } = useTranslation();
|
||||
|
||||
const handleTableChange = (pagination, filters, sorter) => {
|
||||
setState({ ...state, filteredInfo: filters, sortedInfo: sorter });
|
||||
};
|
||||
|
||||
const handleImport = async (filepath) => {
|
||||
setLoading(true);
|
||||
const response = await axios.post("http://localhost:1337/import/", {
|
||||
filepath
|
||||
});
|
||||
const {t} = useTranslation();
|
||||
if (response.data.success) {
|
||||
//Came through
|
||||
if (refetch) refetch();
|
||||
} else {
|
||||
notification["error"]({
|
||||
message: t("jobs.errors.scanimport", { message: response.data.error })
|
||||
});
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
const handleTableChange = (pagination, filters, sorter) => {
|
||||
setState({...state, filteredInfo: filters, sortedInfo: sorter});
|
||||
};
|
||||
const columns = [
|
||||
{
|
||||
title: t("jobs.fields.cieca_id"),
|
||||
dataIndex: "cieca_id",
|
||||
key: "cieca_id",
|
||||
sorter: (a, b) => alphaSort(a, b),
|
||||
sortOrder: state.sortedInfo.columnKey === "cieca_id" && state.sortedInfo.order
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.owner"),
|
||||
dataIndex: "owner",
|
||||
key: "owner",
|
||||
ellipsis: true,
|
||||
sorter: (a, b) => alphaSort(a.owner, b.owner),
|
||||
sortOrder: state.sortedInfo.columnKey === "owner" && state.sortedInfo.order
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.vehicle"),
|
||||
dataIndex: "vehicle",
|
||||
key: "vehicle",
|
||||
sorter: (a, b) => alphaSort(a.vehicle, b.vehicle),
|
||||
sortOrder: state.sortedInfo.columnKey === "vehicle" && state.sortedInfo.order
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.clm_no"),
|
||||
dataIndex: "clm_no",
|
||||
key: "clm_no",
|
||||
sorter: (a, b) => alphaSort(a.clm_no, b.clm_no),
|
||||
sortOrder: state.sortedInfo.columnKey === "clm_no" && state.sortedInfo.order
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.ins_co_nm"),
|
||||
dataIndex: "ins_co_nm",
|
||||
key: "ins_co_nm",
|
||||
sorter: (a, b) => alphaSort(a.ins_co_nm, b.ins_co_nm),
|
||||
sortOrder: state.sortedInfo.columnKey === "ins_co_nm" && state.sortedInfo.order
|
||||
},
|
||||
{
|
||||
title: t("general.labels.actions"),
|
||||
key: "actions",
|
||||
render: (text, record) => (
|
||||
<Button onClick={() => handleImport(record.filepath)}>
|
||||
<DownloadOutlined />
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
];
|
||||
|
||||
const handleImport = async (filepath) => {
|
||||
setLoading(true);
|
||||
const response = await axios.post("http://localhost:1337/import/", {
|
||||
filepath,
|
||||
});
|
||||
if (response.data.success) {
|
||||
//Came through
|
||||
if (refetch) refetch();
|
||||
} else {
|
||||
notification["error"]({
|
||||
message: t("jobs.errors.scanimport", {message: response.data.error}),
|
||||
});
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
const scanEstimates = async () => {
|
||||
setLoading(true);
|
||||
const estimatesOnDiskResponse = await axios.post("http://localhost:1337/scan/");
|
||||
setEstimatesOnDisk(estimatesOnDiskResponse.data);
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: t("jobs.fields.cieca_id"),
|
||||
dataIndex: "cieca_id",
|
||||
key: "cieca_id",
|
||||
sorter: (a, b) => alphaSort(a, b),
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "cieca_id" && state.sortedInfo.order,
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.owner"),
|
||||
dataIndex: "owner",
|
||||
key: "owner",
|
||||
ellipsis: true,
|
||||
sorter: (a, b) => alphaSort(a.owner, b.owner),
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "owner" && state.sortedInfo.order,
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.vehicle"),
|
||||
dataIndex: "vehicle",
|
||||
key: "vehicle",
|
||||
sorter: (a, b) => alphaSort(a.vehicle, b.vehicle),
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "vehicle" && state.sortedInfo.order,
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.clm_no"),
|
||||
dataIndex: "clm_no",
|
||||
key: "clm_no",
|
||||
sorter: (a, b) => alphaSort(a.clm_no, b.clm_no),
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "clm_no" && state.sortedInfo.order,
|
||||
},
|
||||
{
|
||||
title: t("jobs.fields.ins_co_nm"),
|
||||
dataIndex: "ins_co_nm",
|
||||
key: "ins_co_nm",
|
||||
sorter: (a, b) => alphaSort(a.ins_co_nm, b.ins_co_nm),
|
||||
sortOrder:
|
||||
state.sortedInfo.columnKey === "ins_co_nm" && state.sortedInfo.order,
|
||||
},
|
||||
{
|
||||
title: t("general.labels.actions"),
|
||||
key: "actions",
|
||||
render: (text, record) => (
|
||||
<Button onClick={() => handleImport(record.filepath)}>
|
||||
<DownloadOutlined/>
|
||||
</Button>
|
||||
),
|
||||
},
|
||||
];
|
||||
const data = estimatesOnDisk
|
||||
? searchText
|
||||
? estimatesOnDisk.filter(
|
||||
(j) =>
|
||||
(j.owner || "").toLowerCase().includes(searchText.toLowerCase()) ||
|
||||
(j.vehicle || "").toLowerCase().includes(searchText.toLowerCase()) ||
|
||||
(j.clm_no || "").toLowerCase().includes(searchText.toLowerCase())
|
||||
)
|
||||
: estimatesOnDisk
|
||||
: [];
|
||||
|
||||
const scanEstimates = async () => {
|
||||
setLoading(true);
|
||||
const estimatesOnDiskResponse = await axios.post(
|
||||
"http://localhost:1337/scan/"
|
||||
);
|
||||
setEstimatesOnDisk(estimatesOnDiskResponse.data);
|
||||
setLoading(false);
|
||||
};
|
||||
return (
|
||||
<Card
|
||||
title={t("jobs.labels.diskscan")}
|
||||
extra={
|
||||
<Space wrap>
|
||||
<Button
|
||||
loading={loading}
|
||||
disabled={!partnerVersion}
|
||||
onClick={() => {
|
||||
scanEstimates();
|
||||
}}
|
||||
>
|
||||
<SyncOutlined />
|
||||
</Button>
|
||||
|
||||
const data = estimatesOnDisk
|
||||
? searchText
|
||||
? estimatesOnDisk.filter(
|
||||
(j) =>
|
||||
(j.owner || "").toLowerCase().includes(searchText.toLowerCase()) ||
|
||||
(j.vehicle || "")
|
||||
.toLowerCase()
|
||||
.includes(searchText.toLowerCase()) ||
|
||||
(j.clm_no || "").toLowerCase().includes(searchText.toLowerCase())
|
||||
)
|
||||
: estimatesOnDisk
|
||||
: [];
|
||||
|
||||
return (
|
||||
<Card
|
||||
title={t("jobs.labels.diskscan")}
|
||||
extra={
|
||||
<Space wrap>
|
||||
<Button
|
||||
loading={loading}
|
||||
disabled={!partnerVersion}
|
||||
onClick={() => {
|
||||
scanEstimates();
|
||||
}}
|
||||
>
|
||||
<SyncOutlined/>
|
||||
</Button>
|
||||
|
||||
<Input.Search
|
||||
placeholder={t("general.labels.search")}
|
||||
onChange={(e) => {
|
||||
setSearchText(e.currentTarget.value);
|
||||
}}
|
||||
/>
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
<Table
|
||||
loading={loading}
|
||||
pagination={{position: "top"}}
|
||||
columns={columns}
|
||||
rowKey="id"
|
||||
dataSource={data}
|
||||
onChange={handleTableChange}
|
||||
/>
|
||||
</Card>
|
||||
);
|
||||
<Input.Search
|
||||
placeholder={t("general.labels.search")}
|
||||
onChange={(e) => {
|
||||
setSearchText(e.currentTarget.value);
|
||||
}}
|
||||
/>
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
<Table
|
||||
loading={loading}
|
||||
pagination={{ position: "top" }}
|
||||
columns={columns}
|
||||
rowKey="id"
|
||||
dataSource={data}
|
||||
onChange={handleTableChange}
|
||||
/>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user