The header menu had Tasks but nothing for the schedules whose results land in that conversation. It now has Schedules, right under Tasks, opened in a modal that lists only what runs there: a bot's own chat holds the routines that run nowhere, a workspace only that bot's routines in it (`routineScopeSql`, tested against SQLite). The list loads when the modal opens, through `api/admin/bots/list-routines`, which checks the user chats in that conversation first, so the page props stay small. `grabCronJobs` gained an optional `workspace_id`: left out it still means everywhere. The routines page's row, form and edit modal moved to `src/components/general/`, and its subtitle to `src/utils/`, since both the page and the modal use them.
37 lines
1002 B
TypeScript
37 lines
1002 B
TypeScript
import type { CronJobWithNames } from "@/src/types";
|
|
import timeUntil from "./time-until";
|
|
|
|
type Params = {
|
|
cron_job: CronJobWithNames;
|
|
now?: number;
|
|
/**
|
|
* Shown by default; left out where the conversation already is the
|
|
* bot's (or the workspace's).
|
|
*/
|
|
show_bot?: boolean;
|
|
show_workspace?: boolean;
|
|
};
|
|
|
|
/**
|
|
* The line under a routine's name: whose it is, where it runs, its
|
|
* schedule, then when it runs next or why it last couldn't.
|
|
*/
|
|
export default function routineSubtitle({
|
|
cron_job,
|
|
now = Date.now(),
|
|
show_bot = true,
|
|
show_workspace = true,
|
|
}: Params) {
|
|
const next =
|
|
cron_job.enabled && cron_job.next_run_at ? `next ${timeUntil({ at: cron_job.next_run_at, now })}` : "";
|
|
|
|
return [
|
|
show_bot ? cron_job.bot_name || "A bot" : "",
|
|
show_workspace ? cron_job.workspace_name || "" : "",
|
|
`${cron_job.schedule} UTC`,
|
|
cron_job.last_error || next,
|
|
]
|
|
.filter(Boolean)
|
|
.join(" · ");
|
|
}
|