Skip to content

Commit 6eb8842

Browse files
added migration to handle old action handlers in table's button column type
1 parent fafab63 commit 6eb8842

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

client/packages/lowcoder/src/comps/comps/tableComp/column/simpleColumnTypeComps.tsx

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,21 @@ import { CSSProperties } from "react";
1414
import { RecordConstructorToComp } from "lowcoder-core";
1515
import { ToViewReturn } from "@lowcoder-ee/comps/generators/multi";
1616
import { clickEvent, eventHandlerControl } from "comps/controls/eventHandlerControl";
17+
import { migrateOldData } from "@lowcoder-ee/comps/generators/simpleGenerators";
1718

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+
}
1832
export const ColumnValueTooltip = trans("table.columnValueTooltip");
1933

2034
export const ButtonTypeOptions = [
@@ -38,7 +52,7 @@ const childrenMap = {
3852
text: StringControl,
3953
buttonType: dropdownControl(ButtonTypeOptions, "primary"),
4054
onEvent: eventHandlerControl(ButtonEventOptions),
41-
onClick: ActionSelectorControlInContext,
55+
onClick: eventHandlerControl(ButtonEventOptions), //ActionSelectorControlInContext,
4256
loading: BoolCodeControl,
4357
disabled: BoolCodeControl,
4458
prefixIcon: IconControl,
@@ -53,8 +67,7 @@ const ButtonStyled = React.memo(({ props }: { props: ToViewReturn<RecordConstruc
5367
const iconOnly = !hasText && (hasPrefixIcon || hasSuffixIcon);
5468

5569
const handleClick = useCallback((e: React.MouseEvent) => {
56-
props.onClick?.();
57-
// props.onEvent?.("click");
70+
props.onClick?.("click");
5871
}, [props.onClick, props.onEvent]);
5972

6073
const buttonStyle = useMemo(() => ({
@@ -81,7 +94,7 @@ const ButtonStyled = React.memo(({ props }: { props: ToViewReturn<RecordConstruc
8194
);
8295
});
8396

84-
export const ButtonComp = (function () {
97+
const ButtonCompTmp = (function () {
8598
return new ColumnTypeCompBuilder(
8699
childrenMap,
87100
(props) => <ButtonStyled props={props} />,
@@ -105,12 +118,10 @@ export const ButtonComp = (function () {
105118
})}
106119
{loadingPropertyView(children)}
107120
{disabledPropertyView(children)}
108-
{/* {children.onEvent.propertyView()} */}
109-
{children.onClick.propertyView({
110-
label: trans("table.action"),
111-
placement: "table",
112-
})}
121+
{children.onClick.propertyView()}
113122
</>
114123
))
115124
.build();
116125
})();
126+
127+
export const ButtonComp = migrateOldData(ButtonCompTmp, fixOldActionData);

0 commit comments

Comments
 (0)