Skip to content

Commit 46d5b8e

Browse files
committed
fix: based on code review
1 parent 90e141c commit 46d5b8e

File tree

7 files changed

+35
-60
lines changed

7 files changed

+35
-60
lines changed

packages/pluggableWidgets/events-web/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,9 @@
5353
"@mendix/widget-plugin-hooks": "workspace:*",
5454
"@mendix/widget-plugin-platform": "workspace:*",
5555
"@mendix/widget-plugin-test-utils": "workspace:*",
56-
"@types/deep-equal": "^1.0.1",
5756
"cross-env": "^7.0.3"
5857
},
5958
"dependencies": {
60-
"classnames": "^2.3.2",
61-
"deep-equal": "^2.2.3"
59+
"classnames": "^2.3.2"
6260
}
6361
}
Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { Properties, hidePropertiesIn } from "@mendix/pluggable-widgets-tools";
22
import {
33
StructurePreviewProps,
4-
structurePreviewPalette
4+
structurePreviewPalette,
5+
rowLayout,
6+
container,
7+
svgImage,
8+
text
59
} from "@mendix/widget-plugin-platform/preview/structure-preview-api";
610
import { EventsPreviewProps } from "../typings/EventsProps";
711

@@ -21,55 +25,33 @@ export function getProperties(
2125
}
2226

2327
export function getPreview(values: EventsPreviewProps, isDarkMode: boolean): StructurePreviewProps {
24-
const eventsCount = Number(!!values.onComponentLoad) + Number(!!values.onEventChange);
28+
const eventsCount = getEventsCount(values);
2529

2630
const palette = structurePreviewPalette[isDarkMode ? "dark" : "light"];
2731
const activeSVG = isDarkMode ? EventsPreviewDarkSVGActive : EventsPreviewSVGActive;
2832
const normalSVG = isDarkMode ? EventsPreviewDarkSVG : EventsPreviewSVG;
2933
const variant = eventsCount > 0 ? activeSVG : normalSVG;
3034
const doc = decodeURIComponent(variant.replace("data:image/svg+xml,", ""));
3135

32-
return {
33-
type: "RowLayout",
34-
columnSize: "grow",
35-
borders: true,
36-
backgroundColor: palette.background.containerFill,
37-
children: [
38-
{
39-
type: "Container"
40-
},
41-
{
42-
type: "RowLayout", // fills space on the right
43-
grow: 2,
44-
padding: 8,
45-
children: [
46-
{
47-
type: "Image",
48-
document: doc,
49-
height: 15,
50-
grow: 1,
51-
width: 15
52-
},
53-
{
54-
type: "Text",
55-
content:
56-
eventsCount <= 0
57-
? "[Configure events]"
58-
: `[${eventsCount}] Event${eventsCount > 1 ? "s" : ""}`,
59-
fontColor: palette.text.primary,
60-
grow: 10
61-
}
62-
]
63-
},
64-
{
65-
type: "Container"
66-
}
67-
]
68-
};
36+
return rowLayout({ columnSize: "grow", borders: true, backgroundColor: palette.background.containerFill })(
37+
container()(),
38+
rowLayout({ grow: 2, padding: 8 })(
39+
svgImage(doc, 15, 15),
40+
text({ fontColor: palette.text.primary, grow: 10 })(getCaption(eventsCount))
41+
),
42+
container()()
43+
);
6944
}
7045

7146
export function getCustomCaption(values: EventsPreviewProps, _platform = "desktop"): string {
72-
const eventsCount = Number(!!values.onComponentLoad) + Number(!!values.onEventChange);
47+
const caption = getCaption(getEventsCount(values));
48+
return caption;
49+
}
50+
51+
export function getEventsCount(values: EventsPreviewProps): number {
52+
return Number(!!values.onComponentLoad) + Number(!!values.onEventChange);
53+
}
7354

55+
export function getCaption(eventsCount: number): string {
7456
return eventsCount <= 0 ? "[Configure events]" : `[${eventsCount}] Event${eventsCount > 1 ? "s" : ""}`;
7557
}

packages/pluggableWidgets/events-web/src/Events.editorPreview.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ import { ReactElement, createElement } from "react";
22
import { EventsIcon } from "./assets/icons";
33
import "./ui/EventsPreview.css";
44
import { EventsPreviewProps } from "typings/EventsProps";
5+
import { getEventsCount, getCaption } from "./Events.editorConfig";
56
import classNames from "classnames";
67

78
export function preview(props: EventsPreviewProps): ReactElement {
8-
const eventsCount = Number(!!props.onComponentLoad) + Number(!!props.onEventChange);
9+
const eventsCount = getEventsCount(props);
910

1011
return (
1112
<div className={classNames("widget-events-preview", { active: eventsCount > 0 })}>
1213
<EventsIcon isActive={eventsCount > 0} />
13-
{eventsCount <= 0 ? "[Configure events]" : `[${eventsCount}] Event${eventsCount > 1 ? "s" : ""}`}
14+
{getCaption(eventsCount)}
1415
</div>
1516
);
1617
}

packages/pluggableWidgets/events-web/src/Events.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default function Events(props: EventsContainerProps): ReactElement {
1212
componentLoadDelay,
1313
componentLoadRepeat,
1414
componentLoadRepeatInterval,
15-
optionsSourceAttributeDataSource,
15+
onEventChangeAttribute,
1616
onEventChange,
1717
onEventChangeDelay
1818
// optionsSourceType
@@ -29,23 +29,23 @@ export default function Events(props: EventsContainerProps): ReactElement {
2929
useActionTimer({
3030
canExecute: onEventChange?.canExecute,
3131
execute: () => {
32-
if (optionsSourceAttributeDataSource?.status === "loading") {
32+
if (onEventChangeAttribute?.status === "loading") {
3333
return;
3434
}
3535
if (prevOnChangeAttributeValue?.current?.value === undefined) {
3636
// ignore initial load
37-
prevOnChangeAttributeValue.current = optionsSourceAttributeDataSource;
37+
prevOnChangeAttributeValue.current = onEventChangeAttribute;
3838
} else {
39-
if (optionsSourceAttributeDataSource?.value !== prevOnChangeAttributeValue.current?.value) {
40-
prevOnChangeAttributeValue.current = optionsSourceAttributeDataSource;
39+
if (onEventChangeAttribute?.value !== prevOnChangeAttributeValue.current?.value) {
40+
prevOnChangeAttributeValue.current = onEventChangeAttribute;
4141
onEventChange?.execute();
4242
}
4343
}
4444
},
4545
delay: onEventChangeDelay,
4646
interval: 0,
4747
repeat: false,
48-
attribute: optionsSourceAttributeDataSource
48+
attribute: onEventChangeAttribute
4949
});
5050
return <div className={classnames("widget-events", className)}></div>;
5151
}

packages/pluggableWidgets/events-web/src/Events.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
</property>
2626
</propertyGroup>
2727
<propertyGroup caption="On change">
28-
<property key="optionsSourceAttributeDataSource" type="attribute" required="false">
28+
<property key="onEventChangeAttribute" type="attribute" required="false">
2929
<caption>Attribute</caption>
3030
<description />
3131
<attributeTypes>

packages/pluggableWidgets/events-web/typings/EventsProps.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface EventsContainerProps {
1616
componentLoadDelay: number;
1717
componentLoadRepeat: boolean;
1818
componentLoadRepeatInterval: number;
19-
optionsSourceAttributeDataSource?: EditableValue<Big | any | boolean | Date | string>;
19+
onEventChangeAttribute?: EditableValue<Big | any | boolean | Date | string>;
2020
onEventChange?: ActionValue;
2121
onEventChangeDelay: number;
2222
}
@@ -34,7 +34,7 @@ export interface EventsPreviewProps {
3434
componentLoadDelay: number | null;
3535
componentLoadRepeat: boolean;
3636
componentLoadRepeatInterval: number | null;
37-
optionsSourceAttributeDataSource: string;
37+
onEventChangeAttribute: string;
3838
onEventChange: {} | null;
3939
onEventChangeDelay: number | null;
4040
}

pnpm-lock.yaml

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)