25 files changed
+903
-71
No files matched your search
@@ -93,3 +93,20 @@ export const ValueLabel = ({ value, text }: { value: ValueType; text: string })
|
|||||||
</BaseBox>
|
</BaseBox>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const ColoredLabel = ({ text, color }: { text: string; color: string }) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<BaseBox
|
||||||
|
sx={{
|
||||||
|
width: "fit-content",
|
||||||
|
padding: theme.spacing(1, 3),
|
||||||
|
color: color,
|
||||||
|
borderColor: color,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography>{text}</Typography>
|
||||||
|
</BaseBox>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -14,17 +14,19 @@ type AutoCompleteInputProps = Omit<
|
|||||||
renderInput?: AutocompleteProps<any, boolean, boolean, boolean>["renderInput"];
|
renderInput?: AutocompleteProps<any, boolean, boolean, boolean>["renderInput"];
|
||||||
fieldLabel?: string;
|
fieldLabel?: string;
|
||||||
required?: boolean;
|
required?: boolean;
|
||||||
|
renderOptionContent?: (option: any) => React.ReactNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const AutoCompleteInput = ({
|
export const AutoCompleteInput = ({
|
||||||
fieldLabel,
|
fieldLabel,
|
||||||
required,
|
required,
|
||||||
renderInput,
|
renderInput,
|
||||||
|
renderOptionContent,
|
||||||
...props
|
...props
|
||||||
}: AutoCompleteInputProps) => {
|
}: AutoCompleteInputProps) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const multiple = props.multiple;
|
const multiple = props.multiple;
|
||||||
|
const { renderOption: customRenderOption, ...autocompleteProps } = props;
|
||||||
const defaultRenderInput = (params: any) => (
|
const defaultRenderInput = (params: any) => (
|
||||||
<TextField
|
<TextField
|
||||||
{...params}
|
{...params}
|
||||||
@@ -34,7 +36,7 @@ export const AutoCompleteInput = ({
|
|||||||
|
|
||||||
const autocomplete = (
|
const autocomplete = (
|
||||||
<Autocomplete
|
<Autocomplete
|
||||||
{...props}
|
{...autocompleteProps}
|
||||||
disableCloseOnSelect={!!multiple}
|
disableCloseOnSelect={!!multiple}
|
||||||
popupIcon={
|
popupIcon={
|
||||||
<ChevronDown
|
<ChevronDown
|
||||||
@@ -46,24 +48,28 @@ export const AutoCompleteInput = ({
|
|||||||
renderInput={renderInput || defaultRenderInput}
|
renderInput={renderInput || defaultRenderInput}
|
||||||
getOptionKey={(option) => option.id}
|
getOptionKey={(option) => option.id}
|
||||||
renderTags={() => null}
|
renderTags={() => null}
|
||||||
renderOption={(props, option, { selected }) => {
|
renderOption={
|
||||||
const { key, ...optionProps } = props;
|
customRenderOption ||
|
||||||
return (
|
((props, option, { selected }) => {
|
||||||
<ListItem
|
const { key, ...optionProps } = props;
|
||||||
key={key}
|
return (
|
||||||
{...optionProps}
|
<ListItem
|
||||||
>
|
key={key}
|
||||||
<Stack
|
{...optionProps}
|
||||||
direction={"row"}
|
|
||||||
alignItems={"center"}
|
|
||||||
gap={theme.spacing(2)}
|
|
||||||
>
|
>
|
||||||
{multiple && <Checkbox checked={selected} />}
|
<Stack
|
||||||
{option.name}
|
direction={"row"}
|
||||||
</Stack>
|
alignItems={"center"}
|
||||||
</ListItem>
|
gap={theme.spacing(2)}
|
||||||
);
|
width="100%"
|
||||||
}}
|
>
|
||||||
|
{multiple && <Checkbox checked={selected} />}
|
||||||
|
{renderOptionContent ? renderOptionContent(option) : option.name}
|
||||||
|
</Stack>
|
||||||
|
</ListItem>
|
||||||
|
);
|
||||||
|
})
|
||||||
|
}
|
||||||
sx={{
|
sx={{
|
||||||
"&.MuiAutocomplete-root .MuiAutocomplete-input": {
|
"&.MuiAutocomplete-root .MuiAutocomplete-input": {
|
||||||
padding: `0 ${theme.spacing(5)}`,
|
padding: `0 ${theme.spacing(5)}`,
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import { Select, Button } from "@/Components/inputs";
|
import { Select, Autocomplete, Button, TextField } from "@/Components/inputs";
|
||||||
|
import { ColoredLabel } from "@/Components/design-elements";
|
||||||
import MenuItem from "@mui/material/MenuItem";
|
import MenuItem from "@mui/material/MenuItem";
|
||||||
import useMediaQuery from "@mui/material/useMediaQuery";
|
import useMediaQuery from "@mui/material/useMediaQuery";
|
||||||
|
|
||||||
import type { MonitorType } from "@/Types/Monitor";
|
import type { MonitorType } from "@/Types/Monitor";
|
||||||
|
import type { Tag } from "@/Types/Tag";
|
||||||
import { Typography, useTheme } from "@mui/material";
|
import { Typography, useTheme } from "@mui/material";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
@@ -28,22 +30,34 @@ export const ControlsFilter = ({
|
|||||||
setSelectedStatus,
|
setSelectedStatus,
|
||||||
selectedState,
|
selectedState,
|
||||||
setSelectedState,
|
setSelectedState,
|
||||||
|
tagOptions,
|
||||||
|
selectedTags,
|
||||||
|
setSelectedTags,
|
||||||
onClearFilters,
|
onClearFilters,
|
||||||
}: {
|
}: {
|
||||||
showTypes?: boolean;
|
showTypes?: boolean;
|
||||||
selectedTypes?: MonitorType[];
|
selectedTypes?: MonitorType[];
|
||||||
setSelectedTypes?: React.Dispatch<React.SetStateAction<MonitorType[]>>;
|
setSelectedTypes?: React.Dispatch<React.SetStateAction<MonitorType[]>>;
|
||||||
selectedStatus: string;
|
selectedStatus?: string;
|
||||||
setSelectedStatus: React.Dispatch<React.SetStateAction<string>>;
|
setSelectedStatus?: React.Dispatch<React.SetStateAction<string>>;
|
||||||
selectedState: string;
|
selectedState?: string;
|
||||||
setSelectedState: React.Dispatch<React.SetStateAction<string>>;
|
setSelectedState?: React.Dispatch<React.SetStateAction<string>>;
|
||||||
|
tagOptions?: Tag[];
|
||||||
|
selectedTags?: string[];
|
||||||
|
setSelectedTags?: React.Dispatch<React.SetStateAction<string[]>>;
|
||||||
onClearFilters: () => void;
|
onClearFilters: () => void;
|
||||||
}) => {
|
}) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
||||||
const isFilterActive =
|
const isFilterActive =
|
||||||
(selectedTypes?.length ?? 0) > 0 || selectedStatus !== "" || selectedState !== "";
|
(selectedTypes?.length ?? 0) > 0 ||
|
||||||
|
Boolean(selectedStatus) ||
|
||||||
|
Boolean(selectedState) ||
|
||||||
|
(selectedTags?.length ?? 0) > 0;
|
||||||
|
const selectedTagObjects = (tagOptions ?? []).filter((tag) =>
|
||||||
|
(selectedTags ?? []).includes(tag.id)
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
direction={isSmall ? "column" : "row"}
|
direction={isSmall ? "column" : "row"}
|
||||||
@@ -66,34 +80,68 @@ export const ControlsFilter = ({
|
|||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
)}
|
)}
|
||||||
<Select
|
{setSelectedStatus && (
|
||||||
placeholder="Status"
|
<Select
|
||||||
value={selectedStatus}
|
placeholder="Status"
|
||||||
onChange={(e) => setSelectedStatus(e.target.value)}
|
value={selectedStatus ?? ""}
|
||||||
>
|
onChange={(e) => setSelectedStatus(e.target.value)}
|
||||||
{statuses.map((status) => (
|
>
|
||||||
<MenuItem
|
{statuses.map((status) => (
|
||||||
key={status}
|
<MenuItem
|
||||||
value={status}
|
key={status}
|
||||||
>
|
value={status}
|
||||||
<Typography textTransform={"capitalize"}>{status}</Typography>
|
>
|
||||||
</MenuItem>
|
<Typography textTransform={"capitalize"}>{status}</Typography>
|
||||||
))}
|
</MenuItem>
|
||||||
</Select>
|
))}
|
||||||
<Select
|
</Select>
|
||||||
placeholder="State"
|
)}
|
||||||
value={selectedState}
|
{setSelectedState && (
|
||||||
onChange={(e) => setSelectedState(e.target.value)}
|
<Select
|
||||||
>
|
placeholder="State"
|
||||||
{states.map((state) => (
|
value={selectedState ?? ""}
|
||||||
<MenuItem
|
onChange={(e) => setSelectedState(e.target.value)}
|
||||||
key={state}
|
>
|
||||||
value={state}
|
{states.map((state) => (
|
||||||
>
|
<MenuItem
|
||||||
<Typography textTransform={"capitalize"}>{state}</Typography>
|
key={state}
|
||||||
</MenuItem>
|
value={state}
|
||||||
))}
|
>
|
||||||
</Select>
|
<Typography textTransform={"capitalize"}>{state}</Typography>
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
)}
|
||||||
|
{tagOptions && setSelectedTags && (
|
||||||
|
<Autocomplete
|
||||||
|
multiple
|
||||||
|
options={tagOptions}
|
||||||
|
value={selectedTagObjects}
|
||||||
|
getOptionLabel={(option) => option.name}
|
||||||
|
onChange={(_: unknown, newValue: Tag[]) => {
|
||||||
|
setSelectedTags(newValue.map((tag) => tag.id));
|
||||||
|
}}
|
||||||
|
isOptionEqualToValue={(option, value) => option.id === value.id}
|
||||||
|
renderOptionContent={(option) => (
|
||||||
|
<ColoredLabel
|
||||||
|
text={option.name}
|
||||||
|
color={option.color}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
renderInput={(params) => (
|
||||||
|
<TextField
|
||||||
|
{...params}
|
||||||
|
placeholder={t("common.table.headers.tags")}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
slotProps={{
|
||||||
|
popper: {
|
||||||
|
sx: { width: "fit-content !important", minWidth: 280 },
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
sx={{ minWidth: 180 }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{isFilterActive && (
|
{isFilterActive && (
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
User,
|
User,
|
||||||
Lock,
|
Lock,
|
||||||
Users,
|
Users,
|
||||||
|
Tag,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
|
|
||||||
export const getMenu = (t: Function) => {
|
export const getMenu = (t: Function) => {
|
||||||
@@ -41,6 +42,11 @@ export const getMenu = (t: Function) => {
|
|||||||
path: "notifications",
|
path: "notifications",
|
||||||
icon: <Icon icon={Bell} />,
|
icon: <Icon icon={Bell} />,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: t("components.sidebar.menu.tags"),
|
||||||
|
path: "tags",
|
||||||
|
icon: <Icon icon={Tag} />,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: t("components.sidebar.menu.checks"),
|
name: t("components.sidebar.menu.checks"),
|
||||||
path: "checks",
|
path: "checks",
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ const getBaseDefaults = (data?: Monitor | null) => ({
|
|||||||
description: data?.description || "",
|
description: data?.description || "",
|
||||||
interval: data?.interval || 60000,
|
interval: data?.interval || 60000,
|
||||||
notifications: data?.notifications || [],
|
notifications: data?.notifications || [],
|
||||||
|
tags: data?.tags || [],
|
||||||
statusWindowSize: data?.statusWindowSize || 5,
|
statusWindowSize: data?.statusWindowSize || 5,
|
||||||
statusWindowThreshold: data?.statusWindowThreshold || 60,
|
statusWindowThreshold: data?.statusWindowThreshold || 60,
|
||||||
geoCheckEnabled: data?.geoCheckEnabled ?? false,
|
geoCheckEnabled: data?.geoCheckEnabled ?? false,
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { useMemo } from "react";
|
||||||
|
import { tagSchema, type TagFormData } from "@/Validation/tag";
|
||||||
|
import type { Tag } from "@/Types/Tag";
|
||||||
|
|
||||||
|
interface UseTagsFormOptions {
|
||||||
|
data?: Tag | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useTagsForm = ({ data }: UseTagsFormOptions) => {
|
||||||
|
return useMemo(() => {
|
||||||
|
const defaults: TagFormData = {
|
||||||
|
name: data?.name ?? "",
|
||||||
|
color: data?.color ?? "#13715B",
|
||||||
|
};
|
||||||
|
|
||||||
|
return { schema: tagSchema, defaults };
|
||||||
|
}, [data]);
|
||||||
|
};
|
||||||
@@ -18,7 +18,7 @@ import { Trash2 } from "lucide-react";
|
|||||||
import { HeaderDeleteControls } from "@/Components/monitors";
|
import { HeaderDeleteControls } from "@/Components/monitors";
|
||||||
import { GeoContinents } from "@/Types/GeoCheck";
|
import { GeoContinents } from "@/Types/GeoCheck";
|
||||||
|
|
||||||
import { BasePage, ConfigBox } from "@/Components/design-elements";
|
import { BasePage, ColoredLabel, ConfigBox } from "@/Components/design-elements";
|
||||||
import {
|
import {
|
||||||
RadioWithDescription,
|
RadioWithDescription,
|
||||||
Button,
|
Button,
|
||||||
@@ -40,6 +40,7 @@ import {
|
|||||||
DefaultPageSpeedStrategy,
|
DefaultPageSpeedStrategy,
|
||||||
} from "@/Types/Monitor";
|
} from "@/Types/Monitor";
|
||||||
import type { Notification } from "@/Types/Notification";
|
import type { Notification } from "@/Types/Notification";
|
||||||
|
import type { Tag } from "@/Types/Tag";
|
||||||
import type { MonitorFormData } from "@/Validation/monitor";
|
import type { MonitorFormData } from "@/Validation/monitor";
|
||||||
|
|
||||||
interface GeneralSettingsConfig {
|
interface GeneralSettingsConfig {
|
||||||
@@ -237,6 +238,7 @@ const CreateMonitorPage = () => {
|
|||||||
|
|
||||||
const { data: notifications } = useGet<Notification[]>("/notifications/team");
|
const { data: notifications } = useGet<Notification[]>("/notifications/team");
|
||||||
const { data: games } = useGet<GamesMap>("/monitors/games");
|
const { data: games } = useGet<GamesMap>("/monitors/games");
|
||||||
|
const { data: tags } = useGet<Tag[]>("/tags/team");
|
||||||
|
|
||||||
const { schema, defaults } = useMonitorForm({
|
const { schema, defaults } = useMonitorForm({
|
||||||
data: existingMonitor ?? null,
|
data: existingMonitor ?? null,
|
||||||
@@ -923,6 +925,78 @@ const CreateMonitorPage = () => {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<ConfigBox
|
||||||
|
title={t("pages.createMonitor.form.tags.title")}
|
||||||
|
subtitle={t("pages.createMonitor.form.tags.description")}
|
||||||
|
rightContent={
|
||||||
|
<Controller
|
||||||
|
name="tags"
|
||||||
|
control={control}
|
||||||
|
render={({ field }) => {
|
||||||
|
const tagOptions = tags ?? [];
|
||||||
|
const selectedTags = tagOptions.filter((tag) =>
|
||||||
|
(field.value ?? []).includes(tag.id)
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
<Stack spacing={theme.spacing(LAYOUT.MD)}>
|
||||||
|
<Autocomplete
|
||||||
|
multiple
|
||||||
|
options={tagOptions}
|
||||||
|
value={selectedTags}
|
||||||
|
getOptionLabel={(option) => option.name}
|
||||||
|
onChange={(_: unknown, newValue: typeof tagOptions) => {
|
||||||
|
field.onChange(newValue.map((tag) => tag.id));
|
||||||
|
}}
|
||||||
|
isOptionEqualToValue={(option, value) => option.id === value.id}
|
||||||
|
renderOptionContent={(option) => (
|
||||||
|
<ColoredLabel
|
||||||
|
text={option.name}
|
||||||
|
color={option.color}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
{selectedTags.length > 0 && (
|
||||||
|
<Stack
|
||||||
|
flex={1}
|
||||||
|
gap={theme.spacing(SPACING.XL)}
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
{selectedTags.map((tag, index) => (
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
justifyContent={"space-between"}
|
||||||
|
alignItems="center"
|
||||||
|
key={tag.id}
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<ColoredLabel
|
||||||
|
text={tag.name}
|
||||||
|
color={tag.color}
|
||||||
|
/>
|
||||||
|
<div style={{ flexGrow: 1 }} />
|
||||||
|
<IconButton
|
||||||
|
size="small"
|
||||||
|
onClick={() => {
|
||||||
|
field.onChange(
|
||||||
|
(field.value ?? []).filter((id: string) => id !== tag.id)
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
aria-label="Remove tag"
|
||||||
|
>
|
||||||
|
<Trash2 size={16} />
|
||||||
|
</IconButton>
|
||||||
|
{index < selectedTags.length - 1 && <Divider />}
|
||||||
|
</Stack>
|
||||||
|
))}
|
||||||
|
</Stack>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
|
||||||
{(watchedType === "http" ||
|
{(watchedType === "http" ||
|
||||||
watchedType === "grpc" ||
|
watchedType === "grpc" ||
|
||||||
watchedType === "websocket") && (
|
watchedType === "websocket") && (
|
||||||
|
|||||||
@@ -1,7 +1,14 @@
|
|||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
import { Table, Pagination, StatusLabel, Gauge } from "@/Components/design-elements";
|
import {
|
||||||
|
Table,
|
||||||
|
Pagination,
|
||||||
|
StatusLabel,
|
||||||
|
Gauge,
|
||||||
|
ColoredLabel,
|
||||||
|
} from "@/Components/design-elements";
|
||||||
|
import { SPACING } from "@/Utils/Theme/constants";
|
||||||
import type { Header } from "@/Components/design-elements/Table";
|
import type { Header } from "@/Components/design-elements/Table";
|
||||||
import { ActionsMenu, type ActionMenuItem } from "@/Components/actions-menu";
|
import { ActionsMenu, type ActionMenuItem } from "@/Components/actions-menu";
|
||||||
import { ArrowUp, ArrowDown } from "lucide-react";
|
import { ArrowUp, ArrowDown } from "lucide-react";
|
||||||
@@ -13,10 +20,12 @@ import { useNavigate } from "react-router-dom";
|
|||||||
import { usePost } from "@/Hooks/UseApi";
|
import { usePost } from "@/Hooks/UseApi";
|
||||||
|
|
||||||
import type { Monitor } from "@/Types/Monitor";
|
import type { Monitor } from "@/Types/Monitor";
|
||||||
|
import type { Tag } from "@/Types/Tag";
|
||||||
import { Checkbox } from "@/Components/inputs";
|
import { Checkbox } from "@/Components/inputs";
|
||||||
|
|
||||||
interface InfraMonitorsTableProps {
|
interface InfraMonitorsTableProps {
|
||||||
monitors: Monitor[];
|
monitors: Monitor[];
|
||||||
|
tags: Tag[];
|
||||||
refetch: () => void;
|
refetch: () => void;
|
||||||
setSelectedMonitor: (monitor: Monitor | null) => void;
|
setSelectedMonitor: (monitor: Monitor | null) => void;
|
||||||
sortField: string;
|
sortField: string;
|
||||||
@@ -34,6 +43,7 @@ interface InfraMonitorsTableProps {
|
|||||||
|
|
||||||
export const InfraMonitorsTable = ({
|
export const InfraMonitorsTable = ({
|
||||||
monitors,
|
monitors,
|
||||||
|
tags,
|
||||||
refetch,
|
refetch,
|
||||||
setSelectedMonitor,
|
setSelectedMonitor,
|
||||||
sortField,
|
sortField,
|
||||||
@@ -267,6 +277,32 @@ export const InfraMonitorsTable = ({
|
|||||||
return <Gauge progress={diskUsage} />;
|
return <Gauge progress={diskUsage} />;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "tags",
|
||||||
|
content: t("common.table.headers.tags"),
|
||||||
|
render: (row) => {
|
||||||
|
if (row.tags.length === 0) return "-";
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
justifyContent={"center"}
|
||||||
|
direction={isSmall ? "column" : "row"}
|
||||||
|
gap={theme.spacing(SPACING.LG)}
|
||||||
|
>
|
||||||
|
{row.tags.map((tagId) => {
|
||||||
|
const fullTag = tags.find((t) => t.id === tagId);
|
||||||
|
if (!fullTag) return null;
|
||||||
|
return (
|
||||||
|
<ColoredLabel
|
||||||
|
key={fullTag.id}
|
||||||
|
text={fullTag.name}
|
||||||
|
color={fullTag.color}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
id: "actions",
|
id: "actions",
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
import useMediaQuery from "@mui/material/useMediaQuery";
|
import useMediaQuery from "@mui/material/useMediaQuery";
|
||||||
import { MonitorBasePageWithStates } from "@/Components/design-elements";
|
import { MonitorBasePageWithStates, ColoredLabel } from "@/Components/design-elements";
|
||||||
import { HeaderCreate } from "@/Components/common";
|
import { HeaderCreate } from "@/Components/common";
|
||||||
import {
|
import {
|
||||||
ControlsFilter,
|
ControlsFilter,
|
||||||
@@ -13,7 +14,9 @@ import { Play, Pause } from "lucide-react";
|
|||||||
import { useGet, useDelete } from "@/Hooks/UseApi";
|
import { useGet, useDelete } from "@/Hooks/UseApi";
|
||||||
import { useIsAdmin } from "@/Hooks/useIsAdmin";
|
import { useIsAdmin } from "@/Hooks/useIsAdmin";
|
||||||
import type { Monitor, MonitorsWithChecksResponse } from "@/Types/Monitor";
|
import type { Monitor, MonitorsWithChecksResponse } from "@/Types/Monitor";
|
||||||
|
import type { Tag } from "@/Types/Tag";
|
||||||
import { useTheme } from "@mui/material";
|
import { useTheme } from "@mui/material";
|
||||||
|
import { SPACING } from "@/Utils/Theme/constants";
|
||||||
import { useState, useCallback, useMemo } from "react";
|
import { useState, useCallback, useMemo } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useSelector, useDispatch } from "react-redux";
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
@@ -38,12 +41,15 @@ const InfrastructureMonitors = () => {
|
|||||||
// Local state
|
// Local state
|
||||||
const [selectedStatus, setSelectedStatus] = useState<string>("");
|
const [selectedStatus, setSelectedStatus] = useState<string>("");
|
||||||
const [selectedState, setSelectedState] = useState<string>("");
|
const [selectedState, setSelectedState] = useState<string>("");
|
||||||
|
const [selectedTags, setSelectedTags] = useState<string[]>([]);
|
||||||
const [search, setSearch] = useState<string>("");
|
const [search, setSearch] = useState<string>("");
|
||||||
const [page, setPage] = useState<number>(0);
|
const [page, setPage] = useState<number>(0);
|
||||||
const [sortField, setSortField] = useState<string>("");
|
const [sortField, setSortField] = useState<string>("");
|
||||||
const [sortOrder, setSortOrder] = useState<"asc" | "desc">("asc");
|
const [sortOrder, setSortOrder] = useState<"asc" | "desc">("asc");
|
||||||
const [selectedMonitor, setSelectedMonitor] = useState<Monitor | null>(null);
|
const [selectedMonitor, setSelectedMonitor] = useState<Monitor | null>(null);
|
||||||
|
|
||||||
|
const { data: tags } = useGet<Tag[]>("/tags/team");
|
||||||
|
|
||||||
const isDialogOpen = Boolean(selectedMonitor);
|
const isDialogOpen = Boolean(selectedMonitor);
|
||||||
|
|
||||||
const debouncedSearch = useDebounce<string>(search, 300);
|
const debouncedSearch = useDebounce<string>(search, 300);
|
||||||
@@ -51,6 +57,7 @@ const InfrastructureMonitors = () => {
|
|||||||
const handleClearFilters = useCallback(() => {
|
const handleClearFilters = useCallback(() => {
|
||||||
setSelectedStatus("");
|
setSelectedStatus("");
|
||||||
setSelectedState("");
|
setSelectedState("");
|
||||||
|
setSelectedTags([]);
|
||||||
setSearch("");
|
setSearch("");
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -81,6 +88,7 @@ const InfrastructureMonitors = () => {
|
|||||||
const monitorsWithChecksUrl = useMemo(() => {
|
const monitorsWithChecksUrl = useMemo(() => {
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
params.append("type", "hardware");
|
params.append("type", "hardware");
|
||||||
|
selectedTags.forEach((tagId) => params.append("tags", tagId));
|
||||||
params.append("limit", "1");
|
params.append("limit", "1");
|
||||||
if (page !== undefined) params.append("page", String(page));
|
if (page !== undefined) params.append("page", String(page));
|
||||||
if (rowsPerPage) params.append("rowsPerPage", String(rowsPerPage));
|
if (rowsPerPage) params.append("rowsPerPage", String(rowsPerPage));
|
||||||
@@ -88,7 +96,7 @@ const InfrastructureMonitors = () => {
|
|||||||
if (field) params.append("field", field);
|
if (field) params.append("field", field);
|
||||||
if (sortOrder) params.append("order", sortOrder);
|
if (sortOrder) params.append("order", sortOrder);
|
||||||
return `/monitors/team/with-checks?${params.toString()}`;
|
return `/monitors/team/with-checks?${params.toString()}`;
|
||||||
}, [page, rowsPerPage, filter, field, sortOrder]);
|
}, [page, rowsPerPage, filter, field, sortOrder, selectedTags]);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: monitorsWithChecksData,
|
data: monitorsWithChecksData,
|
||||||
@@ -114,7 +122,9 @@ const InfrastructureMonitors = () => {
|
|||||||
} = useBulkMonitorActions(refetch, page);
|
} = useBulkMonitorActions(refetch, page);
|
||||||
|
|
||||||
// Check if any filters are active
|
// Check if any filters are active
|
||||||
const hasActiveFilters = Boolean(selectedStatus || selectedState || search);
|
const hasActiveFilters = Boolean(
|
||||||
|
selectedStatus || selectedState || selectedTags.length > 0 || search
|
||||||
|
);
|
||||||
|
|
||||||
// Show empty state only when there are truly no monitors (not just filtered out)
|
// Show empty state only when there are truly no monitors (not just filtered out)
|
||||||
const effectiveTotalCount =
|
const effectiveTotalCount =
|
||||||
@@ -165,6 +175,9 @@ const InfrastructureMonitors = () => {
|
|||||||
setSelectedStatus={setSelectedStatus}
|
setSelectedStatus={setSelectedStatus}
|
||||||
selectedState={selectedState}
|
selectedState={selectedState}
|
||||||
setSelectedState={setSelectedState}
|
setSelectedState={setSelectedState}
|
||||||
|
tagOptions={tags ?? []}
|
||||||
|
selectedTags={selectedTags}
|
||||||
|
setSelectedTags={setSelectedTags}
|
||||||
onClearFilters={handleClearFilters}
|
onClearFilters={handleClearFilters}
|
||||||
/>
|
/>
|
||||||
<TextField
|
<TextField
|
||||||
@@ -176,6 +189,30 @@ const InfrastructureMonitors = () => {
|
|||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
|
{selectedTags.length > 0 && (
|
||||||
|
<Stack
|
||||||
|
direction={isSmall ? "column" : "row"}
|
||||||
|
alignItems={isSmall ? "flex-start" : "center"}
|
||||||
|
flexWrap="wrap"
|
||||||
|
gap={theme.spacing(SPACING.XL)}
|
||||||
|
>
|
||||||
|
<Typography color={theme.palette.text.secondary}>
|
||||||
|
{t("pages.uptime.filters.activeTags")}
|
||||||
|
</Typography>
|
||||||
|
{selectedTags.map((tagId) => {
|
||||||
|
const tag = tags?.find((t) => t.id === tagId);
|
||||||
|
if (!tag) return null;
|
||||||
|
return (
|
||||||
|
<ColoredLabel
|
||||||
|
key={tag.id}
|
||||||
|
text={tag.name}
|
||||||
|
color={tag.color}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Stack>
|
||||||
|
)}
|
||||||
|
|
||||||
{!isLoading && (
|
{!isLoading && (
|
||||||
<BulkActionsBar
|
<BulkActionsBar
|
||||||
selectedCount={selectedRows.length}
|
selectedCount={selectedRows.length}
|
||||||
@@ -200,6 +237,7 @@ const InfrastructureMonitors = () => {
|
|||||||
|
|
||||||
<InfraMonitorsTable
|
<InfraMonitorsTable
|
||||||
monitors={monitorsWithChecksData?.monitors || []}
|
monitors={monitorsWithChecksData?.monitors || []}
|
||||||
|
tags={tags ?? []}
|
||||||
refetch={refetch}
|
refetch={refetch}
|
||||||
setSelectedMonitor={setSelectedMonitor}
|
setSelectedMonitor={setSelectedMonitor}
|
||||||
sortField={sortField}
|
sortField={sortField}
|
||||||
|
|||||||
@@ -6,8 +6,9 @@ import {
|
|||||||
Pagination,
|
Pagination,
|
||||||
StatusLabel,
|
StatusLabel,
|
||||||
StrategyBadge,
|
StrategyBadge,
|
||||||
|
ColoredLabel,
|
||||||
} from "@/Components/design-elements";
|
} from "@/Components/design-elements";
|
||||||
import { LAYOUT } from "@/Utils/Theme/constants";
|
import { LAYOUT, SPACING } from "@/Utils/Theme/constants";
|
||||||
import { HistogramPageSpeed } from "@/Components/monitors";
|
import { HistogramPageSpeed } from "@/Components/monitors";
|
||||||
import { ArrowDown, ArrowUp } from "lucide-react";
|
import { ArrowDown, ArrowUp } from "lucide-react";
|
||||||
import type { Header } from "@/Components/design-elements/Table";
|
import type { Header } from "@/Components/design-elements/Table";
|
||||||
@@ -20,10 +21,12 @@ import { useNavigate } from "react-router-dom";
|
|||||||
import { usePatch } from "@/Hooks/UseApi";
|
import { usePatch } from "@/Hooks/UseApi";
|
||||||
|
|
||||||
import type { Monitor, MonitorWithChecks } from "@/Types/Monitor";
|
import type { Monitor, MonitorWithChecks } from "@/Types/Monitor";
|
||||||
|
import type { Tag } from "@/Types/Tag";
|
||||||
import type { ActionMenuItem } from "@/Components/actions-menu";
|
import type { ActionMenuItem } from "@/Components/actions-menu";
|
||||||
|
|
||||||
export const PageSpeedMonitorsTable = ({
|
export const PageSpeedMonitorsTable = ({
|
||||||
monitors,
|
monitors,
|
||||||
|
tags,
|
||||||
refetch,
|
refetch,
|
||||||
setSelectedMonitor,
|
setSelectedMonitor,
|
||||||
sortField,
|
sortField,
|
||||||
@@ -37,6 +40,7 @@ export const PageSpeedMonitorsTable = ({
|
|||||||
setRowsPerPage,
|
setRowsPerPage,
|
||||||
}: {
|
}: {
|
||||||
monitors: MonitorWithChecks[];
|
monitors: MonitorWithChecks[];
|
||||||
|
tags: Tag[];
|
||||||
refetch: Function;
|
refetch: Function;
|
||||||
setSelectedMonitor: Function;
|
setSelectedMonitor: Function;
|
||||||
sortField: string;
|
sortField: string;
|
||||||
@@ -233,6 +237,32 @@ export const PageSpeedMonitorsTable = ({
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "tags",
|
||||||
|
content: t("common.table.headers.tags"),
|
||||||
|
render: (row) => {
|
||||||
|
if (row.tags.length === 0) return "-";
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
justifyContent={"center"}
|
||||||
|
direction={isSmall ? "column" : "row"}
|
||||||
|
gap={theme.spacing(SPACING.LG)}
|
||||||
|
>
|
||||||
|
{row.tags.map((tagId) => {
|
||||||
|
const fullTag = tags.find((tag) => tag.id === tagId);
|
||||||
|
if (!fullTag) return null;
|
||||||
|
return (
|
||||||
|
<ColoredLabel
|
||||||
|
key={fullTag.id}
|
||||||
|
text={fullTag.name}
|
||||||
|
color={fullTag.color}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
id: "actions",
|
id: "actions",
|
||||||
|
|||||||
@@ -1,22 +1,32 @@
|
|||||||
import {
|
import {
|
||||||
MonitorBasePageWithStates,
|
MonitorBasePageWithStates,
|
||||||
PageSpeedKeyPriorityFallback,
|
PageSpeedKeyPriorityFallback,
|
||||||
|
ColoredLabel,
|
||||||
} from "@/Components/design-elements";
|
} from "@/Components/design-elements";
|
||||||
import { Dialog } from "@/Components/inputs";
|
import { Dialog, TextField } from "@/Components/inputs";
|
||||||
import { HeaderCreate } from "@/Components/common";
|
import { HeaderCreate } from "@/Components/common";
|
||||||
import { PageSpeedMonitorsTable } from "@/Pages/PageSpeed/Monitors/Components/PageSpeedMonitorsTable";
|
import { PageSpeedMonitorsTable } from "@/Pages/PageSpeed/Monitors/Components/PageSpeedMonitorsTable";
|
||||||
import type { Monitor } from "@/Types/Monitor";
|
import type { Monitor } from "@/Types/Monitor";
|
||||||
|
import type { Tag } from "@/Types/Tag";
|
||||||
|
import Stack from "@mui/material/Stack";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
import useMediaQuery from "@mui/material/useMediaQuery";
|
||||||
|
import { useTheme } from "@mui/material";
|
||||||
|
import { SPACING } from "@/Utils/Theme/constants";
|
||||||
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useMemo, useState } from "react";
|
import { useCallback, useMemo, useState } from "react";
|
||||||
import { useIsAdmin } from "@/Hooks/useIsAdmin";
|
import { useIsAdmin } from "@/Hooks/useIsAdmin";
|
||||||
import { useGet, useDelete } from "@/Hooks/UseApi";
|
import { useGet, useDelete } from "@/Hooks/UseApi";
|
||||||
|
import useDebounce from "@/Hooks/useDebounce";
|
||||||
import type { MonitorsWithChecksResponse } from "@/Types/Monitor";
|
import type { MonitorsWithChecksResponse } from "@/Types/Monitor";
|
||||||
import type { AppSettingsResponse } from "@/Types/Settings";
|
import type { AppSettingsResponse } from "@/Types/Settings";
|
||||||
import { HeaderMonitorsSummary } from "@/Components/monitors";
|
import { ControlsFilter, HeaderMonitorsSummary } from "@/Components/monitors";
|
||||||
|
|
||||||
const PageSpeedMonitorsPage = () => {
|
const PageSpeedMonitorsPage = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const theme = useTheme();
|
||||||
|
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
||||||
const isAdmin = useIsAdmin();
|
const isAdmin = useIsAdmin();
|
||||||
const { deleteFn, loading: isDeleting } = useDelete();
|
const { deleteFn, loading: isDeleting } = useDelete();
|
||||||
|
|
||||||
@@ -33,17 +43,50 @@ const PageSpeedMonitorsPage = () => {
|
|||||||
const [sortOrder, setSortOrder] = useState<"asc" | "desc">("asc");
|
const [sortOrder, setSortOrder] = useState<"asc" | "desc">("asc");
|
||||||
const [page, setPage] = useState(0);
|
const [page, setPage] = useState(0);
|
||||||
const [rowsPerPage, setRowsPerPage] = useState(10);
|
const [rowsPerPage, setRowsPerPage] = useState(10);
|
||||||
|
const [selectedTags, setSelectedTags] = useState<string[]>([]);
|
||||||
|
const [selectedStatus, setSelectedStatus] = useState<string>("");
|
||||||
|
const [selectedState, setSelectedState] = useState<string>("");
|
||||||
|
const [search, setSearch] = useState<string>("");
|
||||||
|
|
||||||
|
const debouncedSearch = useDebounce<string>(search, 300);
|
||||||
|
|
||||||
|
// Status: pass "up"/"down" directly to the API
|
||||||
|
// State: "active" -> true, "paused" -> false
|
||||||
|
const toFilterStatus = useMemo(() => {
|
||||||
|
if (selectedStatus === "up") return "up";
|
||||||
|
if (selectedStatus === "down") return "down";
|
||||||
|
return undefined;
|
||||||
|
}, [selectedStatus]);
|
||||||
|
|
||||||
|
const toFilterActive = useMemo(() => {
|
||||||
|
if (selectedState === "active") return "true";
|
||||||
|
if (selectedState === "paused") return "false";
|
||||||
|
return undefined;
|
||||||
|
}, [selectedState]);
|
||||||
|
|
||||||
|
// Priority: status > isActive > search > sort
|
||||||
|
const filterLookup = new Map<string | undefined, string>([
|
||||||
|
[toFilterStatus, "status"],
|
||||||
|
[toFilterActive, "isActive"],
|
||||||
|
]);
|
||||||
|
const activeFilter = [...filterLookup].find(([key]) => key !== undefined);
|
||||||
|
const field = activeFilter?.[1] || (debouncedSearch ? "name" : sortField || undefined);
|
||||||
|
const filter = activeFilter?.[0] || debouncedSearch;
|
||||||
|
|
||||||
|
const { data: tags } = useGet<Tag[]>("/tags/team");
|
||||||
|
|
||||||
const monitorsWithChecksUrl = useMemo(() => {
|
const monitorsWithChecksUrl = useMemo(() => {
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
params.append("type", "pagespeed");
|
params.append("type", "pagespeed");
|
||||||
|
selectedTags.forEach((tagId) => params.append("tags", tagId));
|
||||||
params.append("limit", "25");
|
params.append("limit", "25");
|
||||||
if (page !== undefined) params.append("page", String(page));
|
if (page !== undefined) params.append("page", String(page));
|
||||||
if (rowsPerPage) params.append("rowsPerPage", String(rowsPerPage));
|
if (rowsPerPage) params.append("rowsPerPage", String(rowsPerPage));
|
||||||
if (sortField) params.append("field", sortField);
|
if (filter) params.append("filter", filter);
|
||||||
|
if (field) params.append("field", field);
|
||||||
if (sortOrder) params.append("order", sortOrder);
|
if (sortOrder) params.append("order", sortOrder);
|
||||||
return `/monitors/team/with-checks?${params.toString()}`;
|
return `/monitors/team/with-checks?${params.toString()}`;
|
||||||
}, [page, rowsPerPage, sortField, sortOrder]);
|
}, [page, rowsPerPage, sortOrder, selectedTags, filter, field]);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: monitorsData,
|
data: monitorsData,
|
||||||
@@ -75,12 +118,28 @@ const PageSpeedMonitorsPage = () => {
|
|||||||
setSelectedMonitor(null);
|
setSelectedMonitor(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleClearFilters = useCallback(() => {
|
||||||
|
setSelectedStatus("");
|
||||||
|
setSelectedState("");
|
||||||
|
setSelectedTags([]);
|
||||||
|
setSearch("");
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const hasActiveFilters = Boolean(
|
||||||
|
selectedStatus || selectedState || selectedTags.length > 0 || search
|
||||||
|
);
|
||||||
|
|
||||||
|
const effectiveTotalCount =
|
||||||
|
hasActiveFilters && (summary?.totalMonitors ?? 0) === 0
|
||||||
|
? 1
|
||||||
|
: (summary?.totalMonitors ?? 0);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MonitorBasePageWithStates
|
<MonitorBasePageWithStates
|
||||||
headerKey="pageSpeed"
|
headerKey="pageSpeed"
|
||||||
loading={isLoading}
|
loading={isLoading}
|
||||||
error={monitorsError || settingsError}
|
error={monitorsError || settingsError}
|
||||||
totalCount={summary?.totalMonitors ?? 0}
|
totalCount={effectiveTotalCount}
|
||||||
page="pageSpeed"
|
page="pageSpeed"
|
||||||
actionLink="/pagespeed/create"
|
actionLink="/pagespeed/create"
|
||||||
priorityFallback={showApiKeyWarning ? <PageSpeedKeyPriorityFallback /> : undefined}
|
priorityFallback={showApiKeyWarning ? <PageSpeedKeyPriorityFallback /> : undefined}
|
||||||
@@ -91,8 +150,59 @@ const PageSpeedMonitorsPage = () => {
|
|||||||
isAdmin={isAdmin}
|
isAdmin={isAdmin}
|
||||||
/>
|
/>
|
||||||
<HeaderMonitorsSummary summary={summary} />
|
<HeaderMonitorsSummary summary={summary} />
|
||||||
|
|
||||||
|
<Stack
|
||||||
|
direction={isSmall ? "column" : "row"}
|
||||||
|
justifyContent={isSmall ? "flex-start" : "space-between"}
|
||||||
|
gap={theme.spacing(4)}
|
||||||
|
>
|
||||||
|
<ControlsFilter
|
||||||
|
showTypes={false}
|
||||||
|
selectedStatus={selectedStatus}
|
||||||
|
setSelectedStatus={setSelectedStatus}
|
||||||
|
selectedState={selectedState}
|
||||||
|
setSelectedState={setSelectedState}
|
||||||
|
tagOptions={tags ?? []}
|
||||||
|
selectedTags={selectedTags}
|
||||||
|
setSelectedTags={setSelectedTags}
|
||||||
|
onClearFilters={handleClearFilters}
|
||||||
|
/>
|
||||||
|
<TextField
|
||||||
|
placeholder={t("pages.uptime.filters.search.placeholder")}
|
||||||
|
value={search}
|
||||||
|
onChange={(event) => {
|
||||||
|
setSearch(event.target.value);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
|
||||||
|
{selectedTags.length > 0 && (
|
||||||
|
<Stack
|
||||||
|
direction={isSmall ? "column" : "row"}
|
||||||
|
alignItems={isSmall ? "flex-start" : "center"}
|
||||||
|
flexWrap="wrap"
|
||||||
|
gap={theme.spacing(SPACING.XL)}
|
||||||
|
>
|
||||||
|
<Typography color={theme.palette.text.secondary}>
|
||||||
|
{t("pages.uptime.filters.activeTags")}
|
||||||
|
</Typography>
|
||||||
|
{selectedTags.map((tagId) => {
|
||||||
|
const tag = tags?.find((t) => t.id === tagId);
|
||||||
|
if (!tag) return null;
|
||||||
|
return (
|
||||||
|
<ColoredLabel
|
||||||
|
key={tag.id}
|
||||||
|
text={tag.name}
|
||||||
|
color={tag.color}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Stack>
|
||||||
|
)}
|
||||||
|
|
||||||
<PageSpeedMonitorsTable
|
<PageSpeedMonitorsTable
|
||||||
monitors={monitors || []}
|
monitors={monitors || []}
|
||||||
|
tags={tags ?? []}
|
||||||
refetch={refetch}
|
refetch={refetch}
|
||||||
setSelectedMonitor={setSelectedMonitor}
|
setSelectedMonitor={setSelectedMonitor}
|
||||||
sortField={sortField}
|
sortField={sortField}
|
||||||
|
|||||||
@@ -0,0 +1,103 @@
|
|||||||
|
import { ActionsMenu, type ActionMenuItem } from "@/Components/actions-menu";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
import type { Header } from "@/Components/design-elements/Table";
|
||||||
|
import { Table, ColoredLabel } from "@/Components/design-elements";
|
||||||
|
import { Pagination } from "@/Components/design-elements/Table";
|
||||||
|
import { useClientPagination } from "@/Hooks/useClientPagination";
|
||||||
|
|
||||||
|
import type { Tag } from "@/Types/Tag";
|
||||||
|
import { useNavigate } from "react-router";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useTheme } from "@mui/material";
|
||||||
|
|
||||||
|
interface TagsTableProps {
|
||||||
|
tags: Tag[];
|
||||||
|
setSelectedTag: Function;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const TagsTable = ({ tags, setSelectedTag }: TagsTableProps) => {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const theme = useTheme();
|
||||||
|
const { pagedRows, paginationProps } = useClientPagination(tags);
|
||||||
|
|
||||||
|
const getActions = (tag: Tag): ActionMenuItem[] => {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
label: t("pages.common.monitors.actions.configure"),
|
||||||
|
action: () => {
|
||||||
|
navigate(`/tags/configure/${tag.id}`);
|
||||||
|
},
|
||||||
|
closeMenu: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
label: (
|
||||||
|
<Typography color={theme.palette.error.main}>
|
||||||
|
{t("pages.common.monitors.actions.delete")}
|
||||||
|
</Typography>
|
||||||
|
),
|
||||||
|
action: async () => {
|
||||||
|
setSelectedTag(tag);
|
||||||
|
},
|
||||||
|
closeMenu: true,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
const getHeaders = () => {
|
||||||
|
const headers: Header<Tag>[] = [
|
||||||
|
{
|
||||||
|
id: "name",
|
||||||
|
content: t("common.table.headers.name"),
|
||||||
|
render: (row) => {
|
||||||
|
return <Typography>{row?.name}</Typography>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
id: "color",
|
||||||
|
content: t("pages.tags.table.headers.color"),
|
||||||
|
render: (row) => {
|
||||||
|
return <Typography textTransform={"capitalize"}>{row?.color}</Typography>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "chip",
|
||||||
|
content: t("pages.tags.table.headers.appearance"),
|
||||||
|
render: (row) => {
|
||||||
|
return (
|
||||||
|
<ColoredLabel
|
||||||
|
text={row.name}
|
||||||
|
color={row.color}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
id: "actions",
|
||||||
|
content: t("common.table.headers.actions"),
|
||||||
|
render: (row) => {
|
||||||
|
return <ActionsMenu items={getActions(row)} />;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
return headers;
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Table
|
||||||
|
headers={getHeaders()}
|
||||||
|
data={pagedRows}
|
||||||
|
onRowClick={(row) => {
|
||||||
|
navigate(`/tags/configure/${row.id}`);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{tags.length > 0 && <Pagination {...paginationProps} />}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
import { BasePage, ConfigBox } from "@/Components/design-elements";
|
||||||
|
import { TextField, Button, ColorInput } from "@/Components/inputs";
|
||||||
|
import Stack from "@mui/material/Stack";
|
||||||
|
import { useTheme } from "@mui/material/styles";
|
||||||
|
|
||||||
|
import { useEffect } from "react";
|
||||||
|
import { useParams } from "react-router-dom";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { Controller, useForm } from "react-hook-form";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import { mutate } from "swr";
|
||||||
|
import { useGet, usePost, usePatch } from "@/Hooks/UseApi";
|
||||||
|
import type { TagFormData } from "@/Validation/tag";
|
||||||
|
import type { Tag } from "@/Types/Tag";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useTagsForm } from "@/Hooks/useTagsForm";
|
||||||
|
|
||||||
|
const TagsCreatePage = () => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const theme = useTheme();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const { tagId } = useParams<{ tagId: string }>();
|
||||||
|
const isEditMode = Boolean(tagId);
|
||||||
|
|
||||||
|
const { data: existingTag } = useGet<Tag>(isEditMode ? `/tags/${tagId}` : null);
|
||||||
|
|
||||||
|
const { post, loading: isSubmitting } = usePost<TagFormData, Tag>();
|
||||||
|
const { patch, loading: isPatching } = usePatch<TagFormData, Tag>();
|
||||||
|
|
||||||
|
const { schema, defaults } = useTagsForm({ data: existingTag });
|
||||||
|
|
||||||
|
const form = useForm<TagFormData>({
|
||||||
|
resolver: zodResolver(schema),
|
||||||
|
defaultValues: defaults,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { control, reset, handleSubmit } = form;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
reset(defaults);
|
||||||
|
}, [defaults, reset]);
|
||||||
|
|
||||||
|
const onSubmit = async (data: TagFormData) => {
|
||||||
|
const result = isEditMode
|
||||||
|
? await patch(`/tags/${tagId}`, data)
|
||||||
|
: await post("/tags", data);
|
||||||
|
if (result?.success) {
|
||||||
|
await mutate((key) => typeof key === "string" && key.startsWith("/tags"));
|
||||||
|
navigate("/tags");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<BasePage
|
||||||
|
component="form"
|
||||||
|
onSubmit={handleSubmit(onSubmit)}
|
||||||
|
>
|
||||||
|
<ConfigBox
|
||||||
|
title={t("pages.tags.form.name.title")}
|
||||||
|
subtitle={t("pages.tags.form.name.description")}
|
||||||
|
rightContent={
|
||||||
|
<Controller
|
||||||
|
name="name"
|
||||||
|
control={control}
|
||||||
|
defaultValue={defaults.name}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<TextField
|
||||||
|
{...field}
|
||||||
|
type="text"
|
||||||
|
fieldLabel={t("pages.tags.form.name.optionName")}
|
||||||
|
placeholder={t("pages.tags.form.name.placeholder")}
|
||||||
|
fullWidth
|
||||||
|
error={!!fieldState.error}
|
||||||
|
helperText={fieldState.error?.message ?? ""}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<ConfigBox
|
||||||
|
title={t("pages.tags.form.color.title")}
|
||||||
|
subtitle={t("pages.tags.form.color.description")}
|
||||||
|
rightContent={
|
||||||
|
<Controller
|
||||||
|
name="color"
|
||||||
|
control={control}
|
||||||
|
defaultValue={defaults.color}
|
||||||
|
render={({ field }) => (
|
||||||
|
<ColorInput
|
||||||
|
format="hex"
|
||||||
|
value={field.value}
|
||||||
|
onChange={field.onChange}
|
||||||
|
fieldLabel={t("pages.tags.form.color.optionName")}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
justifyContent="flex-end"
|
||||||
|
spacing={theme.spacing(2)}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
loading={isSubmitting || isPatching}
|
||||||
|
type="submit"
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
>
|
||||||
|
{t("common.buttons.save")}
|
||||||
|
</Button>
|
||||||
|
</Stack>
|
||||||
|
</BasePage>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TagsCreatePage;
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
import { BasePageWithStates } from "@/Components/design-elements";
|
||||||
|
import { TagsTable } from "@/Pages/Tags/components/TagsTable";
|
||||||
|
import { Dialog } from "@/Components/inputs";
|
||||||
|
import { HeaderCreate } from "@/Components/common";
|
||||||
|
|
||||||
|
import { useState } from "react";
|
||||||
|
import { useGet, useDelete } from "@/Hooks/UseApi";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import type { Tag } from "@/Types/Tag";
|
||||||
|
import { useIsAdmin } from "@/Hooks/useIsAdmin";
|
||||||
|
|
||||||
|
const TagsPage = () => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const isAdmin = useIsAdmin();
|
||||||
|
|
||||||
|
const [selectedTag, setSelectedTag] = useState<Tag | null>(null);
|
||||||
|
const isDialogOpen = Boolean(selectedTag);
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: tags,
|
||||||
|
isLoading,
|
||||||
|
isValidating,
|
||||||
|
error,
|
||||||
|
refetch,
|
||||||
|
} = useGet<Tag[]>("/tags/team", {}, { keepPreviousData: true });
|
||||||
|
|
||||||
|
const { deleteFn, loading: isDeleting } = useDelete();
|
||||||
|
|
||||||
|
const handleConfirm = async () => {
|
||||||
|
if (!selectedTag) return;
|
||||||
|
await deleteFn(`/tags/${selectedTag.id}`);
|
||||||
|
setSelectedTag(null);
|
||||||
|
refetch();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCancel = () => {
|
||||||
|
setSelectedTag(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<BasePageWithStates
|
||||||
|
headerKey="tags"
|
||||||
|
page={t("pages.tags.fallback.title")}
|
||||||
|
description={t("pages.tags.fallback.description")}
|
||||||
|
loading={isLoading || isValidating}
|
||||||
|
error={!!error}
|
||||||
|
totalCount={tags?.length ?? 0}
|
||||||
|
actionButtonText={t("pages.tags.fallback.actionButton")}
|
||||||
|
actionLink="/tags/create"
|
||||||
|
>
|
||||||
|
<HeaderCreate
|
||||||
|
path="/tags/create"
|
||||||
|
isLoading={isLoading || isValidating}
|
||||||
|
isAdmin={isAdmin}
|
||||||
|
/>
|
||||||
|
<TagsTable
|
||||||
|
tags={tags ?? []}
|
||||||
|
setSelectedTag={setSelectedTag}
|
||||||
|
/>
|
||||||
|
<Dialog
|
||||||
|
open={isDialogOpen}
|
||||||
|
title={t("common.dialogs.delete.title")}
|
||||||
|
content={t("common.dialogs.delete.description")}
|
||||||
|
onConfirm={handleConfirm}
|
||||||
|
onCancel={handleCancel}
|
||||||
|
loading={isDeleting}
|
||||||
|
/>
|
||||||
|
</BasePageWithStates>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TagsPage;
|
||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
type Header,
|
type Header,
|
||||||
Pagination,
|
Pagination,
|
||||||
StatusLabel,
|
StatusLabel,
|
||||||
|
ColoredLabel,
|
||||||
} from "@/Components/design-elements";
|
} from "@/Components/design-elements";
|
||||||
import { HeatmapResponseTime, HistogramResponseTime } from "@/Components/common";
|
import { HeatmapResponseTime, HistogramResponseTime } from "@/Components/common";
|
||||||
import { ActionsMenu } from "@/Components/actions-menu";
|
import { ActionsMenu } from "@/Components/actions-menu";
|
||||||
@@ -16,14 +17,18 @@ import { useTheme } from "@mui/material/styles";
|
|||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { usePost } from "@/Hooks/UseApi";
|
import { usePost } from "@/Hooks/UseApi";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
|
import useMediaQuery from "@mui/material/useMediaQuery";
|
||||||
|
|
||||||
import type { Monitor } from "@/Types/Monitor";
|
import type { Monitor } from "@/Types/Monitor";
|
||||||
import type { ActionMenuItem } from "@/Components/actions-menu";
|
import type { ActionMenuItem } from "@/Components/actions-menu";
|
||||||
import type { RootState } from "@/Types/state";
|
import type { RootState } from "@/Types/state";
|
||||||
import { Checkbox } from "@/Components/inputs";
|
import { Checkbox } from "@/Components/inputs";
|
||||||
|
import type { Tag } from "@/Types/Tag";
|
||||||
|
import { SPACING } from "@/Utils/Theme/constants";
|
||||||
|
|
||||||
interface MonitorTableProps {
|
interface MonitorTableProps {
|
||||||
monitors: Monitor[];
|
monitors: Monitor[];
|
||||||
|
tags: Tag[];
|
||||||
refetch: () => void;
|
refetch: () => void;
|
||||||
setSelectedMonitor: (monitor: Monitor | null) => void;
|
setSelectedMonitor: (monitor: Monitor | null) => void;
|
||||||
sortField: string;
|
sortField: string;
|
||||||
@@ -41,6 +46,7 @@ interface MonitorTableProps {
|
|||||||
|
|
||||||
export const MonitorTable = ({
|
export const MonitorTable = ({
|
||||||
monitors,
|
monitors,
|
||||||
|
tags,
|
||||||
refetch,
|
refetch,
|
||||||
setSelectedMonitor,
|
setSelectedMonitor,
|
||||||
sortField,
|
sortField,
|
||||||
@@ -60,6 +66,7 @@ export const MonitorTable = ({
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const chartType = useSelector((state: RootState) => state.ui?.chartType ?? "histogram");
|
const chartType = useSelector((state: RootState) => state.ui?.chartType ?? "histogram");
|
||||||
const { post } = usePost<Record<string, never>, Monitor>();
|
const { post } = usePost<Record<string, never>, Monitor>();
|
||||||
|
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
||||||
|
|
||||||
const selectedSet = new Set(selectedRows);
|
const selectedSet = new Set(selectedRows);
|
||||||
const isAllSelected =
|
const isAllSelected =
|
||||||
@@ -252,6 +259,33 @@ export const MonitorTable = ({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "tags",
|
||||||
|
content: t("common.table.headers.tags"),
|
||||||
|
render: (row) => {
|
||||||
|
if (row.tags.length === 0) return "-";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
justifyContent={"center"}
|
||||||
|
direction={isSmall ? "column" : "row"}
|
||||||
|
gap={theme.spacing(SPACING.LG)}
|
||||||
|
>
|
||||||
|
{row.tags.map((tag) => {
|
||||||
|
const fullTag = tags.find((t) => t.id === tag);
|
||||||
|
if (!fullTag) return null;
|
||||||
|
return (
|
||||||
|
<ColoredLabel
|
||||||
|
key={fullTag.id}
|
||||||
|
text={fullTag.name}
|
||||||
|
color={fullTag.color}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: "type",
|
id: "type",
|
||||||
mobileLabel: t("common.table.headers.type"),
|
mobileLabel: t("common.table.headers.type"),
|
||||||
|
|||||||
@@ -3,17 +3,19 @@ import {
|
|||||||
HeaderMonitorsSummary,
|
HeaderMonitorsSummary,
|
||||||
BulkActionsBar,
|
BulkActionsBar,
|
||||||
} from "@/Components/monitors";
|
} from "@/Components/monitors";
|
||||||
import { MonitorBasePageWithStates } from "@/Components/design-elements";
|
import { MonitorBasePageWithStates, ColoredLabel } from "@/Components/design-elements";
|
||||||
import { TextField, Dialog, Button } from "@/Components/inputs";
|
import { TextField, Dialog, Button } from "@/Components/inputs";
|
||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import { MonitorTable } from "@/Pages/Uptime/Monitors/Components/UptimeMonitorsTable";
|
import { MonitorTable } from "@/Pages/Uptime/Monitors/Components/UptimeMonitorsTable";
|
||||||
import { HeaderCreate } from "@/Components/common";
|
import { HeaderCreate } from "@/Components/common";
|
||||||
import { Play, Pause } from "lucide-react";
|
import { Play, Pause } from "lucide-react";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import useMediaQuery from "@mui/material/useMediaQuery";
|
import useMediaQuery from "@mui/material/useMediaQuery";
|
||||||
import { useGet, useDelete } from "@/Hooks/UseApi";
|
import { useGet, useDelete } from "@/Hooks/UseApi";
|
||||||
import type { Monitor, MonitorType, MonitorsWithChecksResponse } from "@/Types/Monitor";
|
import type { Monitor, MonitorType, MonitorsWithChecksResponse } from "@/Types/Monitor";
|
||||||
|
import type { Tag } from "@/Types/Tag";
|
||||||
import { useState, useMemo, useCallback } from "react";
|
import { useState, useMemo, useCallback } from "react";
|
||||||
import { useSelector, useDispatch } from "react-redux";
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
import { setRowsPerPage } from "@/Features/UI/uiSlice.js";
|
import { setRowsPerPage } from "@/Features/UI/uiSlice.js";
|
||||||
@@ -22,6 +24,7 @@ import type { RootState } from "@/Types/state";
|
|||||||
import { useTheme } from "@mui/material";
|
import { useTheme } from "@mui/material";
|
||||||
import useDebounce from "@/Hooks/useDebounce";
|
import useDebounce from "@/Hooks/useDebounce";
|
||||||
import { useBulkMonitorActions } from "@/Hooks/useBulkMonitorActions";
|
import { useBulkMonitorActions } from "@/Hooks/useBulkMonitorActions";
|
||||||
|
import { SPACING } from "@/Utils/Theme/constants";
|
||||||
|
|
||||||
const UptimeMonitorsPage = () => {
|
const UptimeMonitorsPage = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -38,6 +41,7 @@ const UptimeMonitorsPage = () => {
|
|||||||
const [selectedTypes, setSelectedTypes] = useState<MonitorType[]>([]);
|
const [selectedTypes, setSelectedTypes] = useState<MonitorType[]>([]);
|
||||||
const [selectedStatus, setSelectedStatus] = useState<string>("");
|
const [selectedStatus, setSelectedStatus] = useState<string>("");
|
||||||
const [selectedState, setSelectedState] = useState<string>("");
|
const [selectedState, setSelectedState] = useState<string>("");
|
||||||
|
const [selectedTags, setSelectedTags] = useState<string[]>([]);
|
||||||
const [page, setPage] = useState<number>(0);
|
const [page, setPage] = useState<number>(0);
|
||||||
const [search, setSearch] = useState<string>("");
|
const [search, setSearch] = useState<string>("");
|
||||||
const [sortField, setSortField] = useState<string>("");
|
const [sortField, setSortField] = useState<string>("");
|
||||||
@@ -83,6 +87,7 @@ const UptimeMonitorsPage = () => {
|
|||||||
const monitorsWithChecksUrl = useMemo(() => {
|
const monitorsWithChecksUrl = useMemo(() => {
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
effectiveTypes.forEach((type) => params.append("type", type));
|
effectiveTypes.forEach((type) => params.append("type", type));
|
||||||
|
selectedTags.forEach((tagId) => params.append("tags", tagId));
|
||||||
params.append("limit", "25");
|
params.append("limit", "25");
|
||||||
if (page !== undefined) params.append("page", String(page));
|
if (page !== undefined) params.append("page", String(page));
|
||||||
if (rowsPerPage) params.append("rowsPerPage", String(rowsPerPage));
|
if (rowsPerPage) params.append("rowsPerPage", String(rowsPerPage));
|
||||||
@@ -90,7 +95,7 @@ const UptimeMonitorsPage = () => {
|
|||||||
if (field) params.append("field", field);
|
if (field) params.append("field", field);
|
||||||
if (sortOrder) params.append("order", sortOrder);
|
if (sortOrder) params.append("order", sortOrder);
|
||||||
return `/monitors/team/with-checks?${params.toString()}`;
|
return `/monitors/team/with-checks?${params.toString()}`;
|
||||||
}, [effectiveTypes, page, rowsPerPage, filter, field, sortOrder]);
|
}, [effectiveTypes, selectedTags, page, rowsPerPage, filter, field, sortOrder]);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: monitorsWithChecksData,
|
data: monitorsWithChecksData,
|
||||||
@@ -103,6 +108,8 @@ const UptimeMonitorsPage = () => {
|
|||||||
{ refreshInterval: 5000, keepPreviousData: true }
|
{ refreshInterval: 5000, keepPreviousData: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const { data: tags } = useGet<Tag[]>("/tags/team");
|
||||||
|
|
||||||
const {
|
const {
|
||||||
monitors: monitorsWithChecks,
|
monitors: monitorsWithChecks,
|
||||||
summary,
|
summary,
|
||||||
@@ -126,6 +133,7 @@ const UptimeMonitorsPage = () => {
|
|||||||
setSelectedTypes([]);
|
setSelectedTypes([]);
|
||||||
setSelectedStatus("");
|
setSelectedStatus("");
|
||||||
setSelectedState("");
|
setSelectedState("");
|
||||||
|
setSelectedTags([]);
|
||||||
setSearch("");
|
setSearch("");
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -144,7 +152,11 @@ const UptimeMonitorsPage = () => {
|
|||||||
|
|
||||||
// Check if any filters are active
|
// Check if any filters are active
|
||||||
const hasActiveFilters = Boolean(
|
const hasActiveFilters = Boolean(
|
||||||
selectedTypes.length > 0 || selectedStatus || selectedState || search
|
selectedTypes.length > 0 ||
|
||||||
|
selectedStatus ||
|
||||||
|
selectedState ||
|
||||||
|
selectedTags.length > 0 ||
|
||||||
|
search
|
||||||
);
|
);
|
||||||
|
|
||||||
// Show empty state only when there are truly no monitors (not just filtered out)
|
// Show empty state only when there are truly no monitors (not just filtered out)
|
||||||
@@ -183,6 +195,9 @@ const UptimeMonitorsPage = () => {
|
|||||||
setSelectedStatus={setSelectedStatus}
|
setSelectedStatus={setSelectedStatus}
|
||||||
selectedState={selectedState}
|
selectedState={selectedState}
|
||||||
setSelectedState={setSelectedState}
|
setSelectedState={setSelectedState}
|
||||||
|
tagOptions={tags ?? []}
|
||||||
|
selectedTags={selectedTags}
|
||||||
|
setSelectedTags={setSelectedTags}
|
||||||
onClearFilters={handleClearFilters}
|
onClearFilters={handleClearFilters}
|
||||||
/>
|
/>
|
||||||
<TextField
|
<TextField
|
||||||
@@ -194,6 +209,30 @@ const UptimeMonitorsPage = () => {
|
|||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
|
{selectedTags.length > 0 && (
|
||||||
|
<Stack
|
||||||
|
direction={isSmall ? "column" : "row"}
|
||||||
|
alignItems={isSmall ? "flex-start" : "center"}
|
||||||
|
flexWrap="wrap"
|
||||||
|
gap={theme.spacing(SPACING.XL)}
|
||||||
|
>
|
||||||
|
<Typography color={theme.palette.text.secondary}>
|
||||||
|
{t("pages.uptime.filters.activeTags")}
|
||||||
|
</Typography>
|
||||||
|
{selectedTags.map((tagId) => {
|
||||||
|
const tag = tags?.find((t) => t.id === tagId);
|
||||||
|
if (!tag) return null;
|
||||||
|
return (
|
||||||
|
<ColoredLabel
|
||||||
|
key={tag.id}
|
||||||
|
text={tag.name}
|
||||||
|
color={tag.color}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Stack>
|
||||||
|
)}
|
||||||
|
|
||||||
{!isLoading && (
|
{!isLoading && (
|
||||||
<BulkActionsBar
|
<BulkActionsBar
|
||||||
selectedCount={selectedRows.length}
|
selectedCount={selectedRows.length}
|
||||||
@@ -218,6 +257,7 @@ const UptimeMonitorsPage = () => {
|
|||||||
|
|
||||||
<MonitorTable
|
<MonitorTable
|
||||||
monitors={monitorsWithChecks || []}
|
monitors={monitorsWithChecks || []}
|
||||||
|
tags={tags || []}
|
||||||
refetch={refetch}
|
refetch={refetch}
|
||||||
setSelectedMonitor={setSelectedMonitor}
|
setSelectedMonitor={setSelectedMonitor}
|
||||||
count={count || 0}
|
count={count || 0}
|
||||||
|
|||||||
@@ -31,9 +31,14 @@ import CreateStatus from "@/Pages/StatusPage/Create/";
|
|||||||
import StatusPages from "@/Pages/StatusPage/StatusPages";
|
import StatusPages from "@/Pages/StatusPage/StatusPages";
|
||||||
import Status from "@/Pages/StatusPage/Status";
|
import Status from "@/Pages/StatusPage/Status";
|
||||||
|
|
||||||
|
// Notifications
|
||||||
import Notifications from "@/Pages/Notifications";
|
import Notifications from "@/Pages/Notifications";
|
||||||
import CreateNotifications from "@/Pages/Notifications/create";
|
import CreateNotifications from "@/Pages/Notifications/create";
|
||||||
|
|
||||||
|
// Tags
|
||||||
|
import Tags from "@/Pages/Tags";
|
||||||
|
import CreateTags from "@/Pages/Tags/create";
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
import Account from "@/Pages/Account";
|
import Account from "@/Pages/Account";
|
||||||
import EditUser from "@/Pages/Account/EditUser";
|
import EditUser from "@/Pages/Account/EditUser";
|
||||||
@@ -159,6 +164,19 @@ const Routes = () => {
|
|||||||
path="notifications/configure/:notificationId"
|
path="notifications/configure/:notificationId"
|
||||||
element={<CreateNotifications />}
|
element={<CreateNotifications />}
|
||||||
/>
|
/>
|
||||||
|
<Route
|
||||||
|
path="tags"
|
||||||
|
element={<Tags />}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path="tags/create"
|
||||||
|
element={<CreateTags />}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Route
|
||||||
|
path="tags/configure/:tagId"
|
||||||
|
element={<CreateTags />}
|
||||||
|
/>
|
||||||
|
|
||||||
<Route
|
<Route
|
||||||
path="maintenance"
|
path="maintenance"
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ export interface Monitor {
|
|||||||
interval: number;
|
interval: number;
|
||||||
uptimePercentage?: number;
|
uptimePercentage?: number;
|
||||||
notifications: string[];
|
notifications: string[];
|
||||||
|
tags: string[];
|
||||||
secret?: string;
|
secret?: string;
|
||||||
cpuAlertThreshold: number;
|
cpuAlertThreshold: number;
|
||||||
cpuAlertCounter: number;
|
cpuAlertCounter: number;
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
export interface Tag {
|
||||||
|
id: string;
|
||||||
|
teamId: string;
|
||||||
|
name: string;
|
||||||
|
color: string;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ const baseSchema = z.object({
|
|||||||
description: z.string().optional(),
|
description: z.string().optional(),
|
||||||
interval: z.number().min(15000, "Interval must be at least 15 seconds"),
|
interval: z.number().min(15000, "Interval must be at least 15 seconds"),
|
||||||
notifications: z.array(z.string()),
|
notifications: z.array(z.string()),
|
||||||
|
tags: z.array(z.string()),
|
||||||
statusWindowSize: z
|
statusWindowSize: z
|
||||||
.number({ message: "Status window size is required" })
|
.number({ message: "Status window size is required" })
|
||||||
.min(1, "Status window size must be at least 1")
|
.min(1, "Status window size must be at least 1")
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
export const tagSchema = z.object({
|
||||||
|
name: z.string().min(1, "Please enter a tag name"),
|
||||||
|
color: z
|
||||||
|
.string()
|
||||||
|
.regex(/^#([0-9a-fA-F]{6})$/, "Color must be a 6-digit hex value (e.g. #13715B)"),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type TagFormData = z.infer<typeof tagSchema>;
|
||||||
@@ -131,7 +131,8 @@
|
|||||||
"url": "Url",
|
"url": "Url",
|
||||||
"interval": "Interval",
|
"interval": "Interval",
|
||||||
"active": "Active",
|
"active": "Active",
|
||||||
"responseTime": "Response time"
|
"responseTime": "Response time",
|
||||||
|
"tags": "Tags"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -184,6 +185,7 @@
|
|||||||
"pagespeed": "Pagespeed",
|
"pagespeed": "Pagespeed",
|
||||||
"infrastructure": "Infrastructure",
|
"infrastructure": "Infrastructure",
|
||||||
"notifications": "Notifications",
|
"notifications": "Notifications",
|
||||||
|
"tags": "Tags",
|
||||||
"checks": "Checks",
|
"checks": "Checks",
|
||||||
"incidents": "Incidents",
|
"incidents": "Incidents",
|
||||||
"statusPages": "Status pages",
|
"statusPages": "Status pages",
|
||||||
@@ -627,6 +629,10 @@
|
|||||||
"description": "Select the notification channels you want to use",
|
"description": "Select the notification channels you want to use",
|
||||||
"title": "Notifications"
|
"title": "Notifications"
|
||||||
},
|
},
|
||||||
|
"tags": {
|
||||||
|
"description": "Select the tags you want to apply to this monitor",
|
||||||
|
"title": "Tags"
|
||||||
|
},
|
||||||
"type": {
|
"type": {
|
||||||
"description": "Select the type of check to perform",
|
"description": "Select the type of check to perform",
|
||||||
"optionDockerDescription": "Use Docker to monitor if a container is running.",
|
"optionDockerDescription": "Use Docker to monitor if a container is running.",
|
||||||
@@ -876,6 +882,37 @@
|
|||||||
"description": "Track server performance, identify bottlenecks, and ensure reliability with real-time infrastructure monitoring."
|
"description": "Track server performance, identify bottlenecks, and ensure reliability with real-time infrastructure monitoring."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"tags": {
|
||||||
|
"header": {
|
||||||
|
"title": "Tags",
|
||||||
|
"description": "Organize your monitors with tags"
|
||||||
|
},
|
||||||
|
"fallback": {
|
||||||
|
"title": "No tags yet",
|
||||||
|
"description": "Organize your monitors with tags. Once you create a tag and assign it to a monitor, you'll be able to filter by that tag across the app and see tag details here.",
|
||||||
|
"actionButton": "Create a tag"
|
||||||
|
},
|
||||||
|
"table": {
|
||||||
|
"headers": {
|
||||||
|
"color": "Color",
|
||||||
|
"appearance": "Appearance"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"form": {
|
||||||
|
"name": {
|
||||||
|
"title": "Tag name",
|
||||||
|
"description": "Choose a name for your tag",
|
||||||
|
"optionName": "Tag name",
|
||||||
|
"placeholder": "e.g. Group 1"
|
||||||
|
},
|
||||||
|
"color": {
|
||||||
|
"title": "Tag color",
|
||||||
|
"description": "Choose a color for your tag",
|
||||||
|
"optionName": "Tag color",
|
||||||
|
"placeholder": "e.g. #13715B"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"logs": {
|
"logs": {
|
||||||
"fallback": {
|
"fallback": {
|
||||||
"title": "No logs yet",
|
"title": "No logs yet",
|
||||||
@@ -1523,7 +1560,8 @@
|
|||||||
"filters": {
|
"filters": {
|
||||||
"search": {
|
"search": {
|
||||||
"placeholder": "Search monitors..."
|
"placeholder": "Search monitors..."
|
||||||
}
|
},
|
||||||
|
"activeTags": "Active tags"
|
||||||
},
|
},
|
||||||
"table": {
|
"table": {
|
||||||
"headers": {
|
"headers": {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ export interface TeamQueryConfig {
|
|||||||
|
|
||||||
export interface SummaryConfig {
|
export interface SummaryConfig {
|
||||||
type?: MonitorType | MonitorType[];
|
type?: MonitorType | MonitorType[];
|
||||||
|
tags?: string | string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IMonitorsRepository {
|
export interface IMonitorsRepository {
|
||||||
|
|||||||
@@ -292,6 +292,10 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
|||||||
if (config?.type !== undefined) {
|
if (config?.type !== undefined) {
|
||||||
match.type = Array.isArray(config.type) ? { $in: config.type } : config.type;
|
match.type = Array.isArray(config.type) ? { $in: config.type } : config.type;
|
||||||
}
|
}
|
||||||
|
if (config?.tags !== undefined) {
|
||||||
|
const tagIds = (Array.isArray(config.tags) ? config.tags : [config.tags]).map((tag) => new mongoose.Types.ObjectId(tag));
|
||||||
|
match.tags = { $in: tagIds };
|
||||||
|
}
|
||||||
const pipeline = [
|
const pipeline = [
|
||||||
{ $match: match },
|
{ $match: match },
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -391,7 +391,7 @@ export class MonitorService implements IMonitorService {
|
|||||||
field?: string;
|
field?: string;
|
||||||
order?: "asc" | "desc";
|
order?: "asc" | "desc";
|
||||||
}): Promise<MonitorsWithChecksByTeamIdResult> => {
|
}): Promise<MonitorsWithChecksByTeamIdResult> => {
|
||||||
const summary = await this.monitorsRepository.findMonitorsSummaryByTeamId(teamId, { type });
|
const summary = await this.monitorsRepository.findMonitorsSummaryByTeamId(teamId, { type, tags });
|
||||||
const count = await this.monitorsRepository.findMonitorCountByTeamIdAndType(teamId, { type, tags, filter });
|
const count = await this.monitorsRepository.findMonitorCountByTeamIdAndType(teamId, { type, tags, filter });
|
||||||
const monitors = await this.monitorsRepository.findByTeamId(teamId, {
|
const monitors = await this.monitorsRepository.findByTeamId(teamId, {
|
||||||
limit,
|
limit,
|
||||||
|
|||||||
Reference in new issue
Block a user