Skip to content

Commit

Permalink
fix(frontend): fix postman trigger validation (#2025)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgeepc committed Feb 23, 2023
1 parent 6b04b92 commit 6ec95a8
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 63 deletions.
Expand Up @@ -37,18 +37,9 @@ const UploadCollection = () => {
onRefreshData();
}, [onRefreshData]);

const onValidateUrlChange = useCallback(async () => {
try {
await form.validateFields();
onIsFormValid(true);
} catch (err) {
onIsFormValid(false);
}
}, [form, onIsFormValid]);

useEffect(() => {
onValidateUrlChange();
}, [currentUrl, onValidateUrlChange]);
onValidate(null, form.getFieldsValue());
}, [currentUrl, form, onValidate]);

return (
<Step.Step>
Expand Down
Expand Up @@ -13,52 +13,50 @@ interface IProps {
form: TDraftTestForm<IPostmanValues>;
}

const UploadCollectionForm = ({form}: IProps) => {
return (
<S.FieldsContainer>
<Row gutter={12}>
<Col span={18}>
<Form.Item name="requests" hidden>
<Input type="hidden" />
</Form.Item>
<Form.Item name="variables" hidden>
<Input type="hidden" />
</Form.Item>
<CollectionFileField form={form} />
</Col>
</Row>
<Row gutter={12}>
<Col span={18}>
<EnvFileField form={form} />
</Col>
</Row>
<Row gutter={12}>
<Col span={18}>
<SelectTestFromCollection form={form} />
</Col>
</Row>
<Row gutter={12}>
<Col span={18}>
<RequestDetailsUrlInput />
</Col>
</Row>
<Row gutter={12}>
<Col span={18}>
<RequestDetailsHeadersInput />
</Col>
</Row>
<Row gutter={12}>
<Col span={18}>
<RequestDetailsAuthInput />
</Col>
</Row>
<Row gutter={12}>
<Col span={18}>
<BodyField body={Form.useWatch('body', form)} setBody={body => form.setFieldsValue({body})} />
</Col>
</Row>
</S.FieldsContainer>
);
};
const UploadCollectionForm = ({form}: IProps) => (
<S.FieldsContainer>
<Row gutter={12}>
<Col span={18}>
<Form.Item name="requests" hidden>
<Input type="hidden" />
</Form.Item>
<Form.Item name="variables" hidden>
<Input type="hidden" />
</Form.Item>
<CollectionFileField form={form} />
</Col>
</Row>
<Row gutter={12}>
<Col span={18}>
<EnvFileField form={form} />
</Col>
</Row>
<Row gutter={12}>
<Col span={18}>
<SelectTestFromCollection form={form} />
</Col>
</Row>
<Row gutter={12}>
<Col span={18}>
<RequestDetailsUrlInput />
</Col>
</Row>
<Row gutter={12}>
<Col span={18}>
<RequestDetailsHeadersInput />
</Col>
</Row>
<Row gutter={12}>
<Col span={18}>
<RequestDetailsAuthInput />
</Col>
</Row>
<Row gutter={12}>
<Col span={18}>
<BodyField body={Form.useWatch('body', form)} setBody={body => form.setFieldsValue({body})} />
</Col>
</Row>
</S.FieldsContainer>
);

export default UploadCollectionForm;
Expand Up @@ -10,7 +10,7 @@ interface IProps {

export const CollectionFileField = ({form}: IProps): React.ReactElement => (
<Form.Item
rules={[{required: true, message: 'Please enter a request url'}]}
rules={[{required: true, message: 'No file selected yet'}]}
name="collectionFile"
label="Upload Postman Collection"
>
Expand Down
Expand Up @@ -13,7 +13,7 @@ export const SelectTestFromCollection = ({form}: IProps) => {
const variables = useWatch<any[]>('variables');
return (
<Form.Item
rules={[{required: true, message: 'Please enter a request url'}]}
rules={[{required: true, message: 'No test selected yet'}]}
name="collectionTest"
label="Select test from Postman Collection"
>
Expand Down
4 changes: 1 addition & 3 deletions web/src/services/Triggers/Postman.service.tsx
Expand Up @@ -40,9 +40,7 @@ const Postman = (): IPostmanTriggerService => ({
async validateDraft(draft) {
const {collectionTest} = draft as IPostmanValues;

const isValid = Validator.required(collectionTest) && Validator.required(collectionTest);

return isValid && HttpService.validateDraft(draft);
return Validator.required(collectionTest) && HttpService.validateDraft(draft);
},
valuesFromRequest(requests, variables, identifier) {
const request = requests.find(({id}) => identifier === id);
Expand Down

0 comments on commit 6ec95a8

Please sign in to comment.