Skip to content

[Fix]: backward compatibility for button, link and links column types #1769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 14, 2025
Prev Previous commit
add backward compatibility for links type
  • Loading branch information
iamfaran committed Jun 13, 2025
commit 62285ce59bb8a9df18f25e70d19106c4b375ff02
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useState, useRef, useEffect, useCallback, useMemo } from "react";
import { default as Menu } from "antd/es/menu";
import { ColumnTypeCompBuilder } from "comps/comps/tableComp/column/columnTypeCompBuilder";
import { ActionSelectorControlInContext } from "comps/controls/actionSelector/actionSelectorControl";
import { BoolCodeControl, StringControl } from "comps/controls/codeControl";
import { manualOptionsControl } from "comps/controls/optionsControl";
import { MultiCompBuilder } from "comps/generators";
Expand All @@ -10,6 +9,9 @@ import { trans } from "i18n";
import styled from "styled-components";
import { ColumnLink } from "comps/comps/tableComp/column/columnTypeComps/columnLinkComp";
import { LightActiveTextColor, PrimaryColor } from "constants/style";
import { clickEvent, eventHandlerControl } from "comps/controls/eventHandlerControl";
import { migrateOldData } from "@lowcoder-ee/comps/generators/simpleGenerators";
import { fixOldActionData } from "comps/comps/tableComp/column/simpleColumnTypeComps";

const MenuLinkWrapper = styled.div`
> a {
Expand Down Expand Up @@ -37,11 +39,13 @@ const MenuWrapper = styled.div`
}
`;

const LinkEventOptions = [clickEvent] as const;

// Memoized menu item component
const MenuItem = React.memo(({ option, index }: { option: any; index: number }) => {
const handleClick = useCallback(() => {
if (!option.disabled && option.onClick) {
option.onClick();
option.onClick("click");
}
}, [option.disabled, option.onClick]);

Expand All @@ -58,10 +62,10 @@ const MenuItem = React.memo(({ option, index }: { option: any; index: number })

MenuItem.displayName = 'MenuItem';

const OptionItem = new MultiCompBuilder(
const OptionItemTmp = new MultiCompBuilder(
{
label: StringControl,
onClick: ActionSelectorControlInContext,
onClick: eventHandlerControl(LinkEventOptions),
hidden: BoolCodeControl,
disabled: BoolCodeControl,
},
Expand All @@ -73,17 +77,16 @@ const OptionItem = new MultiCompBuilder(
return (
<>
{children.label.propertyView({ label: trans("label") })}
{children.onClick.propertyView({
label: trans("table.action"),
placement: "table",
})}
{hiddenPropertyView(children)}
{disabledPropertyView(children)}
{children.onClick.propertyView()}
</>
);
})
.build();

const OptionItem = migrateOldData(OptionItemTmp, fixOldActionData);

// Memoized menu component
const LinksMenu = React.memo(({ options }: { options: any[] }) => {
const mountedRef = useRef(true);
Expand Down Expand Up @@ -114,7 +117,7 @@ const LinksMenu = React.memo(({ options }: { options: any[] }) => {

LinksMenu.displayName = 'LinksMenu';

export const ColumnLinksComp = (function () {
const ColumnLinksCompTmp = (function () {
const childrenMap = {
options: manualOptionsControl(OptionItem, {
initOptions: [{ label: trans("table.option1") }],
Expand All @@ -137,3 +140,5 @@ export const ColumnLinksComp = (function () {
))
.build();
})();

export const ColumnLinksComp = migrateOldData(ColumnLinksCompTmp, fixOldActionData);
Loading