fix schedule sync

This commit is contained in:
Guilhem
2024-10-09 16:34:07 +02:00
parent f27320df23
commit 2e587b3dfa
7 changed files with 58 additions and 38 deletions
+8 -3
View File
@@ -15,7 +15,8 @@
WorkspaceService,
type InputTransform,
type RawScript,
type PathScript
type PathScript,
type Schedule
} from '$lib/gen'
import { inferArgs } from '$lib/infer'
import { copilotInfo, userStore, workspaceStore } from '$lib/stores'
@@ -41,7 +42,7 @@
import { workspacedOpenai } from './copilot/lib'
import type { FlowCopilotContext, FlowCopilotModule } from './copilot/flow'
import { pickScript } from './flows/flowStateUtils'
import type { Schedule } from './flows/scheduleUtils'
import type { Schedule as ScheduleUtils } from './flows/scheduleUtils'
import {
approximateFindPythonRelativePath,
isTypescriptRelativePath,
@@ -466,7 +467,7 @@
}
const flowStateStore = writable({} as FlowState)
const scheduleStore = writable<Schedule>({
const scheduleStore = writable<ScheduleUtils>({
args: {},
cron: '',
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
@@ -482,11 +483,15 @@
const selectedIdStore = writable('settings-metadata')
const selectedTriggerStore = writable('webhooks')
const httpTriggersStore = writable(undefined)
const schedulesStore = writable<Schedule[] | undefined>(undefined)
const primaryScheduleStore = writable<Schedule | undefined | boolean>(undefined)
setContext<FlowEditorContext>('FlowEditorContext', {
selectedId: selectedIdStore,
selectedTrigger: selectedTriggerStore,
httpTriggers: httpTriggersStore,
schedule: scheduleStore,
primarySchedule: primaryScheduleStore,
schedules: schedulesStore,
previewArgs: previewArgsStore,
scriptEditorDrawer,
moving,
@@ -9,7 +9,8 @@
ScriptService,
type OpenFlow,
type RawScript,
type InputTransform
type InputTransform,
type Schedule
} from '$lib/gen'
import { initHistory, push, redo, undo } from '$lib/history'
import {
@@ -40,7 +41,7 @@
import { dfs, getPreviousIds } from './flows/previousResults'
import FlowImportExportMenu from './flows/header/FlowImportExportMenu.svelte'
import FlowPreviewButtons from './flows/header/FlowPreviewButtons.svelte'
import { loadFlowSchedule, type Schedule } from './flows/scheduleUtils'
import { loadFlowSchedule, type Schedule as ScheduleUtils } from './flows/scheduleUtils'
import type { FlowEditorContext, FlowInput } from './flows/types'
import { cleanInputs, emptyFlowModuleState } from './flows/utils'
import {
@@ -375,7 +376,7 @@
return $selectedIdStore
}
const scheduleStore = writable<Schedule>({
const scheduleStore = writable<ScheduleUtils>({
summary: undefined,
args: {},
cron: '',
@@ -401,13 +402,16 @@
}
const httpTriggersStore = writable(undefined)
const schedulesStore = writable<Schedule[] | undefined>(undefined)
let insertButtonOpen = writable<boolean>(false)
const primaryScheduleStore = writable<Schedule | undefined | boolean>(undefined)
setContext<FlowEditorContext>('FlowEditorContext', {
selectedId: selectedIdStore,
selectedTrigger: selectedTriggerStore,
httpTriggers: httpTriggersStore,
schedule: scheduleStore,
primarySchedule: primaryScheduleStore,
schedules: schedulesStore,
previewArgs: previewArgsStore,
scriptEditorDrawer,
moving,
@@ -425,7 +429,7 @@
async function loadSchedule() {
loadFlowSchedule(initialPath, $workspaceStore!)
.then((schedule: Schedule) => {
.then((schedule: ScheduleUtils) => {
scheduleStore.set(schedule)
})
.catch(() => {
@@ -10,12 +10,14 @@
import { type Schedule } from '$lib/gen'
export let light = false
export let schedule: Schedule
export let schedule: any
export let can_write: boolean
export let path: string
export let isFlow: boolean
export let scheduleEditor: ScheduleEditor
export let setScheduleEnabled: (path: string, enabled: boolean) => void
$: schedule = typeof schedule === 'boolean' ? undefined : (schedule as Schedule | undefined)
</script>
<div class="flex flex-col gap-2 grow w-full">
@@ -38,11 +40,11 @@
id="cron-schedule"
name="cron-schedule"
placeholder="*/30 * * * *"
value={schedule.schedule}
value={schedule?.schedule ?? ''}
disabled={true}
/>
<Toggle
checked={schedule.enabled}
checked={schedule?.enabled ?? false}
on:change={(e) => {
if (can_write) {
setScheduleEnabled(path, e.detail)
@@ -88,7 +90,7 @@
{#if !light}
{#if Object.keys(schedule?.args ?? {}).length > 0}
<div class="">
<JobArgs args={schedule.args ?? {}} />
<JobArgs args={schedule?.args ?? {}} />
</div>
{:else}
<div class="text-xs text-tertiary"> No arguments </div>
@@ -9,13 +9,14 @@
import PrimarySchedule from './PrimarySchedule.svelte'
import Label from '$lib/components/Label.svelte'
import Alert from './common/alert/Alert.svelte'
import { getContext } from 'svelte'
import type { FlowEditorContext } from '$lib/components/flows/types'
export let isFlow: boolean
export let path: string
export let can_write: boolean
let scheduleEditor: ScheduleEditor
let schedule: Schedule | false | undefined = undefined
export let schedules: Schedule[] | undefined = undefined
export let newFlow: boolean = false
@@ -24,17 +25,15 @@
export async function loadSchedule() {
try {
let exists = await ScheduleService.existsSchedule({
$primarySchedule = await ScheduleService.existsSchedule({
workspace: $workspaceStore ?? '',
path
})
if (exists) {
schedule = await ScheduleService.getSchedule({
if ($primarySchedule) {
$primarySchedule = await ScheduleService.getSchedule({
workspace: $workspaceStore ?? '',
path
})
} else {
schedule = false
}
} catch (e) {
console.log('no primary schedule')
@@ -70,6 +69,8 @@
loadSchedule()
}
}
const { primarySchedule } = getContext<FlowEditorContext>('FlowEditorContext')
</script>
<ScheduleEditor
@@ -91,9 +92,16 @@
New Schedule
</Button>
{#if schedule}
<PrimarySchedule {schedule} {can_write} {path} {isFlow} {scheduleEditor} {setScheduleEnabled} />
{:else if schedule == undefined}
{#if $primarySchedule}
<PrimarySchedule
schedule={$primarySchedule}
{can_write}
{path}
{isFlow}
{scheduleEditor}
{setScheduleEnabled}
/>
{:else if $primarySchedule == undefined}
<Skeleton layout={[[6]]} />
{/if}
+5 -2
View File
@@ -3,9 +3,10 @@ import type { History } from '$lib/history'
import type { Writable } from 'svelte/store'
import type ScriptEditorDrawer from './content/ScriptEditorDrawer.svelte'
import type { FlowState } from './flowState'
import type { Schedule } from './scheduleUtils'
import type { Schedule as ScheduleUtils } from './scheduleUtils'
import type { FlowBuilderWhitelabelCustomUi } from '../custom_ui'
import { type HttpTrigger } from '$lib/gen'
import type { Schedule } from '$lib/gen'
export type FlowInput = Record<
string,
@@ -32,7 +33,9 @@ export type FlowEditorContext = {
selectedTrigger: Writable<string>
httpTriggers: Writable<(HttpTrigger & { canWrite: boolean })[] | undefined>
moving: Writable<{ module: FlowModule; modules: FlowModule[] } | undefined>
schedule: Writable<Schedule>
schedule: Writable<ScheduleUtils>
primarySchedule: Writable<Schedule | undefined | boolean>
schedules: Writable<Schedule[] | undefined>
previewArgs: Writable<Record<string, any>>
scriptEditorDrawer: Writable<ScriptEditorDrawer | undefined>
history: History<OpenFlow>
@@ -2,7 +2,7 @@
import { Calendar, Mail, Webhook } from 'lucide-svelte'
import TriggerButton from './TriggerButton.svelte'
import { NODE } from '../../util'
import { HttpTriggerService, ScheduleService, type Schedule } from '$lib/gen'
import { HttpTriggerService, ScheduleService } from '$lib/gen'
import { userStore, workspaceStore } from '$lib/stores'
import Popover from '$lib/components/Popover.svelte'
import TriggerCount from './TriggerCount.svelte'
@@ -12,25 +12,21 @@
import { getContext } from 'svelte'
import type { FlowEditorContext } from '../../../flows/types'
let schedules: Schedule[] | undefined = undefined
export let path: string
export let isEditor: boolean
export let newFlow: boolean
let primaryScheduleExists: boolean = false
const dispatch = createEventDispatcher()
async function loadSchedules() {
if (!path) return
try {
primaryScheduleExists = await ScheduleService.existsSchedule({
$primarySchedule = await ScheduleService.existsSchedule({
workspace: $workspaceStore ?? '',
path
})
schedules = (
$schedules = (
await ScheduleService.listSchedules({
workspace: $workspaceStore ?? '',
path: path,
@@ -66,10 +62,8 @@
}
})
const flowEditorContext = getContext<FlowEditorContext>('FlowEditorContext')
const httpTriggers = flowEditorContext?.httpTriggers ?? { subscribe: () => () => {} }
const selectedId = flowEditorContext?.selectedId ?? { subscribe: () => () => {} }
const selectedTrigger = flowEditorContext?.selectedTrigger ?? { subscribe: () => () => {} }
const { httpTriggers, selectedId, selectedTrigger, schedules, primarySchedule } =
getContext<FlowEditorContext>('FlowEditorContext') ?? {}
</script>
{#if isEditor}
@@ -172,7 +166,7 @@
}}
disabled={newFlow}
>
<TriggerCount count={(schedules?.length ?? 0) + (primaryScheduleExists ? 1 : 0)} />
<TriggerCount count={($schedules?.length ?? 0) + ($primarySchedule ? 1 : 0)} />
<Calendar size={12} />
</TriggerButton>
</Popover>
+7 -3
View File
@@ -6,7 +6,7 @@
import FlowPreviewButtons from '$lib/components/flows/header/FlowPreviewButtons.svelte'
import type { FlowEditorContext, FlowInput } from '$lib/components/flows/types'
import { writable } from 'svelte/store'
import { OpenAPI, type FlowModule, type OpenFlow } from '$lib/gen'
import { OpenAPI, type FlowModule, type OpenFlow, type Schedule } from '$lib/gen'
import { initHistory } from '$lib/history'
import type { FlowState } from '$lib/components/flows/flowState'
import FlowModuleSchemaMap from '$lib/components/flows/map/FlowModuleSchemaMap.svelte'
@@ -16,7 +16,7 @@
import { userStore, workspaceStore } from '$lib/stores'
import { getUserExt } from '$lib/user'
import DarkModeToggle from '$lib/components/sidebar/DarkModeToggle.svelte'
import type { Schedule } from '$lib/components/flows/scheduleUtils'
import type { Schedule as ScheduleUtils } from '$lib/components/flows/scheduleUtils'
let token = $page.url.searchParams.get('wm_token') ?? undefined
let workspace = $page.url.searchParams.get('workspace') ?? undefined
@@ -63,7 +63,7 @@
let initialCode = JSON.stringify($flowStore, null, 4)
const flowStateStore = writable({} as FlowState)
const scheduleStore = writable<Schedule>({
const scheduleStore = writable<ScheduleUtils>({
args: {},
cron: '',
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
@@ -80,6 +80,8 @@
const selectedIdStore = writable('settings-metadata')
const selectedTriggerStore = writable('webhooks')
const httpTriggersStore = writable(undefined)
const schedulesStore = writable<Schedule[] | undefined>(undefined)
const primaryScheduleStore = writable<Schedule | undefined | boolean>(undefined)
// function select(selectedId: string) {
// selectedIdStore.set(selectedId)
// }
@@ -89,6 +91,8 @@
selectedTrigger: selectedTriggerStore,
httpTriggers: httpTriggersStore,
schedule: scheduleStore,
primarySchedule: primaryScheduleStore,
schedules: schedulesStore,
previewArgs: previewArgsStore,
scriptEditorDrawer,
moving,