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" ;
@@ -11,6 +10,8 @@ import styled from "styled-components";
1110import { ColumnLink } from "comps/comps/tableComp/column/columnTypeComps/columnLinkComp" ;
1211import { LightActiveTextColor , PrimaryColor } from "constants/style" ;
1312import { clickEvent , eventHandlerControl } from "comps/controls/eventHandlerControl" ;
13+ import { migrateOldData } from "@lowcoder-ee/comps/generators/simpleGenerators" ;
14+ import { fixOldActionData } from "comps/comps/tableComp/column/simpleColumnTypeComps" ;
1415
1516const MenuLinkWrapper = styled . div `
1617 > a {
@@ -38,16 +39,35 @@ const MenuWrapper = styled.div`
3839 }
3940` ;
4041
41- const LinksEventOptions = [ clickEvent ] as const ;
42+ const LinkEventOptions = [ clickEvent ] as const ;
4243
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 (
4566 {
4667 label : StringControl ,
47- onClick : ActionSelectorControlInContext ,
68+ onClick : eventHandlerControl ( LinkEventOptions ) ,
4869 hidden : BoolCodeControl ,
4970 disabled : BoolCodeControl ,
50- onEvent : eventHandlerControl ( LinksEventOptions ) ,
5171 } ,
5272 ( props ) => {
5373 return props ;
@@ -57,50 +77,18 @@ const OptionItem = new MultiCompBuilder(
5777 return (
5878 < >
5979 { children . label . propertyView ( { label : trans ( "label" ) } ) }
60- { children . onClick . propertyView ( {
61- label : trans ( "table.action" ) ,
62- placement : "table" ,
63- } ) }
6480 { hiddenPropertyView ( children ) }
6581 { disabledPropertyView ( children ) }
66- { /* { children.onEvent .propertyView()} */ }
82+ { children . onClick . propertyView ( ) }
6783 </ >
6884 ) ;
6985 } )
7086 . build ( ) ;
7187
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 ) ;
10189
10290// Memoized menu component
103- const LinksMenu = React . memo ( ( { options, onEvent } : { options : any [ ] ; onEvent ?: ( eventName : string ) => void } ) => {
91+ const LinksMenu = React . memo ( ( { options } : { options : any [ ] } ) => {
10492 const mountedRef = useRef ( true ) ;
10593
10694 // Cleanup on unmount
@@ -115,9 +103,9 @@ const LinksMenu = React.memo(({ options, onEvent }: { options: any[]; onEvent?:
115103 . filter ( ( o ) => ! o . hidden )
116104 . map ( ( option , index ) => ( {
117105 key : index ,
118- label : < MenuItem option = { option } index = { index } onMainEvent = { onEvent } />
106+ label : < MenuItem option = { option } index = { index } />
119107 } ) ) ,
120- [ options , onEvent ]
108+ [ options ]
121109 ) ;
122110
123111 return (
@@ -129,17 +117,16 @@ const LinksMenu = React.memo(({ options, onEvent }: { options: any[]; onEvent?:
129117
130118LinksMenu . displayName = 'LinksMenu' ;
131119
132- export const ColumnLinksComp = ( function ( ) {
120+ const ColumnLinksCompTmp = ( function ( ) {
133121 const childrenMap = {
134122 options : manualOptionsControl ( OptionItem , {
135123 initOptions : [ { label : trans ( "table.option1" ) } ] ,
136124 } ) ,
137- onEvent : eventHandlerControl ( LinksEventOptions ) ,
138125 } ;
139126 return new ColumnTypeCompBuilder (
140127 childrenMap ,
141128 ( props ) => {
142- return < LinksMenu options = { props . options } onEvent = { props . onEvent } /> ;
129+ return < LinksMenu options = { props . options } /> ;
143130 } ,
144131 ( ) => ""
145132 )
@@ -149,8 +136,9 @@ export const ColumnLinksComp = (function () {
149136 newOptionLabel : trans ( "table.option" ) ,
150137 title : trans ( "table.optionList" ) ,
151138 } ) }
152- { children . onEvent . propertyView ( ) }
153139 </ >
154140 ) )
155141 . build ( ) ;
156142} ) ( ) ;
143+
144+ export const ColumnLinksComp = migrateOldData ( ColumnLinksCompTmp , fixOldActionData ) ;
0 commit comments