fixing partition dropdown (#2073)

This commit is contained in:
Robert Azizbekyan 2022-06-02 13:21:20 +04:00 committed by GitHub
parent c0b3ca3bc6
commit 70d3cee0bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 19 deletions

View file

@ -22,11 +22,19 @@ import {
getPartitionsByTopicName, getPartitionsByTopicName,
getTopicMessageSchemaFetched, getTopicMessageSchemaFetched,
} from 'redux/reducers/topics/selectors'; } from 'redux/reducers/topics/selectors';
import Select, { SelectOption } from 'components/common/Select/Select';
import useAppParams from 'lib/hooks/useAppParams'; import useAppParams from 'lib/hooks/useAppParams';
import validateMessage from './validateMessage'; import validateMessage from './validateMessage';
import * as S from './SendMessage.styled'; import * as S from './SendMessage.styled';
type FieldValues = Partial<{
key: string;
content: string;
headers: string;
partition: number | string;
}>;
const SendMessage: React.FC = () => { const SendMessage: React.FC = () => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const { clusterName, topicName } = useAppParams<RouteParamsClusterTopic>(); const { clusterName, topicName } = useAppParams<RouteParamsClusterTopic>();
@ -46,6 +54,10 @@ const SendMessage: React.FC = () => {
getPartitionsByTopicName(state, topicName) getPartitionsByTopicName(state, topicName)
); );
const schemaIsFetched = useAppSelector(getTopicMessageSchemaFetched); const schemaIsFetched = useAppSelector(getTopicMessageSchemaFetched);
const selectPartitionOptions: Array<SelectOption> = partitions.map((p) => {
const value = String(p.partition);
return { value, label: value };
});
const keyDefaultValue = React.useMemo(() => { const keyDefaultValue = React.useMemo(() => {
if (!schemaIsFetched || !messageSchema) { if (!schemaIsFetched || !messageSchema) {
@ -70,12 +82,11 @@ const SendMessage: React.FC = () => {
}, [messageSchema, schemaIsFetched]); }, [messageSchema, schemaIsFetched]);
const { const {
register,
handleSubmit, handleSubmit,
formState: { isSubmitting, isDirty }, formState: { isSubmitting, isDirty },
control, control,
reset, reset,
} = useForm({ } = useForm<FieldValues>({
mode: 'onChange', mode: 'onChange',
defaultValues: { defaultValues: {
key: keyDefaultValue, key: keyDefaultValue,
@ -156,24 +167,30 @@ const SendMessage: React.FC = () => {
<S.Wrapper> <S.Wrapper>
<form onSubmit={handleSubmit(onSubmit)}> <form onSubmit={handleSubmit(onSubmit)}>
<div className="columns"> <div className="columns">
<div className="column is-one-third"> <div>
<label className="label" htmlFor="select"> <label
className="label"
id="selectPartitionOptions"
htmlFor="selectPartitionOptions"
>
Partition Partition
</label> </label>
<div className="select is-block"> <Controller
<select control={control}
id="select" name="partition"
defaultValue={partitions[0].partition} defaultValue={selectPartitionOptions[0].value}
disabled={isSubmitting} render={({ field: { name, onChange } }) => (
{...register('partition')} <Select
> id="selectPartitionOptions"
{partitions.map((partition) => ( aria-labelledby="selectPartitionOptions"
<option key={partition.partition} value={partition.partition}> name={name}
{partition.partition} onChange={onChange}
</option> minWidth="100%"
))} options={selectPartitionOptions}
</select> value={selectPartitionOptions[0].value}
</div> />
)}
/>
</div> </div>
</div> </div>

View file

@ -64,7 +64,12 @@ const renderAndSubmitData = async (error: string[] = []) => {
await renderComponent(); await renderComponent();
expect(screen.queryByRole('progressbar')).not.toBeInTheDocument(); expect(screen.queryByRole('progressbar')).not.toBeInTheDocument();
await act(() => { await act(() => {
userEvent.selectOptions(screen.getByLabelText('Partition'), '0'); userEvent.click(screen.getByLabelText('Partition'));
});
await act(() => {
userEvent.click(screen.getAllByRole('option')[1]);
});
await act(() => {
(validateMessage as Mock).mockImplementation(() => error); (validateMessage as Mock).mockImplementation(() => error);
userEvent.click(screen.getByText('Send')); userEvent.click(screen.getByText('Send'));
}); });