Skip to content

Commit b0d1a35

Browse files
authored
fix: Handle no crawling defaults (#2549)
Fixes regression introduced by 7c6bae8 ## Changes Handles orgs without any crawl defaults correctly. Areas that use crawling defaults are also more strongly typed now to prevent similar issues.
1 parent 0cb3bd1 commit b0d1a35

File tree

4 files changed

+32
-20
lines changed

4 files changed

+32
-20
lines changed

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"thread-loader": "^4.0.4",
8484
"ts-loader": "^9.2.6",
8585
"tsconfig-paths-webpack-plugin": "^4.1.0",
86+
"type-fest": "^4.39.1",
8687
"typescript": "^5.3.3",
8788
"update-dotenv": "^1.1.1",
8889
"url-pattern": "^1.0.3",

frontend/src/pages/org/settings/components/crawling-defaults.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { css, html, type TemplateResult } from "lit";
77
import { customElement, query, state } from "lit/decorators.js";
88
import { guard } from "lit/directives/guard.js";
99
import { ifDefined } from "lit/directives/if-defined.js";
10+
import type { Entries } from "type-fest";
1011

1112
import { BtrixElement } from "@/classes/BtrixElement";
1213
import type { LanguageSelect } from "@/components/ui/language-select";
@@ -86,7 +87,7 @@ export class OrgSettingsCrawlWorkflows extends BtrixElement {
8687
return html` ${this.renderWorkflowDefaults()} `;
8788
}
8889

89-
get fields(): Partial<Record<SectionsEnum, Partial<Field>>> {
90+
get fields() {
9091
const orgDefaults: Partial<CrawlingDefaults> = this.org
9192
?.crawlingDefaults || {
9293
exclude: PLACEHOLDER_EXCLUSIONS,
@@ -269,26 +270,30 @@ export class OrgSettingsCrawlWorkflows extends BtrixElement {
269270
limits,
270271
behaviors,
271272
browserSettings,
272-
} as const;
273+
} as const satisfies Partial<Record<SectionsEnum, Partial<Field>>>;
273274
}
274275

275276
private renderWorkflowDefaults() {
276277
return html`
277278
<div class="rounded-lg border">
278279
<form @submit=${this.onSubmit}>
279280
${guard([this.defaults, this.org], () =>
280-
Object.entries(this.fields).map(([sectionName, fields]) =>
281-
section(
282-
sectionName as SectionsEnum,
283-
Object.entries(fields)
284-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
285-
.filter(([, field]) => field)
286-
.map(([fieldName, field]) => [
287-
field,
288-
infoTextFor[fieldName as keyof typeof infoTextFor],
289-
]),
290-
),
291-
),
281+
Object.entries(this.fields).map(([sectionName, fields]) => {
282+
const cols: Cols = [];
283+
284+
(Object.entries(fields) as Entries<Field>).forEach(
285+
([fieldName, field]) => {
286+
if (field) {
287+
cols.push([
288+
field,
289+
infoTextFor[fieldName as keyof typeof infoTextFor],
290+
]);
291+
}
292+
},
293+
);
294+
295+
return section(sectionName as SectionsEnum, cols);
296+
}),
292297
)}
293298
<footer class="flex justify-end border-t px-4 py-3">
294299
<sl-button type="submit" size="small" variant="primary">

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { mergeDeep } from "immutable";
33
import { customElement, property } from "lit/decorators.js";
44
import { ifDefined } from "lit/directives/if-defined.js";
55
import { when } from "lit/directives/when.js";
6+
import type { PartialDeep } from "type-fest";
67

78
import { ScopeType, type Seed, type WorkflowParams } from "./types";
89

@@ -153,20 +154,20 @@ export class WorkflowsNew extends LiteElement {
153154
profileid: org.crawlingDefaults?.profileid,
154155
config: {
155156
exclude: org.crawlingDefaults?.exclude || [""],
156-
behaviorTimeout: org.crawlingDefaults?.behaviorTimeout,
157-
pageLoadTimeout: org.crawlingDefaults?.pageLoadTimeout,
158-
pageExtraDelay: org.crawlingDefaults?.pageExtraDelay,
159-
postLoadDelay: org.crawlingDefaults?.postLoadDelay,
157+
behaviorTimeout: org.crawlingDefaults?.behaviorTimeout ?? null,
158+
pageLoadTimeout: org.crawlingDefaults?.pageLoadTimeout ?? null,
159+
pageExtraDelay: org.crawlingDefaults?.pageExtraDelay ?? null,
160+
postLoadDelay: org.crawlingDefaults?.postLoadDelay ?? null,
160161
userAgent: org.crawlingDefaults?.userAgent,
161162
blockAds: org.crawlingDefaults?.blockAds,
162163
lang: org.crawlingDefaults?.lang,
163-
customBehaviors: org.crawlingDefaults?.customBehaviors,
164+
customBehaviors: org.crawlingDefaults?.customBehaviors || [],
164165
},
165166
crawlTimeout: org.crawlingDefaults?.crawlTimeout,
166167
maxCrawlSize: org.crawlingDefaults?.maxCrawlSize,
167168
crawlerChannel: org.crawlingDefaults?.crawlerChannel,
168169
proxyId: org.crawlingDefaults?.proxyId,
169-
},
170+
} satisfies PartialDeep<WorkflowParams>,
170171
this.initialWorkflow || {},
171172
);
172173

frontend/yarn.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)