add tags to Uptime montitor table
This commit is contained in:
1 parent
7d7926fab9
commit
3f290bc963
3 files changed
+113
-1
No files matched your search
@@ -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") && (
|
||||||
|
|||||||
@@ -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("pages.uptime.table.headers.responseTime"),
|
||||||
|
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"),
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ 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";
|
||||||
@@ -103,6 +104,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,
|
||||||
@@ -218,6 +221,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}
|
||||||
|
|||||||
Reference in new issue
Block a user