Skip to content

Commit

Permalink
validate event sources form and enable create button on yaml form
Browse files Browse the repository at this point in the history
fix unit tests

fix lint error

fix unit tests
  • Loading branch information
sahil143 committed May 18, 2020
1 parent dfed4d1 commit 5275820
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ const EventSource: React.FC<Props> = ({ namespace, activeApplication, contextSou
initialValues={initialValues}
onSubmit={handleSubmit}
onReset={history.goBack}
validateOnBlur={false}
validateOnChange={false}
validationSchema={eventSourceValidationSchema}
>
{(props) => <EventSourceForm {...props} namespace={namespace} />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as _ from 'lodash';
import { useFormikContext, FormikValues } from 'formik';
import { FormGroup } from '@patternfly/react-core';
import { AsyncComponent } from '@console/internal/components/utils/async';
import { DropdownField, getFieldId } from '@console/shared';
import { DropdownField, getFieldId, useFormikValidationFix } from '@console/shared';
import FormSection from '@console/dev-console/src/components/import/section/FormSection';
import ServiceAccountDropdown from '../../dropdowns/ServiceAccountDropdown';

Expand Down Expand Up @@ -33,6 +33,7 @@ const ApiServerSection: React.FC = () => {
Ref: 'Ref',
Resource: 'Resource',
};
useFormikValidationFix(values);
const fieldId = getFieldId(values.type, 'res-input');
return (
<FormSection title="ApiServerSource" extraMargin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import * as _ from 'lodash';
import { useFormikContext, FormikValues } from 'formik';
import { TextInputTypes, FormGroup } from '@patternfly/react-core';
import { InputField, MultiColumnField } from '@console/shared';
import { InputField, MultiColumnField, useFormikValidationFix } from '@console/shared';
import { AsyncComponent } from '@console/internal/components/utils';
import FormSection from '@console/dev-console/src/components/import/section/FormSection';
import { getSuggestedName } from '@console/dev-console/src/utils/imagestream-utils';
Expand Down Expand Up @@ -35,6 +35,7 @@ const ContainerSourceSection: React.FC = () => {
},
[setFieldValue],
);
useFormikValidationFix(values);
return (
<FormSection title="ContainerSource" extraMargin>
<h3 className="co-section-heading-tertiary">Container</h3>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import * as React from 'react';
import { useFormikContext } from 'formik';
import { TextInputTypes } from '@patternfly/react-core';
import { InputField } from '@console/shared';
import { InputField, useFormikValidationFix } from '@console/shared';
import FormSection from '@console/dev-console/src/components/import/section/FormSection';

const CronJobSection: React.FC = () => (
<FormSection title="CronJobSource" extraMargin>
<InputField type={TextInputTypes.text} name="data.cronjobsource.data" label="Data" />
<InputField
type={TextInputTypes.text}
name="data.cronjobsource.schedule"
label="Schedule"
helpText="Schedule is described using the unix-cron string format (* * * * *)"
required
/>
</FormSection>
);
const CronJobSection: React.FC = () => {
const { values } = useFormikContext();
useFormikValidationFix(values);
return (
<FormSection title="CronJobSource" extraMargin>
<InputField type={TextInputTypes.text} name="data.cronjobsource.data" label="Data" />
<InputField
type={TextInputTypes.text}
name="data.cronjobsource.schedule"
label="Schedule"
helpText="Schedule is described using the unix-cron string format (* * * * *)"
required
/>
</FormSection>
);
};

export default CronJobSection;
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ interface EventSourcesSelectorProps {

const EventSourcesSelector: React.FC<EventSourcesSelectorProps> = ({ eventSourceList }) => {
const eventSourceItems = Object.keys(eventSourceList).length;
const { setFieldValue, setFieldTouched, validateForm } = useFormikContext<FormikValues>();
const { setFieldValue, setFieldTouched, validateForm, setErrors } = useFormikContext<
FormikValues
>();
const handleItemChange = React.useCallback(
(item: string) => {
setErrors({});
if (isKnownEventSource(item)) {
const nameData = `data.${item.toLowerCase()}`;
const sourceData = getEventSourceData(item.toLowerCase());
Expand All @@ -33,7 +36,7 @@ const EventSourcesSelector: React.FC<EventSourcesSelectorProps> = ({ eventSource
setFieldTouched('apiVersion', true);
validateForm();
},
[setFieldValue, setFieldTouched, validateForm],
[setErrors, setFieldValue, setFieldTouched, validateForm],
);

const itemSelectorField = (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import * as React from 'react';
import { useFormikContext } from 'formik';
import FormSection from '@console/dev-console/src/components/import/section/FormSection';
import { InputField } from '@console/shared';
import { InputField, useFormikValidationFix } from '@console/shared';
import { TextInputTypes } from '@patternfly/react-core';
import KafkaSourceNetSection from './KafkaSourceNetSection';
import ServiceAccountDropdown from '../../dropdowns/ServiceAccountDropdown';

const KafkaSourceSection: React.FC = () => {
const { values } = useFormikContext();
useFormikValidationFix(values);
return (
<FormSection title="KafkaSource" extraMargin>
<InputField
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import * as React from 'react';
import { useFormikContext } from 'formik';
import { TextInputTypes } from '@patternfly/react-core';
import { InputField } from '@console/shared';
import { InputField, useFormikValidationFix } from '@console/shared';
import FormSection from '@console/dev-console/src/components/import/section/FormSection';

const PingSourceSection: React.FC = () => (
<FormSection title="PingSource" extraMargin>
<InputField type={TextInputTypes.text} name="data.pingsource.data" label="Data" />
<InputField
type={TextInputTypes.text}
name="data.pingsource.schedule"
label="Schedule"
helpText="Schedule is described using the unix-cron string format (* * * * *)"
required
/>
</FormSection>
);
const PingSourceSection: React.FC = () => {
const { values } = useFormikContext();
useFormikValidationFix(values);
return (
<FormSection title="PingSource" extraMargin>
<InputField type={TextInputTypes.text} name="data.pingsource.data" label="Data" />
<InputField
type={TextInputTypes.text}
name="data.pingsource.schedule"
label="Schedule"
helpText="Schedule is described using the unix-cron string format (* * * * *)"
required
/>
</FormSection>
);
};

export default PingSourceSection;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import * as _ from 'lodash';
import { useFormikContext, FormikValues } from 'formik';
import { TextInputTypes, FormGroup } from '@patternfly/react-core';
import { InputField, getFieldId } from '@console/shared';
import { InputField, getFieldId, useFormikValidationFix } from '@console/shared';
import { AsyncComponent } from '@console/internal/components/utils/async';
import FormSection from '@console/dev-console/src/components/import/section/FormSection';

Expand All @@ -13,6 +13,7 @@ const SinkBindingSection: React.FC = () => {
? _.map(initVal, (key, val) => [val, key])
: [['', '']];
const [nameValue, setNameValue] = React.useState(initialValueResources);
useFormikValidationFix(values);
const handleNameValuePairs = React.useCallback(
({ nameValuePairs }) => {
let updatedNameValuePairs = {};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { safeDump } from 'js-yaml';
import { useFormikContext, FormikValues } from 'formik';
import { YAMLEditorField } from '@console/shared';
import { YAMLEditorField, useFormikValidationFix } from '@console/shared';
import FormSection from '@console/dev-console/src/components/import/section/FormSection';
import {
getEventSourcesDepResource,
Expand All @@ -26,6 +26,8 @@ const YAMLEditorSection: React.FC = () => {
}
}, [values.type, setFieldTouched, setFieldValue]);

useFormikValidationFix(values);

return (
<FormSection title={values.type} flexLayout fullWidth>
<YAMLEditorField name="yamlData" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jest.mock('formik', () => ({
setFieldValue: jest.fn(),
setFieldTouched: jest.fn(),
validateForm: jest.fn(),
setErrors: jest.fn(),
values: {
type: 'SinkBinding',
name: 'sink-binding',
Expand Down

0 comments on commit 5275820

Please sign in to comment.