-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Max consecutive auto reply values are not properly displayed in the UI (
#216) * Don't delete a property if it's used buy someother property * Don't show auto reply button while showing retry chat button * WIP: Show numeric stepper input for max consecutive auto reply * Show numeric stepper input for max consecutive auto reply * Show numeric stepper input for max consecutive auto reply * Update error message
- Loading branch information
1 parent
77713fd
commit 6573b47
Showing
8 changed files
with
488 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
app/src/client/components/form/NumericStepperWithClearButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React, { useState } from 'react'; | ||
|
||
interface formElementObjectValues { | ||
default?: string; | ||
description?: string; | ||
enum?: string[]; | ||
title?: string; | ||
type?: string; | ||
} | ||
|
||
interface NumericStepperWithClearButtonProps { | ||
id: string; | ||
formElementObject?: formElementObjectValues; | ||
value: number; // Pass the current value as a prop | ||
onChange: (value: number | null) => void; // Prop to handle value changes | ||
} | ||
|
||
export const NumericStepperWithClearButton: React.FC<NumericStepperWithClearButtonProps> = ({ | ||
id, | ||
formElementObject, | ||
value, | ||
onChange, | ||
}) => { | ||
const [inputValue, setInputValue] = useState<number | null>(value); | ||
|
||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const targetValue = e.target.value; | ||
const newValue = targetValue === '' ? null : parseInt(e.target.value, 10); | ||
setInputValue(newValue); | ||
onChange(newValue); // Call parent onChange with new value | ||
}; | ||
|
||
const handleClear = (e: React.MouseEvent<HTMLButtonElement>) => { | ||
e.preventDefault(); | ||
setInputValue(null); // Clear the local input | ||
onChange(null); // Pass the empty string to parent onChange | ||
}; | ||
|
||
return ( | ||
<div className='flex gap-4'> | ||
<input | ||
className='my-2 p-2 border rounded w-full' | ||
type='number' | ||
data-testid='numeric-stepper' | ||
id={id} | ||
placeholder={`${formElementObject?.description}. Enter a number or 'Clear' to use the default value 'None'.`} | ||
value={inputValue ? inputValue : ''} | ||
onChange={handleChange} | ||
min='1' | ||
/> | ||
<button | ||
onClick={handleClear} | ||
className='rounded-md my-2 px-3.5 py-2.5 text-sm bg-airt-primary text-airt-font-base hover:bg-opacity-85 shadow-sm focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600' | ||
> | ||
Clear | ||
</button> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
app/src/client/tests/NumericStepperWithClearButton.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { describe, test, expect, vi } from 'vitest'; | ||
import { render, fireEvent, screen } from '@testing-library/react'; | ||
import { NumericStepperWithClearButton } from '../components/form/NumericStepperWithClearButton'; | ||
|
||
const renderNumericStepper = (value: any, onChange: any, formElementObject = {}) => { | ||
return render( | ||
<NumericStepperWithClearButton | ||
id='test-numeric-stepper' | ||
value={value} | ||
onChange={onChange} | ||
formElementObject={formElementObject} | ||
/> | ||
); | ||
}; | ||
|
||
describe('NumericStepperWithClearButton', () => { | ||
test('renders and updates value on user interaction with complex formElementObject', () => { | ||
const mockChangeHandler = vi.fn(); | ||
const formElementObject = { | ||
default: '10', | ||
description: 'Age', | ||
enum: ['5', '10', '15'], | ||
title: 'Select Age', | ||
type: 'number', | ||
}; | ||
|
||
const { getByPlaceholderText } = renderNumericStepper(5, mockChangeHandler, formElementObject); | ||
|
||
// Check if component renders with correct placeholder based on description and default value | ||
const placeholderText = "Age. Enter a number or 'Clear' to use the default value 'None'."; | ||
expect(getByPlaceholderText(placeholderText)).toBeInTheDocument(); | ||
|
||
// Simulate user changing value | ||
const input = screen.getByTestId('numeric-stepper'); | ||
fireEvent.change(input, { target: { value: '15' } }); | ||
expect(mockChangeHandler).toHaveBeenCalledWith(15); | ||
expect(input).toHaveValue(15); | ||
|
||
// Test clear functionality | ||
const button = screen.getByRole('button', { name: 'Clear' }); | ||
fireEvent.click(button); | ||
expect(mockChangeHandler).toHaveBeenCalledWith(null); | ||
expect(input).toHaveValue(null); | ||
}); | ||
}); |
Oops, something went wrong.