Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Empty Search Experience #2679

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading