From 6650e8c30eab9092c9c610fa2a0510d3afc0e0f4 Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Mon, 24 Jul 2023 14:52:49 -0500 Subject: [PATCH] feat(drive): added ability to disable drives and add names --- app/components/charts/driveBar.tsx | 6 ++ app/components/driveForms/base.tsx | 100 ++++++++++++++++++ app/models/monitor.server.ts | 49 ++++++++- app/monitors/windows.server.ts | 17 ++- app/notifications/notifier.tsx | 2 +- .../route.tsx | 86 ++++++++++----- .../route.tsx | 56 ++++++---- app/routes/_auth.drive.edit/route.tsx | 66 ++++++++++++ app/routes/_auth.monitor.new/route.tsx | 25 +++-- .../migration.sql | 9 ++ prisma/schema.prisma | 2 +- 11 files changed, 355 insertions(+), 63 deletions(-) create mode 100644 app/components/driveForms/base.tsx create mode 100644 app/routes/_auth.drive.edit/route.tsx create mode 100644 prisma/migrations/20230724185124_inverted_flag/migration.sql diff --git a/app/components/charts/driveBar.tsx b/app/components/charts/driveBar.tsx index 26b86d3..0f9b3b7 100644 --- a/app/components/charts/driveBar.tsx +++ b/app/components/charts/driveBar.tsx @@ -130,6 +130,8 @@ export const StorageChart = ({ url }: { url: string }) => { { fill: true, label: 'Used', + cubicInterpolationMode: 'monotone', + tension: 0.4, data: usageFetcher.data?.drive?.usage?.map((x: Usage) => bytes(Number(x.used), { unit: 'GB' }).replace('GB', ''), ), @@ -153,6 +155,7 @@ export const StorageChart = ({ url }: { url: string }) => { chart.chartArea, darkGradient, ), + pointStyle: false, }, { label: 'Free', @@ -163,6 +166,9 @@ export const StorageChart = ({ url }: { url: string }) => { borderColor: '#cbd5e1', backgroundColor: '#e2e8f0', borderRadius: { topLeft: 2, topRight: 2 }, + cubicInterpolationMode: 'monotone', + pointStyle: false, + tension: 0.4, }, ], }; diff --git a/app/components/driveForms/base.tsx b/app/components/driveForms/base.tsx new file mode 100644 index 0000000..44ee88c --- /dev/null +++ b/app/components/driveForms/base.tsx @@ -0,0 +1,100 @@ +import { Form, useFetcher } from '@remix-run/react'; +import { useEffect, useState } from 'react'; +import { Button } from '~/components/ui/button'; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from '~/components/ui/dialog'; +import { Input } from '~/components/ui/input'; +import { Label } from '~/components/ui/label'; + +import { Textarea } from '~/components/ui/textarea'; + +import type { Drive } from '~/models/monitor.server'; +import { Switch } from '../ui/switch'; + +export default function Drive({ drive, children }: { drive: Drive }) { + const [open, setOpen] = useState(false); + const fetcher = useFetcher(); + + const [data, setData] = useState(drive); + + useEffect(() => setData(drive), [drive]); + + useEffect(() => { + if (fetcher.state === 'idle' && fetcher.data?.drive != null) { + setOpen(false); + } + }, [fetcher]); + + return ( + + {children} + + + {drive.name} + Editing drive. + + {fetcher.state !== 'submitting' && fetcher.data?.form?.error ? ( + {fetcher.data.form.error} + ) : null} +
+
+
+ +
+ setData({ ...data, enabled })} + /> +
+ + setData({ ...data, title: e.target.value })} + /> + +