Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed missing notification on cloud storage creation page when manifest file is required #4921

Merged
merged 5 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,8 @@ export default function CreateCloudStorageForm(props: Props): JSX.Element {
}
}, []);

const onSubmit = async (): Promise<void> => {
let cloudStorageData: Record<string, any> = {};
const formValues = await form.validateFields();
cloudStorageData = { ...formValues };
const handleOnFinish = (formValues: CloudStorageForm): void => {
const cloudStorageData: Record<string, any> = { ...formValues };
// specific attributes
const specificAttributes = new URLSearchParams();

Expand Down Expand Up @@ -269,6 +267,20 @@ export default function CreateCloudStorageForm(props: Props): JSX.Element {
}
};

const handleOnFinishFailed = (
{ errorFields }: { errorFields: any[] },
): void => {
const [manifestsErrors] = errorFields.filter((value) => value.name[0] === 'manifests');
if (manifestsErrors) {
const msg = manifestsErrors.errors.join('; ');
notification.error({
message: 'Could not attach a cloud storage',
description: msg,
className: 'cvat-notification-attach-cloud-storage',
});
}
};

const resetCredentialsValues = (): void => {
form.setFieldsValue({
key: undefined,
Expand Down Expand Up @@ -607,7 +619,13 @@ export default function CreateCloudStorageForm(props: Props): JSX.Element {
};

return (
<Form className='cvat-cloud-storage-form' layout='vertical' form={form}>
<Form
className='cvat-cloud-storage-form'
layout='vertical'
form={form}
onFinish={(values: CloudStorageForm): void => handleOnFinish(values)}
onFinishFailed={(values: any): void => handleOnFinishFailed(values)}
>
<Form.Item
{...commonProps}
label='Display name'
Expand Down Expand Up @@ -672,7 +690,6 @@ export default function CreateCloudStorageForm(props: Props): JSX.Element {
<Button
type='primary'
htmlType='submit'
onClick={onSubmit}
className='cvat-cloud-storage-submit-button'
loading={loading}
disabled={loading}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export default function ManifestsManager(props: Props): JSX.Element {
return (
<>
<Form.Item
name='manifests'
className='cvat-manifests-manager-form-item'
label={(
<>
Marishka17 marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -87,9 +86,21 @@ export default function ManifestsManager(props: Props): JSX.Element {
</Tooltip>
</>
)}
rules={[{ required: true, message: 'Please, specify at least one manifest file' }]}
required
/>
<Form.List name='manifests'>
<Form.List
name='manifests'
rules={[
{
validator: async (_, names) => {
if (!names || !names.length) {
return Promise.reject(new Error('Please, specify at least one manifest file'));
}
return Promise.resolve();
},
Marishka17 marked this conversation as resolved.
Show resolved Hide resolved
},
]}
>
{
(fields) => (
<>
Expand Down