task: Display built-in behaviors as list (#2518)
- Displays built-in behaviors as single field in workflow settings - Standardizes how "None" is displayed in workflow settings - Refactors behavior names into enum
This commit is contained in:
parent
61809ab3c5
commit
df8c80f3cc
@ -8,7 +8,13 @@ import capitalize from "lodash/fp/capitalize";
|
|||||||
import RegexColorize from "regex-colorize";
|
import RegexColorize from "regex-colorize";
|
||||||
|
|
||||||
import { BtrixElement } from "@/classes/BtrixElement";
|
import { BtrixElement } from "@/classes/BtrixElement";
|
||||||
import type { CrawlConfig, Seed, SeedConfig } from "@/pages/org/types";
|
import { none, notSpecified } from "@/layouts/empty";
|
||||||
|
import {
|
||||||
|
Behavior,
|
||||||
|
type CrawlConfig,
|
||||||
|
type Seed,
|
||||||
|
type SeedConfig,
|
||||||
|
} from "@/pages/org/types";
|
||||||
import { labelFor } from "@/strings/crawl-workflows/labels";
|
import { labelFor } from "@/strings/crawl-workflows/labels";
|
||||||
import scopeTypeLabel from "@/strings/crawl-workflows/scopeType";
|
import scopeTypeLabel from "@/strings/crawl-workflows/scopeType";
|
||||||
import sectionStrings from "@/strings/crawl-workflows/section";
|
import sectionStrings from "@/strings/crawl-workflows/section";
|
||||||
@ -162,22 +168,15 @@ export class ConfigDetails extends BtrixElement {
|
|||||||
heading: sectionStrings.behaviors,
|
heading: sectionStrings.behaviors,
|
||||||
renderDescItems: (seedsConfig) => html`
|
renderDescItems: (seedsConfig) => html`
|
||||||
${this.renderSetting(
|
${this.renderSetting(
|
||||||
|
labelFor.behaviors,
|
||||||
|
[
|
||||||
|
seedsConfig?.behaviors?.includes(Behavior.AutoScroll) &&
|
||||||
labelFor.autoscrollBehavior,
|
labelFor.autoscrollBehavior,
|
||||||
seedsConfig?.behaviors &&
|
seedsConfig?.behaviors?.includes(Behavior.AutoClick) &&
|
||||||
!seedsConfig.behaviors.includes("autoscroll")
|
|
||||||
? msg("Disabled")
|
|
||||||
: html`<span class="text-neutral-400"
|
|
||||||
>${msg("Enabled (default)")}</span
|
|
||||||
>`,
|
|
||||||
)}
|
|
||||||
${this.renderSetting(
|
|
||||||
labelFor.autoclickBehavior,
|
labelFor.autoclickBehavior,
|
||||||
seedsConfig?.behaviors &&
|
]
|
||||||
seedsConfig.behaviors.includes("autoclick")
|
.filter((v) => v)
|
||||||
? msg("Enabled")
|
.join(", ") || none,
|
||||||
: html`<span class="text-neutral-400"
|
|
||||||
>${msg("Disabled (default)")}</span
|
|
||||||
>`,
|
|
||||||
)}
|
)}
|
||||||
${this.renderSetting(
|
${this.renderSetting(
|
||||||
labelFor.pageLoadTimeoutSeconds,
|
labelFor.pageLoadTimeoutSeconds,
|
||||||
@ -424,7 +423,7 @@ export class ConfigDetails extends BtrixElement {
|
|||||||
)}
|
)}
|
||||||
</ul>
|
</ul>
|
||||||
`
|
`
|
||||||
: msg("None"),
|
: none,
|
||||||
true,
|
true,
|
||||||
),
|
),
|
||||||
)}
|
)}
|
||||||
@ -463,7 +462,7 @@ export class ConfigDetails extends BtrixElement {
|
|||||||
})}
|
})}
|
||||||
</ul>
|
</ul>
|
||||||
`
|
`
|
||||||
: msg("None"),
|
: none,
|
||||||
true,
|
true,
|
||||||
)}
|
)}
|
||||||
${when(
|
${when(
|
||||||
@ -477,7 +476,7 @@ export class ConfigDetails extends BtrixElement {
|
|||||||
</btrix-queue-exclusion-table>
|
</btrix-queue-exclusion-table>
|
||||||
</div>
|
</div>
|
||||||
`,
|
`,
|
||||||
() => this.renderSetting(msg("Exclusions"), msg("None")),
|
() => this.renderSetting(msg("Exclusions"), none),
|
||||||
)}
|
)}
|
||||||
`;
|
`;
|
||||||
};
|
};
|
||||||
@ -490,11 +489,9 @@ export class ConfigDetails extends BtrixElement {
|
|||||||
} else if (typeof value === "boolean") {
|
} else if (typeof value === "boolean") {
|
||||||
content = value ? msg("Yes") : msg("No");
|
content = value ? msg("Yes") : msg("No");
|
||||||
} else if (Array.isArray(value) && !value.length) {
|
} else if (Array.isArray(value) && !value.length) {
|
||||||
content = html`<span class="text-neutral-400">${msg("None")}</span>`;
|
content = none;
|
||||||
} else if (typeof value !== "number" && !value) {
|
} else if (typeof value !== "number" && !value) {
|
||||||
content = html`<span class="text-neutral-400"
|
content = notSpecified;
|
||||||
>${msg("Not specified")}</span
|
|
||||||
>`;
|
|
||||||
}
|
}
|
||||||
return html`
|
return html`
|
||||||
<btrix-desc-list-item label=${label} class=${breakAll ? "break-all" : ""}>
|
<btrix-desc-list-item label=${label} class=${breakAll ? "break-all" : ""}>
|
||||||
|
@ -62,7 +62,12 @@ import { labelFor } from "@/strings/crawl-workflows/labels";
|
|||||||
import scopeTypeLabels from "@/strings/crawl-workflows/scopeType";
|
import scopeTypeLabels from "@/strings/crawl-workflows/scopeType";
|
||||||
import sectionStrings from "@/strings/crawl-workflows/section";
|
import sectionStrings from "@/strings/crawl-workflows/section";
|
||||||
import { AnalyticsTrackEvent } from "@/trackEvents";
|
import { AnalyticsTrackEvent } from "@/trackEvents";
|
||||||
import { ScopeType, type Seed, type WorkflowParams } from "@/types/crawler";
|
import {
|
||||||
|
Behavior,
|
||||||
|
ScopeType,
|
||||||
|
type Seed,
|
||||||
|
type WorkflowParams,
|
||||||
|
} from "@/types/crawler";
|
||||||
import type { UnderlyingFunction } from "@/types/utils";
|
import type { UnderlyingFunction } from "@/types/utils";
|
||||||
import { NewWorkflowOnlyScopeType } from "@/types/workflow";
|
import { NewWorkflowOnlyScopeType } from "@/types/workflow";
|
||||||
import { track } from "@/utils/analytics";
|
import { track } from "@/utils/analytics";
|
||||||
@ -111,11 +116,10 @@ type ProgressState = {
|
|||||||
tabs: Tabs;
|
tabs: Tabs;
|
||||||
};
|
};
|
||||||
const DEFAULT_BEHAVIORS = [
|
const DEFAULT_BEHAVIORS = [
|
||||||
"autoscroll",
|
Behavior.AutoPlay,
|
||||||
"autoplay",
|
Behavior.AutoFetch,
|
||||||
"autofetch",
|
Behavior.SiteSpecific,
|
||||||
"siteSpecific",
|
] as const;
|
||||||
];
|
|
||||||
const formName = "newJobConfig" as const;
|
const formName = "newJobConfig" as const;
|
||||||
const panelSuffix = "--panel" as const;
|
const panelSuffix = "--panel" as const;
|
||||||
|
|
||||||
@ -1182,7 +1186,7 @@ https://archiveweb.page/images/${"logo.svg"}`}
|
|||||||
|
|
||||||
private renderBehaviors() {
|
private renderBehaviors() {
|
||||||
return html`
|
return html`
|
||||||
${this.renderSectionHeading(msg("Built-in Behaviors"))}
|
${this.renderSectionHeading(labelFor.behaviors)}
|
||||||
${inputCol(
|
${inputCol(
|
||||||
html`<sl-checkbox
|
html`<sl-checkbox
|
||||||
name="autoscrollBehavior"
|
name="autoscrollBehavior"
|
||||||
@ -2206,17 +2210,17 @@ https://archiveweb.page/images/${"logo.svg"}`}
|
|||||||
}
|
}
|
||||||
|
|
||||||
private setBehaviors(): string {
|
private setBehaviors(): string {
|
||||||
let behaviors = (
|
const behaviors: Behavior[] = [...DEFAULT_BEHAVIORS];
|
||||||
this.formState.autoscrollBehavior
|
|
||||||
? DEFAULT_BEHAVIORS
|
|
||||||
: DEFAULT_BEHAVIORS.slice(1)
|
|
||||||
).join(",");
|
|
||||||
|
|
||||||
if (this.formState.autoclickBehavior) {
|
if (this.formState.autoscrollBehavior) {
|
||||||
behaviors += ",autoclick";
|
behaviors.unshift(Behavior.AutoScroll);
|
||||||
}
|
}
|
||||||
|
|
||||||
return behaviors;
|
if (this.formState.autoclickBehavior) {
|
||||||
|
behaviors.push(Behavior.AutoClick);
|
||||||
|
}
|
||||||
|
|
||||||
|
return behaviors.join(",");
|
||||||
}
|
}
|
||||||
|
|
||||||
private parseUrlListConfig(): Pick<
|
private parseUrlListConfig(): Pick<
|
||||||
|
11
frontend/src/layouts/empty.ts
Normal file
11
frontend/src/layouts/empty.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { html } from "lit";
|
||||||
|
|
||||||
|
import { stringFor } from "@/strings/ui";
|
||||||
|
|
||||||
|
export const notSpecified = html`<span class="text-neutral-400">
|
||||||
|
${stringFor.notSpecified}
|
||||||
|
</span>`;
|
||||||
|
|
||||||
|
export const none = html`<span class="text-neutral-400">
|
||||||
|
${stringFor.none}
|
||||||
|
</span>`;
|
@ -1,6 +1,7 @@
|
|||||||
import { msg } from "@lit/localize";
|
import { msg } from "@lit/localize";
|
||||||
|
|
||||||
export const labelFor = {
|
export const labelFor = {
|
||||||
|
behaviors: msg("Built-in Behaviors"),
|
||||||
autoscrollBehavior: msg("Autoscroll"),
|
autoscrollBehavior: msg("Autoscroll"),
|
||||||
autoclickBehavior: msg("Autoclick"),
|
autoclickBehavior: msg("Autoclick"),
|
||||||
pageLoadTimeoutSeconds: msg("Page Load Limit"),
|
pageLoadTimeoutSeconds: msg("Page Load Limit"),
|
||||||
|
@ -1,8 +1,15 @@
|
|||||||
import { msg } from "@lit/localize";
|
import { msg } from "@lit/localize";
|
||||||
import { html, type TemplateResult } from "lit";
|
import { html, type TemplateResult } from "lit";
|
||||||
|
|
||||||
export const noData = "--";
|
export const stringFor: Record<string, string> = {
|
||||||
export const notApplicable = msg("n/a");
|
noData: "--",
|
||||||
|
notApplicable: msg("n/a"),
|
||||||
|
notSpecified: msg("Not specified"),
|
||||||
|
none: msg("None"),
|
||||||
|
};
|
||||||
|
|
||||||
|
export const noData = stringFor.noData;
|
||||||
|
export const notApplicable = stringFor.notApplicable;
|
||||||
|
|
||||||
// TODO Refactor all generic confirmation messages to use utility
|
// TODO Refactor all generic confirmation messages to use utility
|
||||||
export const deleteConfirmation = (name: string | TemplateResult) =>
|
export const deleteConfirmation = (name: string | TemplateResult) =>
|
||||||
|
@ -10,6 +10,14 @@ export enum ScopeType {
|
|||||||
Any = "any",
|
Any = "any",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum Behavior {
|
||||||
|
AutoScroll = "autoscroll",
|
||||||
|
AutoClick = "autoclick",
|
||||||
|
AutoPlay = "autoplay",
|
||||||
|
AutoFetch = "autofetch",
|
||||||
|
SiteSpecific = "siteSpecific",
|
||||||
|
}
|
||||||
|
|
||||||
export type Seed = {
|
export type Seed = {
|
||||||
url: string;
|
url: string;
|
||||||
scopeType: ScopeType | undefined;
|
scopeType: ScopeType | undefined;
|
||||||
|
@ -5,6 +5,7 @@ import { getAppSettings } from "./app";
|
|||||||
|
|
||||||
import type { Tags } from "@/components/ui/tag-input";
|
import type { Tags } from "@/components/ui/tag-input";
|
||||||
import {
|
import {
|
||||||
|
Behavior,
|
||||||
ScopeType,
|
ScopeType,
|
||||||
type Profile,
|
type Profile,
|
||||||
type Seed,
|
type Seed,
|
||||||
@ -284,10 +285,10 @@ export function getInitialFormState(params: {
|
|||||||
pageLimit:
|
pageLimit:
|
||||||
params.initialWorkflow.config.limit ?? defaultFormState.pageLimit,
|
params.initialWorkflow.config.limit ?? defaultFormState.pageLimit,
|
||||||
autoscrollBehavior: params.initialWorkflow.config.behaviors
|
autoscrollBehavior: params.initialWorkflow.config.behaviors
|
||||||
? params.initialWorkflow.config.behaviors.includes("autoscroll")
|
? params.initialWorkflow.config.behaviors.includes(Behavior.AutoScroll)
|
||||||
: defaultFormState.autoscrollBehavior,
|
: defaultFormState.autoscrollBehavior,
|
||||||
autoclickBehavior: params.initialWorkflow.config.behaviors
|
autoclickBehavior: params.initialWorkflow.config.behaviors
|
||||||
? params.initialWorkflow.config.behaviors.includes("autoclick")
|
? params.initialWorkflow.config.behaviors.includes(Behavior.AutoClick)
|
||||||
: defaultFormState.autoclickBehavior,
|
: defaultFormState.autoclickBehavior,
|
||||||
userAgent:
|
userAgent:
|
||||||
params.initialWorkflow.config.userAgent ?? defaultFormState.userAgent,
|
params.initialWorkflow.config.userAgent ?? defaultFormState.userAgent,
|
||||||
|
Loading…
Reference in New Issue
Block a user