diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d6c570b2..c0c021c81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,30 @@ +## [1.21.1-fix-queryitem.valueselector.cascader-various-fixes.1](https://github.com/mParticle/aquarium/compare/v1.21.0...v1.21.1-fix-queryitem.valueselector.cascader-various-fixes.1) (2024-07-19) + +### Bug Fixes + +- a useEffect Hook has been added to detect if the value received from parameter changed ([d8c6f10](https://github.com/mParticle/aquarium/commit/d8c6f10b7ed3df7e742b0fb23a0657bf0102e843)) +- extra validation added to cascader selectedDisplayValue state ([ed3e159](https://github.com/mParticle/aquarium/commit/ed3e15910a1485b4426b49b13a72c8e4fe1dbda3)) + +## [1.21.1-fix-queryitem.valueselector.cascader-intial-value-validation.1](https://github.com/mParticle/aquarium/compare/v1.21.0...v1.21.1-fix-queryitem.valueselector.cascader-intial-value-validation.1) (2024-07-19) + +### Bug Fixes + +- a useEffect Hook has been added to detect if the value received from parameter changed ([d8c6f10](https://github.com/mParticle/aquarium/commit/d8c6f10b7ed3df7e742b0fb23a0657bf0102e843)) +- extra validation added to cascader selectedDisplayValue state ([ed3e159](https://github.com/mParticle/aquarium/commit/ed3e15910a1485b4426b49b13a72c8e4fe1dbda3)) + +## [1.21.1-fix-queryitem.valueselector.cascader-intial-value-validation.1](https://github.com/mParticle/aquarium/compare/v1.21.0...v1.21.1-fix-queryitem.valueselector.cascader-intial-value-validation.1) (2024-07-17) + +### Bug Fixes + +- a useEffect Hook has been added to detect if the value received from parameter changed ([d8c6f10](https://github.com/mParticle/aquarium/commit/d8c6f10b7ed3df7e742b0fb23a0657bf0102e843)) +- extra validation added to cascader selectedDisplayValue state ([ed3e159](https://github.com/mParticle/aquarium/commit/ed3e15910a1485b4426b49b13a72c8e4fe1dbda3)) + +## [1.21.1-fix-queryitem.valueselector.cascader-intial-value-validation.1](https://github.com/mParticle/aquarium/compare/v1.21.0...v1.21.1-fix-queryitem.valueselector.cascader-intial-value-validation.1) (2024-07-17) + +### Bug Fixes + +- extra validation added to cascader selectedDisplayValue state ([ed3e159](https://github.com/mParticle/aquarium/commit/ed3e15910a1485b4426b49b13a72c8e4fe1dbda3)) + # [1.21.0](https://github.com/mParticle/aquarium/compare/v1.20.0...v1.21.0) (2024-07-16) ### Features diff --git a/package-lock.json b/package-lock.json index 346c87413..3c68d13ec 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@mparticle/aquarium", - "version": "1.21.0", + "version": "1.21.1-fix-queryitem.valueselector.cascader-various-fixes.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@mparticle/aquarium", - "version": "1.21.0", + "version": "1.21.1-fix-queryitem.valueselector.cascader-various-fixes.1", "license": "Apache-2.0", "dependencies": { "lodash.clonedeep": "4.5.0" diff --git a/package.json b/package.json index d41b88957..758273aeb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mparticle/aquarium", - "version": "1.21.0", + "version": "1.21.1-fix-queryitem.valueselector.cascader-various-fixes.1", "description": "mParticle Component Library", "license": "Apache-2.0", "keywords": [ diff --git a/src/components/data-entry/QueryItem/Cascader.tsx b/src/components/data-entry/QueryItem/Cascader.tsx index 821937982..b96fcd61f 100644 --- a/src/components/data-entry/QueryItem/Cascader.tsx +++ b/src/components/data-entry/QueryItem/Cascader.tsx @@ -28,6 +28,7 @@ export interface ICascaderProps { onChange?: (values: Array, selectedOptions: any) => Promise loadData?: (value: string) => void value?: Array + classNameInput?: string } const Cascader = (props: ICascaderProps) => { @@ -38,7 +39,7 @@ const Cascader = (props: ICascaderProps) => { const [searchValue, setSearchValue] = useState('') const [selectedValue, setSelectedValue] = useState>(props.value ?? []) const [selectedDisplayValue, setSelectedDisplayValue] = useState( - props.value ? (props.value.slice(-1)[0] as any).label : '', + props.value && props.value.length > 0 ? (props.value.slice(-1)[0] as any).label : '', ) const [isOpen, setIsOpen] = useState(false) @@ -46,6 +47,12 @@ const Cascader = (props: ICascaderProps) => { setItems(props.options) }, [props.options]) + useEffect(() => { + if (props.value && props.value.length > 0) { + setSelectedValue(props.value) + } + }, [props.value]) + const onSearch = ({ target: { value } }: { target: { value: string } }) => { if (debouncedLoadData) { if (value.length > 3) { @@ -117,6 +124,8 @@ const Cascader = (props: ICascaderProps) => { if (isOpen) inputClasses += ' query-item--open' if (selectedValue && selectedValue.length !== 0) inputClasses += ' query-item--selected' if (props.errorMessage) inputClasses += ' query-item--error' + if (props.classNameInput) inputClasses += ` ${props.classNameInput}` + const displayValue = selectedDisplayValue ?? selectedValue.slice(-1) return ( @@ -179,4 +188,4 @@ const Cascader = (props: ICascaderProps) => { } } -export default Cascader \ No newline at end of file +export default Cascader