Skip to content

Commit

Permalink
add support for creating camel source
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesis09 committed Apr 16, 2020
1 parent de83364 commit b9e072d
Show file tree
Hide file tree
Showing 27 changed files with 276 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import ApplicationSelector from './ApplicationSelector';
export interface AppSectionProps {
project: ProjectData;
noProjectsAvailable?: boolean;
extraMargin?: boolean;
}

const AppSection: React.FC<AppSectionProps> = ({ project, noProjectsAvailable }) => {
const AppSection: React.FC<AppSectionProps> = ({ project, noProjectsAvailable, extraMargin }) => {
const [initialApplication] = useField('application.initial');
const [formType] = useField('formType');
return (
<FormSection title="General">
<FormSection title="General" extraMargin={extraMargin}>
{noProjectsAvailable && (
<>
<InputField
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.odc-form-section__heading {
margin: 0;
.odc-form-section {
&__heading {
margin: 0;
}
&--extra-margin {
margin: var(--pf-global--spacer--md) 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,32 @@ export interface FormSectionProps {
subTitle?: React.ReactNode;
fullWidth?: boolean;
children: React.ReactNode;
flexLayout?: boolean;
extraMargin?: boolean;
}

const FormSection: React.FC<FormSectionProps> = ({ title, subTitle, fullWidth, children }) => (
<div className={cx('pf-c-form', { 'co-m-pane__form': !fullWidth })}>
const flexStyle: React.CSSProperties = {
display: 'flex',
flex: 1,
flexDirection: 'column',
margin: 'var(--pf-global--spacer--md) 0',
};

const FormSection: React.FC<FormSectionProps> = ({
title,
subTitle,
fullWidth,
children,
flexLayout,
extraMargin,
}) => (
<div
className={cx('pf-c-form', {
'co-m-pane__form': !fullWidth,
'odc-form-section--extra-margin': extraMargin,
})}
style={flexLayout ? flexStyle : {}}
>
{title && <h2 className="odc-form-section__heading">{title}</h2>}
{subTitle && <FormHelperText isHidden={false}>{subTitle}</FormHelperText>}
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`PipelineResourceSection component It should match the previous pipeline
Array [
<div
className="pf-c-form"
style={Object {}}
>
<h2
className="odc-form-section__heading"
Expand All @@ -25,6 +26,7 @@ Array [
</div>,
<div
className="pf-c-form"
style={Object {}}
>
<h2
className="odc-form-section__heading"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ Object {
"app": "test-app",
"app.kubernetes.io/component": "test-app",
"app.kubernetes.io/instance": "test-app",
"app.kubernetes.io/name": "",
"app.kubernetes.io/part-of": "mock-app",
"app.openshift.io/runtime": "",
"app.openshift.io/runtime-version": "latest",
},
"name": "test-app",
Expand Down Expand Up @@ -49,9 +47,7 @@ Object {
"app": "test-app",
"app.kubernetes.io/component": "test-app",
"app.kubernetes.io/instance": "test-app",
"app.kubernetes.io/name": undefined,
"app.kubernetes.io/part-of": "mock-app",
"app.openshift.io/runtime": undefined,
"app.openshift.io/runtime-version": "latest",
},
"name": "test-app",
Expand Down Expand Up @@ -84,9 +80,7 @@ Object {
"app": "test-app",
"app.kubernetes.io/component": "test-app",
"app.kubernetes.io/instance": "test-app",
"app.kubernetes.io/name": "",
"app.kubernetes.io/part-of": "mock-app",
"app.openshift.io/runtime": "",
"app.openshift.io/runtime-version": "latest",
},
"name": "test-app",
Expand Down Expand Up @@ -116,9 +110,7 @@ Object {
"app": "test-app",
"app.kubernetes.io/component": "test-app",
"app.kubernetes.io/instance": "test-app",
"app.kubernetes.io/name": undefined,
"app.kubernetes.io/part-of": "mock-app",
"app.openshift.io/runtime": undefined,
"app.openshift.io/runtime-version": "latest",
},
"name": "test-app",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ export const getAppLabels = (
app: name,
'app.kubernetes.io/instance': name,
'app.kubernetes.io/component': name,
'app.kubernetes.io/name': imageStreamName,
'app.openshift.io/runtime': imageStreamName,
...(imageStreamName && {
'app.kubernetes.io/name': imageStreamName,
'app.openshift.io/runtime': imageStreamName,
}),
};

if (application && application.trim().length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const AdvancedSection: React.FC = () => {
};

return (
<FormSection title="Advanced Options" fullWidth>
<FormSection title="Advanced Options" fullWidth extraMargin>
<ProgressiveList
text="Click on the names to access advanced options for"
visibleItems={visibleItems}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const EventSource: React.FC<Props> = ({
},
type: '',
data: {},
yamlData: '',
};

const createResources = (rawFormData: any): Promise<K8sResourceKind> => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
import * as React from 'react';
import * as _ from 'lodash';
import { FormikProps, FormikValues } from 'formik';
import { FormFooter } from '@console/shared';
import { Form } from '@patternfly/react-core';
import AppSection from '@console/dev-console/src/components/import/app/AppSection';
import { FormFooter, FlexForm } from '@console/shared';
import { FirehoseList } from '@console/dev-console/src/components/import/import-types';
import { useEventSourceList } from '../../utils/create-eventsources-utils';
import CronJobSection from './event-sources/CronJobSection';
import SinkBindingSection from './event-sources/SinkBindingSection';
import ApiServerSection from './event-sources/ApiServerSection';
import SinkSection from './event-sources/SinkSection';
import { EventSources } from './import-types';
import EventSourcesSelector from './event-sources/EventSourcesSelector';
import KafkaSourceSection from './event-sources/KafkaSourceSection';
import AdvancedSection from './AdvancedSection';
import ContainerSourceSection from './event-sources/ContainerSourceSection';
import { useEventSourceList } from '../../utils/create-eventsources-utils';
import EventSourceSection from './event-sources/EventSourceSection';

interface OwnProps {
namespace: string;
projects: FirehoseList;
}

const EventSourceForm: React.FC<FormikProps<FormikValues> & OwnProps> = ({
values,
errors,
handleSubmit,
handleReset,
Expand All @@ -32,29 +22,19 @@ const EventSourceForm: React.FC<FormikProps<FormikValues> & OwnProps> = ({
namespace,
projects,
}) => (
<Form className="co-deploy-image" onSubmit={handleSubmit}>
<FlexForm onSubmit={handleSubmit}>
<EventSourcesSelector eventSourceList={useEventSourceList(namespace)} />
{values.type === EventSources.CronJobSource && <CronJobSection />}
{values.type === EventSources.SinkBinding && <SinkBindingSection />}
{values.type === EventSources.ApiServerSource && <ApiServerSection />}
{values.type === EventSources.KafkaSource && <KafkaSourceSection />}
{values.type === EventSources.ContainerSource && <ContainerSourceSection />}
<SinkSection namespace={namespace} />
<AppSection
project={values.project}
noProjectsAvailable={projects?.loaded && _.isEmpty(projects.data)}
/>
{values.type === EventSources.KafkaSource && <AdvancedSection />}
<EventSourceSection projects={projects} namespace={namespace} />
<FormFooter
handleReset={handleReset}
errorMessage={status && status.submitError}
isSubmitting={isSubmitting}
submitLabel="Create"
sticky
disableSubmit={!dirty || !_.isEmpty(errors)}
resetLabel="Cancel"
sticky
/>
</Form>
</FlexForm>
);

export default EventSourceForm;
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { Helmet } from 'react-helmet';
import { RouteComponentProps } from 'react-router';
import { PageBody } from '@console/shared';
import { PageHeading, Firehose } from '@console/internal/components/utils';
import { ProjectModel } from '@console/internal/models';
import NamespacedPage, {
Expand All @@ -21,15 +22,15 @@ const EventSourcePage: React.FC<EventSourcePageProps> = ({ match, location }) =>
<title>Event Sources</title>
</Helmet>
<PageHeading title="Event Sources" />
<div className="co-m-pane__body">
<PageBody flexLayout>
<Firehose resources={resources}>
<EventSource
namespace={namespace}
selectedApplication={searchParams.get(QUERY_PROPERTIES.APPLICATION)}
contextSource={searchParams.get(QUERY_PROPERTIES.CONTEXT_SOURCE)}
/>
</Firehose>
</div>
</PageBody>
</NamespacedPage>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import * as React from 'react';
import { shallow } from 'enzyme';
import { cloneDeep } from 'lodash';
import { formikFormProps } from '@console/shared/src/test-utils/formik-props-utils';
import EventSourceForm from '../EventSourceForm';
import EventSourcesSelector from '../event-sources/EventSourcesSelector';
import CronJobSection from '../event-sources/CronJobSection';
import SinkSection from '../event-sources/SinkSection';
import { getDefaultEventingData } from '../../../utils/__tests__/knative-serving-data';
import { EventSources } from '../import-types';
import KafkaSourceSection from '../event-sources/KafkaSourceSection';
import AdvancedSection from '../AdvancedSection';
import EventSourceSection from '../event-sources/EventSourceSection';

type EventSourceFormProps = React.ComponentProps<typeof EventSourceForm>;
let formProps: EventSourceFormProps;
Expand All @@ -17,77 +14,23 @@ describe('EventSource Form', () => {
const defaultEventingData = getDefaultEventingData(EventSources.CronJobSource);
beforeEach(() => {
formProps = {
...formikFormProps,
values: {
type: 'CronJobSource',
},
namespace: 'myapp',
errors: {},
touched: {},
isSubmitting: true,
isValidating: true,
status: {},
submitCount: 0,
dirty: false,
handleReset: jest.fn(),
handleSubmit: jest.fn(),
getFieldProps: jest.fn(),
handleBlur: jest.fn(),
handleChange: jest.fn(),
initialErrors: {},
initialStatus: {},
initialTouched: {},
isValid: true,
projects: { loaded: true, loadError: '', data: [] },
initialValues: defaultEventingData,
registerField: jest.fn(),
resetForm: jest.fn(),
setErrors: jest.fn(),
setFieldError: jest.fn(),
setFieldTouched: jest.fn(),
setFieldValue: jest.fn(),
setFormikState: jest.fn(),
setStatus: jest.fn(),
setSubmitting: jest.fn(),
setTouched: jest.fn(),
setValues: jest.fn(),
submitForm: jest.fn(),
unregisterField: jest.fn(),
validateField: jest.fn(),
validateForm: jest.fn(),
getFieldMeta: jest.fn(),
validateOnBlur: true,
validateOnChange: true,
};
});
it('should render SinkSection , EventSourcesSelector for all sources', () => {

it('should render EventSourcesSelector ', () => {
const eventSourceForm = shallow(<EventSourceForm {...formProps} />);
expect(eventSourceForm.find(SinkSection)).toHaveLength(1);
expect(eventSourceForm.find(EventSourcesSelector)).toHaveLength(1);
});

it('should render CronJobSection for cronJob source', () => {
it('should render EventSourceSection ', () => {
const eventSourceForm = shallow(<EventSourceForm {...formProps} />);
expect(eventSourceForm.find(CronJobSection)).toHaveLength(1);
});

it('should not render CronJobSection for other source', () => {
const modFormProps = cloneDeep(formProps);
modFormProps.values.type = 'SinkBinding';
const eventSourceForm = shallow(<EventSourceForm {...modFormProps} />);
expect(eventSourceForm.find(CronJobSection)).toHaveLength(0);
});

it('should render KafkaSource section when KafkaSource type is selected', () => {
const modFormProps = cloneDeep(formProps);
modFormProps.values.type = 'KafkaSource';
const eventSourceForm = shallow(<EventSourceForm {...modFormProps} />);
expect(eventSourceForm.find(KafkaSourceSection)).toHaveLength(1);
});

it('should render Advanced options section when KafkaSource type is selected', () => {
const modFormProps = cloneDeep(formProps);
modFormProps.values.type = 'KafkaSource';
const eventSourceForm = shallow(<EventSourceForm {...modFormProps} />);
expect(eventSourceForm.find(AdvancedSection)).toHaveLength(1);
expect(eventSourceForm.find(EventSourceSection)).toHaveLength(1);
});
});

0 comments on commit b9e072d

Please sign in to comment.