Skip to content

Commit 9c8b97b

Browse files
author
hulutter
committed
feat(client): remove id property as it might interfere with other features and add data-testid to enable test automation
1 parent e14cab9 commit 9c8b97b

File tree

3 files changed

+32
-27
lines changed

3 files changed

+32
-27
lines changed

client/packages/lowcoder/src/comps/generators/uiCompBuilder.tsx

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import { trans } from "i18n";
2828
export type NewChildren<ChildrenCompMap extends Record<string, Comp<unknown>>> =
2929
ChildrenCompMap & {
3030
hidden: InstanceType<typeof BoolCodeControl>;
31-
id: InstanceType<typeof StringControl>;
3231
className: InstanceType<typeof StringControl>;
32+
dataTestId: InstanceType<typeof StringControl>;
3333
};
3434

3535
export function HidableView(props: {
@@ -56,15 +56,15 @@ export function HidableView(props: {
5656

5757
export function ExtendedComponentView(props: {
5858
children: JSX.Element | React.ReactNode;
59-
id: string;
6059
className: string;
60+
dataTestId: string;
6161
}) {
62-
if (!props.id && !props.className) {
62+
if (!props.className && !props.dataTestId) {
6363
return <>{props.children}</>;
64-
}
65-
64+
}
65+
6666
return (
67-
<div id={props.id} className={props.className}>
67+
<div className={props.className} data-testid={props.dataTestId}>
6868
{props.children}
6969
</div>
7070
);
@@ -73,17 +73,17 @@ export function ExtendedComponentView(props: {
7373
export function ExtendedPropertyView<
7474
ChildrenCompMap extends Record<string, Comp<unknown>>,
7575
>(props: {
76-
children: JSX.Element | React.ReactNode,
77-
childrenMap: NewChildren<ChildrenCompMap>
78-
}
76+
children: JSX.Element | React.ReactNode,
77+
childrenMap: NewChildren<ChildrenCompMap>
78+
}
7979
) {
8080
return (
8181
<>
82-
{props.children}
83-
<Section name={ trans("prop.component") }>
84-
{props.childrenMap.id?.propertyView({ label: trans("prop.id") })}
85-
{props.childrenMap.className?.propertyView({ label: trans("prop.className") })}
86-
</Section>
82+
{props.children}
83+
<Section name={trans("prop.component")}>
84+
{props.childrenMap.className?.propertyView({ label: trans("prop.className") })}
85+
{props.childrenMap.dataTestId?.propertyView({ label: trans("prop.dataTestId") })}
86+
</Section>
8787
</>
8888
);
8989
}
@@ -93,7 +93,12 @@ export function uiChildren<
9393
>(
9494
childrenMap: ToConstructor<ChildrenCompMap>
9595
): ToConstructor<NewChildren<ChildrenCompMap>> {
96-
return { ...childrenMap, hidden: BoolCodeControl, id: StringControl, className: StringControl } as any;
96+
return {
97+
...childrenMap,
98+
hidden: BoolCodeControl,
99+
className: StringControl,
100+
dataTestId: StringControl
101+
} as any;
97102
}
98103

99104
type ViewReturn = ReactNode;
@@ -160,14 +165,11 @@ export class UICompBuilder<
160165
}
161166

162167
build() {
163-
if (this.childrenMap.hasOwnProperty("hidden")) {
164-
throw new Error("already has hidden");
165-
}
166-
if (this.childrenMap.hasOwnProperty("id")) {
167-
throw new Error("already has id");
168-
}
169-
if (this.childrenMap.hasOwnProperty("className")) {
170-
throw new Error("already has className");
168+
const reservedProps = ["hidden", "className", "dataTestId"];
169+
for (const reservedProp of reservedProps) {
170+
if (this.childrenMap.hasOwnProperty(reservedProp)) {
171+
throw new Error(`Property »${reservedProp}« is reserved and must not be implemented in components!`);
172+
}
171173
}
172174
const newChildrenMap = uiChildren(this.childrenMap);
173175
const builder = this;
@@ -178,7 +180,7 @@ export class UICompBuilder<
178180
ToNodeType<NewChildren<ChildrenCompMap>>
179181
> {
180182
ref: React.RefObject<HTMLDivElement> = React.createRef();
181-
183+
182184
override parseChildrenFromValue(
183185
params: CompParams<ToDataType<NewChildren<ChildrenCompMap>>>
184186
): NewChildren<ChildrenCompMap> {
@@ -241,7 +243,10 @@ function UIView(props: { comp: any; viewFn: any }) {
241243
//END ADD BY FRED
242244

243245
return (
244-
<ExtendedComponentView id={childrenProps.id as string} className={childrenProps.className as string}>
246+
<ExtendedComponentView
247+
className={childrenProps.className as string}
248+
dataTestId={childrenProps.dataTestId as string}
249+
>
245250
<HidableView hidden={childrenProps.hidden as boolean}>
246251
{props.viewFn(childrenProps, comp.dispatch)}
247252
</HidableView>

client/packages/lowcoder/src/i18n/locales/de.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ export const de = {
184184
"maskClosable": "Zum Schließen auf \"Draußen\" klicken",
185185
"showMask": "Maske zeigen",
186186
"component": "Komponente",
187-
"id": "ID",
188187
"className": "Klasse",
188+
"dataTestId": "Test ID",
189189
},
190190
"autoHeightProp": {
191191
"auto": "Auto",

client/packages/lowcoder/src/i18n/locales/en.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ export const en = {
212212
"horizontal": "Horizontal",
213213
"minHorizontalWidth": "Minimum Horizontal Width",
214214
"component": "Component",
215-
"id": "ID",
216215
"className": "Class",
216+
"dataTestId": "Test ID",
217217
},
218218
"autoHeightProp": {
219219
"auto": "Auto",

0 commit comments

Comments
 (0)