@@ -14,7 +14,21 @@ import { CSSProperties } from "react";
14
14
import { RecordConstructorToComp } from "lowcoder-core" ;
15
15
import { ToViewReturn } from "@lowcoder-ee/comps/generators/multi" ;
16
16
import { clickEvent , eventHandlerControl } from "comps/controls/eventHandlerControl" ;
17
+ import { migrateOldData } from "@lowcoder-ee/comps/generators/simpleGenerators" ;
17
18
19
+ export const fixOldActionData = ( oldData : any ) => {
20
+ if ( ! oldData ) return oldData ;
21
+ if ( Boolean ( oldData . onClick ) ) {
22
+ return {
23
+ ...oldData ,
24
+ onClick : [ {
25
+ name : "click" ,
26
+ handler : oldData . onClick ,
27
+ } ] ,
28
+ } ;
29
+ }
30
+ return oldData ;
31
+ }
18
32
export const ColumnValueTooltip = trans ( "table.columnValueTooltip" ) ;
19
33
20
34
export const ButtonTypeOptions = [
@@ -37,8 +51,7 @@ const ButtonEventOptions = [clickEvent] as const;
37
51
const childrenMap = {
38
52
text : StringControl ,
39
53
buttonType : dropdownControl ( ButtonTypeOptions , "primary" ) ,
40
- onClick : ActionSelectorControlInContext ,
41
- onEvent : eventHandlerControl ( ButtonEventOptions ) ,
54
+ onClick : eventHandlerControl ( ButtonEventOptions ) ,
42
55
loading : BoolCodeControl ,
43
56
disabled : BoolCodeControl ,
44
57
prefixIcon : IconControl ,
@@ -53,11 +66,8 @@ const ButtonStyled = React.memo(({ props }: { props: ToViewReturn<RecordConstruc
53
66
const iconOnly = ! hasText && ( hasPrefixIcon || hasSuffixIcon ) ;
54
67
55
68
const handleClick = useCallback ( ( e : React . MouseEvent ) => {
56
- // Trigger legacy onClick action for backward compatibility
57
- props . onClick ?.( ) ;
58
- // Trigger new event handlers
59
- props . onEvent ?.( "click" ) ;
60
- } , [ props . onClick , props . onEvent ] ) ;
69
+ props . onClick ?.( "click" ) ;
70
+ } , [ props . onClick ] ) ;
61
71
62
72
const buttonStyle = useMemo ( ( ) => ( {
63
73
margin : 0 ,
@@ -83,43 +93,34 @@ const ButtonStyled = React.memo(({ props }: { props: ToViewReturn<RecordConstruc
83
93
) ;
84
94
} ) ;
85
95
86
- export const ButtonComp = ( function ( ) {
96
+ const ButtonCompTmp = ( function ( ) {
87
97
return new ColumnTypeCompBuilder (
88
98
childrenMap ,
89
99
( props ) => < ButtonStyled props = { props } /> ,
90
100
( nodeValue ) => nodeValue . text . value
91
101
)
92
- . setPropertyViewFn ( ( children ) => {
93
- // Check if there's a legacy action configured
94
- const hasLegacyAction = children . onClick . getView ( ) &&
95
- typeof children . onClick . getView ( ) === 'function' &&
96
- children . onClick . displayName ( ) !== trans ( "eventHandler.incomplete" ) ;
97
-
98
- return (
99
- < >
100
- { children . text . propertyView ( {
101
- label : trans ( "table.columnValue" ) ,
102
- tooltip : ColumnValueTooltip ,
103
- } ) }
104
- { children . prefixIcon . propertyView ( {
105
- label : trans ( "button.prefixIcon" ) ,
106
- } ) }
107
- { children . suffixIcon . propertyView ( {
108
- label : trans ( "button.suffixIcon" ) ,
109
- } ) }
110
- { children . buttonType . propertyView ( {
111
- label : trans ( "table.type" ) ,
112
- radioButton : true ,
113
- } ) }
114
- { loadingPropertyView ( children ) }
115
- { disabledPropertyView ( children ) }
116
- { children . onEvent . propertyView ( ) }
117
- { hasLegacyAction && children . onClick . propertyView ( {
118
- label : trans ( "table.action" ) ,
119
- placement : "table" ,
120
- } ) }
121
- </ >
122
- ) ;
123
- } )
102
+ . setPropertyViewFn ( ( children ) => (
103
+ < >
104
+ { children . text . propertyView ( {
105
+ label : trans ( "table.columnValue" ) ,
106
+ tooltip : ColumnValueTooltip ,
107
+ } ) }
108
+ { children . prefixIcon . propertyView ( {
109
+ label : trans ( "button.prefixIcon" ) ,
110
+ } ) }
111
+ { children . suffixIcon . propertyView ( {
112
+ label : trans ( "button.suffixIcon" ) ,
113
+ } ) }
114
+ { children . buttonType . propertyView ( {
115
+ label : trans ( "table.type" ) ,
116
+ radioButton : true ,
117
+ } ) }
118
+ { loadingPropertyView ( children ) }
119
+ { disabledPropertyView ( children ) }
120
+ { children . onClick . propertyView ( ) }
121
+ </ >
122
+ ) )
124
123
. build ( ) ;
125
124
} ) ( ) ;
125
+
126
+ export const ButtonComp = migrateOldData ( ButtonCompTmp , fixOldActionData ) ;
0 commit comments