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
Conversation
/assign @rohitkrai03 |
}; | ||
|
||
const createResources = (rawFormData: any): Promise<K8sResourceKind> => { | ||
const knEventSourceResource = getEventSourcesDepResource(rawFormData); | ||
let knEventSourceResource = getEventSourcesDepResource(rawFormData); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 = () => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 />} |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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} />} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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,
}),
......
})
There was a problem hiding this comment.
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'} /> |
There was a problem hiding this comment.
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.
<YAMLEditorField name={'yamlData'} /> | |
<YAMLEditorField name="yamlData" /> |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
editorType?: string; | |
editorType?: EditorType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
</Form> | ||
); | ||
}) => { | ||
return ( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
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') { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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`; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolute imports first
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
232b781
to
8250960
Compare
setFieldValue('editorType', EditorType.Form); | ||
setFieldTouched('editorType', true); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
setFieldValue( | ||
'yamlData', | ||
safeDump(getEventSourceYaml(namespaceField.value, item.toLowerCase())), | ||
); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
?
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', { |
There was a problem hiding this comment.
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,
}),
.....
})
There was a problem hiding this comment.
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.
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, | |
}), | |
}); |
There was a problem hiding this comment.
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
export enum EditorType { | ||
YAML = 'YAMLEditor', | ||
Form = 'FormEditor', | ||
} | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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);
}
There was a problem hiding this comment.
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
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; | ||
}; |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PTAL #4960 (comment)
const [field] = useField('type'); | ||
return ( | ||
<FormSection fullWidth title={field.value}> | ||
<YAMLEditorField name="yamlData" /> |
There was a problem hiding this comment.
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} />
There was a problem hiding this comment.
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.
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: { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
/kind feature |
setFieldValue( | ||
'yamlData', | ||
safeDump(getEventSourceYaml(namespaceField.value, item.toLowerCase())), | ||
); |
There was a problem hiding this comment.
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" /> |
There was a problem hiding this comment.
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.
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', { |
There was a problem hiding this comment.
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.
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, | |
}), | |
}); |
@nemesis09 Needs rebase |
a70e0ae
to
7851ca0
Compare
d55ede8
to
5ec1670
Compare
@@ -33,9 +39,10 @@ const EventSource: React.FC<Props> = ({ | |||
activeApplication, | |||
contextSource, | |||
}) => { | |||
const typeEventSource = EventSources.CronJobSource; | |||
const typeEventSource = KnownEventSources.CronJobSource; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
/retest |
</Form> | ||
); | ||
}) => { | ||
return ( |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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} />} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const getResourceFromForm = (formData: any): K8sResourceKind => { | |
const getResourceFromFormData = (formData: any): K8sResourceKind => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
case Object.values(KnownEventSources).find( | ||
(knownEventSource) => formData.type === knownEventSource, | ||
): | ||
return getResourceFromForm(formData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
<FormFooter | ||
handleReset={handleReset} | ||
errorMessage={status && status.submitError} | ||
isSubmitting={isSubmitting} | ||
submitLabel="Create" | ||
sticky |
There was a problem hiding this comment.
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,
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
/retest |
8f3b5f8
to
37414af
Compare
There was a problem hiding this 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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 -
EventSource = values.type && !isKnownEventSource(values.type) ? <YAMLEditorSection /> : null; | |
EventSource = <YAMLEditorSection />; |
There was a problem hiding this comment.
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(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yamldata: yup.string(), | |
yamlData: yup.string(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
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. |
@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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
jira issue tracking the bug for validation |
/restest |
/retest |
/test e2e-gcp-console |
There was a problem hiding this 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
/lgtm |
Verified locally, works as expected /lgtm |
[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 |
/retest Please review the full test history for this PR and help us cut down flakes. |
1 similar comment
/retest Please review the full test history for this PR and help us cut down flakes. |
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:
Unit Test Coverage:
Browser Conformance: