From eacfa93f0e1a08020ec1c62b81e8e4eb572f7ab9 Mon Sep 17 00:00:00 2001 From: Aaron George <79060613+octatau@users.noreply.github.com> Date: Thu, 29 Feb 2024 21:41:50 -0500 Subject: [PATCH 1/3] Remove js-lenvenshtein lib from objectSelector --- .../main/lwc/objectSelector/js-levenshtein.js | 100 ------------------ 1 file changed, 100 deletions(-) delete mode 100644 dlrs/main/lwc/objectSelector/js-levenshtein.js diff --git a/dlrs/main/lwc/objectSelector/js-levenshtein.js b/dlrs/main/lwc/objectSelector/js-levenshtein.js deleted file mode 100644 index 30571559..00000000 --- a/dlrs/main/lwc/objectSelector/js-levenshtein.js +++ /dev/null @@ -1,100 +0,0 @@ -// https://github.com/gustf/js-levenshtein/blob/master/index.js -// MIT License -function _min(d0, d1, d2, bx, ay) { - return d0 < d1 || d2 < d1 - ? d0 > d2 - ? d2 + 1 - : d0 + 1 - : bx === ay - ? d1 - : d1 + 1; -} - -export default function (a, b) { - if (a === b) { - return 0; - } - - if (a.length > b.length) { - let tmp = a; - a = b; - b = tmp; - } - - let la = a.length; - let lb = b.length; - - while (la > 0 && a.charCodeAt(la - 1) === b.charCodeAt(lb - 1)) { - la--; - lb--; - } - - let offset = 0; - - while (offset < la && a.charCodeAt(offset) === b.charCodeAt(offset)) { - offset++; - } - - la -= offset; - lb -= offset; - - if (la === 0 || lb < 3) { - return lb; - } - - let x = 0; - let y; - let d0; - let d1; - let d2; - let d3; - let dd; - let dy; - let ay; - let bx0; - let bx1; - let bx2; - let bx3; - - let vector = []; - - for (y = 0; y < la; y++) { - vector.push(y + 1); - vector.push(a.charCodeAt(offset + y)); - } - - let len = vector.length - 1; - - for (; x < lb - 3; ) { - bx0 = b.charCodeAt(offset + (d0 = x)); - bx1 = b.charCodeAt(offset + (d1 = x + 1)); - bx2 = b.charCodeAt(offset + (d2 = x + 2)); - bx3 = b.charCodeAt(offset + (d3 = x + 3)); - dd = x += 4; - for (y = 0; y < len; y += 2) { - dy = vector[y]; - ay = vector[y + 1]; - d0 = _min(dy, d0, d1, bx0, ay); - d1 = _min(d0, d1, d2, bx1, ay); - d2 = _min(d1, d2, d3, bx2, ay); - dd = _min(d2, d3, dd, bx3, ay); - vector[y] = dd; - d3 = d2; - d2 = d1; - d1 = d0; - d0 = dy; - } - } - - for (; x < lb; ) { - bx0 = b.charCodeAt(offset + (d0 = x)); - dd = ++x; - for (y = 0; y < len; y += 2) { - dy = vector[y]; - vector[y] = dd = _min(dy, d0, dd, bx0, vector[y + 1]); - d0 = dy; - } - } - - return dd; -} From e70394961ca7b7f059c82ae6940d71c0c8f3f4ff Mon Sep 17 00:00:00 2001 From: Aaron George <79060613+octatau@users.noreply.github.com> Date: Thu, 29 Feb 2024 22:54:31 -0500 Subject: [PATCH 2/3] Remove unused propoerties from object selector --- .../main/lwc/objectSelector/objectSelector.js | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/dlrs/main/lwc/objectSelector/objectSelector.js b/dlrs/main/lwc/objectSelector/objectSelector.js index c788569d..a7cf6662 100644 --- a/dlrs/main/lwc/objectSelector/objectSelector.js +++ b/dlrs/main/lwc/objectSelector/objectSelector.js @@ -22,18 +22,9 @@ export default class ObjectSelector extends LightningElement { searchRequired = true; maxSearchResults = 5; objectApiNames = []; - objectIconCache; - lstResult = []; // to store list of returned records - searchKey = ""; // to store input field value - isSearchLoading = false; // to control loading spinner - delayTimeout; selectedRecord = ""; - selectedRecordIconName; objects = []; - preventBlur = false; connectedCallback() { - this.selectedRecordIconName = this.iconName; - this.isSearchLoading = true; //GET LIST OF ALL OBJECTS getAllObjects() .then((objects) => { @@ -51,9 +42,6 @@ export default class ObjectSelector extends LightningElement { this.error = error; this.objects = {}; }) - .finally(() => { - this.isSearchLoading = false; - }); } // use the UI API to determine the iconName for each object @@ -84,10 +72,6 @@ export default class ObjectSelector extends LightningElement { const matches = iconNameRegEx.exec(o.iconUrl); if (matches) { o.iconName = `${matches[1]}:${matches[2]}`; - // We just got a new icon for the selected image! - if (o.fullName === this._currentSelection) { - this.selectedRecordIconName = o.iconName; - } } } }); @@ -110,7 +94,7 @@ export default class ObjectSelector extends LightningElement { // method to update selected record from search result handleSelectedRecord(event) { - const selectedName = event.detail.selectedOption.value; // event.target.getAttribute("data-objname"); // get selected record Idrd from list + const selectedName = event.detail.selectedOption.value; // get selected record Id from list this.selectObject(selectedName); this.lookupUpdatehandler(selectedName); // update value on parent component as well from helper function } @@ -125,7 +109,6 @@ export default class ObjectSelector extends LightningElement { } const obj = this.objects.find((o) => o.fullName === val); this.selectedRecord = obj.fullName; - this.selectedRecordIconName = obj.iconName; } // send selected lookup record to parent component using custom event From add470fa8551d3d5bf081683ff2af6503fb38d7d Mon Sep 17 00:00:00 2001 From: Aaron George <79060613+octatau@users.noreply.github.com> Date: Thu, 29 Feb 2024 23:17:33 -0500 Subject: [PATCH 3/3] Render icons immediately after they are available --- dlrs/main/lwc/objectSelector/objectSelector.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dlrs/main/lwc/objectSelector/objectSelector.js b/dlrs/main/lwc/objectSelector/objectSelector.js index a7cf6662..bb3baae7 100644 --- a/dlrs/main/lwc/objectSelector/objectSelector.js +++ b/dlrs/main/lwc/objectSelector/objectSelector.js @@ -59,9 +59,9 @@ export default class ObjectSelector extends LightningElement { t[v.result.apiName] = v.result?.themeInfo; return t; }, {}); - this.objects.forEach((o) => { + this.objects = this.objects.map((o) => { if (!objectIconCache[o.fullName]?.iconUrl) { - return; + return o; } o.iconUrl = objectIconCache[o.fullName].iconUrl; o.iconColor = `#${objectIconCache[o.fullName].color}`; @@ -74,6 +74,7 @@ export default class ObjectSelector extends LightningElement { o.iconName = `${matches[1]}:${matches[2]}`; } } + return o; }); } }