Added vendor table filtering.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { Button, Table } from "antd";
|
import { SyncOutlined } from "@ant-design/icons";
|
||||||
|
import { Button, Input, Table } from "antd";
|
||||||
import queryString from "query-string";
|
import queryString from "query-string";
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
@@ -10,6 +11,7 @@ export default function VendorsListComponent({
|
|||||||
loading,
|
loading,
|
||||||
handleOnRowClick,
|
handleOnRowClick,
|
||||||
vendors,
|
vendors,
|
||||||
|
refetch,
|
||||||
}) {
|
}) {
|
||||||
const search = queryString.parse(useLocation().search);
|
const search = queryString.parse(useLocation().search);
|
||||||
const { selectedvendor } = search;
|
const { selectedvendor } = search;
|
||||||
@@ -18,7 +20,7 @@ export default function VendorsListComponent({
|
|||||||
sortedInfo: {},
|
sortedInfo: {},
|
||||||
filteredInfo: { text: "" },
|
filteredInfo: { text: "" },
|
||||||
});
|
});
|
||||||
|
const [searchText, setSearchText] = useState("");
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
@@ -39,13 +41,13 @@ export default function VendorsListComponent({
|
|||||||
state.sortedInfo.columnKey === "cost_center" && state.sortedInfo.order,
|
state.sortedInfo.columnKey === "cost_center" && state.sortedInfo.order,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: t("vendors.fields.street1"),
|
title: t("vendors.fields.phone"),
|
||||||
dataIndex: "street1",
|
dataIndex: "phone",
|
||||||
key: "street1",
|
key: "phone",
|
||||||
width: "10%",
|
width: "10%",
|
||||||
sorter: (a, b) => alphaSort(a.street1, b.street1),
|
sorter: (a, b) => alphaSort(a.phone, b.phone),
|
||||||
sortOrder:
|
sortOrder:
|
||||||
state.sortedInfo.columnKey === "street1" && state.sortedInfo.order,
|
state.sortedInfo.columnKey === "phone" && state.sortedInfo.order,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: t("vendors.fields.city"),
|
title: t("vendors.fields.city"),
|
||||||
@@ -58,24 +60,51 @@ export default function VendorsListComponent({
|
|||||||
setState({ ...state, filteredInfo: filters, sortedInfo: sorter });
|
setState({ ...state, filteredInfo: filters, sortedInfo: sorter });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const filteredVendors = vendors
|
||||||
|
? searchText === ""
|
||||||
|
? vendors
|
||||||
|
: vendors.filter(
|
||||||
|
(j) =>
|
||||||
|
(j.name || "")
|
||||||
|
.toString()
|
||||||
|
.toLowerCase()
|
||||||
|
.includes(searchText.toLowerCase()) ||
|
||||||
|
(j.phone || "").toLowerCase().includes(searchText.toLowerCase()) ||
|
||||||
|
(j.city || "").toLowerCase().includes(searchText.toLowerCase())
|
||||||
|
)
|
||||||
|
: [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Table
|
<Table
|
||||||
loading={loading}
|
loading={loading}
|
||||||
title={() => {
|
title={() => {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className="imex-table-header">
|
||||||
<Button onClick={handleNewVendor}>
|
<Button onClick={handleNewVendor}>
|
||||||
{t("vendors.actions.new")}
|
{t("vendors.actions.new")}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
<Button onClick={() => refetch()}>
|
||||||
|
<SyncOutlined />
|
||||||
|
</Button>
|
||||||
|
<Input.Search
|
||||||
|
className="imex-table-header__search"
|
||||||
|
placeholder={t("general.labels.search")}
|
||||||
|
onChange={(e) => {
|
||||||
|
setSearchText(e.target.value);
|
||||||
|
}}
|
||||||
|
value={searchText}
|
||||||
|
enterButton
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
size="small"
|
size="small"
|
||||||
pagination={{ position: "top" }}
|
pagination={{ position: "top" }}
|
||||||
columns={columns.map((item) => ({ ...item }))}
|
columns={columns}
|
||||||
rowKey="id"
|
rowKey="id"
|
||||||
onChange={handleTableChange}
|
onChange={handleTableChange}
|
||||||
dataSource={vendors}
|
dataSource={filteredVendors}
|
||||||
rowSelection={{
|
rowSelection={{
|
||||||
onSelect: handleOnRowClick,
|
onSelect: handleOnRowClick,
|
||||||
type: "radio",
|
type: "radio",
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import queryString from "query-string";
|
|||||||
import { useHistory, useLocation } from "react-router-dom";
|
import { useHistory, useLocation } from "react-router-dom";
|
||||||
|
|
||||||
export default function VendorsListContainer() {
|
export default function VendorsListContainer() {
|
||||||
const { loading, error, data } = useQuery(QUERY_ALL_VENDORS);
|
const { loading, error, data, refetch } = useQuery(QUERY_ALL_VENDORS);
|
||||||
const search = queryString.parse(useLocation().search);
|
const search = queryString.parse(useLocation().search);
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
|
||||||
@@ -26,13 +26,14 @@ export default function VendorsListContainer() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (error) return <AlertComponent message={error.message} type='error' />;
|
if (error) return <AlertComponent message={error.message} type="error" />;
|
||||||
return (
|
return (
|
||||||
<VendorsListComponent
|
<VendorsListComponent
|
||||||
handleNewVendor={handleNewVendor}
|
handleNewVendor={handleNewVendor}
|
||||||
handleOnRowClick={handleOnRowClick}
|
handleOnRowClick={handleOnRowClick}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
vendors={data ? data.vendors : null}
|
vendors={data ? data.vendors : null}
|
||||||
|
refetch={refetch}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ export const QUERY_TIME_TICKETS_IN_RANGE = gql`
|
|||||||
id
|
id
|
||||||
employee_number
|
employee_number
|
||||||
first_name
|
first_name
|
||||||
cost_center
|
|
||||||
last_name
|
last_name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,9 +39,9 @@ export const QUERY_ALL_VENDORS = gql`
|
|||||||
vendors(order_by: { name: asc }) {
|
vendors(order_by: { name: asc }) {
|
||||||
name
|
name
|
||||||
id
|
id
|
||||||
street1
|
|
||||||
cost_center
|
cost_center
|
||||||
city
|
city
|
||||||
|
phone
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|||||||
Reference in New Issue
Block a user