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
Move Formik fields and form helpers from @console/dev-console to @console/shared #3516
Conversation
cc @rohitkrai03 |
01778f6
to
1c82e90
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.
@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'; |
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 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.
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 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.
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.
Never mind, I already see that it is being used by noobaa-storage-plugin
already, so answer is yes.
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
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> = ({ |
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.
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.
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.
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.
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.
@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.
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 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.
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.
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'; |
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.
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 :)
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. 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'; |
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.
import ResourceDropdownField from '../../../../../console-shared/src/components/formik-fields/ResourceDropdownField'; | |
import { ResourceDropdownField } from '@console/shared'; |
After the above change is 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.
Done
@@ -10,7 +10,7 @@ import { | |||
MultiColumnField, | |||
InputField, | |||
DropdownField, | |||
} from '@console/dev-console/src/components/formik-fields'; | |||
} from '@console/shared/src/components/formik-fields'; |
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.
Oh, this is a great change. Good catch! knative-plugin
shouldn't rely on dev-console
.
This is a good update, thanks for taking this on @jtomasek |
export { default as SwitchField } from './SwitchField'; | ||
export { default as TextAreaField } from './TextAreaField'; | ||
export * from './field-utils'; | ||
export * from './field-types'; |
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 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?
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 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?
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.
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.
1824d34
to
45099f3
Compare
/assign |
* 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
to '@console/shared'
45099f3
to
f775ed4
Compare
Rebased + removed dependency on #3469 |
Need an approver to apply the other label. @christianvogt @spadgett |
/approve |
[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 |
Logged tickets to cover these.
https://jira.coreos.com/browse/ODC-2468
|
/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. |
/retest |
/retest Please review the full test history for this PR and help us cut down flakes. |
15 similar comments
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
@jtomasek: The following test failed, say
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. |
Depends on #3469