IO-2261 Sample open search replacement.
This commit is contained in:
@@ -2,7 +2,7 @@ import { SyncOutlined } from "@ant-design/icons";
|
||||
import { Button, Card, Input, Space, Table, Typography } from "antd";
|
||||
import _ from "lodash";
|
||||
import queryString from "query-string";
|
||||
import React from "react";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { Link, useHistory, useLocation } from "react-router-dom";
|
||||
@@ -11,6 +11,7 @@ import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import CurrencyFormatter from "../../utils/CurrencyFormatter";
|
||||
import StartChatButton from "../chat-open-button/chat-open-button.component";
|
||||
import OwnerNameDisplay from "../owner-name-display/owner-name-display.component";
|
||||
import axios from "axios";
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
//currentUser: selectCurrentUser
|
||||
bodyshop: selectBodyshop,
|
||||
@@ -21,6 +22,7 @@ const mapDispatchToProps = (dispatch) => ({
|
||||
|
||||
export function JobsList({ bodyshop, refetch, loading, jobs, total }) {
|
||||
const search = queryString.parse(useLocation().search);
|
||||
const [openSearchResults, setOpenSearchResults] = useState([]);
|
||||
const { page, sortcolumn, sortorder } = search;
|
||||
const history = useHistory();
|
||||
|
||||
@@ -193,6 +195,28 @@ export function JobsList({ bodyshop, refetch, loading, jobs, total }) {
|
||||
history.push({ search: queryString.stringify(search) });
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (search.search && search.search.trim() !== "") {
|
||||
// setLoading(true);
|
||||
searchJobs();
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
async function searchJobs(value) {
|
||||
try {
|
||||
const searchData = await axios.post("/search", {
|
||||
search: value || search.search,
|
||||
index: "jobs",
|
||||
});
|
||||
|
||||
setOpenSearchResults(searchData.data.hits.hits.map((s) => s._source));
|
||||
} catch (error) {
|
||||
} finally {
|
||||
//setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Card
|
||||
extra={
|
||||
@@ -220,6 +244,7 @@ export function JobsList({ bodyshop, refetch, loading, jobs, total }) {
|
||||
onSearch={(value) => {
|
||||
search.search = value;
|
||||
history.push({ search: queryString.stringify(search) });
|
||||
searchJobs(value);
|
||||
}}
|
||||
enterButton
|
||||
/>
|
||||
@@ -228,16 +253,20 @@ export function JobsList({ bodyshop, refetch, loading, jobs, total }) {
|
||||
>
|
||||
<Table
|
||||
loading={loading}
|
||||
pagination={{
|
||||
position: "top",
|
||||
pageSize: 25,
|
||||
current: parseInt(page || 1),
|
||||
total: total,
|
||||
showSizeChanger: false,
|
||||
}}
|
||||
pagination={
|
||||
search?.search
|
||||
? { pageSize: 25 }
|
||||
: {
|
||||
position: "top",
|
||||
pageSize: 25,
|
||||
current: parseInt(page || 1),
|
||||
total: total,
|
||||
showSizeChanger: false,
|
||||
}
|
||||
}
|
||||
columns={columns}
|
||||
rowKey="id"
|
||||
dataSource={jobs}
|
||||
dataSource={search?.search ? openSearchResults : jobs}
|
||||
onChange={handleTableChange}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
@@ -1781,14 +1781,12 @@ export const QUERY_ALL_JOB_FIELDS = gql`
|
||||
|
||||
export const QUERY_ALL_JOBS_PAGINATED_STATUS_FILTERED = gql`
|
||||
query QUERY_ALL_JOBS_PAGINATED_STATUS_FILTERED(
|
||||
$search: String
|
||||
$offset: Int
|
||||
$limit: Int
|
||||
$order: [jobs_order_by!]
|
||||
$statusList: [String!]
|
||||
) {
|
||||
search_jobs(
|
||||
args: { search: $search }
|
||||
jobs(
|
||||
offset: $offset
|
||||
limit: $limit
|
||||
order_by: $order
|
||||
@@ -1819,10 +1817,7 @@ export const QUERY_ALL_JOBS_PAGINATED_STATUS_FILTERED = gql`
|
||||
updated_at
|
||||
ded_amt
|
||||
}
|
||||
search_jobs_aggregate(
|
||||
args: { search: $search }
|
||||
where: { status: { _in: $statusList } }
|
||||
) {
|
||||
jobs_aggregate(where: { status: { _in: $statusList } }) {
|
||||
aggregate {
|
||||
count(distinct: true)
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ export function AllJobs({ setBreadcrumbs, setSelectedHeader }) {
|
||||
fetchPolicy: "network-only",
|
||||
nextFetchPolicy: "network-only",
|
||||
variables: {
|
||||
search: search || "",
|
||||
offset: page ? (page - 1) * 25 : 0,
|
||||
limit: 25,
|
||||
...(statusFilters ? { statusList: JSON.parse(statusFilters) } : {}),
|
||||
@@ -67,8 +66,8 @@ export function AllJobs({ setBreadcrumbs, setSelectedHeader }) {
|
||||
refetch={refetch}
|
||||
loading={loading}
|
||||
searchParams={searchParams}
|
||||
total={data ? data.search_jobs_aggregate.aggregate.count : 0}
|
||||
jobs={data ? data.search_jobs : []}
|
||||
total={data ? data.jobs_aggregate.aggregate.count : 0}
|
||||
jobs={data ? data.jobs : []}
|
||||
/>
|
||||
</RbacWrapper>
|
||||
);
|
||||
|
||||
@@ -75,6 +75,9 @@ async function OpenSearchUpdateHandler(req, res) {
|
||||
"v_model_yr",
|
||||
"v_make_desc",
|
||||
"v_model_desc",
|
||||
"clm_total",
|
||||
"plate_no",
|
||||
"ownr_ph1",
|
||||
]);
|
||||
document.bodyshopid = req.body.event.data.new.shopid;
|
||||
break;
|
||||
@@ -176,7 +179,7 @@ async function OpenSearchUpdateHandler(req, res) {
|
||||
|
||||
async function OpensearchSearchHandler(req, res) {
|
||||
try {
|
||||
const { search, bodyshopid } = req.body;
|
||||
const { search, bodyshopid, index } = req.body;
|
||||
if (!req.user) {
|
||||
res.sendStatus(401);
|
||||
return;
|
||||
@@ -205,6 +208,7 @@ async function OpensearchSearchHandler(req, res) {
|
||||
var osClient = await getClient();
|
||||
|
||||
const { body } = await osClient.search({
|
||||
...(index ? { index } : {}),
|
||||
body: {
|
||||
size: 100,
|
||||
query: {
|
||||
|
||||
Reference in New Issue
Block a user