feat(web): manage independent schedules and restore recorded stage navigation
This commit is contained in:
@@ -67,6 +67,7 @@ import {
|
||||
readEphemeralChatIds,
|
||||
} from "./views/chat.js";
|
||||
import { createSearchView } from "./views/search.js";
|
||||
import { createSchedulesView } from "./views/schedules.js";
|
||||
import { installMobileViewport } from "./mobileViewport.js";
|
||||
|
||||
function defaultServerUrl() {
|
||||
@@ -1318,6 +1319,7 @@ function setError(err) {
|
||||
* caller so a stale, invalid URL field cannot spray an error into the UI on every
|
||||
* visibilitychange/online event.
|
||||
*/
|
||||
let schedulesEndpoint = null;
|
||||
function openConfiguredEndpoint({ surfaceError = true } = {}) {
|
||||
const validated = validateServerUrl(state.url);
|
||||
if (!validated.valid) {
|
||||
@@ -1338,6 +1340,12 @@ function openConfiguredEndpoint({ surfaceError = true } = {}) {
|
||||
state.error = "";
|
||||
state.urlError = "";
|
||||
writeServerUrl(localStorage, state.url);
|
||||
if (schedulesEndpoint !== validated.wsUrl) {
|
||||
views.schedules.clearScheduleCache();
|
||||
modal.close("schedule-editor");
|
||||
modal.close("schedule-delete");
|
||||
schedulesEndpoint = validated.wsUrl;
|
||||
}
|
||||
repo.connect(validated);
|
||||
}
|
||||
|
||||
@@ -1367,6 +1375,7 @@ function onForegroundActive() {
|
||||
}
|
||||
|
||||
async function onConnected() {
|
||||
views.schedules.clearScheduleCache();
|
||||
// Establish the run-event watch immediately once the socket is up (R10): the
|
||||
// unsubscribe/subscribe pair is sent before anything else is read, and its
|
||||
// authoritative `list_runs` resync is the one the view then reuses, so a
|
||||
@@ -1724,6 +1733,7 @@ function consumeRunAction(route) {
|
||||
}
|
||||
|
||||
async function loadCurrentView(force = false, { runsFresh = false } = {}) {
|
||||
if (force && state.view === "pipelines") views.schedules.clearScheduleCache();
|
||||
// Settings is local: it has no server-backed list to (re)load, so switching to
|
||||
// or refreshing it must never raise the "connect first" error.
|
||||
if (state.view === "settings") {
|
||||
@@ -2083,6 +2093,12 @@ function scheduleRunDetailSync(runId) {
|
||||
function applyRunEvent(frame) {
|
||||
const runId = Number(frame?.run_id);
|
||||
if (!(runId > 0)) return;
|
||||
if (state.runsLoaded && !state.runs.some((run) => run.id === runId) && Number(frame.schedule_id) > 0 &&
|
||||
state.view === "pipelines" && state.pipelineDetail?.id === Number(frame.pipeline_id)) {
|
||||
// A newly dispatched timer advanced NextDue. Refresh once on insertion,
|
||||
// not on every stage delta, while retaining the no-polling run lifecycle.
|
||||
void views.schedules.loadPipelineSchedules(Number(frame.pipeline_id), { force: true });
|
||||
}
|
||||
let listChanged = false;
|
||||
if (state.runsLoaded) {
|
||||
const fold = foldRunEvent(state.runs, frame);
|
||||
@@ -2384,6 +2400,22 @@ const runtime = {
|
||||
selectPipeline,
|
||||
selectRun,
|
||||
refreshRunDetail: scheduleRunDetailSync,
|
||||
scheduleChanged: async (pipelineId) => {
|
||||
const endpoint = state.url;
|
||||
const pipelines = await repo.listPipelines();
|
||||
if (endpoint !== state.url) return;
|
||||
state.pipelines = pipelines;
|
||||
state.pipelinesLoaded = true;
|
||||
touchView("pipelines");
|
||||
if (state.pipelineDetail?.id === pipelineId) {
|
||||
const version = state.pipelineDetail.version;
|
||||
const detail = await repo.getPipeline(pipelineId, version);
|
||||
if (endpoint === state.url && state.pipelineDetail?.id === pipelineId && state.pipelineDetail.version === version) {
|
||||
state.pipelineDetail = detail;
|
||||
}
|
||||
}
|
||||
renderContent();
|
||||
},
|
||||
setError,
|
||||
loadCurrentView,
|
||||
};
|
||||
@@ -2398,6 +2430,7 @@ const views = {
|
||||
runDetail: createRunDetailView(runtime),
|
||||
chat: createChatView(runtime),
|
||||
search: createSearchView(runtime),
|
||||
schedules: createSchedulesView(runtime),
|
||||
};
|
||||
runtime.views = views;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user