fix: Enable saving workflow with default select links (#2537)

Allows users to save a workflow with an empty "Link Selectors" table,
using the default value. This is aligned with how we use default values
for other empty inputs, and prevents a case where a user may
inadvertently removed a row and now cannot save a workflow with the
default link selector.

Also updates the info text to show the default value.
This commit is contained in:
sua yoo 2025-04-07 19:19:36 -07:00 committed by GitHub
parent a51f7c635e
commit 0aaae17110
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 7 deletions

View File

@ -12,7 +12,7 @@ import type { SyntaxInput } from "@/components/ui/syntax-input";
import type { SeedConfig } from "@/types/crawler"; import type { SeedConfig } from "@/types/crawler";
import { tw } from "@/utils/tailwind"; import { tw } from "@/utils/tailwind";
const SELECTOR_DELIMITER = "->" as const; export const SELECTOR_DELIMITER = "->" as const;
const emptyCells = ["", ""]; const emptyCells = ["", ""];
/** /**
@ -153,8 +153,8 @@ export class LinkSelectorTable extends BtrixElement {
class="flex-1" class="flex-1"
value=${sel} value=${sel}
language="css" language="css"
placeholder="Enter selector" placeholder=${msg("Enter selector")}
required ?required=${Boolean(attr)}
@sl-change=${(e: CustomEvent) => { @sl-change=${(e: CustomEvent) => {
const el = e.currentTarget as SyntaxInput; const el = e.currentTarget as SyntaxInput;
const value = el.input?.value.trim() || ""; const value = el.input?.value.trim() || "";
@ -197,8 +197,8 @@ export class LinkSelectorTable extends BtrixElement {
class="flex-1" class="flex-1"
value=${attr} value=${attr}
language="xml" language="xml"
placeholder="Enter attribute" placeholder=${msg("Enter attribute")}
required ?required=${Boolean(sel)}
@sl-change=${(e: CustomEvent) => { @sl-change=${(e: CustomEvent) => {
const el = e.currentTarget as SyntaxInput; const el = e.currentTarget as SyntaxInput;
const value = el.input?.value.trim() || ""; const value = el.input?.value.trim() || "";

View File

@ -33,7 +33,10 @@ import isEqual from "lodash/fp/isEqual";
import throttle from "lodash/fp/throttle"; import throttle from "lodash/fp/throttle";
import uniq from "lodash/fp/uniq"; import uniq from "lodash/fp/uniq";
import type { LinkSelectorTable } from "./link-selector-table"; import {
SELECTOR_DELIMITER,
type LinkSelectorTable,
} from "./link-selector-table";
import { BtrixElement } from "@/classes/BtrixElement"; import { BtrixElement } from "@/classes/BtrixElement";
import type { import type {
@ -1131,6 +1134,15 @@ https://archiveweb.page/images/${"logo.svg"}`}
private renderLinkSelectors() { private renderLinkSelectors() {
const selectors = this.formState.selectLinks; const selectors = this.formState.selectLinks;
const isCustom = !isEqual(defaultFormState.selectLinks, selectors); const isCustom = !isEqual(defaultFormState.selectLinks, selectors);
const [defaultSel, defaultAttr] =
DEFAULT_SELECT_LINKS[0].split(SELECTOR_DELIMITER);
const defaultValue = html`<span
class="inline-flex items-center gap-0.5 rounded border px-1"
>
<btrix-code language="css" value=${defaultSel}></btrix-code
><code class="text-neutral-400">${SELECTOR_DELIMITER}</code
><btrix-code language="xml" value=${defaultAttr}></btrix-code>
</span>`;
return html` return html`
<div class="col-span-5"> <div class="col-span-5">
@ -1151,7 +1163,17 @@ https://archiveweb.page/images/${"logo.svg"}`}
}} }}
></btrix-link-selector-table>`, ></btrix-link-selector-table>`,
)} )}
${this.renderHelpTextCol(infoTextStrings["selectLinks"], false)} ${this.renderHelpTextCol(
html`
${infoTextStrings["selectLinks"]}
<br /><br />
${msg(
html`If none are specified, the crawler will default to
${defaultValue}.`,
)}
`,
false,
)}
</div> </div>
</btrix-details> </btrix-details>
</div> </div>