Skip to content

Commit

Permalink
Fixes stale and empty search value. (#2679)
Browse files Browse the repository at this point in the history
Co-authored-by: phix <[email protected]>
  • Loading branch information
phixMe and phix authored Nov 8, 2023
1 parent 752ac23 commit 3cd3419
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
56 changes: 29 additions & 27 deletions web/src/components/search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ const i18next = require('i18next')
const INITIAL_SEARCH_FILTER = [
{
text: i18next.t('search.filter.all'),
value: 'All'
value: 'All',
},
{
icon: faCog,
foregroundColor: theme.palette.common.white,
backgroundColor: theme.palette.primary.main,
text: i18next.t('search.filter.jobs'),
value: 'JOB'
value: 'JOB',
},
{
icon: faDatabase,
foregroundColor: theme.palette.common.white,
backgroundColor: theme.palette.primary.main,
text: i18next.t('search.filter.datasets'),
value: 'DATASET'
}
value: 'DATASET',
},
]

const INITIAL_SEARCH_SORT_FILTER = [
Expand All @@ -55,12 +55,12 @@ const INITIAL_SEARCH_SORT_FILTER = [
},
{
text: i18next.t('search.filter.updated'),
value: 'UPDATE_AT'
value: 'UPDATE_AT',
},
{
text: i18next.t('search.filter.name'),
value: 'NAME'
}
value: 'NAME',
},
]

interface StateProps {
Expand Down Expand Up @@ -97,7 +97,7 @@ const Search: React.FC<SearchProps> = (props: SearchProps) => {
props.fetchSearch(q, filter, sort)
}

debounce(fetchSearch, 300) // TODO check if we need to move it in a useEffect []
debounce(fetchSearch, 300)

const location = useLocation()
React.useEffect(() => {
Expand All @@ -107,10 +107,9 @@ const Search: React.FC<SearchProps> = (props: SearchProps) => {

const onSearch = (event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
setState({ ...state, search: event.target.value, open: true })

setTimeout(() => {
fetchSearch(state.search, state.filter.toUpperCase(), state.sort.toUpperCase())
}, 1)
if (event.target.value.length > 0) {
fetchSearch(event.target.value, state.filter.toUpperCase(), state.sort.toUpperCase())
}
}

const onSelectFilter = (label: string) => {
Expand Down Expand Up @@ -241,7 +240,9 @@ const Search: React.FC<SearchProps> = (props: SearchProps) => {
{props.searchResults.size === 0 && (
<Box m={2} display={'flex'} alignItems={'center'} justifyContent={'center'}>
<MqText>
{isSearching || !isSearchingInit ? i18next.t('search.status') : i18next.t('search.none')}
{isSearching || !isSearchingInit
? i18next.t('search.status')
: i18next.t('search.none')}
</MqText>
</Box>
)}
Expand Down Expand Up @@ -284,20 +285,21 @@ const Search: React.FC<SearchProps> = (props: SearchProps) => {
<Box key={result[0].group + index}>
{result.map((listItem) => {
return (
<SearchListItem
key={listItem.name}
searchResult={listItem}
search={state.search}
selected={listItem.name === state.selected}
onClick={(nodeName) => {
setState({
...state,
open: false,
search: nodeName,
})
props.setSelectedNode(listItem.nodeId)
}}
/>
<React.Fragment key={listItem.name}>
<SearchListItem
searchResult={listItem}
search={state.search}
selected={listItem.name === state.selected}
onClick={(nodeName) => {
setState({
...state,
open: false,
search: nodeName,
})
props.setSelectedNode(listItem.nodeId)
}}
/>
</React.Fragment>
)
})}
</Box>
Expand Down
5 changes: 1 addition & 4 deletions web/src/components/search/SearchListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import React from 'react'
import moment from 'moment'

interface OwnProps {
key: string | number
searchResult: SearchResult
search: string
onClick: (nodeName: string) => void
Expand All @@ -30,7 +29,6 @@ const searchResultIcon: { [key in JobOrDataset]: JSX.Element } = {
type DkSearchListItemProps = OwnProps

const SearchListItem: React.FC<DkSearchListItemProps> = ({
key,
searchResult,
search,
onClick,
Expand All @@ -43,7 +41,6 @@ const SearchListItem: React.FC<DkSearchListItemProps> = ({
const searchMatchIndex = name.toLowerCase().indexOf(search.toLowerCase())
return (
<RouterLink
key={key}
style={{
textDecoration: 'none',
}}
Expand All @@ -69,7 +66,7 @@ const SearchListItem: React.FC<DkSearchListItemProps> = ({
'&:hover, &.selected': {
backgroundColor: darken(theme.palette.background.paper, 0.02),
},
'&:nth-child(even)': {
'&:nth-pf-type(even)': {
backgroundColor: darken(theme.palette.background.paper, 0.2),
'&:hover, &.selected': {
backgroundColor: darken(theme.palette.background.paper, 0.02),
Expand Down

0 comments on commit 3cd3419

Please sign in to comment.