Add Global search to Active Jobs.
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
import {BranchesOutlined, ExclamationCircleFilled, PauseCircleOutlined, SyncOutlined,} from "@ant-design/icons";
|
import {BranchesOutlined, ExclamationCircleFilled, PauseCircleOutlined, SyncOutlined,} from "@ant-design/icons";
|
||||||
import {useQuery} from "@apollo/client";
|
import {useQuery} from "@apollo/client";
|
||||||
import {Button, Card, Grid, Input, Space, Table, Tooltip} from "antd";
|
import {Button, Card, Grid, Input, Space, Table, Tooltip, Typography} from "antd";
|
||||||
import queryString from "query-string";
|
import queryString from "query-string";
|
||||||
import React, {useState} from "react";
|
import React, {useEffect, useState} from "react";
|
||||||
import {useTranslation} from "react-i18next";
|
import {useTranslation} from "react-i18next";
|
||||||
import {connect} from "react-redux";
|
import {connect} from "react-redux";
|
||||||
import {Link, useHistory, useLocation} from "react-router-dom";
|
import {Link, useHistory, useLocation} from "react-router-dom";
|
||||||
@@ -15,22 +15,27 @@ import AlertComponent from "../alert/alert.component";
|
|||||||
import ChatOpenButton from "../chat-open-button/chat-open-button.component";
|
import ChatOpenButton from "../chat-open-button/chat-open-button.component";
|
||||||
import OwnerNameDisplay from "../owner-name-display/owner-name-display.component";
|
import OwnerNameDisplay from "../owner-name-display/owner-name-display.component";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
|
import { pageLimit } from '../../utils/config';
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const mapDispatchToProps = () => ({
|
||||||
|
});
|
||||||
|
|
||||||
export function JobsList({bodyshop,}) {
|
export function JobsList({bodyshop,}) {
|
||||||
const pageLimit = 10;
|
const search = queryString.parse(useLocation().search);
|
||||||
const searchParams = queryString.parse(useLocation().search);
|
const [openSearchResults, setOpenSearchResults] = useState([]);
|
||||||
const {page, selected, sortorder, sortcolumn} = searchParams;
|
const [searchLoading, setSearchLoading] = useState(false);
|
||||||
console.dir({page, selected, sortorder, sortcolumn});
|
const {page, selected, sortorder, sortcolumn} = search;
|
||||||
|
|
||||||
const selectedBreakpoint = Object.entries(Grid.useBreakpoint())
|
const selectedBreakpoint = Object.entries(Grid.useBreakpoint())
|
||||||
.filter((screen) => !!screen[1])
|
.filter((screen) => !!screen[1])
|
||||||
.slice(-1)[0];
|
.slice(-1)[0];
|
||||||
|
|
||||||
const {loading, error, data, refetch} = useQuery(QUERY_ALL_ACTIVE_JOBS_PAGINATED, {
|
const {loading, error, data, refetch} = useQuery(QUERY_ALL_ACTIVE_JOBS_PAGINATED, {
|
||||||
|
|
||||||
variables: {
|
variables: {
|
||||||
offset: page ? (page - 1) * pageLimit : 0,
|
offset: page ? (page - 1) * pageLimit : 0,
|
||||||
limit: 10,
|
limit: 10,
|
||||||
@@ -58,34 +63,56 @@ export function JobsList({bodyshop,}) {
|
|||||||
|
|
||||||
const {t} = useTranslation();
|
const {t} = useTranslation();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const [searchText, setSearchText] = useState("");
|
|
||||||
|
|
||||||
if (error) return <AlertComponent message={error.message} type="error"/>;
|
|
||||||
|
|
||||||
const jobs = data?.jobs || [];
|
const jobs = data?.jobs || [];
|
||||||
|
|
||||||
const handleTableChange = (pagination, filters, sorter) => {
|
const handleTableChange = (pagination, filters, sorter) => {
|
||||||
|
// TODO: Is this needed?
|
||||||
setState({...state, filteredInfo: filters});
|
setState({...state, filteredInfo: filters});
|
||||||
|
|
||||||
searchParams.page = pagination.current;
|
search.page = pagination.current;
|
||||||
searchParams.sortcolumn = sorter.column && sorter.column.key;
|
search.sortcolumn = sorter.column && sorter.column.key;
|
||||||
searchParams.sortorder = sorter.order;
|
search.sortorder = sorter.order;
|
||||||
|
|
||||||
if (filters.status) {
|
if (filters.status) {
|
||||||
searchParams.statusFilters = JSON.stringify(_.flattenDeep(filters.status));
|
search.statusFilters = JSON.stringify(_.flattenDeep(filters.status));
|
||||||
} else {
|
} else {
|
||||||
delete searchParams.statusFilters;
|
delete search.statusFilters;
|
||||||
}
|
}
|
||||||
|
|
||||||
history.push({search: queryString.stringify(searchParams)});
|
history.push({search: queryString.stringify(search)});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (search.search && search.search.trim() !== "") {
|
||||||
|
searchJobs();
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (error) return <AlertComponent message={error.message} type="error"/>;
|
||||||
|
|
||||||
|
async function searchJobs(value) {
|
||||||
|
try {
|
||||||
|
setSearchLoading(true);
|
||||||
|
const searchData = await axios.post("/search", {
|
||||||
|
search: value || search.search,
|
||||||
|
index: "jobs",
|
||||||
|
});
|
||||||
|
setOpenSearchResults(searchData.data.hits.hits.map((s) => s._source));
|
||||||
|
} catch (error) {
|
||||||
|
console.log("Error while fetching search results", error);
|
||||||
|
} finally {
|
||||||
|
setSearchLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleOnRowClick = (record) => {
|
const handleOnRowClick = (record) => {
|
||||||
if (record) {
|
if (record) {
|
||||||
if (record.id) {
|
if (record.id) {
|
||||||
history.push({
|
history.push({
|
||||||
search: queryString.stringify({
|
search: queryString.stringify({
|
||||||
...searchParams,
|
...search,
|
||||||
selected: record.id,
|
selected: record.id,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
@@ -328,24 +355,42 @@ export function JobsList({bodyshop,}) {
|
|||||||
title={t("titles.bc.jobs-active")}
|
title={t("titles.bc.jobs-active")}
|
||||||
extra={
|
extra={
|
||||||
<Space wrap>
|
<Space wrap>
|
||||||
|
{search.search && (
|
||||||
|
<>
|
||||||
|
<Typography.Title level={4}>
|
||||||
|
{t("general.labels.searchresults", { search: search.search })}
|
||||||
|
</Typography.Title>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
delete search.search;
|
||||||
|
delete search.page;
|
||||||
|
history.push({ search: queryString.stringify(search) });
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("general.actions.clear")}
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
<Button onClick={() => refetch()}>
|
<Button onClick={() => refetch()}>
|
||||||
<SyncOutlined/>
|
<SyncOutlined />
|
||||||
</Button>
|
</Button>
|
||||||
<Input.Search
|
<Input.Search
|
||||||
placeholder={t("general.labels.search")}
|
placeholder={search.search || t("general.labels.search")}
|
||||||
onChange={(e) => {
|
onSearch={(value) => {
|
||||||
setSearchText(e.target.value);
|
search.search = value;
|
||||||
|
history.push({ search: queryString.stringify(search) });
|
||||||
|
searchJobs(value);
|
||||||
}}
|
}}
|
||||||
value={searchText}
|
loading={loading || searchLoading}
|
||||||
enterButton
|
enterButton
|
||||||
/>
|
/>
|
||||||
</Space>
|
</Space>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Table
|
<Table
|
||||||
loading={loading}
|
loading={loading || searchLoading }
|
||||||
pagination={
|
pagination={
|
||||||
searchParams?.search
|
search?.search
|
||||||
? {
|
? {
|
||||||
pageSize: pageLimit,
|
pageSize: pageLimit,
|
||||||
showSizeChanger: false,
|
showSizeChanger: false,
|
||||||
@@ -360,7 +405,7 @@ export function JobsList({bodyshop,}) {
|
|||||||
}
|
}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
rowKey="id"
|
rowKey="id"
|
||||||
dataSource={jobs}
|
dataSource={search?.search ? openSearchResults : jobs}
|
||||||
scroll={{
|
scroll={{
|
||||||
x: selectedBreakpoint ? scrollMapper[selectedBreakpoint[0]] : "100%",
|
x: selectedBreakpoint ? scrollMapper[selectedBreakpoint[0]] : "100%",
|
||||||
}}
|
}}
|
||||||
@@ -372,9 +417,9 @@ export function JobsList({bodyshop,}) {
|
|||||||
type: "radio",
|
type: "radio",
|
||||||
}}
|
}}
|
||||||
onChange={handleTableChange}
|
onChange={handleTableChange}
|
||||||
onRow={(record, rowIndex) => {
|
onRow={(record) => {
|
||||||
return {
|
return {
|
||||||
onClick: (event) => {
|
onClick: () => {
|
||||||
handleOnRowClick(record);
|
handleOnRowClick(record);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -384,4 +429,4 @@ export function JobsList({bodyshop,}) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default connect(mapStateToProps, null)(JobsList);
|
export default connect(mapStateToProps, mapDispatchToProps)(JobsList);
|
||||||
|
|||||||
1
client/src/utils/config.js
Normal file
1
client/src/utils/config.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export const pageLimit = 10;
|
||||||
Reference in New Issue
Block a user