feat: add search functionality to infrastructure moniter
This commit is contained in:
1 parent
275f2384c0
commit
7189c19d55
9 files changed
+158
-21
No files matched your search
@@ -0,0 +1,46 @@
|
|||||||
|
import { CircularProgress, Box } from "@mui/material";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
const LoadingSpinner = ({ shouldRender }) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
if (shouldRender === false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Box
|
||||||
|
width="100%"
|
||||||
|
height="100%"
|
||||||
|
position="absolute"
|
||||||
|
sx={{
|
||||||
|
backgroundColor: theme.palette.primary.main,
|
||||||
|
opacity: 0.8,
|
||||||
|
zIndex: 100,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Box
|
||||||
|
height="100%"
|
||||||
|
position="absolute"
|
||||||
|
top="50%"
|
||||||
|
left="50%"
|
||||||
|
sx={{
|
||||||
|
transform: "translateX(-50%)",
|
||||||
|
zIndex: 101,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<CircularProgress
|
||||||
|
sx={{
|
||||||
|
color: theme.palette.accent.main,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
LoadingSpinner.propTypes = {
|
||||||
|
shouldRender: PropTypes.bool,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default LoadingSpinner;
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
// Components
|
// Components
|
||||||
|
import { Box } from "@mui/material";
|
||||||
import DataTable from "../../../../../Components/Table";
|
import DataTable from "../../../../../Components/Table";
|
||||||
import Host from "../../../../../Components/Host";
|
import Host from "../../../../../Components/Host";
|
||||||
import { StatusLabel } from "../../../../../Components/Label";
|
import { StatusLabel } from "../../../../../Components/Label";
|
||||||
import { Stack } from "@mui/material";
|
import { Stack } from "@mui/material";
|
||||||
import { InfrastructureMenu } from "../MonitorsTableMenu";
|
import { InfrastructureMenu } from "../MonitorsTableMenu";
|
||||||
|
import LoadingSpinner from "../LoadingSpinner";
|
||||||
// Assets
|
// Assets
|
||||||
import CPUChipIcon from "../../../../../assets/icons/cpu-chip.svg?react";
|
import CPUChipIcon from "../../../../../assets/icons/cpu-chip.svg?react";
|
||||||
import CustomGauge from "../../../../../Components/Charts/CustomGauge";
|
import CustomGauge from "../../../../../Components/Charts/CustomGauge";
|
||||||
@@ -15,7 +17,7 @@ import { useNavigate } from "react-router-dom";
|
|||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
const MonitorsTable = ({ shouldRender, monitors, isAdmin, handleActionMenuDelete }) => {
|
const MonitorsTable = ({ shouldRender, monitors, isAdmin, handleActionMenuDelete, isSearching }) => {
|
||||||
// Utils
|
// Utils
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -119,23 +121,26 @@ const MonitorsTable = ({ shouldRender, monitors, isAdmin, handleActionMenuDelete
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DataTable
|
<Box position="relative">
|
||||||
shouldRender={shouldRender}
|
<LoadingSpinner shouldRender={isSearching} />
|
||||||
headers={headers}
|
<DataTable
|
||||||
data={data}
|
shouldRender={shouldRender}
|
||||||
config={{
|
headers={headers}
|
||||||
/* TODO this behavior seems to be repeated. Put it on the root table? */
|
data={data}
|
||||||
rowSX: {
|
config={{
|
||||||
cursor: "pointer",
|
/* TODO this behavior seems to be repeated. Put it on the root table? */
|
||||||
"&:hover td": {
|
rowSX: {
|
||||||
backgroundColor: theme.palette.tertiary.main,
|
cursor: "pointer",
|
||||||
transition: "background-color .3s ease",
|
"&:hover td": {
|
||||||
|
backgroundColor: theme.palette.tertiary.main,
|
||||||
|
transition: "background-color .3s ease",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
onRowClick: (row) => openDetails(row.id),
|
||||||
onRowClick: (row) => openDetails(row.id),
|
emptyView: "No monitors found",
|
||||||
emptyView: "No monitors found",
|
}}
|
||||||
}}
|
/>
|
||||||
/>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -144,6 +149,7 @@ MonitorsTable.propTypes = {
|
|||||||
monitors: PropTypes.array,
|
monitors: PropTypes.array,
|
||||||
isAdmin: PropTypes.bool,
|
isAdmin: PropTypes.bool,
|
||||||
handleActionMenuDelete: PropTypes.func,
|
handleActionMenuDelete: PropTypes.func,
|
||||||
|
isSearching: PropTypes.bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default MonitorsTable;
|
export default MonitorsTable;
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import Search from "../../../../../Components/Inputs/Search";
|
||||||
|
import { Box } from "@mui/material";
|
||||||
|
import useDebounce from "../../Hooks/useDebounce";
|
||||||
|
import { useEffect, useRef } from "react";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
|
const SearchComponent = ({ monitors = [], onSearchChange, setIsSearching }) => {
|
||||||
|
const isFirstRender = useRef(true);
|
||||||
|
const [localSearch, setLocalSearch] = useState("");
|
||||||
|
const debouncedSearch = useDebounce(localSearch, 500);
|
||||||
|
useEffect(() => {
|
||||||
|
if (isFirstRender.current === true) {
|
||||||
|
isFirstRender.current = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
onSearchChange(debouncedSearch);
|
||||||
|
setIsSearching(false);
|
||||||
|
}, [debouncedSearch, onSearchChange, setIsSearching]);
|
||||||
|
|
||||||
|
const handleSearch = (value) => {
|
||||||
|
setLocalSearch(value);
|
||||||
|
setIsSearching(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box
|
||||||
|
width="25%"
|
||||||
|
minWidth={150}
|
||||||
|
ml="auto"
|
||||||
|
mt={2}
|
||||||
|
>
|
||||||
|
<Search
|
||||||
|
options={monitors}
|
||||||
|
filteredBy="name"
|
||||||
|
inputValue={localSearch}
|
||||||
|
handleInputChange={handleSearch}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
SearchComponent.propTypes = {
|
||||||
|
monitors: PropTypes.array,
|
||||||
|
onSearchChange: PropTypes.func,
|
||||||
|
setIsSearching: PropTypes.func,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SearchComponent;
|
||||||
@@ -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;
|
||||||
@@ -3,7 +3,7 @@ import { useSelector } from "react-redux";
|
|||||||
import { networkService } from "../../../../main";
|
import { networkService } from "../../../../main";
|
||||||
import { createToast } from "../../../../Utils/toastUtils";
|
import { createToast } from "../../../../Utils/toastUtils";
|
||||||
|
|
||||||
const useMonitorFetch = ({ page, field, filter, rowsPerPage, updateTrigger }) => {
|
const useMonitorFetch = ({ page, field, filter, rowsPerPage, updateTrigger, search }) => {
|
||||||
// Redux state
|
// Redux state
|
||||||
const { user } = useSelector((state) => state.auth);
|
const { user } = useSelector((state) => state.auth);
|
||||||
|
|
||||||
@@ -24,6 +24,7 @@ const useMonitorFetch = ({ page, field, filter, rowsPerPage, updateTrigger }) =>
|
|||||||
types: ["hardware"],
|
types: ["hardware"],
|
||||||
page: page,
|
page: page,
|
||||||
rowsPerPage: rowsPerPage,
|
rowsPerPage: rowsPerPage,
|
||||||
|
search: search
|
||||||
});
|
});
|
||||||
setMonitors(response?.data?.data?.filteredMonitors ?? []);
|
setMonitors(response?.data?.data?.filteredMonitors ?? []);
|
||||||
setSummary(response?.data?.data?.summary ?? {});
|
setSummary(response?.data?.data?.summary ?? {});
|
||||||
@@ -38,7 +39,7 @@ const useMonitorFetch = ({ page, field, filter, rowsPerPage, updateTrigger }) =>
|
|||||||
};
|
};
|
||||||
|
|
||||||
fetchMonitors();
|
fetchMonitors();
|
||||||
}, [page, field, filter, rowsPerPage, user.teamId, updateTrigger]);
|
}, [page, field, filter, rowsPerPage, user.teamId, updateTrigger, search]);
|
||||||
|
|
||||||
return { monitors, summary, isLoading, networkError };
|
return { monitors, summary, isLoading, networkError };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import Pagination from "../../..//Components/Table/TablePagination";
|
|||||||
import GenericFallback from "../../../Components/GenericFallback";
|
import GenericFallback from "../../../Components/GenericFallback";
|
||||||
import Fallback from "../../../Components/Fallback";
|
import Fallback from "../../../Components/Fallback";
|
||||||
import Filter from "./Components/Filters";
|
import Filter from "./Components/Filters";
|
||||||
|
import SearchComponent from "./Components/SearchComponent";
|
||||||
// Utils
|
// Utils
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { useMonitorFetch } from "./Hooks/useMonitorFetch";
|
import { useMonitorFetch } from "./Hooks/useMonitorFetch";
|
||||||
@@ -24,6 +25,8 @@ const InfrastructureMonitors = () => {
|
|||||||
const [updateTrigger, setUpdateTrigger] = useState(false);
|
const [updateTrigger, setUpdateTrigger] = useState(false);
|
||||||
const [selectedStatus, setSelectedStatus] = useState(undefined);
|
const [selectedStatus, setSelectedStatus] = useState(undefined);
|
||||||
const [toFilterStatus, setToFilterStatus] = useState(undefined);
|
const [toFilterStatus, setToFilterStatus] = useState(undefined);
|
||||||
|
const [search, setSearch] = useState(undefined);
|
||||||
|
const [isSearching, setIsSearching] = useState(false);
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@@ -56,6 +59,7 @@ const InfrastructureMonitors = () => {
|
|||||||
filter: toFilterStatus,
|
filter: toFilterStatus,
|
||||||
rowsPerPage,
|
rowsPerPage,
|
||||||
updateTrigger,
|
updateTrigger,
|
||||||
|
search
|
||||||
});
|
});
|
||||||
|
|
||||||
if (networkError === true) {
|
if (networkError === true) {
|
||||||
@@ -108,12 +112,19 @@ const InfrastructureMonitors = () => {
|
|||||||
setToFilterStatus={setToFilterStatus}
|
setToFilterStatus={setToFilterStatus}
|
||||||
handleReset={handleReset}
|
handleReset={handleReset}
|
||||||
/>
|
/>
|
||||||
|
<SearchComponent
|
||||||
|
monitors={monitors}
|
||||||
|
onSearchChange={setSearch}
|
||||||
|
setIsSearching={setIsSearching}
|
||||||
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
<MonitorsTable
|
<MonitorsTable
|
||||||
shouldRender={!isLoading}
|
shouldRender={!isLoading}
|
||||||
monitors={monitors}
|
monitors={monitors}
|
||||||
isAdmin={isAdmin}
|
isAdmin={isAdmin}
|
||||||
handleActionMenuDelete={handleActionMenuDelete}
|
handleActionMenuDelete={handleActionMenuDelete}
|
||||||
|
isSearching={isSearching}
|
||||||
/>
|
/>
|
||||||
<Pagination
|
<Pagination
|
||||||
itemCount={summary?.totalMonitors}
|
itemCount={summary?.totalMonitors}
|
||||||
|
|||||||
@@ -182,11 +182,12 @@ class NetworkService {
|
|||||||
* @param {string} [config.filter] - The filter to apply to the monitors.
|
* @param {string} [config.filter] - The filter to apply to the monitors.
|
||||||
* @param {string} [config.field] - The field to sort by.
|
* @param {string} [config.field] - The field to sort by.
|
||||||
* @param {string} [config.order] - The order in which to sort the field.
|
* @param {string} [config.order] - The order in which to sort the field.
|
||||||
|
* @param {string} [config.search] - The search term to filter monitors by name.
|
||||||
* @returns {Promise<AxiosResponse>} The response from the axios GET request.
|
* @returns {Promise<AxiosResponse>} The response from the axios GET request.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
async getMonitorsByTeamId(config) {
|
async getMonitorsByTeamId(config) {
|
||||||
const { teamId, limit, types, page, rowsPerPage, filter, field, order } = config;
|
const { teamId, limit, types, page, rowsPerPage, filter, field, order, search } = config;
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
|
|
||||||
if (limit) params.append("limit", limit);
|
if (limit) params.append("limit", limit);
|
||||||
@@ -200,6 +201,7 @@ class NetworkService {
|
|||||||
if (filter) params.append("filter", filter);
|
if (filter) params.append("filter", filter);
|
||||||
if (field) params.append("field", field);
|
if (field) params.append("field", field);
|
||||||
if (order) params.append("order", order);
|
if (order) params.append("order", order);
|
||||||
|
if (search) params.append("search", search);
|
||||||
|
|
||||||
return this.axiosInstance.get(`/monitors/team/${teamId}?${params.toString()}`, {
|
return this.axiosInstance.get(`/monitors/team/${teamId}?${params.toString()}`, {
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@@ -510,7 +510,7 @@ const getMonitorById = async (monitorId) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getMonitorsByTeamId = async (req) => {
|
const getMonitorsByTeamId = async (req) => {
|
||||||
let { limit, type, page, rowsPerPage, filter, field, order } = req.query;
|
let { limit, type, page, rowsPerPage, filter, field, order, search } = req.query;
|
||||||
limit = parseInt(limit);
|
limit = parseInt(limit);
|
||||||
page = parseInt(page);
|
page = parseInt(page);
|
||||||
rowsPerPage = parseInt(rowsPerPage);
|
rowsPerPage = parseInt(rowsPerPage);
|
||||||
@@ -523,6 +523,9 @@ const getMonitorsByTeamId = async (req) => {
|
|||||||
if (type !== undefined) {
|
if (type !== undefined) {
|
||||||
matchStage.type = Array.isArray(type) ? { $in: type } : type;
|
matchStage.type = Array.isArray(type) ? { $in: type } : type;
|
||||||
}
|
}
|
||||||
|
if (search) {
|
||||||
|
matchStage.name = { $regex: search, $options: "i" };
|
||||||
|
}
|
||||||
|
|
||||||
const summaryResult = await Monitor.aggregate(
|
const summaryResult = await Monitor.aggregate(
|
||||||
buildMonitorSummaryByTeamIdPipeline({ matchStage })
|
buildMonitorSummaryByTeamIdPipeline({ matchStage })
|
||||||
|
|||||||
@@ -147,6 +147,7 @@ const getMonitorsByTeamIdQueryValidation = joi.object({
|
|||||||
filter: joi.string(),
|
filter: joi.string(),
|
||||||
field: joi.string(),
|
field: joi.string(),
|
||||||
order: joi.string().valid("asc", "desc"),
|
order: joi.string().valid("asc", "desc"),
|
||||||
|
search: joi.string()
|
||||||
});
|
});
|
||||||
|
|
||||||
const getMonitorStatsByIdParamValidation = joi.object({
|
const getMonitorStatsByIdParamValidation = joi.object({
|
||||||
|
|||||||
Reference in new issue
Block a user