11import React , { useState , useRef , useEffect , useCallback , useMemo } from "react" ;
22import { default as Menu } from "antd/es/menu" ;
33import { ColumnTypeCompBuilder } from "comps/comps/tableComp/column/columnTypeCompBuilder" ;
4- import { ActionSelectorControlInContext } from "comps/controls/actionSelector/actionSelectorControl" ;
54import { BoolCodeControl , StringControl } from "comps/controls/codeControl" ;
65import { manualOptionsControl } from "comps/controls/optionsControl" ;
76import { MultiCompBuilder } from "comps/generators" ;
@@ -12,6 +11,8 @@ import { ColumnLink } from "comps/comps/tableComp/column/columnTypeComps/columnL
1211import { LightActiveTextColor , PrimaryColor } from "constants/style" ;
1312import { clickEvent , eventHandlerControl , doubleClickEvent } from "comps/controls/eventHandlerControl" ;
1413import { 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" ;
1516
1617const MenuLinkWrapper = styled . div `
1718 > a {
@@ -39,16 +40,35 @@ const MenuWrapper = styled.div`
3940 }
4041` ;
4142
42- const LinksEventOptions = [ clickEvent , doubleClickEvent ] as const ;
43+ const LinkEventOptions = [ clickEvent , doubleClickEvent ] as const ;
4344
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 (
4667 {
4768 label : StringControl ,
48- onClick : ActionSelectorControlInContext ,
69+ onClick : eventHandlerControl ( LinkEventOptions ) ,
4970 hidden : BoolCodeControl ,
5071 disabled : BoolCodeControl ,
51- onEvent : eventHandlerControl ( LinksEventOptions ) ,
5272 } ,
5373 ( props ) => {
5474 return props ;
@@ -58,56 +78,18 @@ const OptionItem = new MultiCompBuilder(
5878 return (
5979 < >
6080 { children . label . propertyView ( { label : trans ( "label" ) } ) }
61- { children . onClick . propertyView ( {
62- label : trans ( "table.action" ) ,
63- placement : "table" ,
64- } ) }
6581 { hiddenPropertyView ( children ) }
6682 { disabledPropertyView ( children ) }
67- { /* { children.onEvent .propertyView()} */ }
83+ { children . onClick . propertyView ( ) }
6884 </ >
6985 ) ;
7086 } )
7187 . build ( ) ;
7288
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 ) ;
10890
10991// Memoized menu component
110- const LinksMenu = React . memo ( ( { options, onEvent } : { options : any [ ] ; onEvent ?: ( eventName : string ) => void } ) => {
92+ const LinksMenu = React . memo ( ( { options } : { options : any [ ] } ) => {
11193 const mountedRef = useRef ( true ) ;
11294
11395 // Cleanup on unmount
@@ -122,9 +104,9 @@ const LinksMenu = React.memo(({ options, onEvent }: { options: any[]; onEvent?:
122104 . filter ( ( o ) => ! o . hidden )
123105 . map ( ( option , index ) => ( {
124106 key : index ,
125- label : < MenuItem option = { option } index = { index } onMainEvent = { onEvent } />
107+ label : < MenuItem option = { option } index = { index } />
126108 } ) ) ,
127- [ options , onEvent ]
109+ [ options ]
128110 ) ;
129111
130112 return (
@@ -136,17 +118,16 @@ const LinksMenu = React.memo(({ options, onEvent }: { options: any[]; onEvent?:
136118
137119LinksMenu . displayName = 'LinksMenu' ;
138120
139- export const ColumnLinksComp = ( function ( ) {
121+ const ColumnLinksCompTmp = ( function ( ) {
140122 const childrenMap = {
141123 options : manualOptionsControl ( OptionItem , {
142124 initOptions : [ { label : trans ( "table.option1" ) } ] ,
143125 } ) ,
144- onEvent : eventHandlerControl ( LinksEventOptions ) ,
145126 } ;
146127 return new ColumnTypeCompBuilder (
147128 childrenMap ,
148129 ( props ) => {
149- return < LinksMenu options = { props . options } onEvent = { props . onEvent } /> ;
130+ return < LinksMenu options = { props . options } /> ;
150131 } ,
151132 ( ) => ""
152133 )
@@ -156,8 +137,9 @@ export const ColumnLinksComp = (function () {
156137 newOptionLabel : trans ( "table.option" ) ,
157138 title : trans ( "table.optionList" ) ,
158139 } ) }
159- { children . onEvent . propertyView ( ) }
160140 </ >
161141 ) )
162142 . build ( ) ;
163143} ) ( ) ;
144+
145+ export const ColumnLinksComp = migrateOldData ( ColumnLinksCompTmp , fixOldActionData ) ;
0 commit comments