Expanded scheduled tasks + keyboard shortcuts
- scripts/run-task.sh: dispatcher for say / backup / snapshot-prune with
safe arg handling (message stripped of CR/LF, integer-clamped keep
count). Logs to ~/logs/mc-dashboard/tasks.log (falls back to /tmp).
- New /api/schedule/tasks GET/POST/DELETE route: stores tasks as
crontab lines with `# mc-task:<base64(json)>` marker so the UI can
round-trip them. Strict server-side validation:
- Cron expression regex (5 fields, * / N / N-N / N,N / */N)
- say message: 1–120 chars, no newlines/backticks/shell quotes
- snapshot-prune keep: integer 1–50
- task id: 16-hex only
Single-quote-escaped message in the generated shell command.
- ScheduledTasks UI under ServerControls (alongside the existing single
ScheduledRestart): pick type (Announce / Backup / Prune snapshots),
preset schedule (daily at HH:MM or every N hours), adds with one
click. Tasks list shows human-readable schedule + "next in Xh" hint
computed client-side. Hover-reveal Remove action.
- Admin keyboard shortcuts: when not typing,
r — refetch the active tab's query keys (toast feedback)
/ — focus the first input/contenteditable in the active panel
? — toast the shortcuts cheat sheet
Chord-free, mirrors existing ⌘K palette and Esc handlers.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
359a12ef9d
commit
cf467b26c7
5 changed files with 677 additions and 0 deletions
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
import { useEffect, useState } from "react";
|
||||
import dynamic from "next/dynamic";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { toast } from "sonner";
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||
import { ServerControls } from "@/components/ServerControls";
|
||||
import { Analytics } from "@/components/Analytics";
|
||||
|
|
@ -44,10 +46,60 @@ const TABS = [
|
|||
{ value: "logs", label: "Logs" },
|
||||
];
|
||||
|
||||
const TAB_QUERIES: Record<string, string[]> = {
|
||||
server: "status analytics schedule schedule-tasks".split(" "),
|
||||
players: ["players"],
|
||||
chat: ["chat"],
|
||||
mods: "mods mod-updates snapshots".split(" "),
|
||||
backups: ["backups"],
|
||||
logs: ["logs"],
|
||||
};
|
||||
|
||||
export function AdminTabs() {
|
||||
const queryClient = useQueryClient();
|
||||
const [mounted, setMounted] = useState(false);
|
||||
const [value, setValue] = useState<string>("server");
|
||||
|
||||
useEffect(() => {
|
||||
const isEditable = (el: Element | null) => {
|
||||
if (!el) return false;
|
||||
const tag = (el as HTMLElement).tagName;
|
||||
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
||||
return (el as HTMLElement).isContentEditable;
|
||||
};
|
||||
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.metaKey || e.ctrlKey || e.altKey) return;
|
||||
if (isEditable(document.activeElement)) return;
|
||||
|
||||
if (e.key === "r") {
|
||||
e.preventDefault();
|
||||
const keys = TAB_QUERIES[value] || [];
|
||||
keys.forEach((k) => {
|
||||
queryClient.refetchQueries({ queryKey: [k] });
|
||||
});
|
||||
toast.success(`Refreshing ${value}...`, { duration: 1500 });
|
||||
} else if (e.key === "/") {
|
||||
const panel = document.querySelector(
|
||||
'[data-slot="tabs-content"] input, [data-slot="tabs-content"] [contenteditable="true"]'
|
||||
) as HTMLElement | null;
|
||||
if (panel) {
|
||||
e.preventDefault();
|
||||
panel.focus();
|
||||
}
|
||||
} else if (e.key === "?") {
|
||||
e.preventDefault();
|
||||
toast.message("Keyboard shortcuts", {
|
||||
description:
|
||||
"⌘K palette · r refresh · / focus search · Esc close · hash links jump tabs",
|
||||
duration: 5000,
|
||||
});
|
||||
}
|
||||
};
|
||||
window.addEventListener("keydown", onKey);
|
||||
return () => window.removeEventListener("keydown", onKey);
|
||||
}, [value, queryClient]);
|
||||
|
||||
useEffect(() => {
|
||||
setMounted(true);
|
||||
const hash = window.location.hash.replace("#", "");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue