Improve Page Time Limit UX (#503)

This commit is contained in:
sua yoo 2023-01-18 20:13:27 -08:00 committed by GitHub
parent 24a7b14d63
commit be10ea5239
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 33 deletions

View File

@ -88,6 +88,12 @@ export class ConfigDetails extends LiteElement {
`, `,
() => this.renderSetting(msg("Exclusions"), msg("None")) () => this.renderSetting(msg("Exclusions"), msg("None"))
)} )}
${this.renderSetting(
msg("Page Time Limit"),
crawlConfig?.config.behaviorTimeout
? msg(str`${crawlConfig?.config.behaviorTimeout / 60} minute(s)`)
: msg("None")
)}
${this.renderSetting( ${this.renderSetting(
msg("Crawl Time Limit"), msg("Crawl Time Limit"),
crawlConfig?.crawlTimeout crawlConfig?.crawlTimeout
@ -111,9 +117,9 @@ export class ConfigDetails extends LiteElement {
crawlConfig?.profileid, crawlConfig?.profileid,
() => html`<a () => html`<a
class="text-blue-500 hover:text-blue-600" class="text-blue-500 hover:text-blue-600"
href=${`/orgs/${ href=${`/orgs/${crawlConfig!.oid}/browser-profiles/profile/${
crawlConfig!.oid crawlConfig!.profileid
}/browser-profiles/profile/${crawlConfig!.profileid}`} }`}
@click=${this.navLink} @click=${this.navLink}
> >
${crawlConfig?.profileName} ${crawlConfig?.profileName}
@ -129,12 +135,6 @@ export class ConfigDetails extends LiteElement {
msg("Language"), msg("Language"),
ISO6391.getName(crawlConfig?.config.lang!) ISO6391.getName(crawlConfig?.config.lang!)
)} )}
${this.renderSetting(
msg("Page Time Limit"),
crawlConfig?.config.behaviorTimeout
? msg(str`${crawlConfig?.config.behaviorTimeout / 60} minute(s)`)
: msg("None")
)}
</btrix-desc-list> </btrix-desc-list>
</section> </section>
<section id="crawl-scheduling" class="mb-8"> <section id="crawl-scheduling" class="mb-8">

View File

@ -176,6 +176,7 @@ function validURL(url: string) {
const trimExclusions = flow(uniq, compact); const trimExclusions = flow(uniq, compact);
const urlListToArray = (str: string) => const urlListToArray = (str: string) =>
str.trim().replace(/,/g, " ").split(/\s+/g); str.trim().replace(/,/g, " ").split(/\s+/g);
const DEFAULT_BEHAVIOR_TIMEOUT_MINUTES = 5;
@localized() @localized()
export class CrawlConfigEditor extends LiteElement { export class CrawlConfigEditor extends LiteElement {
@ -200,6 +201,9 @@ export class CrawlConfigEditor extends LiteElement {
@state() @state()
private progressState!: ProgressState; private progressState!: ProgressState;
@state()
private defaultBehaviorTimeoutMinutes?: number;
@state() @state()
private formState!: FormState; private formState!: FormState;
@ -274,6 +278,9 @@ export class CrawlConfigEditor extends LiteElement {
} }
willUpdate(changedProperties: Map<string, any>) { willUpdate(changedProperties: Map<string, any>) {
if (changedProperties.has("authState") && this.authState) {
this.fetchAPIDefaults();
}
if ( if (
changedProperties.get("initialCrawlConfig") && changedProperties.get("initialCrawlConfig") &&
this.initialCrawlConfig this.initialCrawlConfig
@ -393,9 +400,13 @@ export class CrawlConfigEditor extends LiteElement {
if (this.initialCrawlConfig.tags?.length) { if (this.initialCrawlConfig.tags?.length) {
formState.tags = this.initialCrawlConfig.tags; formState.tags = this.initialCrawlConfig.tags;
} }
if (this.initialCrawlConfig.crawlTimeout) { if (typeof this.initialCrawlConfig.crawlTimeout === "number") {
formState.crawlTimeoutMinutes = this.initialCrawlConfig.crawlTimeout / 60; formState.crawlTimeoutMinutes = this.initialCrawlConfig.crawlTimeout / 60;
} }
if (typeof this.initialCrawlConfig.config.behaviorTimeout === "number") {
formState.pageTimeoutMinutes =
this.initialCrawlConfig.config.behaviorTimeout / 60;
}
return { return {
jobName: this.initialCrawlConfig.name, jobName: this.initialCrawlConfig.name,
@ -1016,6 +1027,26 @@ https://example.net`}
private renderCrawlScale() { private renderCrawlScale() {
return html` return html`
${this.renderSectionHeading(msg("Crawl Limits"))} ${this.renderSectionHeading(msg("Crawl Limits"))}
${this.renderFormCol(html`
<sl-input
name="pageTimeoutMinutes"
type="number"
label=${msg("Page Time Limit")}
placeholder=${msg("Unlimited")}
value=${ifDefined(
this.formState.pageTimeoutMinutes ??
this.defaultBehaviorTimeoutMinutes
)}
?disabled=${this.defaultBehaviorTimeoutMinutes === undefined}
required
>
<span slot="suffix">${msg("minutes")}</span>
</sl-input>
`)}
${this.renderHelpTextCol(
html`Adds a hard time limit for how long the crawler can spend on a
single webpage.`
)}
${this.renderFormCol(html` ${this.renderFormCol(html`
<sl-input <sl-input
name="crawlTimeoutMinutes" name="crawlTimeoutMinutes"
@ -1105,22 +1136,6 @@ https://example.net`}
html`Websites that observe the browsers language setting may serve html`Websites that observe the browsers language setting may serve
content in that language if available.` content in that language if available.`
)} )}
${this.renderSectionHeading(msg("On-Page Behavior"))}
${this.renderFormCol(html`
<sl-input
name="pageTimeoutMinutes"
type="number"
label=${msg("Page Time Limit")}
placeholder=${msg("Unlimited")}
value=${ifDefined(this.formState.pageTimeoutMinutes ?? undefined)}
>
<span slot="suffix">${msg("minutes")}</span>
</sl-input>
`)}
${this.renderHelpTextCol(
html`Adds a hard time limit for how long the crawler can spend on a
single webpage.`
)}
`; `;
} }
@ -1638,9 +1653,7 @@ https://example.net`}
if (crawlId) { if (crawlId) {
this.navTo(`/orgs/${this.orgId}/crawls/crawl/${crawlId}`); this.navTo(`/orgs/${this.orgId}/crawls/crawl/${crawlId}`);
} else { } else {
this.navTo( this.navTo(`/orgs/${this.orgId}/crawl-templates/config/${data.added}`);
`/orgs/${this.orgId}/crawl-templates/config/${data.added}`
);
} }
} catch (e: any) { } catch (e: any) {
if (e?.isApiError) { if (e?.isApiError) {
@ -1707,9 +1720,10 @@ https://example.net`}
...(this.jobType === "seed-crawl" ...(this.jobType === "seed-crawl"
? this.parseSeededConfig() ? this.parseSeededConfig()
: this.parseUrlListConfig()), : this.parseUrlListConfig()),
behaviorTimeout: this.formState.pageTimeoutMinutes behaviorTimeout:
? this.formState.pageTimeoutMinutes * 60 (this.formState.pageTimeoutMinutes ??
: 0, this.defaultBehaviorTimeoutMinutes ??
DEFAULT_BEHAVIOR_TIMEOUT_MINUTES) * 60,
limit: this.formState.pageLimit ? +this.formState.pageLimit : null, limit: this.formState.pageLimit ? +this.formState.pageLimit : null,
extraHops: this.formState.includeLinkedPages ? 1 : 0, extraHops: this.formState.includeLinkedPages ? 1 : 0,
lang: this.formState.lang || null, lang: this.formState.lang || null,
@ -1806,6 +1820,21 @@ https://example.net`}
this.formState = mergeDeep(this.formState, nextState); this.formState = mergeDeep(this.formState, nextState);
} }
} }
private async fetchAPIDefaults() {
try {
const data = await this.apiFetch("/settings", this.authState!);
if (data.defaultBehaviorTimeSeconds) {
this.defaultBehaviorTimeoutMinutes =
data.defaultBehaviorTimeSeconds / 60;
} else {
this.defaultBehaviorTimeoutMinutes = DEFAULT_BEHAVIOR_TIMEOUT_MINUTES;
}
} catch (e: any) {
console.debug(e);
this.defaultBehaviorTimeoutMinutes = DEFAULT_BEHAVIOR_TIMEOUT_MINUTES;
}
}
} }
customElements.define("btrix-crawl-config-editor", CrawlConfigEditor); customElements.define("btrix-crawl-config-editor", CrawlConfigEditor);

View File

@ -71,7 +71,7 @@ export type InitialCrawlConfig = Pick<
jobType?: JobType; jobType?: JobType;
config: Pick< config: Pick<
CrawlConfigParams["config"], CrawlConfigParams["config"],
"seeds" | "scopeType" | "exclude" "seeds" | "scopeType" | "exclude" | "behaviorTimeout"
> & { > & {
extraHops?: CrawlConfigParams["config"]["extraHops"]; extraHops?: CrawlConfigParams["config"]["extraHops"];
}; };