From 8701559d3293f15b8f811bd2416347fb21562a96 Mon Sep 17 00:00:00 2001 From: Pierce Trey Date: Mon, 9 Aug 2021 11:05:45 -0600 Subject: [PATCH] allow specifying uuid type to search for --- src/components/Contract/ContractList.tsx | 62 ++++++++++++++++++- .../Contract/ContractListContainer.tsx | 18 +++++- 2 files changed, 75 insertions(+), 5 deletions(-) diff --git a/src/components/Contract/ContractList.tsx b/src/components/Contract/ContractList.tsx index 8ca078e..03f0437 100644 --- a/src/components/Contract/ContractList.tsx +++ b/src/components/Contract/ContractList.tsx @@ -6,6 +6,9 @@ import { getContractTimeSeries } from 'helpers/contract'; import { Table, TableRow, TD } from 'components/Table'; import { H2 } from 'components/Text'; import { Navbar } from 'components/Navbar'; +import { Dropdown } from 'components/Dropdown'; +import styled from 'styled-components'; +import { Color } from 'Constant'; const contractTimeFormatter = (diffS: number) => { const duration = moment.duration(diffS, 's'); @@ -44,16 +47,71 @@ interface TypeSelectorProps { interface ContractListProps { searchTerm?: string; searchChanged: (term?: string) => void; + searchColumn?: string; + searchColumnChanged: (column: string) => void; contracts: Contract[]; type: string; typeChanged: (type: string) => void; } -const ContractList: FunctionComponent = ({ contracts, searchTerm = '', searchChanged, type, typeChanged }) => { +const SearchToggle = styled.span` + padding: 10px 30px 10px 10px; + border-radius: 4px; + font-size: 1.4rem; + line-height: 2.2rem; + border: 1px solid ${Color.LIGHT_GREY}; + display: inline-block; + position: relative; + + &:hover { + border-color: ${Color.BLUE}; + background-color: ${Color.WHITE}; + } + + &:after { + content: ''; + position: absolute; + right: 10px; + top: 50%; + transform: translateY(-50%); + vertical-align: text-bottom; + border-top: 7.5px solid ${Color.GREY}; + border-left: 5px solid transparent; + border-right: 5px solid transparent; + } +` + +const Equals = styled.div` + margin: 0 5px; +` + +const SearchWrapper = styled.div` + display: flex; + align-items: center; + font-size: 1.4rem; + line-height: 2.2rem; +` + +const SearchableColumns = [ + { key: 'scope_uuid', display: 'Scope Uuid' }, + { key: 'execution_uuid', display: 'Execution Uuid' }, + { key: 'group_uuid', display: 'Group Uuid' }, + { key: 'uuid', display: 'Envelope Uuid' }, +] + +const SearchColumnDisplay = SearchableColumns.reduce((acc, column) => acc.set(column.key, column.display), new Map()) + +const ContractList: FunctionComponent = ({ contracts, searchColumn = '', searchColumnChanged, searchTerm = '', searchChanged, type, typeChanged }) => { return ( <> Contracts}> - + + {SearchColumnDisplay.get(searchColumn)}} menuList={SearchableColumns.map(column => + searchColumnChanged(column.key)}>{column.display} + )}> + = + + { const { params, setParam } = useQueryParams(); - const [searchTerm, setSearchTerm] = useState(params.q); + const [column, uuid] = params.q?.split(',') || ['scope_uuid', '']; + const [searchColumn, setSearchColumn] = useState(column); + const [searchTerm, setSearchTerm] = useState(uuid); const [type, setType] = useState(params.type || 'invoker'); - const { contracts, fetchingContracts } = useContractIndex(searchTerm, type); + const { contracts, fetchingContracts } = useContractIndex(searchTerm?.trim().length > 0 ? `${searchColumn},${searchTerm}` : '', type); + + const setQ = (column, uuid) => setParam('q', `${column},${uuid}`); + + const searchColumnChanged = column => { + setSearchColumn(column); + setQ(column, searchTerm); + }; const searchChanged = term => { setSearchTerm(term); - setParam('q', term); + setQ(searchColumn, term) }; + const typeChanged = type => { setType(type); setParam('type', type); @@ -26,6 +36,8 @@ const ContractListContainer = () => { contracts={contracts} searchTerm={searchTerm} searchChanged={searchChanged} + searchColumn={searchColumn} + searchColumnChanged={searchColumnChanged} type={type} typeChanged={typeChanged} />