Skip to content

Commit 1dbdc1f

Browse files
committed
WIP: Move jsbutton to LWC
1 parent 61930bd commit 1dbdc1f

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
3+
</template>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { LightningElement, api, wire } from "lwc";
2+
import fetchJSFromCmdt from '@salesforce/apex/DynamicSOQLDMLController.getJSFromCmdt';
3+
import executeSoql from '@salesforce/apex/DynamicSOQLDMLController.executeSoqlQuery';
4+
import runDml from '@salesforce/apex/DynamicSOQLDMLController.executeDml';
5+
import getSObjectType from '@salesforce/apex/DynamicSOQLDMLController.getSObjectTypeFromId';
6+
7+
const REGEX_SOQL = "\\|\\|\\s?(select\\s+[^|]+)\\s?\\|\\|";
8+
const REGEX_UPDATE = "\\|\\|\\s?update\\s([^|;]+);?\\s*\\|\\|";
9+
const REGEX_INSERT_UPSERT =
10+
"\\|\\|\\s?(insert|upsert)\\s([\\w\\d_]+)\\s?\\(\\s?(\\w+).*\\|\\|";
11+
const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor;
12+
export default class JsButtonLwc extends LightningElement {
13+
@api js;
14+
@api cmdtName;
15+
@api recordId;
16+
17+
@api
18+
async invoke() {
19+
if (!this.js && this.cmdtName) {
20+
this.js = await fetchJSFromCmdt({ cmdtName });
21+
return await this.runJS();
22+
} else if (this.js) {
23+
return await this.runJS();
24+
}
25+
throw Error("No script found to execute");
26+
}
27+
28+
executeSoql(){
29+
//TODO: implement
30+
}
31+
32+
executeDml(){
33+
//TODO: implement
34+
}
35+
36+
37+
runJS() {
38+
//replace consecutive spaces
39+
this.js = this.js.replace(/\s+/g, " ");
40+
41+
//parse soql
42+
this.js = this.js.replace(
43+
new RegExp(helper.REGEX_SOQL, "gi"),
44+
"await this.executeSoql(cmp,`$1`);"
45+
);
46+
47+
//parse updates
48+
this.js = this.js.replace(
49+
new RegExp(helper.REGEX_UPDATE, "gi"),
50+
"await this.executeDml(cmp,'update',$1);"
51+
);
52+
53+
//parse inserts
54+
this.js = this.js.replace(
55+
new RegExp(helper.REGEX_INSERT_UPSERT, "gi"),
56+
"await this.executeDml(cmp,'$1',$3,'$2');"
57+
);
58+
59+
return await AsyncFunction("recordId", `return ${js}`).bind(this)(recordId);
60+
61+
}
62+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>48.0</apiVersion>
4+
<isExposed>false</isExposed>
5+
</LightningComponentBundle>

0 commit comments

Comments
 (0)