@@ -28,8 +28,8 @@ import { trans } from "i18n";
28
28
export type NewChildren < ChildrenCompMap extends Record < string , Comp < unknown > > > =
29
29
ChildrenCompMap & {
30
30
hidden : InstanceType < typeof BoolCodeControl > ;
31
- id : InstanceType < typeof StringControl > ;
32
31
className : InstanceType < typeof StringControl > ;
32
+ dataTestId : InstanceType < typeof StringControl > ;
33
33
} ;
34
34
35
35
export function HidableView ( props : {
@@ -56,15 +56,15 @@ export function HidableView(props: {
56
56
57
57
export function ExtendedComponentView ( props : {
58
58
children : JSX . Element | React . ReactNode ;
59
- id : string ;
60
59
className : string ;
60
+ dataTestId : string ;
61
61
} ) {
62
- if ( ! props . id && ! props . className ) {
62
+ if ( ! props . className && ! props . dataTestId ) {
63
63
return < > { props . children } </ > ;
64
- }
65
-
64
+ }
65
+
66
66
return (
67
- < div id = { props . id } className = { props . className } >
67
+ < div className = { props . className } data-testid = { props . dataTestId } >
68
68
{ props . children }
69
69
</ div >
70
70
) ;
@@ -73,17 +73,17 @@ export function ExtendedComponentView(props: {
73
73
export function ExtendedPropertyView <
74
74
ChildrenCompMap extends Record < string , Comp < unknown > > ,
75
75
> ( props : {
76
- children : JSX . Element | React . ReactNode ,
77
- childrenMap : NewChildren < ChildrenCompMap >
78
- }
76
+ children : JSX . Element | React . ReactNode ,
77
+ childrenMap : NewChildren < ChildrenCompMap >
78
+ }
79
79
) {
80
80
return (
81
81
< >
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 >
87
87
</ >
88
88
) ;
89
89
}
@@ -93,7 +93,12 @@ export function uiChildren<
93
93
> (
94
94
childrenMap : ToConstructor < ChildrenCompMap >
95
95
) : 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 ;
97
102
}
98
103
99
104
type ViewReturn = ReactNode ;
@@ -160,14 +165,11 @@ export class UICompBuilder<
160
165
}
161
166
162
167
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
+ }
171
173
}
172
174
const newChildrenMap = uiChildren ( this . childrenMap ) ;
173
175
const builder = this ;
@@ -178,7 +180,7 @@ export class UICompBuilder<
178
180
ToNodeType < NewChildren < ChildrenCompMap > >
179
181
> {
180
182
ref : React . RefObject < HTMLDivElement > = React . createRef ( ) ;
181
-
183
+
182
184
override parseChildrenFromValue (
183
185
params : CompParams < ToDataType < NewChildren < ChildrenCompMap > > >
184
186
) : NewChildren < ChildrenCompMap > {
@@ -241,7 +243,10 @@ function UIView(props: { comp: any; viewFn: any }) {
241
243
//END ADD BY FRED
242
244
243
245
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
+ >
245
250
< HidableView hidden = { childrenProps . hidden as boolean } >
246
251
{ props . viewFn ( childrenProps , comp . dispatch ) }
247
252
</ HidableView >
0 commit comments