Fix workflow limit empty values being set to 0 (#795)

* default to null

* pass undefined for removing values

* handle 0 default
This commit is contained in:
sua yoo 2023-05-03 09:25:22 -07:00 committed by GitHub
parent 9500fd97fa
commit 9a1c2ba871
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 21 deletions

View File

@ -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`<span class="text-neutral-400"
>${fallbackValue === Infinity
? msg("Unlimited")
: RelativeDuration.humanize(fallbackValue * 1000, {
verbose: true,
})}
${msg("(default)")}</span
>`
: 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`<span class="text-neutral-400"
>${value} ${msg("(default)")}</span
>`;
}
};
return html`
<section id="crawler-settings" class="mb-8">

View File

@ -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),