Skip to content

Commit 4c48d8a

Browse files
authored
fix: Use org crawling defaults for new browser profile (#2937)
- Uses org crawling defaults when creating new browser profile - Refactors `"default"` image to enum
1 parent 5dd9dfb commit 4c48d8a

File tree

11 files changed

+103
-59
lines changed

11 files changed

+103
-59
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { BtrixElement } from "@/classes/BtrixElement";
99
import { none, notSpecified } from "@/layouts/empty";
1010
import {
1111
Behavior,
12+
CrawlerChannelImage,
1213
type CrawlConfig,
1314
type Seed,
1415
type SeedConfig,
@@ -257,8 +258,9 @@ export class ConfigDetails extends BtrixElement {
257258
)}
258259
${this.renderSetting(
259260
msg("Crawler Channel (Exact Crawler Version)"),
260-
capitalize(crawlConfig?.crawlerChannel || "default") +
261-
(crawlConfig?.image ? ` (${crawlConfig.image})` : ""),
261+
capitalize(
262+
crawlConfig?.crawlerChannel || CrawlerChannelImage.Default,
263+
) + (crawlConfig?.image ? ` (${crawlConfig.image})` : ""),
262264
)}
263265
${this.renderSetting(
264266
msg("Block Ads by Domain"),

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { customElement, property, state } from "lit/decorators.js";
55
import { ifDefined } from "lit/directives/if-defined.js";
66
import capitalize from "lodash/fp/capitalize";
77

8-
import type { CrawlerChannel } from "@/pages/org/types";
8+
import { CrawlerChannelImage, type CrawlerChannel } from "@/pages/org/types";
99
import LiteElement from "@/utils/LiteElement";
1010

1111
type SelectCrawlerChangeDetail = {
@@ -131,11 +131,11 @@ export class SelectCrawler extends LiteElement {
131131
}
132132

133133
if (!this.selectedCrawler) {
134-
this.crawlerChannel = "default";
134+
this.crawlerChannel = CrawlerChannelImage.Default;
135135
this.dispatchEvent(
136136
new CustomEvent("on-change", {
137137
detail: {
138-
value: "default",
138+
value: CrawlerChannelImage.Default,
139139
},
140140
}),
141141
);

frontend/src/components/ui/url-input.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export function validURL(url: string) {
1919
* @attr {String} name
2020
* @attr {String} label
2121
* @attr {String} value
22+
* @attr {String} autocomplete
2223
* @attr {Boolean} required
2324
*/
2425
@customElement("btrix-url-input")

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

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { consume } from "@lit/context";
21
import { localized, msg, str } from "@lit/localize";
32
import { type SlInput } from "@shoelace-style/shoelace";
4-
import { nothing } from "lit";
3+
import { html, nothing, type PropertyValues } from "lit";
54
import {
65
customElement,
76
property,
@@ -12,17 +11,23 @@ import {
1211
import { ifDefined } from "lit/directives/if-defined.js";
1312
import queryString from "query-string";
1413

14+
import { BtrixElement } from "@/classes/BtrixElement";
1515
import type { Dialog } from "@/components/ui/dialog";
1616
import { type SelectCrawlerChangeEvent } from "@/components/ui/select-crawler";
1717
import { type SelectCrawlerProxyChangeEvent } from "@/components/ui/select-crawler-proxy";
18-
import { proxiesContext, type ProxiesContext } from "@/context/org";
19-
import LiteElement, { html } from "@/utils/LiteElement";
18+
import { CrawlerChannelImage, type Proxy } from "@/types/crawler";
2019

2120
@customElement("btrix-new-browser-profile-dialog")
2221
@localized()
23-
export class NewBrowserProfileDialog extends LiteElement {
24-
@consume({ context: proxiesContext, subscribe: true })
25-
private readonly proxies?: ProxiesContext;
22+
export class NewBrowserProfileDialog extends BtrixElement {
23+
@property({ type: String })
24+
defaultProxyId?: string;
25+
26+
@property({ type: String })
27+
defaultCrawlerChannel?: string;
28+
29+
@property({ type: Array })
30+
proxyServers?: Proxy[];
2631

2732
@property({ type: Boolean })
2833
open = false;
@@ -31,7 +36,7 @@ export class NewBrowserProfileDialog extends LiteElement {
3136
private isSubmitting = false;
3237

3338
@state()
34-
private crawlerChannel = "default";
39+
private crawlerChannel: string = CrawlerChannelImage.Default;
3540

3641
@state()
3742
private proxyId: string | null = null;
@@ -42,6 +47,22 @@ export class NewBrowserProfileDialog extends LiteElement {
4247
@queryAsync("#browserProfileForm")
4348
private readonly form!: Promise<HTMLFormElement>;
4449

50+
protected willUpdate(changedProperties: PropertyValues): void {
51+
if (changedProperties.has("defaultProxyId") && this.defaultProxyId) {
52+
this.proxyId = this.proxyId || this.defaultProxyId;
53+
}
54+
55+
if (
56+
changedProperties.has("defaultCrawlerChannel") &&
57+
this.defaultCrawlerChannel
58+
) {
59+
this.crawlerChannel =
60+
(this.crawlerChannel !== (CrawlerChannelImage.Default as string) &&
61+
this.crawlerChannel) ||
62+
this.defaultCrawlerChannel;
63+
}
64+
}
65+
4566
render() {
4667
return html` <btrix-dialog
4768
.label=${msg(str`Create a New Browser Profile`)}
@@ -61,43 +82,28 @@ export class NewBrowserProfileDialog extends LiteElement {
6182
@reset=${this.onReset}
6283
@submit=${this.onSubmit}
6384
>
64-
<div class="grid">
65-
<div>
66-
<label
67-
id="startingUrlLabel"
68-
class="text-sm leading-normal"
69-
style="margin-bottom: var(--sl-spacing-3x-small)"
70-
>${msg("Starting URL")}
71-
</label>
72-
73-
<div class="flex">
74-
<sl-input
75-
class="grow"
76-
name="url"
77-
placeholder=${msg("https://example.com")}
78-
autocomplete="off"
79-
aria-labelledby="startingUrlLabel"
80-
required
81-
>
82-
</sl-input>
83-
</div>
84-
</div>
85-
</div>
86-
<div class="mt-1">
85+
<btrix-url-input
86+
label=${msg("Starting URL")}
87+
name="url"
88+
placeholder=${msg("https://example.com")}
89+
autocomplete="off"
90+
required
91+
>
92+
</btrix-url-input>
93+
94+
<div class="mt-4">
8795
<btrix-select-crawler
8896
.crawlerChannel=${this.crawlerChannel}
8997
@on-change=${(e: SelectCrawlerChangeEvent) =>
9098
(this.crawlerChannel = e.detail.value!)}
9199
></btrix-select-crawler>
92100
</div>
93-
${this.proxies?.servers.length
101+
${this.proxyServers?.length
94102
? html`
95103
<div class="mt-4">
96104
<btrix-select-crawler-proxy
97-
defaultProxyId=${ifDefined(
98-
this.proxies.default_proxy_id ?? undefined,
99-
)}
100-
.proxyServers=${this.proxies.servers}
105+
defaultProxyId=${ifDefined(this.defaultProxyId || undefined)}
106+
.proxyServers=${this.proxyServers}
101107
.proxyId="${this.proxyId || ""}"
102108
@btrix-change=${(e: SelectCrawlerProxyChangeEvent) =>
103109
(this.proxyId = e.detail.value)}
@@ -156,15 +162,15 @@ export class NewBrowserProfileDialog extends LiteElement {
156162
proxyId: this.proxyId,
157163
});
158164

159-
this.notify({
165+
this.notify.toast({
160166
message: msg("Starting up browser for new profile..."),
161167
variant: "success",
162168
icon: "check2-circle",
163169
id: "browser-profile-update-status",
164170
});
165171
await this.hideDialog();
166-
this.navTo(
167-
`${this.orgBasePath}/browser-profiles/profile/browser/${
172+
this.navigate.to(
173+
`${this.navigate.orgBasePath}/browser-profiles/profile/browser/${
168174
data.browserid
169175
}?${queryString.stringify({
170176
url,
@@ -174,7 +180,7 @@ export class NewBrowserProfileDialog extends LiteElement {
174180
})}`,
175181
);
176182
} catch (e) {
177-
this.notify({
183+
this.notify.toast({
178184
message: msg("Sorry, couldn't create browser profile at this time."),
179185
variant: "danger",
180186
icon: "exclamation-octagon",
@@ -199,7 +205,7 @@ export class NewBrowserProfileDialog extends LiteElement {
199205
proxyId,
200206
};
201207

202-
return this.apiFetch<{ browserid: string }>(
208+
return this.api.fetch<{ browserid: string }>(
203209
`/orgs/${this.orgId}/profiles/browser`,
204210
{
205211
method: "POST",

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ import { AnalyticsTrackEvent } from "@/trackEvents";
8888
import { APIErrorDetail } from "@/types/api";
8989
import {
9090
Behavior,
91+
CrawlerChannelImage,
9192
ScopeType,
9293
type Seed,
9394
type WorkflowParams,
@@ -3228,7 +3229,8 @@ https://archiveweb.page/images/${"logo.svg"}`}
32283229
clickSelector:
32293230
this.formState.clickSelector || DEFAULT_AUTOCLICK_SELECTOR,
32303231
},
3231-
crawlerChannel: this.formState.crawlerChannel || "default",
3232+
crawlerChannel:
3233+
this.formState.crawlerChannel || CrawlerChannelImage.Default,
32323234
proxyId: this.formState.proxyId,
32333235
};
32343236

frontend/src/pages/org/archived-item-detail/archived-item-detail.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,8 +948,9 @@ export class ArchivedItemDetail extends BtrixElement {
948948
}
949949

950950
const text =
951-
capitalize(this.item.crawlerChannel || "default") +
952-
(this.item.image ? ` (${this.item.image})` : "");
951+
(this.item.crawlerChannel
952+
? capitalize(this.item.crawlerChannel)
953+
: msg("Default")) + (this.item.image ? ` (${this.item.image})` : "");
953954

954955
return html` <btrix-desc-list-item
955956
label=${msg("Crawler Channel (Exact Crawler Version)")}

frontend/src/pages/org/browser-profiles-new.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { customElement, property, query, state } from "lit/decorators.js";
44
import { ifDefined } from "lit/directives/if-defined.js";
55
import queryString from "query-string";
66

7+
import { CrawlerChannelImage } from "./types";
8+
79
import { BtrixElement } from "@/classes/BtrixElement";
810
import type { Dialog } from "@/components/ui/dialog";
911
import type { BrowserConnectionChange } from "@/features/browser-profiles/profile-browser";
@@ -279,7 +281,8 @@ export class BrowserProfilesNew extends BtrixElement {
279281
return;
280282
}
281283

282-
const crawlerChannel = this.browserParams.crawlerChannel || "default";
284+
const crawlerChannel =
285+
this.browserParams.crawlerChannel || CrawlerChannelImage.Default;
283286
const proxyId = this.browserParams.proxyId;
284287
const data = await this.createBrowser({
285288
url,

frontend/src/pages/org/index.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ const UUID_REGEX =
100100
@needLogin
101101
export class Org extends BtrixElement {
102102
@provide({ context: proxiesContext })
103+
@state()
103104
proxies: ProxiesContext = null;
104105

105106
@property({ type: Object })
@@ -450,11 +451,29 @@ export class Org extends BtrixElement {
450451
}
451452
}}
452453
></btrix-file-uploader>
453-
<btrix-new-browser-profile-dialog
454-
?open=${this.openDialogName === "browser-profile"}
455-
@sl-hide=${() => (this.openDialogName = undefined)}
456-
>
457-
</btrix-new-browser-profile-dialog>
454+
455+
${when(this.org, (org) =>
456+
when(
457+
this.proxies,
458+
(proxies) => html`
459+
<btrix-new-browser-profile-dialog
460+
.proxyServers=${proxies.servers}
461+
defaultProxyId=${ifDefined(
462+
org.crawlingDefaults?.proxyId ||
463+
proxies.default_proxy_id ||
464+
undefined,
465+
)}
466+
defaultCrawlerChannel=${ifDefined(
467+
org.crawlingDefaults?.crawlerChannel || undefined,
468+
)}
469+
?open=${this.openDialogName === "browser-profile"}
470+
@sl-hide=${() => (this.openDialogName = undefined)}
471+
>
472+
</btrix-new-browser-profile-dialog>
473+
`,
474+
),
475+
)}
476+
458477
<btrix-collection-create-dialog
459478
?open=${this.openDialogName === "collection"}
460479
@sl-hide=${() => (this.openDialogName = undefined)}

frontend/src/pages/org/workflows-new.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import { ifDefined } from "lit/directives/if-defined.js";
77
import { when } from "lit/directives/when.js";
88
import type { PartialDeep } from "type-fest";
99

10-
import { ScopeType, type Seed, type WorkflowParams } from "./types";
10+
import {
11+
CrawlerChannelImage,
12+
ScopeType,
13+
type Seed,
14+
type WorkflowParams,
15+
} from "./types";
1116

1217
import { BtrixElement } from "@/classes/BtrixElement";
1318
import { pageNav, type Breadcrumb } from "@/layouts/pageHeader";
@@ -72,7 +77,7 @@ export class WorkflowsNew extends BtrixElement {
7277
jobType: "custom",
7378
browserWindows: this.appState.settings?.numBrowsersPerInstance || 1,
7479
autoAddCollections: [],
75-
crawlerChannel: "default",
80+
crawlerChannel: CrawlerChannelImage.Default,
7681
proxyId: null,
7782
};
7883
}

frontend/src/types/crawler.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ export enum Behavior {
1919
SiteSpecific = "siteSpecific",
2020
}
2121

22+
export enum CrawlerChannelImage {
23+
Default = "default",
24+
}
25+
2226
export type Seed = {
2327
url: string;
2428
scopeType: ScopeType | undefined;
@@ -200,7 +204,7 @@ export type Upload = ArchivedItemBase & {
200204
type: "upload";
201205
cid: undefined;
202206
resources: undefined;
203-
crawlerChannel: "default";
207+
crawlerChannel: CrawlerChannelImage.Default;
204208
image: null;
205209
manual: true;
206210
};

0 commit comments

Comments
 (0)