Merge pull request #2400 from automatisch/AUT-1494
feat: fix search bar to work in harmony with folders
This commit is contained in:
@@ -7,7 +7,7 @@ import FormControl from '@mui/material/FormControl';
|
|||||||
import SearchIcon from '@mui/icons-material/Search';
|
import SearchIcon from '@mui/icons-material/Search';
|
||||||
import useFormatMessage from 'hooks/useFormatMessage';
|
import useFormatMessage from 'hooks/useFormatMessage';
|
||||||
|
|
||||||
export default function SearchInput({ onChange, defaultValue = '' }) {
|
export default function SearchInput({ onChange, defaultValue = '', value }) {
|
||||||
const formatMessage = useFormatMessage();
|
const formatMessage = useFormatMessage();
|
||||||
return (
|
return (
|
||||||
<FormControl variant="outlined" fullWidth>
|
<FormControl variant="outlined" fullWidth>
|
||||||
@@ -16,6 +16,7 @@ export default function SearchInput({ onChange, defaultValue = '' }) {
|
|||||||
</InputLabel>
|
</InputLabel>
|
||||||
|
|
||||||
<OutlinedInput
|
<OutlinedInput
|
||||||
|
value={value}
|
||||||
defaultValue={defaultValue}
|
defaultValue={defaultValue}
|
||||||
id="search-input"
|
id="search-input"
|
||||||
type="text"
|
type="text"
|
||||||
@@ -36,4 +37,5 @@ export default function SearchInput({ onChange, defaultValue = '' }) {
|
|||||||
SearchInput.propTypes = {
|
SearchInput.propTypes = {
|
||||||
onChange: PropTypes.func,
|
onChange: PropTypes.func,
|
||||||
defaultValue: PropTypes.string,
|
defaultValue: PropTypes.string,
|
||||||
|
value: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ export default function Flows() {
|
|||||||
const flowName = searchParams.get('flowName') || '';
|
const flowName = searchParams.get('flowName') || '';
|
||||||
const folderId = searchParams.get('folderId');
|
const folderId = searchParams.get('folderId');
|
||||||
const currentUserAbility = useCurrentUserAbility();
|
const currentUserAbility = useCurrentUserAbility();
|
||||||
|
const [searchValue, setSearchValue] = React.useState(flowName);
|
||||||
|
|
||||||
const { data, isSuccess, isLoading } = useFlows({ flowName, page, folderId });
|
const { data, isSuccess, isLoading } = useFlows({ flowName, page, folderId });
|
||||||
|
|
||||||
@@ -47,9 +48,17 @@ export default function Flows() {
|
|||||||
const hasFlows = flows?.length;
|
const hasFlows = flows?.length;
|
||||||
const navigateToLastPage = isSuccess && !hasFlows && page > 1;
|
const navigateToLastPage = isSuccess && !hasFlows && page > 1;
|
||||||
|
|
||||||
const onSearchChange = React.useCallback((event) => {
|
const onSearchChange = React.useCallback(
|
||||||
setSearchParams({ flowName: event.target.value });
|
(event) => {
|
||||||
}, []);
|
const value = event.target.value;
|
||||||
|
setSearchValue(value);
|
||||||
|
setSearchParams({
|
||||||
|
flowName: value,
|
||||||
|
...(folderId && { folderId }),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[folderId, setSearchParams],
|
||||||
|
);
|
||||||
|
|
||||||
const getPathWithSearchParams = (page, flowName) => {
|
const getPathWithSearchParams = (page, flowName) => {
|
||||||
const searchParams = new URLSearchParams();
|
const searchParams = new URLSearchParams();
|
||||||
@@ -75,6 +84,15 @@ export default function Flows() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
React.useEffect(
|
||||||
|
function resetSearchValue() {
|
||||||
|
if (!searchParams.has('flowName')) {
|
||||||
|
setSearchValue('');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[searchParams],
|
||||||
|
);
|
||||||
|
|
||||||
React.useEffect(
|
React.useEffect(
|
||||||
function redirectToLastPage() {
|
function redirectToLastPage() {
|
||||||
if (navigateToLastPage) {
|
if (navigateToLastPage) {
|
||||||
@@ -99,7 +117,7 @@ export default function Flows() {
|
|||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<Grid item xs={12} md="auto" order={{ xs: 2, md: 1 }}>
|
<Grid item xs={12} md="auto" order={{ xs: 2, md: 1 }}>
|
||||||
<SearchInput onChange={onSearchChange} defaultValue={flowName} />
|
<SearchInput onChange={onSearchChange} value={searchValue} />
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<Grid
|
<Grid
|
||||||
|
|||||||
Reference in New Issue
Block a user