Skip to content

Commit df8c80f

Browse files
authored
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
1 parent 61809ab commit df8c80f

File tree

7 files changed

+71
-42
lines changed

7 files changed

+71
-42
lines changed

frontend/src/components/ui/config-details.ts

+21-24
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ import capitalize from "lodash/fp/capitalize";
88
import RegexColorize from "regex-colorize";
99

1010
import { BtrixElement } from "@/classes/BtrixElement";
11-
import type { CrawlConfig, Seed, SeedConfig } from "@/pages/org/types";
11+
import { none, notSpecified } from "@/layouts/empty";
12+
import {
13+
Behavior,
14+
type CrawlConfig,
15+
type Seed,
16+
type SeedConfig,
17+
} from "@/pages/org/types";
1218
import { labelFor } from "@/strings/crawl-workflows/labels";
1319
import scopeTypeLabel from "@/strings/crawl-workflows/scopeType";
1420
import sectionStrings from "@/strings/crawl-workflows/section";
@@ -162,22 +168,15 @@ export class ConfigDetails extends BtrixElement {
162168
heading: sectionStrings.behaviors,
163169
renderDescItems: (seedsConfig) => html`
164170
${this.renderSetting(
165-
labelFor.autoscrollBehavior,
166-
seedsConfig?.behaviors &&
167-
!seedsConfig.behaviors.includes("autoscroll")
168-
? msg("Disabled")
169-
: html`<span class="text-neutral-400"
170-
>${msg("Enabled (default)")}</span
171-
>`,
172-
)}
173-
${this.renderSetting(
174-
labelFor.autoclickBehavior,
175-
seedsConfig?.behaviors &&
176-
seedsConfig.behaviors.includes("autoclick")
177-
? msg("Enabled")
178-
: html`<span class="text-neutral-400"
179-
>${msg("Disabled (default)")}</span
180-
>`,
171+
labelFor.behaviors,
172+
[
173+
seedsConfig?.behaviors?.includes(Behavior.AutoScroll) &&
174+
labelFor.autoscrollBehavior,
175+
seedsConfig?.behaviors?.includes(Behavior.AutoClick) &&
176+
labelFor.autoclickBehavior,
177+
]
178+
.filter((v) => v)
179+
.join(", ") || none,
181180
)}
182181
${this.renderSetting(
183182
labelFor.pageLoadTimeoutSeconds,
@@ -424,7 +423,7 @@ export class ConfigDetails extends BtrixElement {
424423
)}
425424
</ul>
426425
`
427-
: msg("None"),
426+
: none,
428427
true,
429428
),
430429
)}
@@ -463,7 +462,7 @@ export class ConfigDetails extends BtrixElement {
463462
})}
464463
</ul>
465464
`
466-
: msg("None"),
465+
: none,
467466
true,
468467
)}
469468
${when(
@@ -477,7 +476,7 @@ export class ConfigDetails extends BtrixElement {
477476
</btrix-queue-exclusion-table>
478477
</div>
479478
`,
480-
() => this.renderSetting(msg("Exclusions"), msg("None")),
479+
() => this.renderSetting(msg("Exclusions"), none),
481480
)}
482481
`;
483482
};
@@ -490,11 +489,9 @@ export class ConfigDetails extends BtrixElement {
490489
} else if (typeof value === "boolean") {
491490
content = value ? msg("Yes") : msg("No");
492491
} else if (Array.isArray(value) && !value.length) {
493-
content = html`<span class="text-neutral-400">${msg("None")}</span>`;
492+
content = none;
494493
} else if (typeof value !== "number" && !value) {
495-
content = html`<span class="text-neutral-400"
496-
>${msg("Not specified")}</span
497-
>`;
494+
content = notSpecified;
498495
}
499496
return html`
500497
<btrix-desc-list-item label=${label} class=${breakAll ? "break-all" : ""}>

frontend/src/features/crawl-workflows/workflow-editor.ts

+18-14
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ import { labelFor } from "@/strings/crawl-workflows/labels";
6262
import scopeTypeLabels from "@/strings/crawl-workflows/scopeType";
6363
import sectionStrings from "@/strings/crawl-workflows/section";
6464
import { AnalyticsTrackEvent } from "@/trackEvents";
65-
import { ScopeType, type Seed, type WorkflowParams } from "@/types/crawler";
65+
import {
66+
Behavior,
67+
ScopeType,
68+
type Seed,
69+
type WorkflowParams,
70+
} from "@/types/crawler";
6671
import type { UnderlyingFunction } from "@/types/utils";
6772
import { NewWorkflowOnlyScopeType } from "@/types/workflow";
6873
import { track } from "@/utils/analytics";
@@ -111,11 +116,10 @@ type ProgressState = {
111116
tabs: Tabs;
112117
};
113118
const DEFAULT_BEHAVIORS = [
114-
"autoscroll",
115-
"autoplay",
116-
"autofetch",
117-
"siteSpecific",
118-
];
119+
Behavior.AutoPlay,
120+
Behavior.AutoFetch,
121+
Behavior.SiteSpecific,
122+
] as const;
119123
const formName = "newJobConfig" as const;
120124
const panelSuffix = "--panel" as const;
121125

@@ -1182,7 +1186,7 @@ https://archiveweb.page/images/${"logo.svg"}`}
11821186

11831187
private renderBehaviors() {
11841188
return html`
1185-
${this.renderSectionHeading(msg("Built-in Behaviors"))}
1189+
${this.renderSectionHeading(labelFor.behaviors)}
11861190
${inputCol(
11871191
html`<sl-checkbox
11881192
name="autoscrollBehavior"
@@ -2206,17 +2210,17 @@ https://archiveweb.page/images/${"logo.svg"}`}
22062210
}
22072211

22082212
private setBehaviors(): string {
2209-
let behaviors = (
2210-
this.formState.autoscrollBehavior
2211-
? DEFAULT_BEHAVIORS
2212-
: DEFAULT_BEHAVIORS.slice(1)
2213-
).join(",");
2213+
const behaviors: Behavior[] = [...DEFAULT_BEHAVIORS];
2214+
2215+
if (this.formState.autoscrollBehavior) {
2216+
behaviors.unshift(Behavior.AutoScroll);
2217+
}
22142218

22152219
if (this.formState.autoclickBehavior) {
2216-
behaviors += ",autoclick";
2220+
behaviors.push(Behavior.AutoClick);
22172221
}
22182222

2219-
return behaviors;
2223+
return behaviors.join(",");
22202224
}
22212225

22222226
private parseUrlListConfig(): Pick<

frontend/src/layouts/empty.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { html } from "lit";
2+
3+
import { stringFor } from "@/strings/ui";
4+
5+
export const notSpecified = html`<span class="text-neutral-400">
6+
${stringFor.notSpecified}
7+
</span>`;
8+
9+
export const none = html`<span class="text-neutral-400">
10+
${stringFor.none}
11+
</span>`;

frontend/src/strings/crawl-workflows/labels.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { msg } from "@lit/localize";
22

33
export const labelFor = {
4+
behaviors: msg("Built-in Behaviors"),
45
autoscrollBehavior: msg("Autoscroll"),
56
autoclickBehavior: msg("Autoclick"),
67
pageLoadTimeoutSeconds: msg("Page Load Limit"),

frontend/src/strings/ui.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import { msg } from "@lit/localize";
22
import { html, type TemplateResult } from "lit";
33

4-
export const noData = "--";
5-
export const notApplicable = msg("n/a");
4+
export const stringFor: Record<string, string> = {
5+
noData: "--",
6+
notApplicable: msg("n/a"),
7+
notSpecified: msg("Not specified"),
8+
none: msg("None"),
9+
};
10+
11+
export const noData = stringFor.noData;
12+
export const notApplicable = stringFor.notApplicable;
613

714
// TODO Refactor all generic confirmation messages to use utility
815
export const deleteConfirmation = (name: string | TemplateResult) =>

frontend/src/types/crawler.ts

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ export enum ScopeType {
1010
Any = "any",
1111
}
1212

13+
export enum Behavior {
14+
AutoScroll = "autoscroll",
15+
AutoClick = "autoclick",
16+
AutoPlay = "autoplay",
17+
AutoFetch = "autofetch",
18+
SiteSpecific = "siteSpecific",
19+
}
20+
1321
export type Seed = {
1422
url: string;
1523
scopeType: ScopeType | undefined;

frontend/src/utils/workflow.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getAppSettings } from "./app";
55

66
import type { Tags } from "@/components/ui/tag-input";
77
import {
8+
Behavior,
89
ScopeType,
910
type Profile,
1011
type Seed,
@@ -284,10 +285,10 @@ export function getInitialFormState(params: {
284285
pageLimit:
285286
params.initialWorkflow.config.limit ?? defaultFormState.pageLimit,
286287
autoscrollBehavior: params.initialWorkflow.config.behaviors
287-
? params.initialWorkflow.config.behaviors.includes("autoscroll")
288+
? params.initialWorkflow.config.behaviors.includes(Behavior.AutoScroll)
288289
: defaultFormState.autoscrollBehavior,
289290
autoclickBehavior: params.initialWorkflow.config.behaviors
290-
? params.initialWorkflow.config.behaviors.includes("autoclick")
291+
? params.initialWorkflow.config.behaviors.includes(Behavior.AutoClick)
291292
: defaultFormState.autoclickBehavior,
292293
userAgent:
293294
params.initialWorkflow.config.userAgent ?? defaultFormState.userAgent,

0 commit comments

Comments
 (0)