fix: Handle no crawling defaults (#2549)

Fixes regression introduced by
7c6bae8d61

## Changes

Handles orgs without any crawl defaults correctly. Areas that use
crawling defaults are also more strongly typed now to prevent similar
issues.
This commit is contained in:
sua yoo 2025-04-09 09:48:12 -07:00 committed by GitHub
parent 0cb3bd19f6
commit b0d1a35563
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 32 additions and 20 deletions

View File

@ -83,6 +83,7 @@
"thread-loader": "^4.0.4", "thread-loader": "^4.0.4",
"ts-loader": "^9.2.6", "ts-loader": "^9.2.6",
"tsconfig-paths-webpack-plugin": "^4.1.0", "tsconfig-paths-webpack-plugin": "^4.1.0",
"type-fest": "^4.39.1",
"typescript": "^5.3.3", "typescript": "^5.3.3",
"update-dotenv": "^1.1.1", "update-dotenv": "^1.1.1",
"url-pattern": "^1.0.3", "url-pattern": "^1.0.3",

View File

@ -7,6 +7,7 @@ import { css, html, type TemplateResult } from "lit";
import { customElement, query, state } from "lit/decorators.js"; import { customElement, query, state } from "lit/decorators.js";
import { guard } from "lit/directives/guard.js"; import { guard } from "lit/directives/guard.js";
import { ifDefined } from "lit/directives/if-defined.js"; import { ifDefined } from "lit/directives/if-defined.js";
import type { Entries } from "type-fest";
import { BtrixElement } from "@/classes/BtrixElement"; import { BtrixElement } from "@/classes/BtrixElement";
import type { LanguageSelect } from "@/components/ui/language-select"; import type { LanguageSelect } from "@/components/ui/language-select";
@ -86,7 +87,7 @@ export class OrgSettingsCrawlWorkflows extends BtrixElement {
return html` ${this.renderWorkflowDefaults()} `; return html` ${this.renderWorkflowDefaults()} `;
} }
get fields(): Partial<Record<SectionsEnum, Partial<Field>>> { get fields() {
const orgDefaults: Partial<CrawlingDefaults> = this.org const orgDefaults: Partial<CrawlingDefaults> = this.org
?.crawlingDefaults || { ?.crawlingDefaults || {
exclude: PLACEHOLDER_EXCLUSIONS, exclude: PLACEHOLDER_EXCLUSIONS,
@ -269,7 +270,7 @@ export class OrgSettingsCrawlWorkflows extends BtrixElement {
limits, limits,
behaviors, behaviors,
browserSettings, browserSettings,
} as const; } as const satisfies Partial<Record<SectionsEnum, Partial<Field>>>;
} }
private renderWorkflowDefaults() { private renderWorkflowDefaults() {
@ -277,18 +278,22 @@ export class OrgSettingsCrawlWorkflows extends BtrixElement {
<div class="rounded-lg border"> <div class="rounded-lg border">
<form @submit=${this.onSubmit}> <form @submit=${this.onSubmit}>
${guard([this.defaults, this.org], () => ${guard([this.defaults, this.org], () =>
Object.entries(this.fields).map(([sectionName, fields]) => Object.entries(this.fields).map(([sectionName, fields]) => {
section( const cols: Cols = [];
sectionName as SectionsEnum,
Object.entries(fields) (Object.entries(fields) as Entries<Field>).forEach(
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition ([fieldName, field]) => {
.filter(([, field]) => field) if (field) {
.map(([fieldName, field]) => [ cols.push([
field, field,
infoTextFor[fieldName as keyof typeof infoTextFor], infoTextFor[fieldName as keyof typeof infoTextFor],
]), ]);
), }
), },
);
return section(sectionName as SectionsEnum, cols);
}),
)} )}
<footer class="flex justify-end border-t px-4 py-3"> <footer class="flex justify-end border-t px-4 py-3">
<sl-button type="submit" size="small" variant="primary"> <sl-button type="submit" size="small" variant="primary">

View File

@ -3,6 +3,7 @@ import { mergeDeep } from "immutable";
import { customElement, property } from "lit/decorators.js"; import { customElement, property } from "lit/decorators.js";
import { ifDefined } from "lit/directives/if-defined.js"; import { ifDefined } from "lit/directives/if-defined.js";
import { when } from "lit/directives/when.js"; import { when } from "lit/directives/when.js";
import type { PartialDeep } from "type-fest";
import { ScopeType, type Seed, type WorkflowParams } from "./types"; import { ScopeType, type Seed, type WorkflowParams } from "./types";
@ -153,20 +154,20 @@ export class WorkflowsNew extends LiteElement {
profileid: org.crawlingDefaults?.profileid, profileid: org.crawlingDefaults?.profileid,
config: { config: {
exclude: org.crawlingDefaults?.exclude || [""], exclude: org.crawlingDefaults?.exclude || [""],
behaviorTimeout: org.crawlingDefaults?.behaviorTimeout, behaviorTimeout: org.crawlingDefaults?.behaviorTimeout ?? null,
pageLoadTimeout: org.crawlingDefaults?.pageLoadTimeout, pageLoadTimeout: org.crawlingDefaults?.pageLoadTimeout ?? null,
pageExtraDelay: org.crawlingDefaults?.pageExtraDelay, pageExtraDelay: org.crawlingDefaults?.pageExtraDelay ?? null,
postLoadDelay: org.crawlingDefaults?.postLoadDelay, postLoadDelay: org.crawlingDefaults?.postLoadDelay ?? null,
userAgent: org.crawlingDefaults?.userAgent, userAgent: org.crawlingDefaults?.userAgent,
blockAds: org.crawlingDefaults?.blockAds, blockAds: org.crawlingDefaults?.blockAds,
lang: org.crawlingDefaults?.lang, lang: org.crawlingDefaults?.lang,
customBehaviors: org.crawlingDefaults?.customBehaviors, customBehaviors: org.crawlingDefaults?.customBehaviors || [],
}, },
crawlTimeout: org.crawlingDefaults?.crawlTimeout, crawlTimeout: org.crawlingDefaults?.crawlTimeout,
maxCrawlSize: org.crawlingDefaults?.maxCrawlSize, maxCrawlSize: org.crawlingDefaults?.maxCrawlSize,
crawlerChannel: org.crawlingDefaults?.crawlerChannel, crawlerChannel: org.crawlingDefaults?.crawlerChannel,
proxyId: org.crawlingDefaults?.proxyId, proxyId: org.crawlingDefaults?.proxyId,
}, } satisfies PartialDeep<WorkflowParams>,
this.initialWorkflow || {}, this.initialWorkflow || {},
); );

5
frontend/yarn.lock generated
View File

@ -9172,6 +9172,11 @@ type-fest@^2.12.2:
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-2.19.0.tgz#88068015bb33036a598b952e55e9311a60fd3a9b" resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-2.19.0.tgz#88068015bb33036a598b952e55e9311a60fd3a9b"
integrity sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA== integrity sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==
type-fest@^4.39.1:
version "4.39.1"
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-4.39.1.tgz#7521f6944e279abaf79cf60cfbc4823f4858083e"
integrity sha512-uW9qzd66uyHYxwyVBYiwS4Oi0qZyUqwjU+Oevr6ZogYiXt99EOYtwvzMSLw1c3lYo2HzJsep/NB23iEVEgjG/w==
type-is@^1.6.16, type-is@~1.6.18: type-is@^1.6.16, type-is@~1.6.18:
version "1.6.18" version "1.6.18"
resolved "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz" resolved "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz"