feat: add Cron Editor tool
Visual cron expression editor with field-by-field builder, presets select, human-readable description, and live schedule preview showing next occurrences. Registered in tools registry with CronIcon. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
47
lib/cron/store.ts
Normal file
47
lib/cron/store.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { create } from 'zustand';
|
||||
import { persist } from 'zustand/middleware';
|
||||
|
||||
export interface CronHistoryEntry {
|
||||
id: string;
|
||||
expression: string;
|
||||
label?: string;
|
||||
savedAt: number;
|
||||
}
|
||||
|
||||
interface CronStore {
|
||||
expression: string;
|
||||
history: CronHistoryEntry[];
|
||||
setExpression: (expr: string) => void;
|
||||
addToHistory: (expr: string, label?: string) => void;
|
||||
removeFromHistory: (id: string) => void;
|
||||
clearHistory: () => void;
|
||||
}
|
||||
|
||||
export const useCronStore = create<CronStore>()(
|
||||
persist(
|
||||
(set) => ({
|
||||
expression: '0 9 * * 1-5',
|
||||
history: [],
|
||||
|
||||
setExpression: (expression) => set({ expression }),
|
||||
|
||||
addToHistory: (expression, label) =>
|
||||
set((state) => {
|
||||
const entry: CronHistoryEntry = {
|
||||
id: `${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
||||
expression,
|
||||
label,
|
||||
savedAt: Date.now(),
|
||||
};
|
||||
const filtered = state.history.filter((h) => h.expression !== expression);
|
||||
return { history: [entry, ...filtered].slice(0, 30) };
|
||||
}),
|
||||
|
||||
removeFromHistory: (id) =>
|
||||
set((state) => ({ history: state.history.filter((h) => h.id !== id) })),
|
||||
|
||||
clearHistory: () => set({ history: [] }),
|
||||
}),
|
||||
{ name: 'kit-cron-v1' },
|
||||
),
|
||||
);
|
||||
Reference in New Issue
Block a user