Skip to content

Commit 1511f9b

Browse files
SuaYooikreymer
andauthored
feat: Standardize browser profile display and proxy setting (#3004)
- Updates browser profile and workflow form controls to make relationship between profile and proxy more apparent - Displays suggested browser profiles based on workflow seed URLs - Displays browser profile details when selecting a profile from a workflow - Fixes profile not saved to crawling defaults - Consistency fixes for how proxies and crawler release channel is displayed --------- Co-authored-by: Ilya Kreymer <[email protected]>
1 parent 67a914e commit 1511f9b

File tree

23 files changed

+712
-271
lines changed

23 files changed

+712
-271
lines changed

.github/workflows/k3d-ci.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ jobs:
4545
needs: paths-filter
4646
if: needs.paths-filter.outputs.matches == 'true'
4747
steps:
48+
- name: Initial Disk Cleanup
49+
uses: mathio/gha-cleanup@v1
50+
with:
51+
remove-browsers: true
52+
verbose: true
53+
54+
4855
- name: Create k3d Cluster
4956
uses: AbsaOSS/k3d-action@v2
5057
with:

frontend/src/components/ui/badge.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export type BadgeVariant =
1414
| "cyan"
1515
| "blue"
1616
| "high-contrast"
17-
| "text";
17+
| "text"
18+
| "text-neutral";
1819

1920
/**
2021
* Show numeric value in a label
@@ -66,6 +67,7 @@ export class Badge extends TailwindElement {
6667
cyan: tw`bg-cyan-50 text-cyan-600 ring-cyan-600`,
6768
blue: tw`bg-blue-50 text-blue-600 ring-blue-600`,
6869
text: tw`text-blue-500 ring-blue-600`,
70+
"text-neutral": tw`text-neutral-500 ring-neutral-600`,
6971
}[this.variant],
7072
]
7173
: {
@@ -78,6 +80,7 @@ export class Badge extends TailwindElement {
7880
cyan: tw`bg-cyan-50 text-cyan-600`,
7981
blue: tw`bg-blue-50 text-blue-600`,
8082
text: tw`text-blue-500`,
83+
"text-neutral": tw`text-neutral-500`,
8184
}[this.variant],
8285
this.pill
8386
? [

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

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { consume } from "@lit/context";
12
import { localized, msg, str } from "@lit/localize";
23
import ISO6391 from "iso-639-1";
34
import { html, nothing, type TemplateResult } from "lit";
@@ -6,6 +7,10 @@ import { when } from "lit/directives/when.js";
67
import capitalize from "lodash/fp/capitalize";
78

89
import { BtrixElement } from "@/classes/BtrixElement";
10+
import {
11+
orgProxiesContext,
12+
type OrgProxiesContext,
13+
} from "@/context/org-proxies";
914
import { none, notSpecified } from "@/layouts/empty";
1015
import {
1116
Behavior,
@@ -36,6 +41,9 @@ import { getServerDefaults } from "@/utils/workflow";
3641
@customElement("btrix-config-details")
3742
@localized()
3843
export class ConfigDetails extends BtrixElement {
44+
@consume({ context: orgProxiesContext, subscribe: true })
45+
private readonly orgProxies?: OrgProxiesContext;
46+
3947
@property({ type: Object })
4048
crawlConfig?: CrawlConfig;
4149

@@ -235,23 +243,31 @@ export class ConfigDetails extends BtrixElement {
235243
msg("Browser Profile"),
236244
when(
237245
crawlConfig?.profileid,
238-
() =>
239-
html`<a
240-
class="text-blue-500 hover:text-blue-600"
246+
() => html`
247+
<btrix-link
241248
href=${`${this.navigate.orgBasePath}/browser-profiles/profile/${
242249
crawlConfig!.profileid
243250
}`}
244-
@click=${this.navigate.link}
251+
hideIcon
245252
>
246253
${crawlConfig?.profileName}
247-
</a>`,
254+
</btrix-link>
255+
`,
248256
() =>
249257
crawlConfig?.profileName ||
250258
html`<span class="text-neutral-400"
251259
>${msg("No custom profile")}</span
252260
>`,
253261
),
254262
)}
263+
${crawlConfig?.proxyId
264+
? this.renderSetting(
265+
msg("Crawler Proxy Server"),
266+
this.orgProxies?.servers.find(
267+
({ id }) => id === crawlConfig.proxyId,
268+
)?.label || capitalize(crawlConfig.proxyId),
269+
)
270+
: nothing}
255271
${this.renderSetting(
256272
msg("Browser Windows"),
257273
crawlConfig?.browserWindows ? `${crawlConfig.browserWindows}` : "",
@@ -284,9 +300,6 @@ export class ConfigDetails extends BtrixElement {
284300
ISO6391.getName(seedsConfig.lang),
285301
)
286302
: nothing}
287-
${crawlConfig?.proxyId
288-
? this.renderSetting(msg("Proxy"), capitalize(crawlConfig.proxyId))
289-
: nothing}
290303
`,
291304
})}
292305
${this.renderSection({

frontend/src/components/ui/link.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import clsx from "clsx";
2-
import { html } from "lit";
2+
import { html, nothing } from "lit";
33
import { customElement, property } from "lit/decorators.js";
44
import { ifDefined } from "lit/directives/if-defined.js";
55

@@ -19,13 +19,16 @@ export class Link extends BtrixElement {
1919
@property({ type: String })
2020
variant: "primary" | "neutral" = "neutral";
2121

22+
@property({ type: Boolean })
23+
hideIcon = false;
24+
2225
render() {
2326
if (!this.href) return;
2427

2528
return html`
2629
<a
2730
class=${clsx(
28-
"group inline-flex items-center gap-1 transition-colors",
31+
"group inline-flex items-center gap-1 transition-colors duration-fast",
2932
{
3033
primary: "text-primary-500 hover:text-primary-600",
3134
neutral: "text-blue-500 hover:text-blue-600",
@@ -39,12 +42,16 @@ export class Link extends BtrixElement {
3942
: this.navigate.link}
4043
>
4144
<slot></slot>
42-
<sl-icon
43-
slot="suffix"
44-
name="arrow-right"
45-
class="size-4 transition-transform group-hover:translate-x-1"
46-
></sl-icon
47-
></a>
45+
${this.hideIcon
46+
? nothing
47+
: html`
48+
<sl-icon
49+
slot="suffix"
50+
name="arrow-right"
51+
class="size-4 transition-transform duration-fast group-hover:translate-x-1"
52+
></sl-icon>
53+
`}
54+
</a>
4855
`;
4956
}
5057
}

frontend/src/components/ui/select-crawler-proxy.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { localized, msg } from "@lit/localize";
22
import type { SlSelect } from "@shoelace-style/shoelace";
3-
import { html } from "lit";
3+
import { html, type PropertyValues } from "lit";
44
import { customElement, property, state } from "lit/decorators.js";
55
import { ifDefined } from "lit/directives/if-defined.js";
66

@@ -40,15 +40,30 @@ export class SelectCrawlerProxy extends BtrixElement {
4040
@property({ type: String })
4141
defaultProxyId: string | null = null;
4242

43+
@property({ type: String })
44+
profileProxyId?: string | null = null;
45+
4346
@property({ type: Array })
4447
proxyServers: Proxy[] = [];
4548

4649
@property({ type: String })
4750
proxyId: string | null = null;
4851

52+
@property({ type: String })
53+
label?: string;
54+
4955
@property({ type: String })
5056
size?: SlSelect["size"];
5157

58+
@property({ type: String })
59+
placeholder?: string;
60+
61+
@property({ type: String })
62+
helpText?: string;
63+
64+
@property({ type: Boolean })
65+
disabled?: boolean;
66+
5267
@state()
5368
private selectedProxy?: Proxy;
5469

@@ -59,6 +74,18 @@ export class SelectCrawlerProxy extends BtrixElement {
5974
return this.selectedProxy?.id || "";
6075
}
6176

77+
protected willUpdate(changedProperties: PropertyValues): void {
78+
if (changedProperties.has("proxyId")) {
79+
if (this.proxyId) {
80+
this.selectedProxy = this.proxyServers.find(
81+
({ id }) => id === this.proxyId,
82+
);
83+
} else if (changedProperties.get("proxyId")) {
84+
this.selectedProxy = undefined;
85+
}
86+
}
87+
}
88+
6289
protected firstUpdated() {
6390
void this.initProxies();
6491
}
@@ -75,18 +102,21 @@ export class SelectCrawlerProxy extends BtrixElement {
75102
return html`
76103
<sl-select
77104
name="proxyId"
78-
label=${msg("Crawler Proxy Server")}
105+
label=${this.label || msg("Crawler Proxy Server")}
79106
value=${this.selectedProxy?.id || ""}
80107
placeholder=${this.defaultProxy
81108
? `${msg(`Default Proxy:`)} ${this.defaultProxy.label}`
82109
: msg("No Proxy")}
83110
hoist
84111
clearable
112+
?disabled=${this.disabled ?? Boolean(this.profileProxyId)}
85113
size=${ifDefined(this.size)}
86114
@sl-change=${this.onChange}
87115
@sl-hide=${this.stopProp}
88116
@sl-after-hide=${this.stopProp}
89117
>
118+
<slot name="prefix" slot="prefix"></slot>
119+
<slot name="suffix" slot="suffix"></slot>
90120
${this.proxyServers.map(
91121
(server) =>
92122
html` <sl-option value=${server.id}>
@@ -118,6 +148,7 @@ export class SelectCrawlerProxy extends BtrixElement {
118148
</div>
119149
`
120150
: ``}
151+
<slot name="help-text" slot="help-text"></slot>
121152
</sl-select>
122153
`;
123154
}

frontend/src/controllers/localize.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ export class LocalizeController extends SlLocalizeController {
5555
})
5656
: seconds > 60
5757
? html`<sl-relative-time
58-
class=${ifDefined(capitalize ? tw`capitalize` : undefined)}
58+
class=${ifDefined(
59+
capitalize
60+
? tw`inline-block first-letter:capitalize`
61+
: undefined,
62+
)}
5963
sync
6064
date=${dateStr}
6165
></sl-relative-time>`

frontend/src/features/browser-profiles/new-browser-profile-dialog.ts

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -116,50 +116,53 @@ export class NewBrowserProfileDialog extends BtrixElement {
116116
>
117117
</btrix-url-input>
118118
119+
${showProxies
120+
? html`
121+
<div class="mt-4">
122+
<btrix-select-crawler-proxy
123+
.label=${msg("Proxy Server")}
124+
defaultProxyId=${ifDefined(
125+
this.defaultProxyId || undefined,
126+
)}
127+
.proxyServers=${proxyServers}
128+
.proxyId="${this.proxyId || ""}"
129+
@btrix-change=${(e: SelectCrawlerProxyChangeEvent) =>
130+
(this.proxyId = e.detail.value)}
131+
>
132+
<div slot="help-text">
133+
${msg(
134+
"When a proxy is selected, websites will see traffic as coming from the IP address of the proxy rather than where Browsertrix is deployed.",
135+
)}
136+
</div>
137+
</btrix-select-crawler-proxy>
138+
</div>
139+
`
140+
: nothing}
141+
119142
<sl-input
120143
class="mt-4"
121144
label=${msg("Profile Name")}
122145
name="profile-name"
123146
placeholder=${msg("example.com")}
124147
value=${ifDefined(this.defaultUrl)}
125-
help-text=${msg("Defaults to site's domain name if omitted.")}
148+
help-text=${msg(
149+
"Defaults to the primary site's domain name if omitted.",
150+
)}
126151
maxlength="50"
127152
>
128153
</sl-input>
129154
130-
${when(
131-
showChannels || showProxies,
132-
() => html`
133-
<btrix-details class="mt-4" open>
134-
<span slot="title">${msg("Crawler Settings")}</span>
135-
136-
${showChannels
137-
? html`<div class="mt-4">
138-
<btrix-select-crawler
139-
.crawlerChannel=${this.crawlerChannel}
140-
@on-change=${(e: SelectCrawlerChangeEvent) =>
141-
(this.crawlerChannel = e.detail.value!)}
142-
></btrix-select-crawler>
143-
</div>`
144-
: nothing}
145-
${showProxies
146-
? html`
147-
<div class="mt-4">
148-
<btrix-select-crawler-proxy
149-
defaultProxyId=${ifDefined(
150-
this.defaultProxyId || undefined,
151-
)}
152-
.proxyServers=${proxyServers}
153-
.proxyId="${this.proxyId || ""}"
154-
@btrix-change=${(e: SelectCrawlerProxyChangeEvent) =>
155-
(this.proxyId = e.detail.value)}
156-
></btrix-select-crawler-proxy>
157-
</div>
158-
`
159-
: nothing}
160-
</btrix-details>
161-
`,
162-
)}
155+
${showChannels
156+
? html`<btrix-details class="mt-4">
157+
<span slot="title">${msg("Browser Session Settings")}</span>
158+
<div class="mt-4">
159+
<btrix-select-crawler
160+
.crawlerChannel=${this.crawlerChannel}
161+
@on-change=${(e: SelectCrawlerChangeEvent) =>
162+
(this.crawlerChannel = e.detail.value!)}
163+
></btrix-select-crawler></div
164+
></btrix-details>`
165+
: nothing}
163166
164167
<input class="invisible block size-0" type="submit" />
165168
</form>

0 commit comments

Comments
 (0)