import type { TemplateResult, LitElement } from "lit"; import { state, property } from "lit/decorators.js"; import { when } from "lit/directives/when.js"; import { msg, localized, str } from "@lit/localize"; import { mergeDeep } from "immutable"; import type { AuthState } from "../../utils/AuthService"; import LiteElement, { html } from "../../utils/LiteElement"; import type { JobType, WorkflowParams } from "./types"; import "./workflow-editor"; import seededCrawlSvg from "../../assets/images/new-crawl-config_Seeded-Crawl.svg"; import urlListSvg from "../../assets/images/new-crawl-config_URL-List.svg"; const defaultValue = { name: "", description: null, profileid: null, schedule: "", config: { seeds: [], scopeType: "prefix", exclude: [""], }, tags: [], crawlTimeout: null, jobType: undefined, scale: 1, } as WorkflowParams; /** * Usage: * ```ts * * ``` */ @localized() export class WorkflowsNew extends LiteElement { @property({ type: Object }) authState!: AuthState; @property({ type: String }) orgId!: string; @property({ type: Boolean }) isCrawler!: boolean; // Use custom property accessor to prevent // overriding default Workflow values @property({ type: Object }) get initialWorkflow(): WorkflowParams { return this._initialWorkflow; } private _initialWorkflow: WorkflowParams = defaultValue; set initialWorkflow(val: Partial) { this._initialWorkflow = mergeDeep(this._initialWorkflow, val); } @state() private jobType?: JobType; connectedCallback() { super.connectedCallback(); if (!this.jobType) { const url = new URL(window.location.href); this.jobType = (url.searchParams.get("jobType") as JobType) || undefined; } } private renderHeader() { let href = `/orgs/${this.orgId}/workflows`; let label = msg("Back to Workflows"); // Allow user to go back to choose crawl type if new (not duplicated) config if (this.jobType && !this.initialWorkflow.jobType) { href = `/orgs/${this.orgId}/workflows?new`; label = msg("Choose Crawl Type"); } return html` { this.navLink(e); this.jobType = undefined; }} > ${label} `; } render() { const jobTypeLabels: Record = { "url-list": msg("URL List"), "seed-crawl": msg("Seeded Crawl"), custom: msg("Custom"), }; const jobType = this.initialWorkflow.jobType || this.jobType; if (this.isCrawler && jobType) { return html` ${this.renderHeader()} ${msg(html`New Workflow — ${jobTypeLabels[jobType]}`)} { await (e.target as LitElement).updateComplete; this.jobType = undefined; }} > `; } return html` ${this.renderHeader()} ${msg("New Workflow")} ${when(this.isCrawler, this.renderChooseJobType, this.renderNoAccess)} `; } private renderChooseJobType = () => { return html` ${msg("Choose Crawl Type")} { this.navLink(e); this.jobType = "url-list"; }} > ${msg("URL List")} ${msg( "The crawler visits every URL specified in a list, and optionally every URL linked on those pages." )} { this.navLink(e); this.jobType = "seed-crawl"; }} > ${msg("Seeded Crawl")} ${msg( "The crawler automatically discovers and archives pages starting from a single seed URL." )} `; }; private renderNoAccess = () => html` ${msg(`You don't have permission to create a new Workflow.`)} `; } customElements.define("btrix-workflows-new", WorkflowsNew);
${msg( "The crawler visits every URL specified in a list, and optionally every URL linked on those pages." )}
${msg( "The crawler automatically discovers and archives pages starting from a single seed URL." )}