fix: provide access to currentRow in table widget menubutton items (#15457)

This commit is contained in:
balajisoundar 2022-08-01 10:31:34 +05:30 committed by GitHub
parent de23ea9d61
commit a6d37625a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 229 additions and 16 deletions

View File

@ -0,0 +1,162 @@
import { ObjectsRegistry } from "../../../../../../support/Objects/Registry";
const propPane = ObjectsRegistry.PropertyPane;
describe("Custom column alias functionality", () => {
before(() => {
cy.dragAndDropToCanvas("tablewidgetv2", { x: 150, y: 300 });
});
it("1. should check that menuitems background color property has access to currentRow", () => {
cy.openPropertyPane("tablewidgetv2");
cy.editColumn("task");
cy.changeColumnType("Menu Button");
cy.get(".t--add-menu-item-btn").click();
cy.get(".t--edit-column-btn").click();
cy.get("[data-colindex='1'][data-rowindex='0'] .bp3-button").click({
force: true,
});
cy.get(".table-menu-button-popover li a").should(
"have.css",
"background-color",
"rgb(255, 255, 255)",
);
cy.get("[data-colindex='1'][data-rowindex='1'] .bp3-button").click({
force: true,
});
cy.get(".table-menu-button-popover li a").should(
"have.css",
"background-color",
"rgb(255, 255, 255)",
);
cy.get(".t--property-control-backgroundcolor .t--js-toggle").click();
propPane.UpdatePropertyFieldValue(
"Background color",
"{{currentRow.step === '#1' ? '#f00' : '#0f0'}}",
);
cy.wait(2000);
cy.get("[data-colindex='1'][data-rowindex='0'] .bp3-button").click({
force: true,
});
cy.get(".table-menu-button-popover li a").should(
"have.css",
"background-color",
"rgb(255, 0, 0)",
);
cy.get("[data-colindex='1'][data-rowindex='1'] .bp3-button").click({
force: true,
});
cy.get(".table-menu-button-popover li a").should(
"have.css",
"background-color",
"rgb(0, 255, 0)",
);
});
it("2. should check that menuitems text color property has access to currentRow", () => {
cy.get("[data-colindex='1'][data-rowindex='0'] .bp3-button").click({
force: true,
});
cy.get(".table-menu-button-popover li a").should(
"have.css",
"color",
"rgb(24, 32, 38)",
);
cy.get("[data-colindex='1'][data-rowindex='1'] .bp3-button").click({
force: true,
});
cy.get(".table-menu-button-popover li a").should(
"have.css",
"color",
"rgb(24, 32, 38)",
);
cy.get(".t--property-control-textcolor .t--js-toggle").click();
propPane.UpdatePropertyFieldValue(
"Text color",
"{{currentRow.step === '#1' ? '#f00' : '#0f0'}}",
);
cy.wait(2000);
cy.get("[data-colindex='1'][data-rowindex='0'] .bp3-button").click({
force: true,
});
cy.get(".table-menu-button-popover li a").should(
"have.css",
"color",
"rgb(255, 0, 0)",
);
cy.get("[data-colindex='1'][data-rowindex='1'] .bp3-button").click({
force: true,
});
cy.get(".table-menu-button-popover li a").should(
"have.css",
"color",
"rgb(0, 255, 0)",
);
});
it("3. should check that menuitems isDisabled property has access to currentRow", () => {
cy.get("[data-colindex='1'][data-rowindex='0'] .bp3-button").click({
force: true,
});
cy.get(".table-menu-button-popover li a").should(
"have.css",
"background-color",
"rgb(255, 0, 0)",
);
cy.get("[data-colindex='1'][data-rowindex='1'] .bp3-button").click({
force: true,
});
cy.get(".table-menu-button-popover li a").should(
"have.css",
"background-color",
"rgb(0, 255, 0)",
);
cy.get(".t--property-control-disabled .t--js-toggle").click();
propPane.UpdatePropertyFieldValue(
"Disabled",
"{{currentRow.step === '#1'}}",
);
cy.wait(2000);
cy.get("[data-colindex='1'][data-rowindex='0'] .bp3-button").click({
force: true,
});
cy.get(".table-menu-button-popover li a").should(
"have.css",
"background-color",
"rgb(250, 250, 250)",
);
cy.get("[data-colindex='1'][data-rowindex='1'] .bp3-button").click({
force: true,
});
cy.get(".table-menu-button-popover li a").should(
"have.css",
"background-color",
"rgb(0, 255, 0)",
);
});
it("4. should check that menuitems visible property has access to currentRow", () => {
cy.get("[data-colindex='1'][data-rowindex='0'] .bp3-button").click({
force: true,
});
cy.get(".table-menu-button-popover li a").should("exist");
cy.get("[data-colindex='1'][data-rowindex='1'] .bp3-button").click({
force: true,
});
cy.get(".table-menu-button-popover li a").should("exist");
cy.get(".t--property-control-visible .t--js-toggle").click();
propPane.UpdatePropertyFieldValue(
"Visible",
"{{currentRow.step === '#1'}}",
);
cy.wait(2000);
cy.get("[data-colindex='1'][data-rowindex='0'] .bp3-button").click({
force: true,
});
cy.get(".table-menu-button-popover li a").should("exist");
cy.get("[data-colindex='1'][data-rowindex='1'] .bp3-button").click({
force: true,
});
cy.get(".table-menu-button-popover li a").should("not.exist");
});
});

View File

@ -25,6 +25,7 @@ function MenuButton({
menuItems, menuItems,
menuVariant, menuVariant,
onCommandClick, onCommandClick,
rowIndex,
}: MenuButtonProps): JSX.Element { }: MenuButtonProps): JSX.Element {
const handlePropagation = ( const handlePropagation = (
e: React.MouseEvent<HTMLDivElement, MouseEvent>, e: React.MouseEvent<HTMLDivElement, MouseEvent>,
@ -53,6 +54,7 @@ function MenuButton({
menuItems={{ ...menuItems }} menuItems={{ ...menuItems }}
menuVariant={menuVariant} menuVariant={menuVariant}
onItemClicked={onItemClicked} onItemClicked={onItemClicked}
rowIndex={rowIndex}
/> />
</div> </div>
); );
@ -71,6 +73,7 @@ export interface RenderMenuButtonProps extends BaseCellComponentProps {
boxShadow?: string; boxShadow?: string;
iconName?: IconName; iconName?: IconName;
iconAlign?: Alignment; iconAlign?: Alignment;
rowIndex: number;
} }
export function MenuButtonCell(props: RenderMenuButtonProps) { export function MenuButtonCell(props: RenderMenuButtonProps) {

View File

@ -25,6 +25,10 @@ import { MenuItems } from "../Constants";
import tinycolor from "tinycolor2"; import tinycolor from "tinycolor2";
import { Colors } from "constants/Colors"; import { Colors } from "constants/Colors";
import orderBy from "lodash/orderBy"; import orderBy from "lodash/orderBy";
import {
getBooleanPropertyValue,
getPropertyValue,
} from "widgets/TableWidgetV2/widget/utilities";
const MenuButtonContainer = styled.div` const MenuButtonContainer = styled.div`
width: 100%; width: 100%;
@ -197,15 +201,16 @@ interface PopoverContentProps {
menuItems: MenuItems; menuItems: MenuItems;
onItemClicked: (onClick: string | undefined) => void; onItemClicked: (onClick: string | undefined) => void;
isCompact?: boolean; isCompact?: boolean;
rowIndex: number;
} }
function PopoverContent(props: PopoverContentProps) { function PopoverContent(props: PopoverContentProps) {
const { isCompact, menuItems: itemsObj, onItemClicked } = props; const { isCompact, menuItems: itemsObj, onItemClicked, rowIndex } = props;
if (!itemsObj) return <StyledMenu />; if (!itemsObj) return <StyledMenu />;
const visibleItems = Object.keys(itemsObj) const visibleItems = Object.keys(itemsObj)
.map((itemKey) => itemsObj[itemKey]) .map((itemKey) => itemsObj[itemKey])
.filter((item) => item.isVisible); .filter((item) => getBooleanPropertyValue(item.isVisible, rowIndex));
const items = orderBy(visibleItems, ["index"], ["asc"]); const items = orderBy(visibleItems, ["index"], ["asc"]);
@ -224,8 +229,10 @@ function PopoverContent(props: PopoverContentProps) {
return ( return (
<BaseMenuItem <BaseMenuItem
backgroundColor={backgroundColor || "#FFFFFF"} backgroundColor={
disabled={isDisabled} getPropertyValue(backgroundColor, rowIndex) || "#FFFFFF"
}
disabled={getBooleanPropertyValue(isDisabled, rowIndex)}
icon={ icon={
iconAlign !== Alignment.RIGHT ? ( iconAlign !== Alignment.RIGHT ? (
<Icon color={iconColor} icon={iconName || undefined} /> <Icon color={iconColor} icon={iconName || undefined} />
@ -244,7 +251,7 @@ function PopoverContent(props: PopoverContentProps) {
} }
onClick={() => onItemClicked(onClick)} onClick={() => onItemClicked(onClick)}
text={label} text={label}
textColor={textColor} textColor={getPropertyValue(textColor, rowIndex)}
/> />
); );
}); });
@ -306,6 +313,7 @@ export interface MenuButtonComponentProps {
iconName?: IconName; iconName?: IconName;
iconAlign?: Alignment; iconAlign?: Alignment;
onItemClicked: (onClick: string | undefined) => void; onItemClicked: (onClick: string | undefined) => void;
rowIndex: number;
} }
function MenuButtonTableComponent(props: MenuButtonComponentProps) { function MenuButtonTableComponent(props: MenuButtonComponentProps) {
@ -322,6 +330,7 @@ function MenuButtonTableComponent(props: MenuButtonComponentProps) {
menuItems, menuItems,
menuVariant, menuVariant,
onItemClicked, onItemClicked,
rowIndex,
} = props; } = props;
return ( return (
@ -341,6 +350,7 @@ function MenuButtonTableComponent(props: MenuButtonComponentProps) {
isCompact={isCompact} isCompact={isCompact}
menuItems={menuItems} menuItems={menuItems}
onItemClicked={onItemClicked} onItemClicked={onItemClicked}
rowIndex={rowIndex}
/> />
} }
disabled={isDisabled} disabled={isDisabled}

View File

@ -1425,6 +1425,7 @@ class TableWidgetV2 extends BaseWidget<TableWidgetProps, WidgetState> {
eventType: EventType.ON_CLICK, eventType: EventType.ON_CLICK,
}) })
} }
rowIndex={originalIndex}
textColor={cellProperties.textColor} textColor={cellProperties.textColor}
textSize={cellProperties.textSize} textSize={cellProperties.textSize}
verticalAlignment={cellProperties.verticalAlignment} verticalAlignment={cellProperties.verticalAlignment}

View File

@ -275,6 +275,7 @@ export default {
propertyName: "menuVariant", propertyName: "menuVariant",
label: "Menu Variant", label: "Menu Variant",
controlType: "DROP_DOWN", controlType: "DROP_DOWN",
customJSControl: "TABLE_COMPUTE_VALUE",
helpText: "Sets the variant of the menu button", helpText: "Sets the variant of the menu button",
options: [ options: [
{ {
@ -297,15 +298,19 @@ export default {
}, },
isBindProperty: true, isBindProperty: true,
isTriggerProperty: false, isTriggerProperty: false,
defaultValue: ButtonVariantTypes.PRIMARY,
validation: { validation: {
type: ValidationTypes.TEXT, type: ValidationTypes.TABLE_PROPERTY,
params: { params: {
default: ButtonVariantTypes.PRIMARY, type: ValidationTypes.TEXT,
allowedValues: [ params: {
ButtonVariantTypes.PRIMARY, default: ButtonVariantTypes.PRIMARY,
ButtonVariantTypes.SECONDARY, allowedValues: [
ButtonVariantTypes.TERTIARY, ButtonVariantTypes.PRIMARY,
], ButtonVariantTypes.SECONDARY,
ButtonVariantTypes.TERTIARY,
],
},
}, },
}, },
}, },

View File

@ -46,30 +46,56 @@ export default {
helpText: "Sets the background color of a menu item", helpText: "Sets the background color of a menu item",
label: "Background color", label: "Background color",
controlType: "PRIMARY_COLUMNS_COLOR_PICKER_V2", controlType: "PRIMARY_COLUMNS_COLOR_PICKER_V2",
customJSControl: "TABLE_COMPUTE_VALUE",
isJSConvertible: true, isJSConvertible: true,
isBindProperty: true, isBindProperty: true,
isTriggerProperty: false, isTriggerProperty: false,
dependencies: ["primaryColumns", "columnOrder"], dependencies: ["primaryColumns", "columnOrder"],
validation: { type: ValidationTypes.TEXT }, validation: {
type: ValidationTypes.TABLE_PROPERTY,
params: {
type: ValidationTypes.TEXT,
params: {
regex: /^(?![<|{{]).+/,
},
},
},
}, },
{ {
propertyName: "textColor", propertyName: "textColor",
helpText: "Sets the text color of a menu item", helpText: "Sets the text color of a menu item",
label: "Text color", label: "Text color",
controlType: "PRIMARY_COLUMNS_COLOR_PICKER_V2", controlType: "PRIMARY_COLUMNS_COLOR_PICKER_V2",
isBindProperty: false, customJSControl: "TABLE_COMPUTE_VALUE",
isJSConvertible: true,
isBindProperty: true,
isTriggerProperty: false, isTriggerProperty: false,
dependencies: ["primaryColumns", "columnOrder"], dependencies: ["primaryColumns", "columnOrder"],
validation: {
type: ValidationTypes.TABLE_PROPERTY,
params: {
type: ValidationTypes.TEXT,
params: {
regex: /^(?![<|{{]).+/,
},
},
},
}, },
{ {
propertyName: "isDisabled", propertyName: "isDisabled",
helpText: "Disables input to the widget", helpText: "Disables input to the widget",
label: "Disabled", label: "Disabled",
controlType: "SWITCH", controlType: "SWITCH",
customJSControl: "TABLE_COMPUTE_VALUE",
isJSConvertible: true, isJSConvertible: true,
isBindProperty: true, isBindProperty: true,
isTriggerProperty: false, isTriggerProperty: false,
validation: { type: ValidationTypes.BOOLEAN }, validation: {
type: ValidationTypes.TABLE_PROPERTY,
params: {
type: ValidationTypes.BOOLEAN,
},
},
dependencies: ["primaryColumns", "columnOrder"], dependencies: ["primaryColumns", "columnOrder"],
}, },
{ {
@ -77,10 +103,16 @@ export default {
helpText: "Controls the visibility of the widget", helpText: "Controls the visibility of the widget",
label: "Visible", label: "Visible",
controlType: "SWITCH", controlType: "SWITCH",
customJSControl: "TABLE_COMPUTE_VALUE",
isJSConvertible: true, isJSConvertible: true,
isBindProperty: true, isBindProperty: true,
isTriggerProperty: false, isTriggerProperty: false,
validation: { type: ValidationTypes.BOOLEAN }, validation: {
type: ValidationTypes.TABLE_PROPERTY,
params: {
type: ValidationTypes.BOOLEAN,
},
},
dependencies: ["primaryColumns", "columnOrder"], dependencies: ["primaryColumns", "columnOrder"],
}, },
], ],