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

fixes issue with form switch for name-value-editor on eventSources #4918

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import * as fuzzy from 'fuzzysearch';
import { useFormikContext, FormikValues } from 'formik';
import { FormGroup } from '@patternfly/react-core';
import { ServiceAccountModel } from '@console/internal/models';
import { NameValueEditor } from '@console/internal/components/utils/name-value-editor';
import { ResourceDropdownField, DropdownField, getFieldId } from '@console/shared';
import FormSection from '@console/dev-console/src/components/import/section/FormSection';
import NameValueEditorComponent from './NameValueEditorComponent';

interface ApiServerSectionProps {
namespace: string;
Expand Down Expand Up @@ -62,7 +62,7 @@ const ApiServerSection: React.FC<ApiServerSectionProps> = ({ namespace }) => {
return (
<FormSection title="ApiServerSource">
<FormGroup fieldId={fieldId} label="Resource" isRequired>
<NameValueEditor
<NameValueEditorComponent
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 use AsynCOmponent directly here instead of creating this new wrapper component?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I added a separate one as it's used in two of the forms under sources so this way thought of using same wrapper both places.

nameValuePairs={nameValue}
valueString="kind"
nameString="apiVersion"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as React from 'react';
import { AsyncComponent } from '@console/internal/components/utils/async';

const NameValueEditorComponent = (props) => (
<AsyncComponent
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to directly use this in the form. Naming it NameValueEditorComponent creates the confusion that this component does something different that the one from internal core package. I see that you've created this one because it is being used in two places. I won't mind having to use AsyncComponent twice but if you don't want that then maybe we should rename this to something else like AsyncNameValueEditor

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense , I'll update it

Copy link
Member Author

Choose a reason for hiding this comment

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

@rohitkrai03 have renamed to AsyncNameValueEditor and moved to form as well, PTAL.

loader={() =>
import('@console/internal/components/utils/name-value-editor').then((c) => c.NameValueEditor)
}
{...props}
/>
);

export default NameValueEditorComponent;
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import * as _ from 'lodash';
import { useFormikContext, FormikValues } from 'formik';
import { TextInputTypes, FormGroup } from '@patternfly/react-core';
import { InputField, getFieldId } from '@console/shared';
import { NameValueEditor } from '@console/internal/components/utils/name-value-editor';
import FormSection from '@console/dev-console/src/components/import/section/FormSection';
import NameValueEditorComponent from './NameValueEditorComponent';

const SinkBindingSection: React.FC = () => {
const { values, setFieldValue } = useFormikContext<FormikValues>();
Expand Down Expand Up @@ -47,7 +47,7 @@ const SinkBindingSection: React.FC = () => {
required
/>
<FormGroup fieldId={fieldId} label="Match Labels">
<NameValueEditor
<NameValueEditorComponent
nameValuePairs={nameValue}
valueString="Value"
nameString="Name"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as React from 'react';
import { shallow } from 'enzyme';
import { ResourceDropdownField } from '@console/shared';
import { NameValueEditor } from '@console/internal/components/utils/name-value-editor';
import FormSection from '@console/dev-console/src/components/import/section/FormSection';
import ApiServerSection from '../ApiServerSection';
import NameValueEditorComponent from '../NameValueEditorComponent';

jest.mock('formik', () => ({
useField: jest.fn(() => [{}, {}]),
Expand All @@ -26,7 +26,7 @@ describe('ApiServerSection', () => {

it('should render NameValueEditor', () => {
const wrapper = shallow(<ApiServerSection namespace="test-project" />);
const nameValueEditorField = wrapper.find(NameValueEditor);
const nameValueEditorField = wrapper.find(NameValueEditorComponent);
expect(nameValueEditorField).toHaveLength(1);
expect(nameValueEditorField.props().nameString).toBe('apiVersion');
expect(nameValueEditorField.props().valueString).toBe('kind');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as React from 'react';
import { shallow, ShallowWrapper } from 'enzyme';
import { InputField } from '@console/shared';
import { NameValueEditor } from '@console/internal/components/utils/name-value-editor';
import FormSection from '@console/dev-console/src/components/import/section/FormSection';
import SinkBindingSection from '../SinkBindingSection';
import NameValueEditorComponent from '../NameValueEditorComponent';

type SinkBindingSectionProps = React.ComponentProps<typeof SinkBindingSection>;

Expand All @@ -30,7 +30,7 @@ describe('SinkBindingSection', () => {
});

it('should render NameValueEditor', () => {
const nameValueEditorField = wrapper.find(NameValueEditor);
const nameValueEditorField = wrapper.find(NameValueEditorComponent);
expect(nameValueEditorField).toHaveLength(1);
expect(nameValueEditorField.props().nameString).toBe('Name');
expect(nameValueEditorField.props().valueString).toBe('Value');
Expand Down