-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Optimize Target, Alert and Service Discovery pages #5119
Merged
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a117762
add generic component for infinite scroll and search bar
Nexucis 3da39d3
rework service discovery page
Nexucis ede945c
rework alert page
Nexucis 38a29a2
rework target page
Nexucis 8f85960
add entry in the changelog
Nexucis 5f8ec79
fix test
Nexucis a64b514
fix linter issue
Nexucis f0acd64
add infinite scroll on target
Nexucis 352002d
modify the assets
Nexucis 14b2daa
fix Changelog
Nexucis 46031b7
persis the search event
Nexucis 5b55b83
add missing bindata
Nexucis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { ComponentType, useEffect, useState } from 'react'; | ||
import InfiniteScroll from 'react-infinite-scroll-component'; | ||
|
||
const initialNumberOfItemsDisplayed = 50; | ||
|
||
export interface InfiniteScrollItemsProps<T> { | ||
items: T[]; | ||
} | ||
|
||
interface CustomInfiniteScrollProps<T> { | ||
allItems: T[]; | ||
child: ComponentType<InfiniteScrollItemsProps<T>>; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
const CustomInfiniteScroll = <T extends unknown>({ allItems, child }: CustomInfiniteScrollProps<T>) => { | ||
const [items, setItems] = useState<T[]>(allItems.slice(0, 50)); | ||
const [index, setIndex] = useState<number>(initialNumberOfItemsDisplayed); | ||
const [hasMore, setHasMore] = useState<boolean>(allItems.length > initialNumberOfItemsDisplayed); | ||
const Child = child; | ||
|
||
useEffect(() => { | ||
setItems(allItems.slice(0, initialNumberOfItemsDisplayed)); | ||
setHasMore(allItems.length > initialNumberOfItemsDisplayed); | ||
}, [allItems]); | ||
|
||
const fetchMoreData = () => { | ||
if (items.length === allItems.length) { | ||
setHasMore(false); | ||
} else { | ||
const newIndex = index + initialNumberOfItemsDisplayed; | ||
setIndex(newIndex); | ||
setItems(allItems.slice(0, newIndex)); | ||
} | ||
}; | ||
|
||
return ( | ||
<InfiniteScroll | ||
next={fetchMoreData} | ||
hasMore={hasMore} | ||
loader={<h4>loading...</h4>} | ||
dataLength={items.length} | ||
height={items.length > 25 ? '75vh' : ''} | ||
> | ||
<Child items={items} /> | ||
</InfiniteScroll> | ||
); | ||
}; | ||
|
||
export default CustomInfiniteScroll; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React, { ChangeEvent, FC } from 'react'; | ||
import { Input, InputGroup, InputGroupAddon, InputGroupText } from 'reactstrap'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { faSearch } from '@fortawesome/free-solid-svg-icons'; | ||
|
||
export interface SearchBarProps { | ||
handleChange: (e: ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => void; | ||
placeholder: string; | ||
} | ||
|
||
const SearchBar: FC<SearchBarProps> = ({ handleChange, placeholder }) => { | ||
let filterTimeout: NodeJS.Timeout; | ||
|
||
const handleSearchChange = (e: ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => { | ||
clearTimeout(filterTimeout); | ||
filterTimeout = setTimeout(() => { | ||
handleChange(e); | ||
}, 300); | ||
}; | ||
|
||
return ( | ||
<InputGroup> | ||
<InputGroupAddon addonType="prepend"> | ||
<InputGroupText>{<FontAwesomeIcon icon={faSearch} />}</InputGroupText> | ||
</InputGroupAddon> | ||
<Input autoFocus onChange={handleSearchChange} placeholder={placeholder} /> | ||
</InputGroup> | ||
); | ||
}; | ||
|
||
export default SearchBar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
persist()
missing (:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put it in the global component
SearchBar
(see 46031b7).Hopefully that's the only place it's required. The function you are looking here is called by the search component where you have the debounce mechanism. So it's in this component that you should persist the event
On my side it's working, is it still broken on your side @GiedriusS