/* eslint-disable no-console */ import React, { useEffect, useState, useCallback, useRef, ChangeEvent, useMemo, } from "react"; import Select, { SelectProps } from "rc-select"; import { DefaultValueType, LabelValueType, } from "rc-select/lib/interface/generator"; import MenuItemCheckBox, { DropdownStyles, MultiSelectContainer, StyledCheckbox, TextLabelWrapper, StyledLabel, } from "./index.styled"; import { CANVAS_CLASSNAME, MODAL_PORTAL_CLASSNAME, TextSize, } from "constants/WidgetConstants"; import Icon from "components/ads/Icon"; import { Button, Classes, InputGroup } from "@blueprintjs/core"; import { WidgetContainerDiff } from "widgets/WidgetUtils"; import { Colors } from "constants/Colors"; import { uniqBy } from "lodash"; const menuItemSelectedIcon = (props: { isSelected: boolean }) => { return ; }; export interface MultiSelectProps extends Required< Pick< SelectProps, "disabled" | "options" | "placeholder" | "loading" | "dropdownStyle" > > { mode?: "multiple" | "tags"; value: LabelValueType[]; onChange: (value: DefaultValueType) => void; serverSideFiltering: boolean; onFilterChange: (text: string) => void; dropDownWidth: number; width: number; labelText?: string; labelTextColor?: string; labelTextSize?: TextSize; labelStyle?: string; compactMode: boolean; isValid: boolean; allowSelectAll?: boolean; filterText?: string; widgetId: string; isFilterable: boolean; } const DEBOUNCE_TIMEOUT = 1000; function MultiSelectComponent({ allowSelectAll, compactMode, disabled, dropdownStyle, dropDownWidth, filterText, isFilterable, isValid, labelStyle, labelText, labelTextColor, labelTextSize, loading, onChange, onFilterChange, options, placeholder, serverSideFiltering, value, widgetId, width, }: MultiSelectProps): JSX.Element { const [isSelectAll, setIsSelectAll] = useState(false); const [filter, setFilter] = useState(filterText ?? ""); const [filteredOptions, setFilteredOptions] = useState(options); const _menu = useRef(null); const clearButton = useMemo( () => (