From 852fd9c3885729c9d7d0f106c79ba0327188c1ba Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Mon, 1 May 2023 13:04:10 -0700 Subject: [PATCH] IO-2261 Sample open search replacement. --- .../jobs-list-paginated.component.jsx | 47 +++++++++++++++---- client/src/graphql/jobs.queries.js | 9 +--- .../src/pages/jobs-all/jobs-all.container.jsx | 5 +- server/opensearch/os-handler.js | 6 ++- 4 files changed, 47 insertions(+), 20 deletions(-) diff --git a/client/src/components/jobs-list-paginated/jobs-list-paginated.component.jsx b/client/src/components/jobs-list-paginated/jobs-list-paginated.component.jsx index 5ef3ab976..faa8470cc 100644 --- a/client/src/components/jobs-list-paginated/jobs-list-paginated.component.jsx +++ b/client/src/components/jobs-list-paginated/jobs-list-paginated.component.jsx @@ -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 ( { search.search = value; history.push({ search: queryString.stringify(search) }); + searchJobs(value); }} enterButton /> @@ -228,16 +253,20 @@ export function JobsList({ bodyshop, refetch, loading, jobs, total }) { > diff --git a/client/src/graphql/jobs.queries.js b/client/src/graphql/jobs.queries.js index 50225795f..103e21b16 100644 --- a/client/src/graphql/jobs.queries.js +++ b/client/src/graphql/jobs.queries.js @@ -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) } diff --git a/client/src/pages/jobs-all/jobs-all.container.jsx b/client/src/pages/jobs-all/jobs-all.container.jsx index a36745a0e..faa161571 100644 --- a/client/src/pages/jobs-all/jobs-all.container.jsx +++ b/client/src/pages/jobs-all/jobs-all.container.jsx @@ -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 : []} /> ); diff --git a/server/opensearch/os-handler.js b/server/opensearch/os-handler.js index 6bb2adcdc..e1db64fa9 100644 --- a/server/opensearch/os-handler.js +++ b/server/opensearch/os-handler.js @@ -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: {