Skip to content

Commit

Permalink
Merge pull request #1550 from bluewave-labs/fix/be/fe/search
Browse files Browse the repository at this point in the history
fix: be/fe/search, resolves #1549
  • Loading branch information
ajhollid authored Jan 10, 2025
2 parents af8f3a0 + cd14659 commit 9c484a5
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
1 change: 0 additions & 1 deletion Client/src/Components/Inputs/Search/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const Search = ({
disabled,
}) => {
const theme = useTheme();

return (
<Autocomplete
multiple={multiple}
Expand Down
2 changes: 1 addition & 1 deletion Client/src/Pages/Infrastructure/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function Infrastructure() {
page: page,
rowsPerPage: rowsPerPage,
});
setMonitors(response?.data?.data?.monitors ?? []);
setMonitors(response?.data?.data?.filteredMonitors ?? []);
setSummary(response?.data?.data?.summary ?? {});
} catch (error) {
console.error(error);
Expand Down
4 changes: 2 additions & 2 deletions Client/src/Pages/PageSpeed/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ const PageSpeed = () => {
field: null,
order: null,
});
if (res?.data?.data?.monitors) {
setMonitors(res.data.data.monitors);
if (res?.data?.data?.filteredMonitors) {
setMonitors(res.data.data.filteredMonitors);
setSummary(res.data.data.summary);
}
} catch (error) {
Expand Down
4 changes: 3 additions & 1 deletion Client/src/Pages/Uptime/Home/UptimeDataTable/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ const UptimeDataTable = ({
isAdmin,
isLoading,
monitors,
filteredMonitors,
monitorCount,
sort,
setSort,
Expand Down Expand Up @@ -274,7 +275,7 @@ const UptimeDataTable = ({
)}
<DataTable
headers={headers}
data={monitors}
data={filteredMonitors}
config={{
rowSX: {
cursor: "pointer",
Expand All @@ -300,6 +301,7 @@ UptimeDataTable.propTypes = {
isAdmin: PropTypes.bool,
isLoading: PropTypes.bool,
monitors: PropTypes.array,
filteredMonitors: PropTypes.array,
monitorCount: PropTypes.number,
sort: PropTypes.shape({
field: PropTypes.string,
Expand Down
11 changes: 7 additions & 4 deletions Client/src/Pages/Uptime/Home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ const UptimeMonitors = () => {
// Redux state
const rowsPerPage = useSelector((state) => state.ui.monitors.rowsPerPage);
// Local state
const [monitors, setMonitors] = useState([]);
const [sort, setSort] = useState({});
const [search, setSearch] = useState("");
const [page, setPage] = useState(0);
const [isSearching, setIsSearching] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const [monitorUpdateTrigger, setMonitorUpdateTrigger] = useState(false);
const [monitors, setMonitors] = useState([]);
const [filteredMonitors, setFilteredMonitors] = useState([]);
const [monitorsSummary, setMonitorsSummary] = useState({});

// Utils
Expand Down Expand Up @@ -100,11 +101,12 @@ const UptimeMonitors = () => {
field: config.sort.field,
order: config.sort.order,
});
const { monitors, summary } = res.data.data;
const mappedMonitors = monitors.map((monitor) =>
const { monitors, filteredMonitors, summary } = res.data.data;
const mappedMonitors = filteredMonitors.map((monitor) =>
getMonitorWithPercentage(monitor, theme)
);
setMonitors(mappedMonitors);
setMonitors(monitors);
setFilteredMonitors(mappedMonitors);
setMonitorsSummary(summary);
} catch (error) {
createToast({
Expand Down Expand Up @@ -199,6 +201,7 @@ const UptimeMonitors = () => {
<UptimeDataTable
isAdmin={isAdmin}
isLoading={isLoading}
filteredMonitors={filteredMonitors}
monitors={monitors}
monitorCount={totalMonitors}
sort={sort}
Expand Down
16 changes: 13 additions & 3 deletions Server/db/mongo/modules/monitorModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,15 @@ const getMonitorsByTeamId = async (req) => {
},
],
monitors: [
{ $sort: sort },
{
$project: {
_id: 1,
name: 1,
},
},
],
filteredMonitors: [
...(filter !== undefined
? [
{
Expand Down Expand Up @@ -657,20 +666,21 @@ const getMonitorsByTeamId = async (req) => {
{
$project: {
summary: { $arrayElemAt: ["$summary", 0] },
filteredMonitors: 1,
monitors: 1,
},
},
]);

let { monitors, summary } = results[0];
monitors = monitors.map((monitor) => {
let { monitors, filteredMonitors, summary } = results[0];
filteredMonitors = filteredMonitors.map((monitor) => {
if (!monitor.checks) {
return monitor;
}
monitor.checks = NormalizeData(monitor.checks, 10, 100);
return monitor;
});
return { monitors, summary };
return { monitors, filteredMonitors, summary };
};

/**
Expand Down

0 comments on commit 9c484a5

Please sign in to comment.