import React, { useState } from "react"; import { MenuItem, Classes, Button as BButton, Alignment, } from "@blueprintjs/core"; import { CellWrapper, CellCheckboxWrapper, CellCheckbox, ActionWrapper, SortIconWrapper, DraggableHeaderWrapper, } from "./TableStyledWrappers"; import { ColumnAction } from "components/propertyControls/ColumnActionSelectorControl"; import { ColumnTypes, CellAlignmentTypes, VerticalAlignmentTypes, ColumnProperties, CellLayoutProperties, TableStyles, MenuItems, } from "./Constants"; import { isString, isEmpty, findIndex } from "lodash"; import PopoverVideo from "widgets/VideoWidget/component/PopoverVideo"; import Button from "components/editorComponents/Button"; import AutoToolTipComponent from "widgets/TableWidget/component/AutoToolTipComponent"; import { ControlIcons } from "icons/ControlIcons"; import { AnyStyledComponent } from "styled-components"; import styled from "constants/DefaultTheme"; import { Colors } from "constants/Colors"; import { DropdownOption } from "widgets/DropdownWidget/constants"; import { IconName, IconNames } from "@blueprintjs/icons"; import { Select, IItemRendererProps } from "@blueprintjs/select"; import { FontStyleTypes, TextSizes } from "constants/WidgetConstants"; import { noop } from "utils/AppsmithUtils"; import { ReactComponent as CheckBoxLineIcon } from "assets/icons/widget/table/checkbox-line.svg"; import { ReactComponent as CheckBoxCheckIcon } from "assets/icons/widget/table/checkbox-check.svg"; import { ButtonVariant, ButtonBoxShadow, ButtonBorderRadius, } from "components/constants"; //TODO(abstraction leak) import { StyledButton } from "widgets/IconButtonWidget/component"; import MenuButtonTableComponent from "./components/menuButtonTableComponent"; import { stopClickEventPropagation } from "utils/helpers"; export const renderCell = ( value: any, columnType: string, isHidden: boolean, cellProperties: CellLayoutProperties, tableWidth: number, isCellVisible: boolean, onClick: () => void = noop, isSelected?: boolean, ) => { switch (columnType) { case ColumnTypes.IMAGE: if (!value) { return ( ); } else if (!isString(value)) { return (
Invalid Image
); } // better regex: /(? {value .toString() // imageSplitRegex matched "," and char before it, so add space before "," .replace(imageSplitRegex, (match) => match.length > 1 ? `${match.charAt(0)} ,` : " ,", ) .split(imageSplitRegex) .map((item: string, index: number) => { if (imageUrlRegex.test(item) || base64ImageRegex.test(item)) { return (
{ if (isSelected) { e.stopPropagation(); } onClick(); }} >
); } else { return
Invalid Image
; } })} ); case ColumnTypes.VIDEO: const youtubeRegex = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=|\?v=)([^#&?]*).*/; if (!value) { return ( ); } else if (isString(value) && youtubeRegex.test(value)) { return ( ); } else { return ( Invalid Video Link ); } default: return ( {value && columnType === ColumnTypes.URL && cellProperties.displayText ? cellProperties.displayText : !!value ? value.toString() : ""} ); } }; interface RenderIconButtonProps { isSelected: boolean; columnActions?: ColumnAction[]; iconName?: IconName; buttonVariant: ButtonVariant; buttonColor: string; borderRadius: ButtonBorderRadius; boxShadow: ButtonBoxShadow; boxShadowColor: string; onCommandClick: (dynamicTrigger: string, onComplete: () => void) => void; isCellVisible: boolean; } export const renderIconButton = ( props: RenderIconButtonProps, isHidden: boolean, cellProperties: CellLayoutProperties, ) => { if (!props.columnActions) return ; return ( {props.columnActions.map((action: ColumnAction, index: number) => { return ( ); })} ); }; function IconButton(props: { iconName?: IconName; onCommandClick: (dynamicTrigger: string, onComplete: () => void) => void; isSelected: boolean; action: ColumnAction; buttonColor: string; buttonVariant: ButtonVariant; borderRadius: ButtonBorderRadius; boxShadow: ButtonBoxShadow; boxShadowColor: string; }): JSX.Element { const [loading, setLoading] = useState(false); const onComplete = () => { setLoading(false); }; const handlePropagation = ( e: React.MouseEvent, ) => { if (props.isSelected) { e.stopPropagation(); } }; const handleClick = () => { if (props.action.dynamicTrigger) { setLoading(true); props.onCommandClick(props.action.dynamicTrigger, onComplete); } }; return (
); } interface RenderActionProps { isSelected: boolean; columnActions?: ColumnAction[]; backgroundColor: string; buttonLabelColor: string; isDisabled: boolean; isCellVisible: boolean; onCommandClick: (dynamicTrigger: string, onComplete: () => void) => void; } export interface RenderMenuButtonProps { isSelected: boolean; // columnActions?: ColumnAction[]; label: string; isDisabled: boolean; isCellVisible: boolean; onCommandClick: (dynamicTrigger: string, onComplete?: () => void) => void; isCompact?: boolean; menuItems: MenuItems; menuVariant?: ButtonVariant; menuColor?: string; borderRadius?: ButtonBorderRadius; boxShadow?: ButtonBoxShadow; boxShadowColor?: string; iconName?: IconName; iconAlign?: Alignment; } export const renderActions = ( props: RenderActionProps, isHidden: boolean, cellProperties: CellLayoutProperties, ) => { if (!props.columnActions) return ( ); return ( {props.columnActions.map((action: ColumnAction, index: number) => { return ( ); })} ); }; export const renderMenuButton = ( props: RenderMenuButtonProps, isHidden: boolean, cellProperties: CellLayoutProperties, ) => { return ( ); }; interface MenuButtonProps extends Omit { action?: ColumnAction; } function MenuButton({ borderRadius, boxShadow, boxShadowColor, iconAlign, iconName, isCompact, isDisabled, isSelected, label, menuColor, menuItems, menuVariant, onCommandClick, }: MenuButtonProps): JSX.Element { const handlePropagation = ( e: React.MouseEvent, ) => { if (isSelected) { e.stopPropagation(); } }; const onItemClicked = (onClick?: string) => { if (onClick) { onCommandClick(onClick); } }; return (
); } function TableAction(props: { isSelected: boolean; action: ColumnAction; backgroundColor: string; buttonLabelColor: string; isDisabled: boolean; isCellVisible: boolean; onCommandClick: (dynamicTrigger: string, onComplete: () => void) => void; }) { const [loading, setLoading] = useState(false); const onComplete = () => { setLoading(false); }; return ( { if (props.isSelected) { e.stopPropagation(); } }} > {props.isCellVisible ? (