IO-1418 Allow owner re-search on import.

This commit is contained in:
Patrick Fic
2021-10-12 16:17:31 -07:00
parent f9521483e2
commit 7562bf5c95
3 changed files with 43 additions and 22 deletions

View File

@@ -74,7 +74,6 @@ export default function OwnerFindModalComponent({
return ( return (
<div> <div>
<Table <Table
title={() => t("owners.labels.existing_owners")}
pagination={{ position: "bottom" }} pagination={{ position: "bottom" }}
columns={columns} columns={columns}
rowKey="id" rowKey="id"

View File

@@ -1,6 +1,6 @@
import { Modal } from "antd"; import { Input, Modal } from "antd";
import React from "react"; import React, { useState, useEffect } from "react";
import { useQuery } from "@apollo/client"; import { useLazyQuery, useQuery } from "@apollo/client";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { QUERY_SEARCH_OWNER_BY_IDX } from "../../graphql/owners.queries"; import { QUERY_SEARCH_OWNER_BY_IDX } from "../../graphql/owners.queries";
import AlertComponent from "../alert/alert.component"; import AlertComponent from "../alert/alert.component";
@@ -17,14 +17,27 @@ export default function OwnerFindModalContainer({
}) { }) {
//use owner object to run query and find what possible owners there are. //use owner object to run query and find what possible owners there are.
const { t } = useTranslation(); const { t } = useTranslation();
const [searchText, setSearchText] = useState(null);
const ownersList = useQuery(QUERY_SEARCH_OWNER_BY_IDX, { const [callSearchowners, ownersList] = useLazyQuery(
QUERY_SEARCH_OWNER_BY_IDX,
{
variables: { variables: {
search: owner ? `${owner.ownr_fn || ""} ${owner.ownr_ln || ""}` : null, search: searchText,
}, },
skip: !owner, }
fetchPolicy: "network-only", );
});
useEffect(() => {
if (modalProps.visible && owner) {
const s = `${owner.ownr_fn || ""} ${owner.ownr_ln || ""} ${
owner.ownr_co_nm || ""
}`;
setSearchText(s.trim());
callSearchowners({ variables: { search: s.trim() } });
}
}, [callSearchowners, modalProps.visible, owner]);
return ( return (
<Modal <Modal
@@ -35,6 +48,14 @@ export default function OwnerFindModalContainer({
{loading ? <LoadingSpinner /> : null} {loading ? <LoadingSpinner /> : null}
{error ? <AlertComponent message={error.message} type="error" /> : null} {error ? <AlertComponent message={error.message} type="error" /> : null}
{owner ? ( {owner ? (
<>
<Input.Search
value={searchText}
onChange={(e) => setSearchText(e.target.value)}
onSearch={(val) =>
callSearchowners({ variables: { search: val.trim() } })
}
/>
<OwnerFindModalComponent <OwnerFindModalComponent
selectedOwner={selectedOwner} selectedOwner={selectedOwner}
setSelectedOwner={setSelectedOwner} setSelectedOwner={setSelectedOwner}
@@ -45,6 +66,7 @@ export default function OwnerFindModalContainer({
: null : null
} }
/> />
</>
) : null} ) : null}
</Modal> </Modal>
); );

View File

@@ -2,7 +2,7 @@ import { gql } from "@apollo/client";
export const QUERY_SEARCH_OWNER_BY_IDX = gql` export const QUERY_SEARCH_OWNER_BY_IDX = gql`
query QUERY_SEARCH_OWNER_BY_IDX($search: String!) { query QUERY_SEARCH_OWNER_BY_IDX($search: String!) {
search_owners(args: { search: $search }) { search_owners(args: { search: $search }, limit: 100) {
ownr_fn ownr_fn
ownr_ln ownr_ln
ownr_ph1 ownr_ph1