From 25b1928d448e7c33f5fd344d88662910bbf6ca1f Mon Sep 17 00:00:00 2001 From: sua yoo Date: Wed, 21 Aug 2024 15:33:00 -0700 Subject: [PATCH] feat: Enable deleting workflow from list (#2042) Adds back workflow list menu item to delete workflow if it's never been run. --- frontend/src/pages/org/workflow-detail.ts | 61 ++++------------------- frontend/src/pages/org/workflows-list.ts | 45 +++++++---------- 2 files changed, 29 insertions(+), 77 deletions(-) diff --git a/frontend/src/pages/org/workflow-detail.ts b/frontend/src/pages/org/workflow-detail.ts index 8e6372b0..4f2bdb06 100644 --- a/frontend/src/pages/org/workflow-detail.ts +++ b/frontend/src/pages/org/workflow-detail.ts @@ -702,24 +702,19 @@ export class WorkflowDetail extends LiteElement { ${msg("Duplicate Workflow")} - ${when(!this.lastCrawlId, () => { - const shouldDeactivate = workflow.crawlCount && !workflow.inactive; - return html` + ${when( + !this.lastCrawlId, + () => html` - shouldDeactivate - ? void this.deactivate() - : void this.delete()} + @click=${() => void this.delete()} > - ${shouldDeactivate - ? msg("Deactivate Workflow") - : msg("Delete Workflow")} + ${msg("Delete Workflow")} - `; - })} + `, + )} `; @@ -1477,41 +1472,9 @@ export class WorkflowDetail extends LiteElement { }); } - private async deactivate(): Promise { - if (!this.workflow) return; - - try { - await this.apiFetch( - `/orgs/${this.orgId}/crawlconfigs/${this.workflow.id}`, - { - method: "DELETE", - }, - ); - - this.workflow = { - ...this.workflow, - inactive: true, - }; - - this.notify({ - message: msg(html`Deactivated ${this.renderName()}.`), - variant: "success", - icon: "check2-circle", - }); - } catch { - this.notify({ - message: msg("Sorry, couldn't deactivate Workflow at this time."), - variant: "danger", - icon: "exclamation-octagon", - }); - } - } - private async delete(): Promise { if (!this.workflow) return; - const isDeactivating = this.workflow.crawlCount > 0; - try { await this.apiFetch( `/orgs/${this.orgId}/crawlconfigs/${this.workflow.id}`, @@ -1523,17 +1486,15 @@ export class WorkflowDetail extends LiteElement { this.navTo(`${this.orgBasePath}/workflows/crawls`); this.notify({ - message: isDeactivating - ? msg(html`Deactivated ${this.renderName()}.`) - : msg(html`Deleted ${this.renderName()}.`), + message: msg( + html`Deleted ${this.renderName()} Workflow.`, + ), variant: "success", icon: "check2-circle", }); } catch { this.notify({ - message: isDeactivating - ? msg("Sorry, couldn't deactivate Workflow at this time.") - : msg("Sorry, couldn't delete Workflow at this time."), + message: msg("Sorry, couldn't delete Workflow at this time."), variant: "danger", icon: "exclamation-octagon", }); diff --git a/frontend/src/pages/org/workflows-list.ts b/frontend/src/pages/org/workflows-list.ts index 3d0a8e8c..1c5876e7 100644 --- a/frontend/src/pages/org/workflows-list.ts +++ b/frontend/src/pages/org/workflows-list.ts @@ -500,14 +500,28 @@ export class WorkflowsList extends LiteElement { ${when( this.appState.isCrawler, - () => - html` html` + void this.duplicateConfig(workflow)} > ${msg("Duplicate Workflow")} - `, + + ${when( + !workflow.lastCrawlId, + () => html` + + void this.delete(workflow)} + > + + ${msg("Delete Workflow")} + + `, + )} + `, )} `; } @@ -656,29 +670,6 @@ export class WorkflowsList extends LiteElement { } } - private async deactivate(workflow: ListWorkflow): Promise { - try { - await this.apiFetch(`/orgs/${this.orgId}/crawlconfigs/${workflow.id}`, { - method: "DELETE", - }); - - void this.fetchWorkflows(); - this.notify({ - message: msg( - html`Deactivated ${this.renderName(workflow)}.`, - ), - variant: "success", - icon: "check2-circle", - }); - } catch { - this.notify({ - message: msg("Sorry, couldn't deactivate Workflow at this time."), - variant: "danger", - icon: "exclamation-octagon", - }); - } - } - private async delete(workflow: ListWorkflow): Promise { try { await this.apiFetch(`/orgs/${this.orgId}/crawlconfigs/${workflow.id}`, { @@ -688,7 +679,7 @@ export class WorkflowsList extends LiteElement { void this.fetchWorkflows(); this.notify({ message: msg( - html`Deleted ${this.renderName(workflow)}.`, + html`Deleted ${this.renderName(workflow)} Workflow.`, ), variant: "success", icon: "check2-circle",