import type { LitElement } from "lit"; import { property, customElement } from "lit/decorators.js"; import { msg, localized } from "@lit/localize"; import { mergeDeep } from "immutable"; import type { AuthState } from "@/utils/AuthService"; import LiteElement, { html } from "@/utils/LiteElement"; import type { JobType, Seed, WorkflowParams } from "./types"; import type { SelectNewDialogEvent } from "./index"; import "./workflow-editor"; const defaultValue = { name: "", description: null, profileid: null, schedule: "", config: { seeds: [], scopeType: "prefix", exclude: [""], behaviorTimeout: null, pageLoadTimeout: null, pageExtraDelay: null, useSitemap: false, failOnFailedSeed: false, }, tags: [], crawlTimeout: null, maxCrawlSize: null, jobType: undefined, scale: 1, autoAddCollections: [], } as WorkflowParams; /** * Usage: * ```ts * * ``` */ @localized() @customElement("btrix-workflows-new") export class WorkflowsNew extends LiteElement { @property({ type: Object }) authState!: AuthState; @property({ type: String }) orgId!: string; @property({ type: Boolean }) isCrawler!: boolean; @property({ type: Array }) initialSeeds?: Seed[]; @property({ type: String }) jobType?: JobType; @property({ type: Boolean }) orgStorageQuotaReached = false; @property({ type: Boolean }) orgExecutionMinutesQuotaReached = false; // 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); } private renderHeader() { const href = `${this.orgBasePath}/workflows/crawls`; const label = msg("Back to Crawl Workflows"); return html` `; } 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) { return this.renderNoAccess(); } if (jobType) { return html` ${this.renderHeader()}

${msg(html`New Crawl Workflow — ${jobTypeLabels[jobType]}`)}

{ await (e.target as LitElement).updateComplete; this.dispatchEvent( new CustomEvent("select-new-dialog", { detail: "workflow", }) ); }} > `; } return html``; } private renderNoAccess = () => html` ${msg(`You don't have permission to create a new Workflow.`)} `; }