Skip to content

Commit d081c26

Browse files
committed
fix: testing properties
1 parent 8d05c00 commit d081c26

File tree

5 files changed

+179
-103
lines changed

5 files changed

+179
-103
lines changed

src/BoolObjectOptionControl.tsx

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,58 +3,53 @@ import {
33
StringControl,
44
BoolPureControl,
55
withDefault,
6-
BoolControl,
7-
disabledPropertyView,
8-
hiddenPropertyView,
9-
optionsControl,
6+
manualOptionsControl
107
} from 'lowcoder-sdk'
118
import { trans } from "./i18n/comps";
129

13-
type OptionPropertyParam = {
14-
autoMap?: boolean;
15-
};
16-
17-
interface OptionCompProperty {
18-
propertyView(param: OptionPropertyParam): React.ReactNode;
19-
}
20-
2110
var BoolObjectOption = new MultiCompBuilder(
2211
{
2312
label: StringControl,
24-
state: withDefault(BoolPureControl, true),
13+
value: withDefault(BoolPureControl, true),
2514
},
2615
(props: any) => props
2716
).build();
2817

29-
BoolObjectOption = class extends BoolObjectOption implements OptionCompProperty {
30-
propertyView(param: { autoMap?: boolean }) {
18+
BoolObjectOption = class extends BoolObjectOption {
19+
propertyView() {
3120
return (
3221
<>
3322
{this.children.label.propertyView({
34-
name: trans("label"),
35-
placeholder: param.autoMap ? "buttonName" : "",
23+
name: trans("key"),
24+
placeholder: "buttonName",
3625
})}
37-
{this.children.state.propertyView({ label: trans("state") })}
26+
{this.children.value.propertyView({ label: trans("active") })}
3827
</>
3928
);
4029
}
4130
};
4231

43-
export const BoolObjectOptionControl = optionsControl(BoolObjectOption, {
44-
initOptions: [
45-
{ label: "button1", state: true },
46-
{ label: "button2", state: false },
47-
],
48-
uniqField: "label",
49-
});
32+
export const boolObjectOptionControl = function (options: object) {
33+
//ConvertObject to Array
34+
if (!options) {
35+
return manualOptionsControl(BoolObjectOption, {
36+
initOptions: [
37+
{ label: "button1", value: true },
38+
{ label: "button2", value: false },
39+
],
40+
uniqField: "label",
41+
})
42+
}
5043

51-
export function boolObjectOptionControl(defaultValue: any) {
52-
return optionsControl(BoolObjectOption, {
53-
initOptions: defaultValue ? defaultValue : [
54-
{ label: "button1", state: true },
55-
{ label: "button2", state: false },
56-
],
44+
var optionsRec = []
45+
for (const [key, value] of Object.entries(options)) {
46+
optionsRec.push({ label: key, value: value });
47+
}
48+
return manualOptionsControl(BoolObjectOption, {
49+
initOptions: optionsRec,
5750
uniqField: "label",
5851
})
5952
}
6053

54+
55+

src/FeaturesControl.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { ReactNode } from 'react'
2+
import {
3+
MultiCompBuilder,
4+
BoolControl,
5+
withDefault,
6+
} from 'lowcoder-sdk'
7+
8+
export function featureControl(
9+
config: any,
10+
) {
11+
const childrenMap: any = new Object();
12+
Object.keys(config).forEach((k: string, index: any) => {
13+
childrenMap[k] = withDefault(BoolControl, config[k])
14+
})
15+
class FeatureControlTemp extends new MultiCompBuilder(childrenMap, (props: any) => {
16+
return props
17+
})
18+
.setPropertyViewFn((children: any) => (<></>))
19+
.build() {
20+
propertyView(params: {
21+
title: string
22+
}): ReactNode {
23+
var list: any = []
24+
{ Object.keys(this.children).forEach((k, index) => { list.push(this.children[k].propertyView({ label: k })) }) }
25+
return (
26+
<>
27+
{params.title}
28+
{list}
29+
</>
30+
);
31+
}
32+
}
33+
return FeatureControlTemp;
34+
}

src/GEOComp.tsx

Lines changed: 70 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState } from 'react';
1+
import { useState, useEffect } from 'react';
22
import {
33
UICompBuilder,
44
NameConfig,
@@ -26,7 +26,7 @@ import { useResizeDetector } from "react-resize-detector";
2626
import Notification from 'ol-ext/control/Notification'
2727

2828
import { boolObjectOptionControl } from './BoolObjectOptionControl';
29-
29+
import { featureControl } from './FeaturesControl';
3030

3131
export const CompStyles = [
3232
{
@@ -91,6 +91,7 @@ export const CompStyles = [
9191
north: false,
9292
}
9393
*/
94+
9495
var GEOComp = (function () {
9596

9697
//The events supported
@@ -164,17 +165,61 @@ var GEOComp = (function () {
164165
events: jsonObjectExposingStateControl("events"),
165166
event: jsonObjectExposingStateControl("event"),
166167
feature: jsonObjectExposingStateControl("feature"),
167-
buttons: withDefault(JSONObjectControl, "{menu:false,north:false,save:false}"),
168-
features: withDefault(
169-
JSONObjectControl,
170-
"{modify:true,split:false,tracker:false,timeline:false,gpsCentered:true,largeButtons:false,scaleToBottom:false}"
171-
),
172168
onEvent: eventHandlerControl(eventDefintions),
173-
test: boolObjectOptionControl([
174-
{ label: "modify", state: true },
175-
{ label: "splitHorizontal", state: false },
176-
{ label: "splitVertical", state: false },
177-
])
169+
features: document.lowcoderdev ?
170+
withDefault(JSONObjectControl,
171+
`{
172+
menu: false,
173+
zoom: true,
174+
fullscreen: true,
175+
layers: true,
176+
center: true,
177+
modify: false,
178+
split: false,
179+
tracker: false,
180+
timeline: false,
181+
gpsCentered: false,
182+
largeButtons: true,
183+
scaleToBottom: false,
184+
"modify:select": true,
185+
"modify:point": true,
186+
"modify:line": true,
187+
"modify:polygon": true,
188+
"modify:delete": true,
189+
"modify:redo": true,
190+
"modify:undo": true,
191+
save: false,
192+
splitVertical: false,
193+
splitHorizontal: false,
194+
north: false
195+
}`
196+
) :
197+
featureControl({
198+
menu: false,
199+
zoom: true,
200+
fullscreen: true,
201+
layers: true,
202+
center: true,
203+
modify: false,
204+
split: false,
205+
tracker: false,
206+
timeline: false,
207+
gpsCentered: false,
208+
largeButtons: true,
209+
scaleToBottom: false,
210+
"modify:select": true,
211+
"modify:point": true,
212+
"modify:line": true,
213+
"modify:polygon": true,
214+
"modify:delete": true,
215+
"modify:redo": true,
216+
"modify:undo": true,
217+
save: false,
218+
splitVertical: false,
219+
splitHorizontal: false,
220+
north: false
221+
}),
222+
178223
};
179224

180225

@@ -192,22 +237,22 @@ var GEOComp = (function () {
192237
layers: any;
193238
bbox: any;
194239
defaults: any;
195-
buttons: any;
240+
feature: any;
196241
features: any;
197242
menuTitle: string;
198243
menuContent: string;
199244
autoHeight: boolean;
200245
events: any;
201246
event: any;
202-
feature: any
203-
test: any
204247
}) => {
205248
const doDebug = function () {
206249
return props.defaults && props.defaults.debug === true
207250
}
251+
208252
//Default size of component
209253
const [dimensions, setDimensions] = useState({ width: 650, height: 400 });
210254
//Catch the resizing of component
255+
211256
const { width, height, ref: conRef } = useResizeDetector({
212257
onResize: () => {
213258
const container = conRef.current;
@@ -229,6 +274,12 @@ var GEOComp = (function () {
229274
}
230275
});
231276

277+
278+
//Check if feature is Enabled
279+
const featureEnabled = function (name: any) {
280+
return props.features[name] == true
281+
}
282+
232283
//Cache for all events
233284
var _events = {}
234285
//The event handler will also sent the event value to use
@@ -253,7 +304,7 @@ var GEOComp = (function () {
253304
props.feature.onChange(eventObj)
254305
break;
255306
case 'window:resize':
256-
if (props.features && props.features.scaleToBottom == true && props.autoHeight) {
307+
if (featureEnabled('scaleToBottom') && props.autoHeight) {
257308
const el = eventObj.el
258309
const rec = eventObj.windowSize
259310
const bounds = eventObj.bounds.getBoundingClientRect()
@@ -309,13 +360,12 @@ var GEOComp = (function () {
309360
zoom={props.zoom}
310361
maxZoom={props.maxZoom}
311362
rotation={props.rotation}
312-
buttons={props.buttons}
313363
menuContent={props.menuContent}
314364
menuTitle={props.menuTitle}
315365
defaults={props.defaults}
316-
features={props.features}
317366
layers={props.layers}
318367
onEvent={handleEvent}
368+
features={props.features}
319369
/>
320370
</div>
321371
</div>
@@ -338,11 +388,7 @@ var GEOComp = (function () {
338388
{children.onEvent.propertyView()}
339389
</Section>
340390
<Section name="Behavior">
341-
{children.test.propertyView({ label: "test features" })}
342-
{children.features.propertyView({ label: "Enabled features" })}
343-
{children.buttons.propertyView({ label: "Visible buttons" })}
344-
{children.menuTitle.propertyView({ label: "Menu title" })}
345-
{children.menuContent.propertyView({ label: "Menu content" })}
391+
{children.features.propertyView({ title: "Enabled features & Buttons" })}
346392
</Section>
347393
<Section name="Styles">
348394
{children.autoHeight.getPropertyView()}
@@ -360,6 +406,7 @@ var GEOComp = (function () {
360406
.build();
361407
})();
362408

409+
363410
//Add autoheight to component
364411
GEOComp = class extends GEOComp {
365412
autoHeight(): boolean {

src/i18n/comps/locales/en.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ export const en = {
4444
"methods": {
4545
"xml": "Get XML",
4646
},
47-
"label": "label",
48-
"state": "state",
47+
"key": "key",
48+
"active": "active",
4949
"boolObjectOptionControl": {
5050
"optionI": "option{{i}}"
5151
}

0 commit comments

Comments
 (0)