From b0d1a35563a7c9e44856bd4042abe4d734491d0c Mon Sep 17 00:00:00 2001 From: sua yoo Date: Wed, 9 Apr 2025 09:48:12 -0700 Subject: [PATCH] fix: Handle no crawling defaults (#2549) Fixes regression introduced by https://github.com/webrecorder/browsertrix/commit/7c6bae8d618c10bc68e466536ad116d0676fe149 ## Changes Handles orgs without any crawl defaults correctly. Areas that use crawling defaults are also more strongly typed now to prevent similar issues. --- frontend/package.json | 1 + .../settings/components/crawling-defaults.ts | 33 +++++++++++-------- frontend/src/pages/org/workflows-new.ts | 13 ++++---- frontend/yarn.lock | 5 +++ 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/frontend/package.json b/frontend/package.json index c69e07d0..a68c7b84 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -83,6 +83,7 @@ "thread-loader": "^4.0.4", "ts-loader": "^9.2.6", "tsconfig-paths-webpack-plugin": "^4.1.0", + "type-fest": "^4.39.1", "typescript": "^5.3.3", "update-dotenv": "^1.1.1", "url-pattern": "^1.0.3", diff --git a/frontend/src/pages/org/settings/components/crawling-defaults.ts b/frontend/src/pages/org/settings/components/crawling-defaults.ts index a744537f..a0ae5f47 100644 --- a/frontend/src/pages/org/settings/components/crawling-defaults.ts +++ b/frontend/src/pages/org/settings/components/crawling-defaults.ts @@ -7,6 +7,7 @@ import { css, html, type TemplateResult } from "lit"; import { customElement, query, state } from "lit/decorators.js"; import { guard } from "lit/directives/guard.js"; import { ifDefined } from "lit/directives/if-defined.js"; +import type { Entries } from "type-fest"; import { BtrixElement } from "@/classes/BtrixElement"; import type { LanguageSelect } from "@/components/ui/language-select"; @@ -86,7 +87,7 @@ export class OrgSettingsCrawlWorkflows extends BtrixElement { return html` ${this.renderWorkflowDefaults()} `; } - get fields(): Partial>> { + get fields() { const orgDefaults: Partial = this.org ?.crawlingDefaults || { exclude: PLACEHOLDER_EXCLUSIONS, @@ -269,7 +270,7 @@ export class OrgSettingsCrawlWorkflows extends BtrixElement { limits, behaviors, browserSettings, - } as const; + } as const satisfies Partial>>; } private renderWorkflowDefaults() { @@ -277,18 +278,22 @@ export class OrgSettingsCrawlWorkflows extends BtrixElement {
${guard([this.defaults, this.org], () => - Object.entries(this.fields).map(([sectionName, fields]) => - section( - sectionName as SectionsEnum, - Object.entries(fields) - // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition - .filter(([, field]) => field) - .map(([fieldName, field]) => [ - field, - infoTextFor[fieldName as keyof typeof infoTextFor], - ]), - ), - ), + Object.entries(this.fields).map(([sectionName, fields]) => { + const cols: Cols = []; + + (Object.entries(fields) as Entries).forEach( + ([fieldName, field]) => { + if (field) { + cols.push([ + field, + infoTextFor[fieldName as keyof typeof infoTextFor], + ]); + } + }, + ); + + return section(sectionName as SectionsEnum, cols); + }), )}