feat: add delete telemetry feature #34

This commit is contained in:
moonrailgun 2024-03-29 19:59:42 +08:00
parent 99610cffae
commit d862e6cb62
11 changed files with 397 additions and 133 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,15 @@
import { Trans, t } from '@i18next-toolkit/react'; import { Trans, t } from '@i18next-toolkit/react';
import { Button, Collapse, Form, Input, Modal, Table, Typography } from 'antd'; import {
Alert,
Button,
Collapse,
Form,
Input,
Modal,
Popconfirm,
Table,
Typography,
} from 'antd';
import React, { useMemo, useState } from 'react'; import React, { useMemo, useState } from 'react';
import { AppRouterOutput, trpc } from '../../api/trpc'; import { AppRouterOutput, trpc } from '../../api/trpc';
import { useCurrentWorkspaceId } from '../../store/user'; import { useCurrentWorkspaceId } from '../../store/user';
@ -9,11 +19,13 @@ import {
CodeOutlined, CodeOutlined,
EditOutlined, EditOutlined,
PlusOutlined, PlusOutlined,
DeleteOutlined,
} from '@ant-design/icons'; } from '@ant-design/icons';
import { useNavigate } from 'react-router'; import { useNavigate } from 'react-router';
import { PageHeader } from '../PageHeader'; import { PageHeader } from '../PageHeader';
import { useEvent } from '../../hooks/useEvent'; import { useEvent } from '../../hooks/useEvent';
import { TelemetryCounter } from './TelemetryCounter'; import { TelemetryCounter } from './TelemetryCounter';
import { LuDelete, LuTrash } from 'react-icons/lu';
type TelemetryInfo = AppRouterOutput['telemetry']['all'][number]; type TelemetryInfo = AppRouterOutput['telemetry']['all'][number];
@ -189,10 +201,15 @@ const TelemetryListTable: React.FC<{
onShowUsage: (info: TelemetryInfo) => void; onShowUsage: (info: TelemetryInfo) => void;
}> = React.memo((props) => { }> = React.memo((props) => {
const workspaceId = useCurrentWorkspaceId(); const workspaceId = useCurrentWorkspaceId();
const { data = [], isLoading } = trpc.telemetry.all.useQuery({ const {
data = [],
isLoading,
refetch,
} = trpc.telemetry.all.useQuery({
workspaceId, workspaceId,
}); });
const navigate = useNavigate(); const navigate = useNavigate();
const deleteMutation = trpc.telemetry.delete.useMutation();
const columns = useMemo((): ColumnsType<TelemetryInfo> => { const columns = useMemo((): ColumnsType<TelemetryInfo> => {
return [ return [
@ -217,6 +234,25 @@ const TelemetryListTable: React.FC<{
render: (_, record) => { render: (_, record) => {
return ( return (
<div className="flex justify-end gap-2"> <div className="flex justify-end gap-2">
<Popconfirm
title={t('Confirm to delete this telemetry: [{{name}}]', {
name: record.name,
})}
disabled={deleteMutation.isLoading}
onConfirm={async () => {
await deleteMutation.mutateAsync({
telemetryId: record.id,
workspaceId,
});
await refetch();
}}
>
<Button
danger={true}
disabled={deleteMutation.isLoading}
icon={<DeleteOutlined />}
/>
</Popconfirm>
<Button <Button
icon={<CodeOutlined />} icon={<CodeOutlined />}
onClick={() => props.onShowUsage(record)} onClick={() => props.onShowUsage(record)}

View File

@ -40,6 +40,10 @@ const config = {
'YYYY-MM-DD HH:mm', 'YYYY-MM-DD HH:mm',
], ],
}, },
translator: {
type: 'openai',
model: 'gpt-4'
},
}; };
module.exports = config; module.exports = config;

View File

@ -19,7 +19,7 @@
"@ant-design/icons": "^5.2.6", "@ant-design/icons": "^5.2.6",
"@antv/l7": "^2.20.14", "@antv/l7": "^2.20.14",
"@antv/larkmap": "^1.4.13", "@antv/larkmap": "^1.4.13",
"@i18next-toolkit/react": "^1.0.5", "@i18next-toolkit/react": "^1.0.6",
"@loadable/component": "^5.16.3", "@loadable/component": "^5.16.3",
"@monaco-editor/react": "^4.6.0", "@monaco-editor/react": "^4.6.0",
"@tanstack/react-query": "4.33.0", "@tanstack/react-query": "4.33.0",
@ -56,7 +56,7 @@
"zustand": "^4.4.1" "zustand": "^4.4.1"
}, },
"devDependencies": { "devDependencies": {
"@i18next-toolkit/cli": "^1.0.7", "@i18next-toolkit/cli": "^1.1.0",
"@types/leaflet": "^1.9.8", "@types/leaflet": "^1.9.8",
"@types/loadable__component": "^5.13.8", "@types/loadable__component": "^5.13.8",
"@types/lodash-es": "^4.17.12", "@types/lodash-es": "^4.17.12",

View File

@ -146,6 +146,7 @@
"kaa0ccaab": "Von E-Mail", "kaa0ccaab": "Von E-Mail",
"kab56db46": "Herzschläge", "kab56db46": "Herzschläge",
"kacbdae07": "Durchschn. Antwort", "kacbdae07": "Durchschn. Antwort",
"kad9ea10d": "Bestätigen Sie das Löschen dieser Telemetrie: [{{name}}]",
"kadef6c48": "Vorherige {{label}}", "kadef6c48": "Vorherige {{label}}",
"kaf39be20": "Netzwerk", "kaf39be20": "Netzwerk",
"kb01f4f95": "Fertig", "kb01f4f95": "Fertig",
@ -176,7 +177,7 @@
"kcaf5c873": "Aktionen", "kcaf5c873": "Aktionen",
"kcb8fd4ce": "Kein Server online", "kcb8fd4ce": "Kein Server online",
"kcbc00b39": "Wählen Sie Ihren Datumsbereich aus", "kcbc00b39": "Wählen Sie Ihren Datumsbereich aus",
"kcc3b034e": "Url", "kcc3b034e": "URL",
"kcc50957": "Neuen Monitor hinzufügen", "kcc50957": "Neuen Monitor hinzufügen",
"kccaa732a": "Keine aufeinanderfolgenden Bindestriche", "kccaa732a": "Keine aufeinanderfolgenden Bindestriche",
"kccb42483": "Passwort", "kccb42483": "Passwort",
@ -191,13 +192,16 @@
"kdb61adbb": "Offline verbergen", "kdb61adbb": "Offline verbergen",
"kdc51b5db": "Websites", "kdc51b5db": "Websites",
"kdd44ac01": "Anzuzeigender Telemetrie-Name", "kdd44ac01": "Anzuzeigender Telemetrie-Name",
"kdd55936a": "Resolver-Port",
"kde37bc27": "Zurück zum Admin", "kde37bc27": "Zurück zum Admin",
"kde657d5b": "Dashboard", "kde657d5b": "Dashboard",
"kdeba7706": "Geräte", "kdeba7706": "Geräte",
"kdeecbfea": "Resolver-Server",
"kdf5da1d2": "Keine / STARTTLS", "kdf5da1d2": "Keine / STARTTLS",
"kdf97690e": "Länder", "kdf97690e": "Länder",
"ke188f24b": "Absprungrate", "ke188f24b": "Absprungrate",
"ke1b5ca71": "Seiten", "ke1b5ca71": "Seiten",
"ke20a92c7": "Ressourceneintragstyp",
"ke2fe505b": "Diese Woche", "ke2fe505b": "Diese Woche",
"ke3a3f2f2": "Port", "ke3a3f2f2": "Port",
"ke46232fe": "Server hinzufügen", "ke46232fe": "Server hinzufügen",

View File

@ -146,6 +146,7 @@
"kaa0ccaab": "From Email", "kaa0ccaab": "From Email",
"kab56db46": "Heartbeats", "kab56db46": "Heartbeats",
"kacbdae07": "Avg. Response", "kacbdae07": "Avg. Response",
"kad9ea10d": "Confirm to delete this telemetry: [{{name}}]",
"kadef6c48": "Previous {{label}}", "kadef6c48": "Previous {{label}}",
"kaf39be20": "Network", "kaf39be20": "Network",
"kb01f4f95": "Done", "kb01f4f95": "Done",
@ -191,13 +192,16 @@
"kdb61adbb": "Hide Offline", "kdb61adbb": "Hide Offline",
"kdc51b5db": "Websites", "kdc51b5db": "Websites",
"kdd44ac01": "Telemetry Name to Display", "kdd44ac01": "Telemetry Name to Display",
"kdd55936a": "Resolver Port",
"kde37bc27": "Back to Admin", "kde37bc27": "Back to Admin",
"kde657d5b": "Dashboard", "kde657d5b": "Dashboard",
"kdeba7706": "Devices", "kdeba7706": "Devices",
"kdeecbfea": "Resolver Server",
"kdf5da1d2": "None / STARTTLS", "kdf5da1d2": "None / STARTTLS",
"kdf97690e": "Countries", "kdf97690e": "Countries",
"ke188f24b": "bounce rate", "ke188f24b": "bounce rate",
"ke1b5ca71": "Pages", "ke1b5ca71": "Pages",
"ke20a92c7": "Resouce Record Type",
"ke2fe505b": "This week", "ke2fe505b": "This week",
"ke3a3f2f2": "Port", "ke3a3f2f2": "Port",
"ke46232fe": "Add Server", "ke46232fe": "Add Server",

View File

@ -30,7 +30,7 @@
"k2813d1f7": "Ce mois-ci", "k2813d1f7": "Ce mois-ci",
"k2a6a7d8f": "HORS LIGNE", "k2a6a7d8f": "HORS LIGNE",
"k2b2d40d4": "Code de test", "k2b2d40d4": "Code de test",
"k2c2712a4": "CPU", "k2c2712a4": "UC",
"k2e6dbf02": "À l'email", "k2e6dbf02": "À l'email",
"k2ea8a019": "Moniteur", "k2ea8a019": "Moniteur",
"k30b5f01b": "Espaces de travail", "k30b5f01b": "Espaces de travail",
@ -76,7 +76,7 @@
"k621317b5": "Nouvelle page", "k621317b5": "Nouvelle page",
"k62e19375": "Dernière mise à jour : {{date}}", "k62e19375": "Dernière mise à jour : {{date}}",
"k646a3a80": "Métriques de {{monitorName}}", "k646a3a80": "Métriques de {{monitorName}}",
"k646c0ae2": "HDD", "k646c0ae2": "DD",
"k67c5a895": "Hier", "k67c5a895": "Hier",
"k683be220": "Exécuter", "k683be220": "Exécuter",
"k691b7170": "Arrêté", "k691b7170": "Arrêté",
@ -146,6 +146,7 @@
"kaa0ccaab": "De l'email", "kaa0ccaab": "De l'email",
"kab56db46": "Battrements de cœur", "kab56db46": "Battrements de cœur",
"kacbdae07": "Réponse moyenne", "kacbdae07": "Réponse moyenne",
"kad9ea10d": "Confirmer la suppression de cette télémétrie : [{{name}}]",
"kadef6c48": "Précédent {{label}}", "kadef6c48": "Précédent {{label}}",
"kaf39be20": "Réseau", "kaf39be20": "Réseau",
"kb01f4f95": "Terminé", "kb01f4f95": "Terminé",
@ -158,11 +159,11 @@
"kbb58c99c": "Suppression réussie", "kbb58c99c": "Suppression réussie",
"kbcf67f53": "Nouveau mot de passe", "kbcf67f53": "Nouveau mot de passe",
"kbd1e7dee": "Utilisation : {{usage}}ms", "kbd1e7dee": "Utilisation : {{usage}}ms",
"kbd425e0e": "updatedAt", "kbd425e0e": "Mis à jour le",
"kc00cf2c7": "Cela affichera votre résultat récent de votre moniteur", "kc00cf2c7": "Cela affichera votre résultat récent de votre moniteur",
"kc0c6a913": "Nom du nœud", "kc0c6a913": "Nom du nœud",
"kc1f1f6c9": "Type de notification", "kc1f1f6c9": "Type de notification",
"kc45a417b": "OS", "kc45a417b": "SE",
"kc4910af7": "Changer le mot de passe", "kc4910af7": "Changer le mot de passe",
"kc4ab7848": "Effacer le nœud hors ligne", "kc4ab7848": "Effacer le nœud hors ligne",
"kc4e91854": "Êtes-vous sûr de vouloir supprimer tous les battements de cœur pour ce moniteur ?", "kc4e91854": "Êtes-vous sûr de vouloir supprimer tous les battements de cœur pour ce moniteur ?",
@ -176,7 +177,7 @@
"kcaf5c873": "Actions", "kcaf5c873": "Actions",
"kcb8fd4ce": "Aucun serveur en ligne", "kcb8fd4ce": "Aucun serveur en ligne",
"kcbc00b39": "Sélectionnez votre plage de dates", "kcbc00b39": "Sélectionnez votre plage de dates",
"kcc3b034e": "Url", "kcc3b034e": "URL",
"kcc50957": "Ajouter un nouveau moniteur", "kcc50957": "Ajouter un nouveau moniteur",
"kccaa732a": "Pas de tirets consécutifs", "kccaa732a": "Pas de tirets consécutifs",
"kccb42483": "Mot de passe", "kccb42483": "Mot de passe",
@ -191,13 +192,16 @@
"kdb61adbb": "Masquer hors ligne", "kdb61adbb": "Masquer hors ligne",
"kdc51b5db": "Sites Web", "kdc51b5db": "Sites Web",
"kdd44ac01": "Nom de la télémétrie à afficher", "kdd44ac01": "Nom de la télémétrie à afficher",
"kdd55936a": "Port de résolveur",
"kde37bc27": "Retour à l'administrateur", "kde37bc27": "Retour à l'administrateur",
"kde657d5b": "Tableau de bord", "kde657d5b": "Tableau de bord",
"kdeba7706": "Appareils", "kdeba7706": "Appareils",
"kdeecbfea": "Serveur de résolveur",
"kdf5da1d2": "Aucun / STARTTLS", "kdf5da1d2": "Aucun / STARTTLS",
"kdf97690e": "Pays", "kdf97690e": "Pays",
"ke188f24b": "taux de rebond", "ke188f24b": "taux de rebond",
"ke1b5ca71": "Pages", "ke1b5ca71": "Pages",
"ke20a92c7": "Type d'enregistrement de ressource",
"ke2fe505b": "Cette semaine", "ke2fe505b": "Cette semaine",
"ke3a3f2f2": "Port", "ke3a3f2f2": "Port",
"ke46232fe": "Ajouter un serveur", "ke46232fe": "Ajouter un serveur",

View File

@ -146,6 +146,7 @@
"kaa0ccaab": "送信者メール", "kaa0ccaab": "送信者メール",
"kab56db46": "ハートビート", "kab56db46": "ハートビート",
"kacbdae07": "平均応答", "kacbdae07": "平均応答",
"kad9ea10d": "このテレメトリを削除しますか?:[{{name}}]",
"kadef6c48": "前の{{label}}", "kadef6c48": "前の{{label}}",
"kaf39be20": "ネットワーク", "kaf39be20": "ネットワーク",
"kb01f4f95": "完了", "kb01f4f95": "完了",
@ -191,13 +192,16 @@
"kdb61adbb": "オフラインを隠す", "kdb61adbb": "オフラインを隠す",
"kdc51b5db": "ウェブサイト", "kdc51b5db": "ウェブサイト",
"kdd44ac01": "表示するテレメトリー名", "kdd44ac01": "表示するテレメトリー名",
"kdd55936a": "リゾルバーポート",
"kde37bc27": "管理者に戻る", "kde37bc27": "管理者に戻る",
"kde657d5b": "ダッシュボード", "kde657d5b": "ダッシュボード",
"kdeba7706": "デバイス", "kdeba7706": "デバイス",
"kdeecbfea": "リゾルバーサーバー",
"kdf5da1d2": "なし/STARTTLS", "kdf5da1d2": "なし/STARTTLS",
"kdf97690e": "国", "kdf97690e": "国",
"ke188f24b": "直帰率", "ke188f24b": "直帰率",
"ke1b5ca71": "ページ", "ke1b5ca71": "ページ",
"ke20a92c7": "リソースレコードタイプ",
"ke2fe505b": "今週", "ke2fe505b": "今週",
"ke3a3f2f2": "ポート", "ke3a3f2f2": "ポート",
"ke46232fe": "サーバーを追加", "ke46232fe": "サーバーを追加",

View File

@ -146,6 +146,7 @@
"kaa0ccaab": "Email отправителя", "kaa0ccaab": "Email отправителя",
"kab56db46": "Сердцебиение", "kab56db46": "Сердцебиение",
"kacbdae07": "Среднее время ответа", "kacbdae07": "Среднее время ответа",
"kad9ea10d": "Подтвердить удаление этой телеметрии: [{{name}}]",
"kadef6c48": "Предыдущий {{label}}", "kadef6c48": "Предыдущий {{label}}",
"kaf39be20": "Сеть", "kaf39be20": "Сеть",
"kb01f4f95": "Готово", "kb01f4f95": "Готово",
@ -176,7 +177,7 @@
"kcaf5c873": "Действия", "kcaf5c873": "Действия",
"kcb8fd4ce": "Онлайн серверов нет", "kcb8fd4ce": "Онлайн серверов нет",
"kcbc00b39": "Выберите диапазон дат", "kcbc00b39": "Выберите диапазон дат",
"kcc3b034e": "Url", "kcc3b034e": "URL",
"kcc50957": "Добавить новый монитор", "kcc50957": "Добавить новый монитор",
"kccaa732a": "Без последовательных тире", "kccaa732a": "Без последовательных тире",
"kccb42483": "Пароль", "kccb42483": "Пароль",
@ -191,13 +192,16 @@
"kdb61adbb": "Скрыть офлайн", "kdb61adbb": "Скрыть офлайн",
"kdc51b5db": "Веб-сайты", "kdc51b5db": "Веб-сайты",
"kdd44ac01": "Отображаемое имя телеметрии", "kdd44ac01": "Отображаемое имя телеметрии",
"kdd55936a": "Порт разрешителя",
"kde37bc27": "Вернуться к администратору", "kde37bc27": "Вернуться к администратору",
"kde657d5b": "Панель управления", "kde657d5b": "Панель управления",
"kdeba7706": "Устройства", "kdeba7706": "Устройства",
"kdeecbfea": "Сервер разрешителя",
"kdf5da1d2": "Нет / STARTTLS", "kdf5da1d2": "Нет / STARTTLS",
"kdf97690e": "Страны", "kdf97690e": "Страны",
"ke188f24b": "коэффициент отказов", "ke188f24b": "коэффициент отказов",
"ke1b5ca71": "Страницы", "ke1b5ca71": "Страницы",
"ke20a92c7": "Тип ресурсной записи",
"ke2fe505b": "На этой неделе", "ke2fe505b": "На этой неделе",
"ke3a3f2f2": "Порт", "ke3a3f2f2": "Порт",
"ke46232fe": "Добавить сервер", "ke46232fe": "Добавить сервер",

View File

@ -146,6 +146,7 @@
"kaa0ccaab": "发件人邮箱", "kaa0ccaab": "发件人邮箱",
"kab56db46": "心跳", "kab56db46": "心跳",
"kacbdae07": "平均响应", "kacbdae07": "平均响应",
"kad9ea10d": "确认删除此遥测:[{{name}}]",
"kadef6c48": "上一个{{label}}", "kadef6c48": "上一个{{label}}",
"kaf39be20": "网络", "kaf39be20": "网络",
"kb01f4f95": "完成", "kb01f4f95": "完成",
@ -191,13 +192,16 @@
"kdb61adbb": "隐藏离线", "kdb61adbb": "隐藏离线",
"kdc51b5db": "网站", "kdc51b5db": "网站",
"kdd44ac01": "显示的遥测名称", "kdd44ac01": "显示的遥测名称",
"kdd55936a": "解析器端口",
"kde37bc27": "返回管理员", "kde37bc27": "返回管理员",
"kde657d5b": "仪表板", "kde657d5b": "仪表板",
"kdeba7706": "设备", "kdeba7706": "设备",
"kdeecbfea": "解析器服务器",
"kdf5da1d2": "无/STARTTLS", "kdf5da1d2": "无/STARTTLS",
"kdf97690e": "国家", "kdf97690e": "国家",
"ke188f24b": "跳出率", "ke188f24b": "跳出率",
"ke1b5ca71": "页面", "ke1b5ca71": "页面",
"ke20a92c7": "资源记录类型",
"ke2fe505b": "本周", "ke2fe505b": "本周",
"ke3a3f2f2": "端口", "ke3a3f2f2": "端口",
"ke46232fe": "添加服务器", "ke46232fe": "添加服务器",

View File

@ -139,6 +139,29 @@ export const telemetryRouter = router({
}); });
} }
}), }),
delete: workspaceOwnerProcedure
.meta(
buildTelemetryOpenapi({
method: 'POST',
path: '/delete',
})
)
.input(
z.object({
telemetryId: z.string(),
})
)
.output(TelemetryModelSchema)
.mutation(async ({ input }) => {
const { workspaceId, telemetryId } = input;
return prisma.telemetry.delete({
where: {
id: telemetryId,
workspaceId,
},
});
}),
pageviews: workspaceProcedure pageviews: workspaceProcedure
.meta( .meta(
buildTelemetryOpenapi({ buildTelemetryOpenapi({
@ -354,15 +377,18 @@ export const telemetryRouter = router({
}), }),
]); ]);
const stats = Object.keys(metrics[0]).reduce((obj, key) => { const stats = Object.keys(metrics[0]).reduce(
const current = Number(metrics[0][key]) || 0; (obj, key) => {
const prev = Number(prevPeriod[0][key]) || 0; const current = Number(metrics[0][key]) || 0;
obj[key] = { const prev = Number(prevPeriod[0][key]) || 0;
value: current, obj[key] = {
prev, value: current,
}; prev,
return obj; };
}, {} as Record<string, { value: number; prev: number }>); return obj;
},
{} as Record<string, { value: number; prev: number }>
);
return baseStatsSchema.parse(stats); return baseStatsSchema.parse(stats);
}), }),