1
1
import React , { useState , useRef , useEffect , useCallback , useMemo } from "react" ;
2
2
import { default as Menu } from "antd/es/menu" ;
3
3
import { ColumnTypeCompBuilder } from "comps/comps/tableComp/column/columnTypeCompBuilder" ;
4
- import { ActionSelectorControlInContext } from "comps/controls/actionSelector/actionSelectorControl" ;
5
4
import { BoolCodeControl , StringControl } from "comps/controls/codeControl" ;
6
5
import { manualOptionsControl } from "comps/controls/optionsControl" ;
7
6
import { MultiCompBuilder } from "comps/generators" ;
@@ -12,6 +11,8 @@ import { ColumnLink } from "comps/comps/tableComp/column/columnTypeComps/columnL
12
11
import { LightActiveTextColor , PrimaryColor } from "constants/style" ;
13
12
import { clickEvent , eventHandlerControl , doubleClickEvent } from "comps/controls/eventHandlerControl" ;
14
13
import { ComponentClickHandler } from "@lowcoder-ee/comps/utils/componentClickHandler" ;
14
+ import { migrateOldData } from "@lowcoder-ee/comps/generators/simpleGenerators" ;
15
+ import { fixOldActionData } from "comps/comps/tableComp/column/simpleColumnTypeComps" ;
15
16
16
17
const MenuLinkWrapper = styled . div `
17
18
> a {
@@ -39,16 +40,35 @@ const MenuWrapper = styled.div`
39
40
}
40
41
` ;
41
42
42
- const LinksEventOptions = [ clickEvent , doubleClickEvent ] as const ;
43
+ const LinkEventOptions = [ clickEvent , doubleClickEvent ] as const ;
43
44
44
- // Update OptionItem to include event handlers
45
- const OptionItem = new MultiCompBuilder (
45
+ // Memoized menu item component
46
+ const MenuItem = React . memo ( ( { option, index } : { option : any ; index : number } ) => {
47
+ const handleClick = useCallback ( ( ) => {
48
+ if ( ! option . disabled && option . onClick ) {
49
+ option . onClick ( "click" ) ;
50
+ }
51
+ } , [ option . disabled , option . onClick ] ) ;
52
+
53
+ return (
54
+ < MenuLinkWrapper >
55
+ < ColumnLink
56
+ disabled = { option . disabled }
57
+ label = { option . label }
58
+ onClick = { handleClick }
59
+ />
60
+ </ MenuLinkWrapper >
61
+ ) ;
62
+ } ) ;
63
+
64
+ MenuItem . displayName = 'MenuItem' ;
65
+
66
+ const OptionItemTmp = new MultiCompBuilder (
46
67
{
47
68
label : StringControl ,
48
- onClick : ActionSelectorControlInContext ,
69
+ onClick : eventHandlerControl ( LinkEventOptions ) ,
49
70
hidden : BoolCodeControl ,
50
71
disabled : BoolCodeControl ,
51
- onEvent : eventHandlerControl ( LinksEventOptions ) ,
52
72
} ,
53
73
( props ) => {
54
74
return props ;
@@ -58,56 +78,18 @@ const OptionItem = new MultiCompBuilder(
58
78
return (
59
79
< >
60
80
{ children . label . propertyView ( { label : trans ( "label" ) } ) }
61
- { children . onClick . propertyView ( {
62
- label : trans ( "table.action" ) ,
63
- placement : "table" ,
64
- } ) }
65
81
{ hiddenPropertyView ( children ) }
66
82
{ disabledPropertyView ( children ) }
67
- { /* { children.onEvent .propertyView()} */ }
83
+ { children . onClick . propertyView ( ) }
68
84
</ >
69
85
) ;
70
86
} )
71
87
. build ( ) ;
72
88
73
- // Memoized menu item component
74
- const MenuItem = React . memo ( ( { option, index, onMainEvent } : { option : any ; index : number ; onMainEvent ?: ( eventName : string ) => void } ) => {
75
- const handleClick = useCallback ( ( ) => {
76
- if ( ! option . disabled ) {
77
- // Handle both option's event and main event through ComponentClickHandler
78
- const combinedHandler = ( event : "click" | "doubleClick" ) => {
79
- option . onEvent ?.( event ) ;
80
- onMainEvent ?.( event ) ;
81
- } ;
82
- ComponentClickHandler ( { onEvent : combinedHandler } ) ( ) ;
83
- // if (option.onClick) {
84
- // option.onClick();
85
- // }
86
- // // if (option.onEvent) {
87
- // // option.onEvent("click");
88
- // // }
89
- // // Trigger the main component's event handler
90
- // if (onMainEvent) {
91
- // onMainEvent("click");
92
- // }
93
- }
94
- } , [ option . disabled , option . onEvent , onMainEvent ] ) ;
95
-
96
- return (
97
- < MenuLinkWrapper >
98
- < ColumnLink
99
- disabled = { option . disabled }
100
- label = { option . label }
101
- onEvent = { handleClick }
102
- />
103
- </ MenuLinkWrapper >
104
- ) ;
105
- } ) ;
106
-
107
- MenuItem . displayName = 'MenuItem' ;
89
+ const OptionItem = migrateOldData ( OptionItemTmp , fixOldActionData ) ;
108
90
109
91
// Memoized menu component
110
- const LinksMenu = React . memo ( ( { options, onEvent } : { options : any [ ] ; onEvent ?: ( eventName : string ) => void } ) => {
92
+ const LinksMenu = React . memo ( ( { options } : { options : any [ ] } ) => {
111
93
const mountedRef = useRef ( true ) ;
112
94
113
95
// Cleanup on unmount
@@ -122,9 +104,9 @@ const LinksMenu = React.memo(({ options, onEvent }: { options: any[]; onEvent?:
122
104
. filter ( ( o ) => ! o . hidden )
123
105
. map ( ( option , index ) => ( {
124
106
key : index ,
125
- label : < MenuItem option = { option } index = { index } onMainEvent = { onEvent } />
107
+ label : < MenuItem option = { option } index = { index } />
126
108
} ) ) ,
127
- [ options , onEvent ]
109
+ [ options ]
128
110
) ;
129
111
130
112
return (
@@ -136,17 +118,16 @@ const LinksMenu = React.memo(({ options, onEvent }: { options: any[]; onEvent?:
136
118
137
119
LinksMenu . displayName = 'LinksMenu' ;
138
120
139
- export const ColumnLinksComp = ( function ( ) {
121
+ const ColumnLinksCompTmp = ( function ( ) {
140
122
const childrenMap = {
141
123
options : manualOptionsControl ( OptionItem , {
142
124
initOptions : [ { label : trans ( "table.option1" ) } ] ,
143
125
} ) ,
144
- onEvent : eventHandlerControl ( LinksEventOptions ) ,
145
126
} ;
146
127
return new ColumnTypeCompBuilder (
147
128
childrenMap ,
148
129
( props ) => {
149
- return < LinksMenu options = { props . options } onEvent = { props . onEvent } /> ;
130
+ return < LinksMenu options = { props . options } /> ;
150
131
} ,
151
132
( ) => ""
152
133
)
@@ -156,8 +137,9 @@ export const ColumnLinksComp = (function () {
156
137
newOptionLabel : trans ( "table.option" ) ,
157
138
title : trans ( "table.optionList" ) ,
158
139
} ) }
159
- { children . onEvent . propertyView ( ) }
160
140
</ >
161
141
) )
162
142
. build ( ) ;
163
143
} ) ( ) ;
144
+
145
+ export const ColumnLinksComp = migrateOldData ( ColumnLinksCompTmp , fixOldActionData ) ;
0 commit comments