From 6dabcaa04bf75bf9508b14091de9384a54b74ec9 Mon Sep 17 00:00:00 2001 From: Quan Nguyen <86090707+qu8n@users.noreply.github.com> Date: Fri, 27 Sep 2024 12:21:27 +0000 Subject: [PATCH] Temporarily handle table element diffs between SamplesList and RecordsList components --- frontend/src/components/RecordsList.tsx | 10 +- frontend/src/shared/tableElements-records.tsx | 108 ++++++++++++++++++ 2 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 frontend/src/shared/tableElements-records.tsx diff --git a/frontend/src/components/RecordsList.tsx b/frontend/src/components/RecordsList.tsx index f593957..d4825e9 100644 --- a/frontend/src/components/RecordsList.tsx +++ b/frontend/src/components/RecordsList.tsx @@ -21,7 +21,11 @@ import SamplesList, { SampleContext } from "./SamplesList"; import { Sample, SortDirection } from "../generated/graphql"; import { defaultColDef } from "../shared/helpers"; import { PatientIdsTriplet } from "../pages/patients/PatientsPage"; -import { ErrorMessage, LoadingSpinner, Toolbar } from "../shared/tableElements"; +import { + ErrorMessage, + LoadingSpinner, + Toolbar, +} from "../shared/tableElements-records"; import { AgGridReact as AgGridReactType } from "ag-grid-react/lib/agGridReact"; import { BreadCrumb } from "../shared/components/BreadCrumb"; import { Title } from "../shared/components/Title"; @@ -284,6 +288,10 @@ export default function RecordsList({ userSearchVal={userSearchVal} setUserSearchVal={setUserSearchVal} handleSearch={handleSearch} + clearUserSearchVal={() => { + setCustomSearchVals && setCustomSearchVals([]); + setParsedSearchVals([]); + }} matchingResultsCount={`${rowCount?.toLocaleString()} matching ${ rowCount !== 1 ? dataName : dataName.slice(0, -1) }${ diff --git a/frontend/src/shared/tableElements-records.tsx b/frontend/src/shared/tableElements-records.tsx new file mode 100644 index 0000000..9c04e23 --- /dev/null +++ b/frontend/src/shared/tableElements-records.tsx @@ -0,0 +1,108 @@ +// TEMPORARY DUPLICATE OF tableElements.tsx + +import { ApolloError } from "@apollo/client"; +import classNames from "classnames"; +import { Button, Col, Form, Row } from "react-bootstrap"; +import Spinner from "react-spinkit"; +import { DataName } from "./types"; +import { Dispatch, SetStateAction } from "react"; +import { InfoToolTip } from "./components/InfoToolTip"; + +export function LoadingSpinner() { + return ( +
+ +
+ ); +} + +export function ErrorMessage({ error }: { error: ApolloError }) { + return ( + + There was an error loading data ({error.name}: {error.message}). + + ); +} + +interface IToolbarProps { + dataName: DataName; + userSearchVal: string; + setUserSearchVal: Dispatch>; + handleSearch: () => void; + clearUserSearchVal: () => void; + matchingResultsCount: string; + handleDownload: () => void; + customUILeft?: JSX.Element; + customUIRight?: JSX.Element; +} + +export function Toolbar({ + dataName, + userSearchVal, + setUserSearchVal, + handleSearch, + clearUserSearchVal, + matchingResultsCount, + handleDownload, + customUILeft, + customUIRight, +}: IToolbarProps) { + return ( + + {customUILeft} + + + { + if (event.key === "Enter") { + handleSearch(); + } + }} + onInput={(event) => { + const userSearchVal = event.currentTarget.value; + if (userSearchVal === "") { + clearUserSearchVal(); + } + setUserSearchVal(userSearchVal); + }} + /> + + + + + Click on "Search" or press "Enter" to start searching. To bulk search, + input a list of values separated by spaces or commas (example:{" "} + value1 value2 value3). To include multiple words in a + single search term, enclose them in single or double quotes (example:{" "} + "Bone Cancer"). + + + + + + + + {matchingResultsCount} + + {customUIRight} + + + + + + ); +}