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