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

add support for creating camel source #4960

Merged
merged 1 commit into from Apr 17, 2020

Conversation

nemesis09
Copy link
Contributor

@nemesis09 nemesis09 commented Apr 8, 2020

Fixes:
https://issues.redhat.com/browse/ODC-2661

Analysis / Root cause:
User can't create CamelSource via webConsole

Solution Description:
Add support for creation of Camel Source to the Event Source Form in the Add flow

Screens:
camelsourceyaml

Unit Test Coverage:
Screenshot from 2020-04-08 10-02-42

Browser Conformance:

  • Firefox
  • Chrome
  • Safari
  • Edge

@invincibleJai
Copy link
Member

/assign @rohitkrai03

};

const createResources = (rawFormData: any): Promise<K8sResourceKind> => {
const knEventSourceResource = getEventSourcesDepResource(rawFormData);
let knEventSourceResource = getEventSourcesDepResource(rawFormData);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put the assignment into the else block. That way when the editor type is YAML, only one of the function is called to get the resource data.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

const knEventSourceResource = getEventSourcesDepResource(rawFormData);
let knEventSourceResource = getEventSourcesDepResource(rawFormData);
if (rawFormData.editorType === EditorType.YAML) {
knEventSourceResource = getEventSourcesResource(rawFormData);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what is the difference between getEventSourcesResource and getEventSourcesDepResource going by just the name of the functions. Better to name it in a way that gives more info upfront.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed the function name to getEventSourcesResourceFromYAML

import YAMLEditorField from '@console/shared/src/components/formik-fields/YAMLEditorField';
import FormSection from '@console/dev-console/src/components/import/section/FormSection';

const CamelSection: React.FC = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it specifically named CamelSection? I think this should be a generic YAMLSection where you take title as a prop based on the event source type. This should also work for dynamic event sources.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created YAMLEditorSection to take title from formik values

{values.type === EventSources.CronJobSource && <CronJobSection />}
{values.type === EventSources.SinkBinding && <SinkBindingSection />}
{values.type === EventSources.ApiServerSource && <ApiServerSection namespace={namespace} />}
{values.type === EventSources.CamelSource && <CamelSection />}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to check specifically for CamelSource. Just create a white list of all the event sources that have their own section, if the current event source type is in that list render their respective sections else just render default YAMLSection.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would even suggest to move all the logic of checking the event sources into a simple util function renderEventSoiurceSection that has switch case. The default case of that switch returns YAMLSection.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

{values.type === EventSources.SinkBinding && <SinkBindingSection />}
{values.type === EventSources.ApiServerSource && <ApiServerSection namespace={namespace} />}
{values.type === EventSources.CamelSource && <CamelSection />}
{values.editorType !== EditorType.YAML && <SinkSection namespace={namespace} />}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to have this new property called editorType in values. You can simply inverse the above logic and render the contents only when the event source selected is in that white list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the editor type property as to use in validation, as I needed to change the validation schema based on if it is a form or a yaml editor

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nemesis09 validation Schema can be handled based on type right?

something like

const ownEvenstSources = Object.keys(EventSources);
export const eventSourceValidationSchema = yup.object().shape({
  project: yup.object().when('type', {
    is: (type) => ownEvenstSources.includes(type),
    then: projectNameValidationSchema,
  }),
......
})

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and just handle it based on type here as well as @rohitkrai03 commented remove camelSource from EventSources enum i.e if type is not in enum show yamlEditor

const CamelSection: React.FC = () => {
return (
<FormSection fullWidth title="CamelSource">
<YAMLEditorField name={'yamlData'} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to pass a string inside curly braces.

Suggested change
<YAMLEditorField name={'yamlData'} />
<YAMLEditorField name="yamlData" />

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

ApiServerSource = 'ApiServerSource',
KafkaSource = 'KafkaSource',
CamelkSource = 'CamelSource',
CamelSource = 'CamelSource',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just remove this line from the enum and you have your list of event sources that have their own form sections.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -34,6 +33,8 @@ export interface EventSourceFormData {
type: string;
sink: KnativeServiceName;
data?: EventSourceData;
yamlData?: string;
editorType?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
editorType?: string;
editorType?: EditorType;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

</Form>
);
}) => {
return (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this else where in your pr too. Please address all. Prefer immediate return values with no return statement as was present before your change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still see that you have explicit return instead of directly returning the JSX.

const handleItemChange = React.useCallback(
(item: string) => {
const name = `data.${item.toLowerCase()}`;
setFieldValue(name, getEventSourceData(item.toLowerCase()));
setFieldTouched(name, true);
setFieldValue('editorType', EditorType.Form);
setFieldTouched('editorType', true);
if (item.toLowerCase() === 'camelsource') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems setting to be handling specific logic for a specific type here in this genetic component.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed it to check and load form or yaml editor values for any event source selected

eventSource: string,
): K8sResourceKind => {
let eventSourceModel: K8sKind;
const name = `${eventSource}-test`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there a name with test here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed the name to ${eventSource}

} from '../../utils/create-eventsources-utils';
import * as _ from 'lodash';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolute imports first

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@nemesis09 nemesis09 force-pushed the camel-form branch 2 times, most recently from 232b781 to 8250960 Compare April 9, 2020 09:16
Comment on lines 26 to 27
setFieldValue('editorType', EditorType.Form);
setFieldTouched('editorType', true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can avoid this field itself editorType if we rely on type

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


interface EventSourcesSelectorProps {
eventSourceList: NormalizedEventSources;
}

const EventSourcesSelector: React.FC<EventSourcesSelectorProps> = ({ eventSourceList }) => {
const { setFieldValue, setFieldTouched, validateForm } = useFormikContext<FormikValues>();
const [namespaceField] = useField('project.name');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we shouldn't have it here , maybe it's good to introduce a prop on this component onChange and handle these logic in callback in eventSourceForm and access from values

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

const name = `data.${item.toLowerCase()}`;
setFieldValue(name, getEventSourceData(item.toLowerCase()));
setFieldTouched(name, true);
if (isKnownEventSourceSelected(item)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we shouldn't have it here , maybe it's good to introduce a prop on this component onChange and handle these logic in callback in eventSourceForm

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 29 to 32
setFieldValue(
'yamlData',
safeDump(getEventSourceYaml(namespaceField.value, item.toLowerCase())),
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above , I think we shouldn't have it here , maybe it's good to introduce a prop on this component onChange and handle these logic in callback in eventSourceForm and access from values

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can simply move the whole loading yaml logic in YAMLSection itself. Just wrap this logic inside a useEffect with dependency on values.type. It will load the YAML if the section is rendered and when the type changes automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved the logic to eventSourceForm and passed down to EventSourceSelector as a prop.
it handles both the form and yaml editor cases.
should we move just the yaml logic and keep the form logic in handleChange ?

Comment on lines 68 to 76
project: yup.object().when('editorType', {
is: EditorType.Form,
then: projectNameValidationSchema,
}),
application: yup.object().when('editorType', {
is: EditorType.Form,
then: applicationNameValidationSchema,
}),
name: yup.string().when('editorType', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can have validation based on type itself and remove editorType field WDYT?

const ownEvenstSources = Object.keys(EventSources);
export const eventSourceValidationSchema = yup.object().shape({
  project: yup.object().when('type', {
    is: (type) => ownEvenstSources.includes(type),
    then: projectNameValidationSchema,
  }),
.....
})

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or simply add .when to the object and add all the properties based on that one check.

Suggested change
project: yup.object().when('editorType', {
is: EditorType.Form,
then: projectNameValidationSchema,
}),
application: yup.object().when('editorType', {
is: EditorType.Form,
then: applicationNameValidationSchema,
}),
name: yup.string().when('editorType', {
export const eventSourceValidationSchema = yup.object().when('type', {
is: (type) => Object.keys(EventSources).includes(type),
then: yup.object().shape({
project: projectNameValidationSchema,
application: applicationNameValidationSchema,
name: nameValidationSchema,
sink: sinkServiceSchema,
data: sourceDataSpecSchema,
}),
otherwise: yup.object().shape({
data: sourceDataSpecSchema,
}),
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is: (type) => Object.keys(EventSources).includes(type), was throwing error with this message - type is not a function
approached it using yup.lazy(). PTAL

Comment on lines 8 to 12
export enum EditorType {
YAML = 'YAMLEditor',
Form = 'FormEditor',
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if use type for conditional validation schema , we may not need this as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (isKnownEventSourceSelected(rawFormData.type)) {
knEventSourceResource = getEventSourcesDepResource(rawFormData);
} else {
knEventSourceResource = getEventSourcesResourceFromYAML(rawFormData);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need getEventSourcesResourceFromYAML ?

if (isKnownEventSourceSelected(rawFormData.type)) {
      knEventSourceResource = getEventSourcesDepResource(rawFormData);
 } else {
     knEventSourceResource = safeLoad(rawFormData.chartValuesYAML);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getEventSourcesResourceFromYAML adds labels and annotations to the yamldata and returns the updated yaml.
safeLoad(rawFormData.yamlData) would load the sample yaml for the event source, without labels and annotations
I updated the function getEventSourcesDepResource to handle both and moved the logic for handling yamldata and formdata to separate functions. PTAL

Comment on lines 191 to 215
export const getEventSourcesResourceFromYAML = (formData: any): K8sResourceKind => {
const {
application: { name: applicationName },
yamlData,
} = formData;
const eventYaml = safeLoad(yamlData);
const { name } = eventYaml.metadata;
const defaultLabel = getAppLabels(name, applicationName);
const { apiVersion, kind, spec, metadata } = eventYaml;
const eventSourceResource: K8sResourceKind = {
apiVersion,
kind,
metadata: {
...metadata,
labels: {
...defaultLabel,
},
annotations,
},
spec: {
...spec,
},
};
return eventSourceResource;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can avoid it based on #4960 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const [field] = useField('type');
return (
<FormSection fullWidth title={field.value}>
<YAMLEditorField name="yamlData" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will be good have onSave here as well to validate yaml as and when it gets Saved

<YAMLEditorField name="yamlData" onSave={handleSubmit}  />

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, this onSave is triggered when CTRL+S or CMD+S is pressed by the user. If we don't want that key binding to submit the form in case there are still some form fields left then we should not add this.

Comment on lines 154 to 270
export const getEventSourceYaml = (namespace: string, eventSource: string): K8sResourceKind => {
let eventSourceModel: K8sKind;
const name = `${eventSource}`;
switch (eventSource) {
case 'camelsource':
eventSourceModel = EventSourceCamelModel;
break;
default:
eventSourceModel = {
apiGroup: KNATIVE_EVENT_SOURCE_APIGROUP_DEP,
apiVersion: 'v1alpha1',
kind: '',
label: '',
labelPlural: '',
plural: '',
abbr: '',
};
}
return {
apiVersion: `${eventSourceModel.apiGroup}/${eventSourceModel.apiVersion}`,
kind: eventSourceModel.kind,
metadata: {
name,
namespace,
},
spec: {
sink: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make use of getEventSourcesDepResource itself instead of this method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the code for getEventSourcesDepResource. PTAL

@invincibleJai
Copy link
Member

/kind feature

@openshift-ci-robot openshift-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Apr 9, 2020
Comment on lines 29 to 32
setFieldValue(
'yamlData',
safeDump(getEventSourceYaml(namespaceField.value, item.toLowerCase())),
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can simply move the whole loading yaml logic in YAMLSection itself. Just wrap this logic inside a useEffect with dependency on values.type. It will load the YAML if the section is rendered and when the type changes automatically.

const [field] = useField('type');
return (
<FormSection fullWidth title={field.value}>
<YAMLEditorField name="yamlData" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, this onSave is triggered when CTRL+S or CMD+S is pressed by the user. If we don't want that key binding to submit the form in case there are still some form fields left then we should not add this.

Comment on lines 68 to 76
project: yup.object().when('editorType', {
is: EditorType.Form,
then: projectNameValidationSchema,
}),
application: yup.object().when('editorType', {
is: EditorType.Form,
then: applicationNameValidationSchema,
}),
name: yup.string().when('editorType', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or simply add .when to the object and add all the properties based on that one check.

Suggested change
project: yup.object().when('editorType', {
is: EditorType.Form,
then: projectNameValidationSchema,
}),
application: yup.object().when('editorType', {
is: EditorType.Form,
then: applicationNameValidationSchema,
}),
name: yup.string().when('editorType', {
export const eventSourceValidationSchema = yup.object().when('type', {
is: (type) => Object.keys(EventSources).includes(type),
then: yup.object().shape({
project: projectNameValidationSchema,
application: applicationNameValidationSchema,
name: nameValidationSchema,
sink: sinkServiceSchema,
data: sourceDataSpecSchema,
}),
otherwise: yup.object().shape({
data: sourceDataSpecSchema,
}),
});

@invincibleJai
Copy link
Member

@nemesis09 Needs rebase

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 9, 2020
@nemesis09 nemesis09 force-pushed the camel-form branch 2 times, most recently from a70e0ae to 7851ca0 Compare April 13, 2020 01:22
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 13, 2020
@nemesis09 nemesis09 force-pushed the camel-form branch 2 times, most recently from d55ede8 to 5ec1670 Compare April 13, 2020 02:14
@@ -33,9 +39,10 @@ const EventSource: React.FC<Props> = ({
activeApplication,
contextSource,
}) => {
const typeEventSource = EventSources.CronJobSource;
const typeEventSource = KnownEventSources.CronJobSource;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to rename this enum? This creates unnecessary changes all across the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought KnownEventSources should be more descriptive for a name

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should have what;s there currently i.e EventSources we can do just this refactor later if need be as in this PR it brings lot of other chnages. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. we can change the name if required in a separate PR
reverted to EventSources

const EventSourceSection: React.FC = renderEventSourceSection(values.type);
const { setFieldValue, setFieldTouched, validateForm } = useFormikContext<FormikValues>();
const [namespaceField] = useField('project.name');
const handleEventSourceChange = React.useCallback(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have you moved this handler out of the selector component and into this parent form component?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved handler function to EventSourceSelector

formData: any,
isYamlData?: boolean,
): K8sResourceKind => {
if (isYamlData) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not make use of getEventSourceResource itself to send whatever proper resource data needs to be sent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated getEventSourceResource to handle all event sources

return eventSourceResource;
};

const createResourceFromForm = (formData: any): K8sResourceKind => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name doesn't make sense here since no actual resource is being created. Its just creating a data structure like the resource which is then used to create actual resource.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed to getResourceFromForm

import { useField } from 'formik';

const YAMLEditorSection: React.FC = () => {
const [field] = useField('type');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should get the type as a prop and this yaml editor section should act as a field component and take care of loading and updating the yamlData of your form state based on the prop type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated YAMLEditorSection to take prop type and accordingly update yamlData

const eventSourceItems = Object.keys(eventSourceList).length;
const handleItemChange = React.useCallback(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have you removed all this logic from here?

const knEventSourceResource = getEventSourceResource(rawFormData);
const knEventSourceResource = getEventSourcesDepResource(
rawFormData,
!isKnownEventSourceSelected(rawFormData.type),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to do this check here? Why can't this util function do this itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated util function to handle the check

@nemesis09
Copy link
Contributor Author

/retest

</Form>
);
}) => {
return (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still see that you have explicit return instead of directly returning the JSX.

return (
<Form className="co-deploy-image" onSubmit={handleSubmit}>
<EventSourcesSelector eventSourceList={useEventSourceList(namespace)} />
<AsyncComponent
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need an Async loader here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated code to use React.createElement in the util instead

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you so keen on having this in utils only? Why not just create an EventSourceSection component which handles this?

loader={eventSourceSectionLoader(values.type)}
eventSourceType={values.type}
/>
{isKnownEventSourceSelected(values.type) && <SinkSection namespace={namespace} />}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you have two same checks here? Merge them together.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


const YAMLEditorSection: React.FC<YAMLEditorSectionProps> = ({ eventSourceType }) => {
const { setFieldValue, setFieldTouched } = useFormikContext<FormikValues>();
const [namespaceField] = useField('project.name');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add another prop for namespace instead of using useField.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

React.useEffect(() => {
setFieldValue('yamlData', safeDump(getEventSourceYaml(namespaceField.value, eventSourceType)));
setFieldTouched('yamlData', true);
// eslint-disable-next-line react-hooks/exhaustive-deps
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have you disabled the linting rule here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while using useField, the dependency was not allowing the component to load.
removed disable linting rule after updating code to take namespace as a prop

return eventSourceResource;
};

const getResourceFromForm = (formData: any): K8sResourceKind => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const getResourceFromForm = (formData: any): K8sResourceKind => {
const getResourceFromFormData = (formData: any): K8sResourceKind => {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 122 to 125
case Object.values(KnownEventSources).find(
(knownEventSource) => formData.type === knownEventSource,
):
return getResourceFromForm(formData);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
case Object.values(KnownEventSources).find(
(knownEventSource) => formData.type === knownEventSource,
):
return getResourceFromForm(formData);
case KnownEventSources.CronJobSource:
case KnownEventSources.ContainerSource:
case KnownEventSources.ApiServerSource:
case KnownEventSources.SinkBinding:
return getResourceFromForm(formData);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 13, 2020
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 13, 2020
<FormFooter
handleReset={handleReset}
errorMessage={status && status.submitError}
isSubmitting={isSubmitting}
submitLabel="Create"
sticky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have you removed sticky here? I thought all of our forms need to have sticky form footer,

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nemesis09 yes we need that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it slipped while resolving merge conflicts. added sticky

import ApiServerSection from '../components/add/event-sources/ApiServerSection';
import KafkaSourceSection from '../components/add/event-sources/KafkaSourceSection';
// eslint-disable-next-line import/no-cycle
import YAMLEditorSection from '../components/add/event-sources/YAMLEditorSection';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have you disabled this eslint rule here? You cannot just disable any eslint rule that you encounter, they're there for a reason. This creates a cyclic dependency. You cannot have the eventSourceSectionLoader in the utils. Move it out to a separate component.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved the util out to a separate file

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 16, 2020
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 16, 2020
@nemesis09
Copy link
Contributor Author

/retest

@nemesis09 nemesis09 force-pushed the camel-form branch 2 times, most recently from 8f3b5f8 to 37414af Compare April 16, 2020 19:56
Copy link
Contributor

@serenamarie125 serenamarie125 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nemesis09 should the Create button be enabled by default? I thought that the provided YAML should be enough for the user to create an event source without having to provide any additional information. If that's the case Create should be enabled by default. FYI @invincibleJai


const EventSourceSection: React.FC<EventSourceSectionProps> = ({ projects, namespace }) => {
const { values } = useFormikContext<FormikValues>();
let EventSource: React.ReactElement;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this line here instead of doing the check in default case - if (!values.type) return null. We don't want to render anything as the section unless and until a type is selected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

EventSource = <ContainerSourceSection />;
break;
default:
EventSource = values.type && !isKnownEventSource(values.type) ? <YAMLEditorSection /> : null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once you have the above check you can simply say -

Suggested change
EventSource = values.type && !isKnownEventSource(values.type) ? <YAMLEditorSection /> : null;
EventSource = <YAMLEditorSection />;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

});
}
return yup.object().shape({
yamldata: yup.string(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
yamldata: yup.string(),
yamlData: yup.string(),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@nemesis09
Copy link
Contributor Author

@nemesis09 should the Create button be enabled by default? I thought that the provided YAML should be enough for the user to create an event source without having to provide any additional information. If that's the case Create should be enabled by default. FYI @invincibleJai

Currently the yaml editor loads with a prefilled common structure for the event source with an empty spec and the user has to fill in the spec according to the event source requirements.

@invincibleJai
Copy link
Member

@nemesis09 should the Create button be enabled by default? I thought that the provided YAML should be enough for the user to create an event source without having to provide any additional information. If that's the case Create should be enabled by default. FYI @invincibleJai

@serenamarie125 yes Create button should be enabled by default , there is a validation issue with formik which we are facing in some places will log an issue to track it @nemesis09 pls log an issue for it.

Provided yaml won't be complete as we don't have information from CRDs so providing with apiGroup/version/kind and sink in spec

Copy link
Contributor

@rohitkrai03 rohitkrai03 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 16, 2020
@nemesis09
Copy link
Contributor Author

jira issue tracking the bug for validation
https://issues.redhat.com/browse/ODC-3591

@invincibleJai
Copy link
Member

/restest

@invincibleJai
Copy link
Member

/retest

@nemesis09
Copy link
Contributor Author

/test e2e-gcp-console

Copy link
Contributor

@serenamarie125 serenamarie125 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the answers @nemesis09 and @invincibleJai ! Approved by UX

@rohitkrai03
Copy link
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 17, 2020
@invincibleJai
Copy link
Member

Verified locally, works as expected

/lgtm

@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: invincibleJai, nemesis09, rohitkrai03, serenamarie125

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

1 similar comment
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-merge-robot openshift-merge-robot merged commit 5dc9aa8 into openshift:master Apr 17, 2020
@spadgett spadgett added this to the v4.5 milestone Apr 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. component/dev-console Related to dev-console component/knative Related to knative-plugin kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants