import _ from 'lodash'; import React, { useState, useEffect, useRef } from 'react'; import SelectSearch, { fuzzySearch } from 'react-select-search'; export const Multiselect = function Multiselect({ height, properties, styles, exposedVariables, setExposedVariable, fireEvent, }) { const { label, value, values, display_values } = properties; const { borderRadius, visibility, disabledState } = styles; const selectRef = useRef(null); useEffect(() => { let newValues = []; if (_.intersection(values, value)?.length === value?.length) newValues = value; setExposedVariable('values', newValues); setCurrentValue(newValues); // eslint-disable-next-line react-hooks/exhaustive-deps }, [JSON.stringify(values)]); useEffect(() => { setExposedVariable('values', value); setCurrentValue(value); // eslint-disable-next-line react-hooks/exhaustive-deps }, [JSON.stringify(value)]); const [currentValue, setCurrentValue] = useState(() => value); let selectOptions = []; try { selectOptions = [ ...values.map((value, index) => { return { name: display_values[index], value: value }; }), ]; } catch (err) { console.log(err); } useEffect(() => { if (value && !currentValue) { setCurrentValue(properties.value); } if (JSON.stringify(exposedVariables.values) === '{}') { setCurrentValue(properties.value); } // eslint-disable-next-line react-hooks/exhaustive-deps }, []); useEffect(() => { selectRef.current.querySelector('.select-search__input').style.borderRadius = `${Number.parseFloat( borderRadius )}px`; // eslint-disable-next-line react-hooks/exhaustive-deps }, [borderRadius, selectRef.current]); const handleChange = (value) => { // setCurrentValue(value); setExposedVariable('values', value).then(() => fireEvent('onSelect')); }; return (