Merge pull request #2440 from bluewave-labs/fix/remove-team-id-from-requests

fix: remove team id from requests
This commit is contained in:
Alexander Holliday authored and GitHub committed 2025-06-13 10:53:18 +08:00
commit c3a2ca314a
15 files changed
+34 -94

No files matched your search

+1 -1
View File
@@ -57,7 +57,7 @@ Dialog.propTypes = {
onCancel: PropTypes.func.isRequired, onCancel: PropTypes.func.isRequired,
confirmationButtonLabel: PropTypes.string.isRequired, confirmationButtonLabel: PropTypes.string.isRequired,
onConfirm: PropTypes.func.isRequired, onConfirm: PropTypes.func.isRequired,
isLoading: PropTypes.bool.isRequired, isLoading: PropTypes.bool,
}; };
export default Dialog; export default Dialog;
+2 -2
View File
@@ -136,8 +136,8 @@ const StatBox = ({
}; };
StatBox.propTypes = { StatBox.propTypes = {
heading: PropTypes.string.isRequired, heading: PropTypes.string,
subHeading: PropTypes.node.isRequired, subHeading: PropTypes.node,
gradient: PropTypes.bool, gradient: PropTypes.bool,
status: PropTypes.string, status: PropTypes.string,
sx: PropTypes.object, sx: PropTypes.object,
+2 -9
View File
@@ -6,7 +6,7 @@ import { useMonitorUtils } from "./useMonitorUtils";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
const useFetchMonitorsWithSummary = ({ teamId, types, monitorUpdateTrigger }) => { const useFetchMonitorsWithSummary = ({ types, monitorUpdateTrigger }) => {
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const [monitors, setMonitors] = useState(undefined); const [monitors, setMonitors] = useState(undefined);
const [monitorsSummary, setMonitorsSummary] = useState(undefined); const [monitorsSummary, setMonitorsSummary] = useState(undefined);
@@ -17,7 +17,6 @@ const useFetchMonitorsWithSummary = ({ teamId, types, monitorUpdateTrigger }) =>
try { try {
setIsLoading(true); setIsLoading(true);
const res = await networkService.getMonitorsWithSummaryByTeamId({ const res = await networkService.getMonitorsWithSummaryByTeamId({
teamId,
types, types,
}); });
const { monitors, summary } = res?.data?.data ?? {}; const { monitors, summary } = res?.data?.data ?? {};
@@ -34,12 +33,11 @@ const useFetchMonitorsWithSummary = ({ teamId, types, monitorUpdateTrigger }) =>
} }
}; };
fetchMonitors(); fetchMonitors();
}, [teamId, types, monitorUpdateTrigger]); }, [types, monitorUpdateTrigger]);
return [monitors, monitorsSummary, isLoading, networkError]; return [monitors, monitorsSummary, isLoading, networkError];
}; };
const useFetchMonitorsWithChecks = ({ const useFetchMonitorsWithChecks = ({
teamId,
types, types,
limit, limit,
page, page,
@@ -61,7 +59,6 @@ const useFetchMonitorsWithChecks = ({
try { try {
setIsLoading(true); setIsLoading(true);
const res = await networkService.getMonitorsWithChecksByTeamId({ const res = await networkService.getMonitorsWithChecksByTeamId({
teamId,
limit, limit,
types, types,
page, page,
@@ -95,7 +92,6 @@ const useFetchMonitorsWithChecks = ({
order, order,
page, page,
rowsPerPage, rowsPerPage,
teamId,
theme, theme,
types, types,
monitorUpdateTrigger, monitorUpdateTrigger,
@@ -104,7 +100,6 @@ const useFetchMonitorsWithChecks = ({
}; };
const useFetchMonitorsByTeamId = ({ const useFetchMonitorsByTeamId = ({
teamId,
types, types,
limit, limit,
page, page,
@@ -127,7 +122,6 @@ const useFetchMonitorsByTeamId = ({
try { try {
setIsLoading(true); setIsLoading(true);
const res = await networkService.getMonitorsByTeamId({ const res = await networkService.getMonitorsByTeamId({
teamId,
limit, limit,
types, types,
page, page,
@@ -154,7 +148,6 @@ const useFetchMonitorsByTeamId = ({
}; };
fetchMonitors(); fetchMonitors();
}, [ }, [
teamId,
types, types,
limit, limit,
page, page,
@@ -15,7 +15,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 = ({ isLoading, monitors, isAdmin, handleActionMenuDelete }) => {
// Utils // Utils
const theme = useTheme(); const theme = useTheme();
const { t } = useTranslation(); const { t } = useTranslation();
@@ -86,6 +86,7 @@ const MonitorsTable = ({ shouldRender, monitors, isAdmin, handleActionMenuDelete
monitor={row} monitor={row}
isAdmin={isAdmin} isAdmin={isAdmin}
updateCallback={handleActionMenuDelete} updateCallback={handleActionMenuDelete}
isLoading={isLoading}
/> />
), ),
}, },
@@ -120,7 +121,7 @@ const MonitorsTable = ({ shouldRender, monitors, isAdmin, handleActionMenuDelete
return ( return (
<DataTable <DataTable
shouldRender={shouldRender} shouldRender={!isLoading}
headers={headers} headers={headers}
data={data} data={data}
config={{ config={{
@@ -140,7 +141,7 @@ const MonitorsTable = ({ shouldRender, monitors, isAdmin, handleActionMenuDelete
}; };
MonitorsTable.propTypes = { MonitorsTable.propTypes = {
shouldRender: PropTypes.bool, isLoading: PropTypes.bool,
monitors: PropTypes.array, monitors: PropTypes.array,
isAdmin: PropTypes.bool, isAdmin: PropTypes.bool,
handleActionMenuDelete: PropTypes.func, handleActionMenuDelete: PropTypes.func,
@@ -1,7 +1,6 @@
/* TODO I basically copied and pasted this component from the actionsMenu. Check how we can make it reusable */ /* TODO I basically copied and pasted this component from the actionsMenu. Check how we can make it reusable */
import { useRef, useState } from "react"; import { useRef, useState } from "react";
import { useSelector } from "react-redux";
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { createToast } from "../../../../../Utils/toastUtils"; import { createToast } from "../../../../../Utils/toastUtils";
@@ -30,7 +29,6 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => {
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
const [isDialogOpen, setIsDialogOpen] = useState(false); const [isDialogOpen, setIsDialogOpen] = useState(false);
const theme = useTheme(); const theme = useTheme();
const { isLoading } = useSelector((state) => state.uptimeMonitors);
const openMenu = (e) => { const openMenu = (e) => {
e.stopPropagation(); e.stopPropagation();
@@ -117,7 +115,6 @@ const InfrastructureMenu = ({ monitor, isAdmin, updateCallback }) => {
onCancel={cancelRemove} onCancel={cancelRemove}
confirmationButtonLabel="Delete" confirmationButtonLabel="Delete"
onConfirm={handleRemove} onConfirm={handleRemove}
isLoading={isLoading}
modelTitle="modal-delete-monitor" modelTitle="modal-delete-monitor"
modelDescription="delete-monitor-confirmation" modelDescription="delete-monitor-confirmation"
/> />
@@ -11,7 +11,6 @@ import Filter from "./Components/Filters";
// Utils // Utils
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
import { useState } from "react"; import { useState } from "react";
import { useSelector } from "react-redux";
import { useIsAdmin } from "../../../Hooks/useIsAdmin"; import { useIsAdmin } from "../../../Hooks/useIsAdmin";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useFetchMonitorsByTeamId } from "../../../Hooks/monitorHooks"; import { useFetchMonitorsByTeamId } from "../../../Hooks/monitorHooks";
@@ -21,7 +20,6 @@ const BREADCRUMBS = [{ name: `infrastructure`, path: "/infrastructure" }];
const InfrastructureMonitors = () => { const InfrastructureMonitors = () => {
// Redux state // Redux state
const { user } = useSelector((state) => state.auth);
// Local state // Local state
const [page, setPage] = useState(0); const [page, setPage] = useState(0);
@@ -56,7 +54,6 @@ const InfrastructureMonitors = () => {
const field = toFilterStatus !== undefined ? "status" : undefined; const field = toFilterStatus !== undefined ? "status" : undefined;
const [monitors, summary, isLoading, networkError] = useFetchMonitorsByTeamId({ const [monitors, summary, isLoading, networkError] = useFetchMonitorsByTeamId({
teamId: user.teamId,
limit: 1, limit: 1,
types: TYPES, types: TYPES,
page, page,
@@ -118,7 +115,7 @@ const InfrastructureMonitors = () => {
/> />
</Stack> </Stack>
<MonitorsTable <MonitorsTable
shouldRender={!isLoading} isLoading={isLoading}
monitors={monitors} monitors={monitors}
isAdmin={isAdmin} isAdmin={isAdmin}
handleActionMenuDelete={handleActionMenuDelete} handleActionMenuDelete={handleActionMenuDelete}
@@ -135,7 +135,6 @@ const CreateMaintenance = () => {
setIsLoading(true); setIsLoading(true);
try { try {
const response = await networkService.getMonitorsByTeamId({ const response = await networkService.getMonitorsByTeamId({
teamId: user.teamId,
limit: null, limit: null,
types: ["http", "ping", "pagespeed", "port"], types: ["http", "ping", "pagespeed", "port"],
}); });
@@ -9,7 +9,6 @@ import GenericFallback from "../../../Components/GenericFallback";
// Utils // Utils
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
import { useSelector } from "react-redux";
import { useIsAdmin } from "../../../Hooks/useIsAdmin"; import { useIsAdmin } from "../../../Hooks/useIsAdmin";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useFetchMonitorsByTeamId } from "../../../Hooks/monitorHooks"; import { useFetchMonitorsByTeamId } from "../../../Hooks/monitorHooks";
@@ -20,10 +19,8 @@ const PageSpeed = () => {
const theme = useTheme(); const theme = useTheme();
const { t } = useTranslation(); const { t } = useTranslation();
const isAdmin = useIsAdmin(); const isAdmin = useIsAdmin();
const { user } = useSelector((state) => state.auth);
const [monitors, monitorsSummary, isLoading, networkError] = useFetchMonitorsByTeamId({ const [monitors, monitorsSummary, isLoading, networkError] = useFetchMonitorsByTeamId({
teamId: user.teamId,
limit: 10, limit: 10,
types: TYPES, types: TYPES,
page: null, page: null,
@@ -13,7 +13,6 @@ const useMonitorsFetch = () => {
const fetchMonitors = async () => { const fetchMonitors = async () => {
try { try {
const response = await networkService.getMonitorsByTeamId({ const response = await networkService.getMonitorsByTeamId({
teamId: user.teamId,
limit: null, // donot return any checks for the monitors limit: null, // donot return any checks for the monitors
types: ["http", "ping", "port"], // status page is available for uptime, ping, and port monitors types: ["http", "ping", "port"], // status page is available for uptime, ping, and port monitors
}); });
+1 -2
View File
@@ -28,7 +28,6 @@ import { useCreateMonitor } from "../../../Hooks/monitorHooks";
const CreateMonitor = () => { const CreateMonitor = () => {
// Redux state // Redux state
const { user } = useSelector((state) => state.auth); const { user } = useSelector((state) => state.auth);
const { isLoading } = useSelector((state) => state.uptimeMonitors);
// Local state // Local state
const [errors, setErrors] = useState({}); const [errors, setErrors] = useState({});
@@ -467,7 +466,7 @@ const CreateMonitor = () => {
variant="contained" variant="contained"
color="accent" color="accent"
disabled={!Object.values(errors).every((value) => value === undefined)} disabled={!Object.values(errors).every((value) => value === undefined)}
loading={isLoading || isCreating} loading={isCreating}
> >
{t("createMonitor")} {t("createMonitor")}
</Button> </Button>
@@ -64,7 +64,6 @@ CreateMonitorButton.propTypes = {
const UptimeMonitors = () => { const UptimeMonitors = () => {
// Redux state // Redux state
const { user } = useSelector((state) => state.auth);
const rowsPerPage = useSelector((state) => state.ui.monitors.rowsPerPage); const rowsPerPage = useSelector((state) => state.ui.monitors.rowsPerPage);
// Local state // Local state
@@ -106,11 +105,8 @@ const UptimeMonitors = () => {
setMonitorUpdateTrigger((prev) => !prev); setMonitorUpdateTrigger((prev) => !prev);
}, []); }, []);
const teamId = user.teamId;
const [monitors, monitorsSummary, monitorsWithSummaryIsLoading, networkError] = const [monitors, monitorsSummary, monitorsWithSummaryIsLoading, networkError] =
useFetchMonitorsWithSummary({ useFetchMonitorsWithSummary({
teamId,
types: TYPES, types: TYPES,
monitorUpdateTrigger, monitorUpdateTrigger,
}); });
@@ -140,7 +136,6 @@ const UptimeMonitors = () => {
monitorsWithChecksIsLoading, monitorsWithChecksIsLoading,
monitorsWithChecksNetworkError, monitorsWithChecksNetworkError,
] = useFetchMonitorsWithChecks({ ] = useFetchMonitorsWithChecks({
teamId,
types: effectiveTypes, types: effectiveTypes,
limit: 25, limit: 25,
page: page, page: page,
+14 -50
View File
@@ -135,36 +135,6 @@ class NetworkService {
}); });
} }
/**
*
* ************************************
* Gets monitors and summary of stats by TeamID
* ************************************
*
* @async
* @param {Object} config - The configuration object.
* @param {string} config.teamId - Team ID
* @param {Array<string>} config.types - Array of monitor types
* @returns {Promise<AxiosResponse>} The response from the axios POST request.
*/
async getMonitorsSummaryByTeamId(config) {
const params = new URLSearchParams();
if (config.types) {
config.types.forEach((type) => {
params.append("type", type);
});
}
return this.axiosInstance.get(
`/monitors/team/summary/${config.teamId}?${params.toString()}`,
{
headers: {
"Content-Type": "application/json",
},
}
);
}
/** /**
* ************************************ * ************************************
* Get all uptime monitors for a Team * Get all uptime monitors for a Team
@@ -184,7 +154,7 @@ class NetworkService {
*/ */
async getMonitorsByTeamId(config) { async getMonitorsByTeamId(config) {
const { teamId, limit, types, page, rowsPerPage, filter, field, order } = config; const { limit, types, page, rowsPerPage, filter, field, order } = config;
const params = new URLSearchParams(); const params = new URLSearchParams();
if (limit) params.append("limit", limit); if (limit) params.append("limit", limit);
@@ -199,7 +169,7 @@ class NetworkService {
if (field) params.append("field", field); if (field) params.append("field", field);
if (order) params.append("order", order); if (order) params.append("order", order);
return this.axiosInstance.get(`/monitors/team/${teamId}?${params.toString()}`, { return this.axiosInstance.get(`/monitors/team?${params.toString()}`, {
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
@@ -949,7 +919,7 @@ class NetworkService {
// Fetch monitors with summary by TeamID // Fetch monitors with summary by TeamID
// ************************************ // ************************************
async getMonitorsWithSummaryByTeamId(config) { async getMonitorsWithSummaryByTeamId(config) {
const { teamId, types } = config; const { types } = config;
const params = new URLSearchParams(); const params = new URLSearchParams();
if (types) { if (types) {
@@ -958,21 +928,18 @@ class NetworkService {
}); });
} }
return this.axiosInstance.get( return this.axiosInstance.get(`/monitors/summary/team?${params.toString()}`, {
`/monitors/summary/team/${teamId}?${params.toString()}`, headers: {
{ "Content-Type": "application/json",
headers: { },
"Content-Type": "application/json", });
},
}
);
} }
// ************************************ // ************************************
// Fetch monitors with checks by TeamID // Fetch monitors with checks by TeamID
// ************************************ // ************************************
async getMonitorsWithChecksByTeamId(config) { async getMonitorsWithChecksByTeamId(config) {
const { teamId, limit, types, page, rowsPerPage, filter, field, order } = config; const { limit, types, page, rowsPerPage, filter, field, order } = config;
const params = new URLSearchParams(); const params = new URLSearchParams();
if (limit) params.append("limit", limit); if (limit) params.append("limit", limit);
@@ -987,14 +954,11 @@ class NetworkService {
if (field) params.append("field", field); if (field) params.append("field", field);
if (order) params.append("order", order); if (order) params.append("order", order);
return this.axiosInstance.get( return this.axiosInstance.get(`/monitors/team/with-checks?${params.toString()}`, {
`/monitors/team/${teamId}/with-checks?${params.toString()}`, headers: {
{ "Content-Type": "application/json",
headers: { },
"Content-Type": "application/json", });
},
}
);
} }
// ************************************ // ************************************
+4 -3
View File
@@ -519,7 +519,8 @@ const getMonitorsByTeamId = async (req) => {
order = "asc"; order = "asc";
} }
// Build match stage // Build match stage
const matchStage = { teamId: ObjectId.createFromHexString(req.params.teamId) }; const teamId = req.user.teamId;
const matchStage = { teamId: ObjectId.createFromHexString(teamId) };
if (type !== undefined) { if (type !== undefined) {
matchStage.type = Array.isArray(type) ? { $in: type } : type; matchStage.type = Array.isArray(type) ? { $in: type } : type;
} }
@@ -560,7 +561,7 @@ const getMonitorsByTeamId = async (req) => {
const getMonitorsAndSummaryByTeamId = async (req) => { const getMonitorsAndSummaryByTeamId = async (req) => {
try { try {
const { type } = req.query; const { type } = req.query;
const teamId = ObjectId.createFromHexString(req.params.teamId); const teamId = ObjectId.createFromHexString(req.user.teamId);
const matchStage = { teamId }; const matchStage = { teamId };
if (type !== undefined) { if (type !== undefined) {
matchStage.type = Array.isArray(type) ? { $in: type } : type; matchStage.type = Array.isArray(type) ? { $in: type } : type;
@@ -594,7 +595,7 @@ const getMonitorsWithChecksByTeamId = async (req) => {
field = "name"; field = "name";
order = "asc"; order = "asc";
} }
const teamId = ObjectId.createFromHexString(req.params.teamId); const teamId = ObjectId.createFromHexString(req.user.teamId);
// Build match stage // Build match stage
const matchStage = { teamId }; const matchStage = { teamId };
if (type !== undefined) { if (type !== undefined) {
+4 -4
View File
@@ -35,17 +35,17 @@ class MonitorRoutes {
fetchMonitorCertificate fetchMonitorCertificate
); );
}); });
this.router.get("/team", this.monitorController.getMonitorsByTeamId);
this.router.get("/:monitorId", this.monitorController.getMonitorById); this.router.get("/:monitorId", this.monitorController.getMonitorById);
this.router.get("/team/:teamId", this.monitorController.getMonitorsByTeamId);
this.router.get( this.router.get(
"/summary/team/:teamId", "/summary/team",
this.monitorController.getMonitorsAndSummaryByTeamId this.monitorController.getMonitorsAndSummaryByTeamId
); );
this.router.get( this.router.get(
"/team/:teamId/with-checks", "/team/with-checks",
this.monitorController.getMonitorsWithChecksByTeamId this.monitorController.getMonitorsWithChecksByTeamId
); );
+1 -3
View File
@@ -126,9 +126,7 @@ const getMonitorByIdQueryValidation = joi.object({
normalize: joi.boolean(), normalize: joi.boolean(),
}); });
const getMonitorsByTeamIdParamValidation = joi.object({ const getMonitorsByTeamIdParamValidation = joi.object({});
teamId: joi.string().required(),
});
const getMonitorsByTeamIdQueryValidation = joi.object({ const getMonitorsByTeamIdQueryValidation = joi.object({
limit: joi.number(), limit: joi.number(),