From dd073523ff18f21e0ad621afef7d224df7cce087 Mon Sep 17 00:00:00 2001 From: junners Date: Sat, 20 Jul 2024 20:24:58 -0700 Subject: [PATCH] feat: implement loading, sorting improvements and no flow smells --- .../lwc/flowOverview/flowOverview.html | 3 + .../default/lwc/flowOverview/flowOverview.js | 70 +++++++++++++++++-- .../lightningFlowScanner.html | 9 ++- .../lightningFlowScanner.js | 5 +- .../lightningFlowScannerApp.html | 3 +- .../lightningFlowScannerApp.js | 52 ++++++++------ 6 files changed, 113 insertions(+), 29 deletions(-) diff --git a/lfs-app/main/default/lwc/flowOverview/flowOverview.html b/lfs-app/main/default/lwc/flowOverview/flowOverview.html index 4458b33..e15ead6 100644 --- a/lfs-app/main/default/lwc/flowOverview/flowOverview.html +++ b/lfs-app/main/default/lwc/flowOverview/flowOverview.html @@ -13,6 +13,9 @@ columns={columns} hide-checkbox-column="true" onrowaction={handleRowAction} + default-sort-direction={sortDirection} + sorted-by={sortedBy} + onsort={sortRecords} > diff --git a/lfs-app/main/default/lwc/flowOverview/flowOverview.js b/lfs-app/main/default/lwc/flowOverview/flowOverview.js index a70461b..c4485f9 100644 --- a/lfs-app/main/default/lwc/flowOverview/flowOverview.js +++ b/lfs-app/main/default/lwc/flowOverview/flowOverview.js @@ -2,10 +2,22 @@ import { LightningElement, api, track } from "lwc"; import { NavigationMixin } from "lightning/navigation"; export default class FlowOverview extends NavigationMixin(LightningElement) { - @api records = []; + @api + get records() { + return this._data; + } + set records(value) { + this._data = [...value]; + } + + @track _data = []; + @track err; - @track columns = [ - { label: "Label", fieldName: "masterLabel", type: "text" }, + + sortedBy = "lastModifiedDate"; + sortedDirection = "desc"; + columns = [ + { label: "Label", fieldName: "masterLabel", type: "text", sortable: true }, { label: "API Name", fieldName: "developerNameUrl", @@ -13,14 +25,36 @@ export default class FlowOverview extends NavigationMixin(LightningElement) { typeAttributes: { label: { fieldName: "developerName" }, target: "_blank" - } + }, + sortable: true }, { label: "Process Type", fieldName: "processType", type: "text" }, + { label: "Description", fieldName: "flowDescription", type: "text" }, { label: "Is Active", fieldName: "isActive", type: "boolean", - cellAttributes: { alignment: "center" } + cellAttributes: { alignment: "center" }, + sortable: true + }, + { + label: "Last Modified Date", + fieldName: "lastModifiedDate", + type: "date", + typeAttributes: { + year: "numeric", + month: "long", + day: "2-digit", + hour: "2-digit", + minute: "2-digit" + }, + sortable: true + }, + { + label: "Last Modified By", + fieldName: "lastModifiedBy", + type: "text", + sortable: true }, { type: "button", @@ -33,6 +67,32 @@ export default class FlowOverview extends NavigationMixin(LightningElement) { } ]; + reverseDirection = { + asc: "desc", + desc: "asc" + }; + + sortRecords(event) { + const fieldName = event.detail.fieldName; + const sortDirection = this.reverseDirection[this.sortedDirection] ?? "desc"; + const sortData = () => { + let parseData = JSON.parse(JSON.stringify(this.records)); + const keyValue = (a) => { + return a[fieldName]; + }; + const isReverse = sortDirection === "asc" ? 1 : -1; + parseData.sort((x, y) => { + x = keyValue(x) ? keyValue(x) : ""; + y = keyValue(y) ? keyValue(y) : ""; + return isReverse * ((x > y) - (y > x)); + }); + return parseData; + }; + this._data = [...sortData()]; + this.sortedBy = fieldName; + this.sortedDirection = sortDirection; + } + handleRowAction(event) { const actionName = event.detail.action.name; const row = event.detail.row; diff --git a/lfs-app/main/default/lwc/lightningFlowScanner/lightningFlowScanner.html b/lfs-app/main/default/lwc/lightningFlowScanner/lightningFlowScanner.html index 75d7181..a818274 100644 --- a/lfs-app/main/default/lwc/lightningFlowScanner/lightningFlowScanner.html +++ b/lfs-app/main/default/lwc/lightningFlowScanner/lightningFlowScanner.html @@ -17,7 +17,7 @@ Type: {flow.processType}
- API Version: {flow.apiVersion} + API Version: {flow.xmldata.apiVersion}
# Rules Run: {numberOfRules} @@ -25,7 +25,7 @@
- Description: {flow.description} + Description: {flow.xmldata.description}
@@ -58,6 +58,11 @@ + diff --git a/lfs-app/main/default/lwc/lightningFlowScanner/lightningFlowScanner.js b/lfs-app/main/default/lwc/lightningFlowScanner/lightningFlowScanner.js index 807b98d..557c958 100644 --- a/lfs-app/main/default/lwc/lightningFlowScanner/lightningFlowScanner.js +++ b/lfs-app/main/default/lwc/lightningFlowScanner/lightningFlowScanner.js @@ -27,7 +27,6 @@ export default class LightningFlowScanner extends LightningElement { this.flow = { ...new lightningflowscanner.Flow(this.name, this.metadata) // eslint-disable-line no-undef }; - let uri = "/services/data/v61.0/tooling/sobjects/Flow/" + this.id; let parsedFlow = { uri, flow: this.flow }; try { @@ -76,6 +75,10 @@ export default class LightningFlowScanner extends LightningElement { return this.isLoaded && (this.scanResult?.ruleResults?.length > 0 ?? false); } + get noViolations() { + return !this.scanResult?.ruleResults?.find((rule) => rule.occurs); + } + get flowName() { return this.isLoaded && (this.flow?.name ?? ""); } diff --git a/lfs-app/main/default/lwc/lightningFlowScannerApp/lightningFlowScannerApp.html b/lfs-app/main/default/lwc/lightningFlowScannerApp/lightningFlowScannerApp.html index 2c3ee23..862e1c7 100644 --- a/lfs-app/main/default/lwc/lightningFlowScannerApp/lightningFlowScannerApp.html +++ b/lfs-app/main/default/lwc/lightningFlowScannerApp/lightningFlowScannerApp.html @@ -1,6 +1,7 @@