Connect search component to monitor table
This commit is contained in:
1 parent
b8d2dd834a
commit
07190f82d5
4 files changed
+42
-9
No files matched your search
@@ -15,15 +15,26 @@ import SearchIcon from "../../../assets/icons/search.svg?react";
|
|||||||
* @param {Object} props.sx - Additional styles to apply to the component
|
* @param {Object} props.sx - Additional styles to apply to the component
|
||||||
* @returns {JSX.Element} The rendered Search component
|
* @returns {JSX.Element} The rendered Search component
|
||||||
*/
|
*/
|
||||||
const Search = ({ id, options, filteredBy, value, handleChange, sx }) => {
|
const Search = ({
|
||||||
|
id,
|
||||||
|
options,
|
||||||
|
filteredBy,
|
||||||
|
value,
|
||||||
|
handleInputChange,
|
||||||
|
handleChange,
|
||||||
|
sx,
|
||||||
|
}) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Autocomplete
|
<Autocomplete
|
||||||
id={id}
|
id={id}
|
||||||
inputValue={value}
|
inputValue={value}
|
||||||
onInputChange={(event, newValue) => {
|
onInputChange={(_, newValue) => {
|
||||||
handleChange(newValue);
|
handleInputChange(newValue);
|
||||||
|
}}
|
||||||
|
onChange={(_, newValue) => {
|
||||||
|
handleChange && handleChange(newValue);
|
||||||
}}
|
}}
|
||||||
fullWidth
|
fullWidth
|
||||||
freeSolo
|
freeSolo
|
||||||
@@ -131,7 +142,8 @@ Search.propTypes = {
|
|||||||
options: PropTypes.array.isRequired,
|
options: PropTypes.array.isRequired,
|
||||||
filteredBy: PropTypes.string.isRequired,
|
filteredBy: PropTypes.string.isRequired,
|
||||||
value: PropTypes.string.isRequired,
|
value: PropTypes.string.isRequired,
|
||||||
handleChange: PropTypes.func.isRequired,
|
handleInputChange: PropTypes.func.isRequired,
|
||||||
|
handleChange: PropTypes.func,
|
||||||
sx: PropTypes.object,
|
sx: PropTypes.object,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ TablePaginationActions.propTypes = {
|
|||||||
onPageChange: PropTypes.func.isRequired,
|
onPageChange: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
const MonitorTable = ({ isAdmin }) => {
|
const MonitorTable = ({ isAdmin, filter }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
@@ -155,7 +155,7 @@ const MonitorTable = ({ isAdmin }) => {
|
|||||||
normalize: true,
|
normalize: true,
|
||||||
page: page,
|
page: page,
|
||||||
rowsPerPage: rowsPerPage,
|
rowsPerPage: rowsPerPage,
|
||||||
filter: null,
|
filter: filter,
|
||||||
field: sort.field,
|
field: sort.field,
|
||||||
order: sort.order,
|
order: sort.order,
|
||||||
});
|
});
|
||||||
@@ -166,7 +166,7 @@ const MonitorTable = ({ isAdmin }) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchPage();
|
fetchPage();
|
||||||
}, [updateTrigger, authState, page, rowsPerPage]);
|
}, [updateTrigger, authState, page, rowsPerPage, filter, sort]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to calculate the range of displayed rows.
|
* Helper function to calculate the range of displayed rows.
|
||||||
@@ -406,6 +406,7 @@ const MonitorTable = ({ isAdmin }) => {
|
|||||||
|
|
||||||
MonitorTable.propTypes = {
|
MonitorTable.propTypes = {
|
||||||
isAdmin: PropTypes.bool,
|
isAdmin: PropTypes.bool,
|
||||||
|
filter: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
const MemoizedMonitorTable = memo(MonitorTable);
|
const MemoizedMonitorTable = memo(MonitorTable);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import Breadcrumbs from "../../../Components/Breadcrumbs";
|
|||||||
import Greeting from "../../../Utils/greeting";
|
import Greeting from "../../../Utils/greeting";
|
||||||
import MonitorTable from "./MonitorTable";
|
import MonitorTable from "./MonitorTable";
|
||||||
import Search from "../../../Components/Inputs/Search";
|
import Search from "../../../Components/Inputs/Search";
|
||||||
|
import useDebounce from "../../../Utils/debounce";
|
||||||
|
|
||||||
const Monitors = ({ isAdmin }) => {
|
const Monitors = ({ isAdmin }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@@ -21,6 +22,7 @@ const Monitors = ({ isAdmin }) => {
|
|||||||
const authState = useSelector((state) => state.auth);
|
const authState = useSelector((state) => state.auth);
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
const dispatch = useDispatch({});
|
const dispatch = useDispatch({});
|
||||||
|
const debouncedFilter = useDebounce(search, 500);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(getUptimeMonitorsByTeamId(authState.authToken));
|
dispatch(getUptimeMonitorsByTeamId(authState.authToken));
|
||||||
@@ -122,11 +124,11 @@ const Monitors = ({ isAdmin }) => {
|
|||||||
options={monitorState?.monitorsSummary.monitors}
|
options={monitorState?.monitorsSummary.monitors}
|
||||||
filteredBy="name"
|
filteredBy="name"
|
||||||
value={search}
|
value={search}
|
||||||
handleChange={setSearch}
|
handleInputChange={setSearch}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
</Stack>
|
</Stack>
|
||||||
<MonitorTable isAdmin={isAdmin} />
|
<MonitorTable isAdmin={isAdmin} filter={debouncedFilter} />
|
||||||
</Box>
|
</Box>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { useState, useEffect } from "react";
|
||||||
|
|
||||||
|
const useDebounce = (value, delay) => {
|
||||||
|
const [debouncedValue, setDebouncedValue] = useState(value);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handler = setTimeout(() => {
|
||||||
|
setDebouncedValue(value);
|
||||||
|
}, delay);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
clearTimeout(handler);
|
||||||
|
};
|
||||||
|
}, [value, delay]);
|
||||||
|
return debouncedValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useDebounce;
|
||||||
Reference in new issue
Block a user