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