Skip to content

Commit

Permalink
feat: add delete telemetry feature #34
Browse files Browse the repository at this point in the history
  • Loading branch information
moonrailgun committed Mar 29, 2024
1 parent 99610cf commit d862e6c
Show file tree
Hide file tree
Showing 11 changed files with 397 additions and 133 deletions.
400 changes: 287 additions & 113 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

40 changes: 38 additions & 2 deletions src/client/components/telemetry/TelemetryList.tsx
@@ -1,5 +1,15 @@
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 { AppRouterOutput, trpc } from '../../api/trpc';
import { useCurrentWorkspaceId } from '../../store/user';
Expand All @@ -9,11 +19,13 @@ import {
CodeOutlined,
EditOutlined,
PlusOutlined,
DeleteOutlined,
} from '@ant-design/icons';
import { useNavigate } from 'react-router';
import { PageHeader } from '../PageHeader';
import { useEvent } from '../../hooks/useEvent';
import { TelemetryCounter } from './TelemetryCounter';
import { LuDelete, LuTrash } from 'react-icons/lu';

type TelemetryInfo = AppRouterOutput['telemetry']['all'][number];

Expand Down Expand Up @@ -189,10 +201,15 @@ const TelemetryListTable: React.FC<{
onShowUsage: (info: TelemetryInfo) => void;
}> = React.memo((props) => {
const workspaceId = useCurrentWorkspaceId();
const { data = [], isLoading } = trpc.telemetry.all.useQuery({
const {
data = [],
isLoading,
refetch,
} = trpc.telemetry.all.useQuery({
workspaceId,
});
const navigate = useNavigate();
const deleteMutation = trpc.telemetry.delete.useMutation();

const columns = useMemo((): ColumnsType<TelemetryInfo> => {
return [
Expand All @@ -217,6 +234,25 @@ const TelemetryListTable: React.FC<{
render: (_, record) => {
return (
<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
icon={<CodeOutlined />}
onClick={() => props.onShowUsage(record)}
Expand Down
4 changes: 4 additions & 0 deletions src/client/i18next-toolkit.config.cjs
Expand Up @@ -40,6 +40,10 @@ const config = {
'YYYY-MM-DD HH:mm',
],
},
translator: {
type: 'openai',
model: 'gpt-4'
},
};

module.exports = config;
4 changes: 2 additions & 2 deletions src/client/package.json
Expand Up @@ -19,7 +19,7 @@
"@ant-design/icons": "^5.2.6",
"@antv/l7": "^2.20.14",
"@antv/larkmap": "^1.4.13",
"@i18next-toolkit/react": "^1.0.5",
"@i18next-toolkit/react": "^1.0.6",
"@loadable/component": "^5.16.3",
"@monaco-editor/react": "^4.6.0",
"@tanstack/react-query": "4.33.0",
Expand Down Expand Up @@ -56,7 +56,7 @@
"zustand": "^4.4.1"
},
"devDependencies": {
"@i18next-toolkit/cli": "^1.0.7",
"@i18next-toolkit/cli": "^1.1.0",
"@types/leaflet": "^1.9.8",
"@types/loadable__component": "^5.13.8",
"@types/lodash-es": "^4.17.12",
Expand Down
6 changes: 5 additions & 1 deletion src/client/public/locales/de/translation.json
Expand Up @@ -146,6 +146,7 @@
"kaa0ccaab": "Von E-Mail",
"kab56db46": "Herzschläge",
"kacbdae07": "Durchschn. Antwort",
"kad9ea10d": "Bestätigen Sie das Löschen dieser Telemetrie: [{{name}}]",
"kadef6c48": "Vorherige {{label}}",
"kaf39be20": "Netzwerk",
"kb01f4f95": "Fertig",
Expand Down Expand Up @@ -176,7 +177,7 @@
"kcaf5c873": "Aktionen",
"kcb8fd4ce": "Kein Server online",
"kcbc00b39": "Wählen Sie Ihren Datumsbereich aus",
"kcc3b034e": "Url",
"kcc3b034e": "URL",
"kcc50957": "Neuen Monitor hinzufügen",
"kccaa732a": "Keine aufeinanderfolgenden Bindestriche",
"kccb42483": "Passwort",
Expand All @@ -191,13 +192,16 @@
"kdb61adbb": "Offline verbergen",
"kdc51b5db": "Websites",
"kdd44ac01": "Anzuzeigender Telemetrie-Name",
"kdd55936a": "Resolver-Port",
"kde37bc27": "Zurück zum Admin",
"kde657d5b": "Dashboard",
"kdeba7706": "Geräte",
"kdeecbfea": "Resolver-Server",
"kdf5da1d2": "Keine / STARTTLS",
"kdf97690e": "Länder",
"ke188f24b": "Absprungrate",
"ke1b5ca71": "Seiten",
"ke20a92c7": "Ressourceneintragstyp",
"ke2fe505b": "Diese Woche",
"ke3a3f2f2": "Port",
"ke46232fe": "Server hinzufügen",
Expand Down
4 changes: 4 additions & 0 deletions src/client/public/locales/en/translation.json
Expand Up @@ -146,6 +146,7 @@
"kaa0ccaab": "From Email",
"kab56db46": "Heartbeats",
"kacbdae07": "Avg. Response",
"kad9ea10d": "Confirm to delete this telemetry: [{{name}}]",
"kadef6c48": "Previous {{label}}",
"kaf39be20": "Network",
"kb01f4f95": "Done",
Expand Down Expand Up @@ -191,13 +192,16 @@
"kdb61adbb": "Hide Offline",
"kdc51b5db": "Websites",
"kdd44ac01": "Telemetry Name to Display",
"kdd55936a": "Resolver Port",
"kde37bc27": "Back to Admin",
"kde657d5b": "Dashboard",
"kdeba7706": "Devices",
"kdeecbfea": "Resolver Server",
"kdf5da1d2": "None / STARTTLS",
"kdf97690e": "Countries",
"ke188f24b": "bounce rate",
"ke1b5ca71": "Pages",
"ke20a92c7": "Resouce Record Type",
"ke2fe505b": "This week",
"ke3a3f2f2": "Port",
"ke46232fe": "Add Server",
Expand Down
14 changes: 9 additions & 5 deletions src/client/public/locales/fr/translation.json
Expand Up @@ -30,7 +30,7 @@
"k2813d1f7": "Ce mois-ci",
"k2a6a7d8f": "HORS LIGNE",
"k2b2d40d4": "Code de test",
"k2c2712a4": "CPU",
"k2c2712a4": "UC",
"k2e6dbf02": "À l'email",
"k2ea8a019": "Moniteur",
"k30b5f01b": "Espaces de travail",
Expand Down Expand Up @@ -76,7 +76,7 @@
"k621317b5": "Nouvelle page",
"k62e19375": "Dernière mise à jour : {{date}}",
"k646a3a80": "Métriques de {{monitorName}}",
"k646c0ae2": "HDD",
"k646c0ae2": "DD",
"k67c5a895": "Hier",
"k683be220": "Exécuter",
"k691b7170": "Arrêté",
Expand Down Expand Up @@ -146,6 +146,7 @@
"kaa0ccaab": "De l'email",
"kab56db46": "Battrements de cœur",
"kacbdae07": "Réponse moyenne",
"kad9ea10d": "Confirmer la suppression de cette télémétrie : [{{name}}]",
"kadef6c48": "Précédent {{label}}",
"kaf39be20": "Réseau",
"kb01f4f95": "Terminé",
Expand All @@ -158,11 +159,11 @@
"kbb58c99c": "Suppression réussie",
"kbcf67f53": "Nouveau mot de passe",
"kbd1e7dee": "Utilisation : {{usage}}ms",
"kbd425e0e": "updatedAt",
"kbd425e0e": "Mis à jour le",
"kc00cf2c7": "Cela affichera votre résultat récent de votre moniteur",
"kc0c6a913": "Nom du nœud",
"kc1f1f6c9": "Type de notification",
"kc45a417b": "OS",
"kc45a417b": "SE",
"kc4910af7": "Changer le mot de passe",
"kc4ab7848": "Effacer le nœud hors ligne",
"kc4e91854": "Êtes-vous sûr de vouloir supprimer tous les battements de cœur pour ce moniteur ?",
Expand All @@ -176,7 +177,7 @@
"kcaf5c873": "Actions",
"kcb8fd4ce": "Aucun serveur en ligne",
"kcbc00b39": "Sélectionnez votre plage de dates",
"kcc3b034e": "Url",
"kcc3b034e": "URL",
"kcc50957": "Ajouter un nouveau moniteur",
"kccaa732a": "Pas de tirets consécutifs",
"kccb42483": "Mot de passe",
Expand All @@ -191,13 +192,16 @@
"kdb61adbb": "Masquer hors ligne",
"kdc51b5db": "Sites Web",
"kdd44ac01": "Nom de la télémétrie à afficher",
"kdd55936a": "Port de résolveur",
"kde37bc27": "Retour à l'administrateur",
"kde657d5b": "Tableau de bord",
"kdeba7706": "Appareils",
"kdeecbfea": "Serveur de résolveur",
"kdf5da1d2": "Aucun / STARTTLS",
"kdf97690e": "Pays",
"ke188f24b": "taux de rebond",
"ke1b5ca71": "Pages",
"ke20a92c7": "Type d'enregistrement de ressource",
"ke2fe505b": "Cette semaine",
"ke3a3f2f2": "Port",
"ke46232fe": "Ajouter un serveur",
Expand Down
4 changes: 4 additions & 0 deletions src/client/public/locales/jp/translation.json
Expand Up @@ -146,6 +146,7 @@
"kaa0ccaab": "送信者メール",
"kab56db46": "ハートビート",
"kacbdae07": "平均応答",
"kad9ea10d": "このテレメトリを削除しますか?:[{{name}}]",
"kadef6c48": "前の{{label}}",
"kaf39be20": "ネットワーク",
"kb01f4f95": "完了",
Expand Down Expand Up @@ -191,13 +192,16 @@
"kdb61adbb": "オフラインを隠す",
"kdc51b5db": "ウェブサイト",
"kdd44ac01": "表示するテレメトリー名",
"kdd55936a": "リゾルバーポート",
"kde37bc27": "管理者に戻る",
"kde657d5b": "ダッシュボード",
"kdeba7706": "デバイス",
"kdeecbfea": "リゾルバーサーバー",
"kdf5da1d2": "なし/STARTTLS",
"kdf97690e": "",
"ke188f24b": "直帰率",
"ke1b5ca71": "ページ",
"ke20a92c7": "リソースレコードタイプ",
"ke2fe505b": "今週",
"ke3a3f2f2": "ポート",
"ke46232fe": "サーバーを追加",
Expand Down
6 changes: 5 additions & 1 deletion src/client/public/locales/ru/translation.json
Expand Up @@ -146,6 +146,7 @@
"kaa0ccaab": "Email отправителя",
"kab56db46": "Сердцебиение",
"kacbdae07": "Среднее время ответа",
"kad9ea10d": "Подтвердить удаление этой телеметрии: [{{name}}]",
"kadef6c48": "Предыдущий {{label}}",
"kaf39be20": "Сеть",
"kb01f4f95": "Готово",
Expand Down Expand Up @@ -176,7 +177,7 @@
"kcaf5c873": "Действия",
"kcb8fd4ce": "Онлайн серверов нет",
"kcbc00b39": "Выберите диапазон дат",
"kcc3b034e": "Url",
"kcc3b034e": "URL",
"kcc50957": "Добавить новый монитор",
"kccaa732a": "Без последовательных тире",
"kccb42483": "Пароль",
Expand All @@ -191,13 +192,16 @@
"kdb61adbb": "Скрыть офлайн",
"kdc51b5db": "Веб-сайты",
"kdd44ac01": "Отображаемое имя телеметрии",
"kdd55936a": "Порт разрешителя",
"kde37bc27": "Вернуться к администратору",
"kde657d5b": "Панель управления",
"kdeba7706": "Устройства",
"kdeecbfea": "Сервер разрешителя",
"kdf5da1d2": "Нет / STARTTLS",
"kdf97690e": "Страны",
"ke188f24b": "коэффициент отказов",
"ke1b5ca71": "Страницы",
"ke20a92c7": "Тип ресурсной записи",
"ke2fe505b": "На этой неделе",
"ke3a3f2f2": "Порт",
"ke46232fe": "Добавить сервер",
Expand Down
4 changes: 4 additions & 0 deletions src/client/public/locales/zh/translation.json
Expand Up @@ -146,6 +146,7 @@
"kaa0ccaab": "发件人邮箱",
"kab56db46": "心跳",
"kacbdae07": "平均响应",
"kad9ea10d": "确认删除此遥测:[{{name}}]",
"kadef6c48": "上一个{{label}}",
"kaf39be20": "网络",
"kb01f4f95": "完成",
Expand Down Expand Up @@ -191,13 +192,16 @@
"kdb61adbb": "隐藏离线",
"kdc51b5db": "网站",
"kdd44ac01": "显示的遥测名称",
"kdd55936a": "解析器端口",
"kde37bc27": "返回管理员",
"kde657d5b": "仪表板",
"kdeba7706": "设备",
"kdeecbfea": "解析器服务器",
"kdf5da1d2": "无/STARTTLS",
"kdf97690e": "国家",
"ke188f24b": "跳出率",
"ke1b5ca71": "页面",
"ke20a92c7": "资源记录类型",
"ke2fe505b": "本周",
"ke3a3f2f2": "端口",
"ke46232fe": "添加服务器",
Expand Down
44 changes: 35 additions & 9 deletions src/server/trpc/routers/telemetry.ts
Expand Up @@ -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
.meta(
buildTelemetryOpenapi({
Expand Down Expand Up @@ -354,15 +377,18 @@ export const telemetryRouter = router({
}),
]);

const stats = Object.keys(metrics[0]).reduce((obj, key) => {
const current = Number(metrics[0][key]) || 0;
const prev = Number(prevPeriod[0][key]) || 0;
obj[key] = {
value: current,
prev,
};
return obj;
}, {} as Record<string, { value: number; prev: number }>);
const stats = Object.keys(metrics[0]).reduce(
(obj, key) => {
const current = Number(metrics[0][key]) || 0;
const prev = Number(prevPeriod[0][key]) || 0;
obj[key] = {
value: current,
prev,
};
return obj;
},
{} as Record<string, { value: number; prev: number }>
);

return baseStatsSchema.parse(stats);
}),
Expand Down

0 comments on commit d862e6c

Please sign in to comment.