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

Move Formik fields and form helpers from @console/dev-console to @console/shared #3516

Merged

Conversation

jtomasek
Copy link

@jtomasek jtomasek commented Nov 21, 2019

Depends on #3469

@openshift-ci-robot openshift-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 21, 2019
@jtomasek jtomasek mentioned this pull request Nov 21, 2019
@openshift-ci-robot openshift-ci-robot added component/core Related to console core functionality component/dev-console Related to dev-console component/knative Related to knative-plugin component/metal3 Related to metal3-plugin component/shared Related to console-shared labels Nov 21, 2019
@christianvogt
Copy link
Contributor

cc @rohitkrai03

@jtomasek jtomasek force-pushed the formik-fields-console-shared branch 2 times, most recently from 01778f6 to 1c82e90 Compare November 27, 2019 12:21
Copy link
Contributor

@andrewballantyne andrewballantyne left a comment

Choose a reason for hiding this comment

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

@rohitkrai03 should be back on Monday... I didn't see this PR until today.

/assign

import ResourceDropdown from '../dropdown/ResourceDropdown';
import ResourceDropdown from '@console/dev-console/src/components/dropdown/ResourceDropdown';
Copy link
Contributor

Choose a reason for hiding this comment

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

This will be a problem. shared cannot depend on dev-console. The ResourceDropdown doesn't appear to have any dependencies on dev-console, so I suggest moving that over to shared as well.

Copy link
Author

Choose a reason for hiding this comment

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

I am happy to move the ResourceDropdown as well. Just a question: Are the ResourceDropdown, ResourceDropdownField and ResourceLimitField generic enough? Can we expect them to be reused by other packages? If those are fairly specific to dev-console, we should keep them there instead.

Copy link
Author

Choose a reason for hiding this comment

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

Never mind, I already see that it is being used by noobaa-storage-plugin already, so answer is yes.

Copy link
Author

Choose a reason for hiding this comment

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

Done

import { getFieldId } from '@console/dev-console/src/components/formik-fields/field-utils';
import { CheckboxFieldProps } from '@console/dev-console/src/components/formik-fields/field-types';
import { getCheckboxFieldId } from './field-utils';
import { CheckboxFieldProps } from './field-types';

const SwitchField: React.FC<CheckboxFieldProps> = ({
Copy link
Contributor

Choose a reason for hiding this comment

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

Yikes, had no idea SwitchField was so similar to CheckboxField... we need to deduplicate this code using some sort of HOC or something. The logic of both of these components is near identical.

@christianvogt @rohitkrai03 I recommend we look to clean this up after this PR as to keep everything from crossing wires.

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting, this didn't come from dev-console. I just assumed all fields were in our package. Either way, this should probably be cleaned up, it's near identical code.

Copy link
Contributor

Choose a reason for hiding this comment

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

@andrewballantyne I think we can merge both of these components and control the component it renders internally using a prop. Something like

<CheckboxField as="switch" {...prop} />

This is inline with how formik handles rendering form fields with different components. We could make checkbox as default variant as well.

Copy link
Author

Choose a reason for hiding this comment

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

I like keeping SwitchField as a separate component as it is easier for devs to know it exists. How about this? jtomasek@9f2a976
I've used render props pattern and refactored common code into CheckBoxFieldBase component. It would be IMHO better to keep that change in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Definitely agree, it should be another PR, this one should track the refactor (it's a big enough change to be done on it's own).

FWIW, I lean the render prop way that @jtomasek suggested. I had envisioned more of a function composition where the Component would be passed in and invoked with JSX inside a nested function -- but it seems our hook lint doesn't like that idea. The render prop is a decent alternative imo.

@@ -1,5 +1,5 @@
import * as React from 'react';
import { CheckboxField, EnvironmentField } from '../../formik-fields';
import { CheckboxField, EnvironmentField } from '@console/shared/src/components/formik-fields';
Copy link
Contributor

Choose a reason for hiding this comment

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

Recommend we change all of these to be @console/shared and export all the formik fields out of the console-shared/src/components/index.ts file, following the other styles of what are done there. I don't think there is any need to know the path to where the formik fields are located when it's in a common shared package.

There are quite a few of the path updates, so I won't spam comments :)

Copy link
Author

Choose a reason for hiding this comment

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

Done. I've re-exported the components, utils and types from the index and updated the imports.

@@ -18,7 +18,7 @@ import {
getImageStreamTags,
} from '../../../utils/imagestream-utils';
import './ImageStream.scss';
import ResourceDropdownField from '../../formik-fields/ResourceDropdownField';
import ResourceDropdownField from '../../../../../console-shared/src/components/formik-fields/ResourceDropdownField';
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
import ResourceDropdownField from '../../../../../console-shared/src/components/formik-fields/ResourceDropdownField';
import { ResourceDropdownField } from '@console/shared';

After the above change is done.

Copy link
Author

Choose a reason for hiding this comment

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

Done

@@ -10,7 +10,7 @@ import {
MultiColumnField,
InputField,
DropdownField,
} from '@console/dev-console/src/components/formik-fields';
} from '@console/shared/src/components/formik-fields';
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, this is a great change. Good catch! knative-plugin shouldn't rely on dev-console.

@andrewballantyne
Copy link
Contributor

This is a good update, thanks for taking this on @jtomasek

@openshift-ci-robot openshift-ci-robot added the component/noobaa Related to noobaa-storage-plugin label Dec 2, 2019
export { default as SwitchField } from './SwitchField';
export { default as TextAreaField } from './TextAreaField';
export * from './field-utils';
export * from './field-types';
Copy link
Author

Choose a reason for hiding this comment

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

I am slightly concerned if we really want to re-export these. It allows to use '@console/shared' for imports but we could hit naming collisions/confusion as the @console/shared package grows. Should we re-export everything which is used outside the shared package? Should we re-export only selected components and utils? Should we split shared package into multiple packages (e.g. @console/shared-forms) to avoid potential naming conflicts?

Copy link
Contributor

Choose a reason for hiding this comment

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

We could definitely create more packages for isolated use, but we need to be very clear with who is dependant on who otherwise we run the risk of circular references. I wonder if we could just export at a deeper level... something like @console/shared/src/formik or something...

@christianvogt @spadgett thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we circle back to this - you may have a growing issue with rebases as time goes on. Recommend we get this in and circle back to address the export.

@jtomasek jtomasek force-pushed the formik-fields-console-shared branch 2 times, most recently from 1824d34 to 45099f3 Compare December 3, 2019 07:29
@rohitkrai03
Copy link
Contributor

/assign

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 3, 2019
Jiri Tomasek added 5 commits December 3, 2019 16:22
* add hancleCancel function to allow for usecases where form reset and
  cancel is needed
* add ability to specify custom button labels
* make successMessage prop optional
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 3, 2019
@jtomasek
Copy link
Author

jtomasek commented Dec 3, 2019

Rebased + removed dependency on #3469

@andrewballantyne
Copy link
Contributor

Need an approver to apply the other label. @christianvogt @spadgett

@christianvogt
Copy link
Contributor

/approve

@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andrewballantyne, christianvogt, jtomasek, rohitkrai03

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-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 3, 2019
@andrewballantyne
Copy link
Contributor

Logged tickets to cover these.

  1. Investigate a better export methodology for isolated parts of the shared package... such as Formik's Components / Utilities

https://jira.coreos.com/browse/ODC-2468

  1. Address the duplicate nature of Switch Component and Checkbox Component now that they both live under shared

https://jira.coreos.com/browse/ODC-2469

@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.

@jtomasek
Copy link
Author

jtomasek commented Dec 3, 2019

/retest

@openshift-bot
Copy link
Contributor

/retest

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

15 similar comments
@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@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 87c9e3e into openshift:master Dec 4, 2019
@openshift-ci-robot
Copy link
Contributor

@jtomasek: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
ci/prow/e2e-gcp-console f775ed4 link /test e2e-gcp-console

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@jtomasek jtomasek deleted the formik-fields-console-shared branch December 4, 2019 10:23
@spadgett spadgett added this to the v4.4 milestone Dec 4, 2019
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/core Related to console core functionality component/dev-console Related to dev-console component/knative Related to knative-plugin component/metal3 Related to metal3-plugin component/noobaa Related to noobaa-storage-plugin component/shared Related to console-shared lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants