From 9a1c2ba8716a4749fbb8c220299accc902c7a615 Mon Sep 17 00:00:00 2001 From: sua yoo Date: Wed, 3 May 2023 09:25:22 -0700 Subject: [PATCH] Fix workflow limit empty values being set to `0` (#795) * default to null * pass undefined for removing values * handle 0 default --- frontend/src/components/config-details.ts | 35 ++++++++++++++--------- frontend/src/pages/org/workflow-editor.ts | 20 +++++++------ 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/frontend/src/components/config-details.ts b/frontend/src/components/config-details.ts index e2e781f4..faea67f3 100644 --- a/frontend/src/components/config-details.ts +++ b/frontend/src/components/config-details.ts @@ -63,19 +63,28 @@ export class ConfigDetails extends LiteElement { const renderTimeLimit = ( valueSeconds?: number | null, fallbackValue?: number - ) => - valueSeconds - ? RelativeDuration.humanize(valueSeconds * 1000, { verbose: true }) - : typeof fallbackValue === "number" - ? html`${fallbackValue === Infinity - ? msg("Unlimited") - : RelativeDuration.humanize(fallbackValue * 1000, { - verbose: true, - })} - ${msg("(default)")}` - : undefined; + ) => { + if (valueSeconds) { + return RelativeDuration.humanize(valueSeconds * 1000, { + verbose: true, + }); + } + if (typeof fallbackValue === "number") { + let value = ""; + if (fallbackValue === Infinity) { + value = msg("Unlimited"); + } else if (fallbackValue === 0) { + value = msg("0 seconds"); + } else { + value = RelativeDuration.humanize(fallbackValue * 1000, { + verbose: true, + }); + } + return html`${value} ${msg("(default)")}`; + } + }; return html`
diff --git a/frontend/src/pages/org/workflow-editor.ts b/frontend/src/pages/org/workflow-editor.ts index cdd1d521..99924e58 100644 --- a/frontend/src/pages/org/workflow-editor.ts +++ b/frontend/src/pages/org/workflow-editor.ts @@ -150,7 +150,7 @@ const getDefaultFormState = (): FormState => ({ pageExtraDelaySeconds: null, scopeType: "host", exclusions: [], - pageLimit: undefined, + pageLimit: null, scale: 1, blockAds: true, lang: undefined, @@ -1810,8 +1810,12 @@ https://archiveweb.page/images/${"logo.svg"}`} value = elem.value; break; case "sl-input": { - if ((elem as SlInput).type === "number" && elem.value !== "") { - value = +elem.value; + if ((elem as SlInput).type === "number") { + if (elem.value === "") { + value = null; + } else { + value = +elem.value; + } } else { value = elem.value; } @@ -2034,16 +2038,16 @@ https://archiveweb.page/images/${"logo.svg"}`} schedule: this.formState.scheduleType === "cron" ? this.utcSchedule : "", crawlTimeout: this.formState.crawlTimeoutMinutes ? this.formState.crawlTimeoutMinutes * 60 - : 0, + : null, tags: this.formState.tags, config: { ...(this.jobType === "seed-crawl" ? this.parseSeededConfig() : this.parseUrlListConfig()), - behaviorTimeout: +(this.formState.behaviorTimeoutSeconds || ""), - pageLoadTimeout: +(this.formState.pageLoadTimeoutSeconds || ""), - pageExtraDelay: +(this.formState.pageExtraDelaySeconds || ""), - limit: this.formState.pageLimit ? +this.formState.pageLimit : undefined, + behaviorTimeout: this.formState.behaviorTimeoutSeconds, + pageLoadTimeout: this.formState.pageLoadTimeoutSeconds, + pageExtraDelay: this.formState.pageExtraDelaySeconds, + limit: this.formState.pageLimit, lang: this.formState.lang || "", blockAds: this.formState.blockAds, exclude: trimArray(this.formState.exclusions),