Skip to content

Commit bf6e023

Browse files
author
Sierk Hoeksma
committed
fix: setConfig
1 parent 3b457ad commit bf6e023

File tree

4 files changed

+937
-1131
lines changed

4 files changed

+937
-1131
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.yarn/
22
node_modules/
33
lowcoder-comp-bpmn-io-*.tgz
4-
.DS_Store
4+
.DS_Store
5+
package-lock.json

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"react-resize-detector": "^10.0.1",
2424
"react-spinners": "^0.13.8",
2525
"typescript": "^5.3.3",
26-
"vite": "^5.1.4"
26+
"vite": "^5.1.4",
27+
"yarn": "^1.22.22"
2728
},
2829
"lowcoder": {
2930
"description": "A Geo Lowcoder Component Plugin",

src/GEOComp.tsx

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,22 @@ GEOComp = class extends GEOComp {
347347
}
348348
};
349349

350+
const parseFilter = function (data: any, defFilter = ['layers']) {
351+
var filter = data || defFilter
352+
if (!Array.isArray(filter)) {
353+
try {
354+
filter = JSON.parse("[" + filter + "]")
355+
} catch (e) {
356+
try {
357+
filter = JSON.parse('["' + filter + '"]')
358+
} catch (ee) {
359+
filter = defFilter
360+
}
361+
}
362+
}
363+
return filter
364+
}
365+
350366
/**
351367
* Exposes methods on GEOComp component to allow calling from parent component.
352368
* Includes animate, notify, showPopup, addFeatures, and readFeatures methods.
@@ -506,24 +522,43 @@ GEOComp = withMethodExposing(GEOComp, [
506522
{
507523
name: "json",
508524
type: "JSONValue",
509-
}
525+
},
526+
{
527+
name: "filter",
528+
type: "JSONValue",
529+
},
510530
]
511531
},
512532
execute: async (comp: any, params: any) => {
513533
if (params.length == 0) return
534+
//Create filter based on param
535+
const filter = parseFilter(params[1])
514536
try {
515537
var data = params[0]
516-
console.log("Configure 1", params[0])
517538
if (typeof data === 'string' || data instanceof String) {
518539
// @ts-ignore
519540
data = JSON.parse(data)
520541
}
542+
//Filter out data not needed
543+
if (filter.length != 0) {
544+
for (const [key, value] of Object.entries(data)) {
545+
if (!filter.includes(key)) {
546+
delete data[key]
547+
}
548+
}
549+
}
521550
for (const [key, value] of Object.entries(data)) {
522-
console.log(key, comp.children[key])
523-
//comp.children[key].value(value)
551+
var child = comp.children[key]
552+
console.log(key, child)
553+
if (child.value) {
554+
child.value(value)
555+
} else {
556+
console.debug("setConfig not supported for ", child)
557+
}
524558
}
525559
} catch (e) {
526560
console.error("Failed to parse config data", e)
561+
return false
527562
}
528563
}
529564
},
@@ -532,17 +567,32 @@ GEOComp = withMethodExposing(GEOComp, [
532567
name: "getConfig",
533568
description: "Get configuration the plugin by json",
534569
params: [
570+
{
571+
name: "filter",
572+
type: "JSONValue",
573+
},
535574
{
536575
name: "asString",
537576
type: "boolean",
538-
}
577+
},
539578
]
540579
},
541580
execute: (comp: any, params: any) => {
581+
//Create filter based on param
582+
const filter = parseFilter(params[0])
583+
//Get the json config data
542584
var data = comp.toJsonValue();
543-
delete data.onEvent
544-
data = params[0] !== true ? data : JSON.stringify(data, null)
545-
// @ts-ignore
585+
//Filter out data not needed
586+
if (filter.length != 0) {
587+
for (const [key, value] of Object.entries(data)) {
588+
if (!filter.includes(key)) {
589+
delete data[key]
590+
}
591+
}
592+
}
593+
594+
//Should we convert the data into string
595+
data = params[1] !== true ? data : JSON.stringify(data, null)
546596
if (geoContext.previewMode)
547597
console.debug(data)
548598
//Event config needs to be added

0 commit comments

Comments
 (0)