From 0a5b28702330981bf2db1f985c87ca41fbd46927 Mon Sep 17 00:00:00 2001 From: Lio B Date: Fri, 13 Dec 2024 12:06:06 +0100 Subject: [PATCH] feat: update quantity selector pci common (#14566) Co-authored-by: Lionel Bueno --- .../QuantitySelector.component.tsx | 143 +++++------------- 1 file changed, 41 insertions(+), 102 deletions(-) diff --git a/packages/manager/modules/manager-pci-common/src/components/quantity-selector/QuantitySelector.component.tsx b/packages/manager/modules/manager-pci-common/src/components/quantity-selector/QuantitySelector.component.tsx index c1ef57947151..5054b10c9015 100644 --- a/packages/manager/modules/manager-pci-common/src/components/quantity-selector/QuantitySelector.component.tsx +++ b/packages/manager/modules/manager-pci-common/src/components/quantity-selector/QuantitySelector.component.tsx @@ -1,25 +1,12 @@ -import React, { useEffect, useState } from 'react'; +import { ODS_THEME_COLOR_INTENT } from '@ovhcloud/ods-common-theming'; +import { ODS_ICON_NAME, OdsInputChangeEvent } from '@ovhcloud/ods-components'; import { - OsdsButton, - OsdsFormField, - OsdsIcon, - OsdsInput, - OsdsPopover, - OsdsPopoverContent, - OsdsQuantity, - OsdsText, + OdsFormField, + OdsIcon, + OdsPopover, + OdsQuantity, + OdsText, } from '@ovhcloud/ods-components/react'; -import { - ODS_THEME_COLOR_INTENT, - ODS_THEME_TYPOGRAPHY_SIZE, -} from '@ovhcloud/ods-common-theming'; -import { - ODS_BUTTON_SIZE, - ODS_BUTTON_VARIANT, - ODS_ICON_NAME, - ODS_ICON_SIZE, - ODS_INPUT_TYPE, -} from '@ovhcloud/ods-components'; import { useTranslation } from 'react-i18next'; import '../../translations/quantity-selector'; @@ -48,116 +35,68 @@ export function QuantitySelector({ contentClassName, }: Readonly) { const { t } = useTranslation('pci-quantity-selector'); - const [, setCounter] = useState(0); const error = { min: min !== undefined && value < min, max: max !== undefined && value > max, nan: Number.isNaN(value), }; - const isValid = !error.min && !error.max && !error.nan; - const forceRedraw = () => setCounter((i) => i + 1); - - // forced redraw to fix ODS quantity not refreshing - useEffect(forceRedraw, [min, max]); return ( - +
{label && ( - + {label} - + )} {labelHelpText && ( - - - {labelHelpText} - + <> +
+ +
+ + {labelHelpText} + + )}
{description && ( - + {description} - + )} - - - - - { - forceRedraw(); - onValueChange(Number(event.detail.value)); - }} - min={min} - max={max} - /> - max ? true : undefined} - > - - - + + onValueChange(Number(event.detail.value)) + } + min={min} + max={max} + name="quantity" + isDisabled={min !== undefined && value - 1 < min ? true : undefined} + />
{error.min && ( - + {t('common_field_error_min', { min })} - + )} {error.max && ( - + {t('common_field_error_max', { max })} - + )} {error.nan && ( - + {t('common_field_error_number')} - + )} -
+ ); }