-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[HOLD for payment 2020-01-03] [$2000] Allow Form component to detect children that are Class components #13524
Comments
Current assignee @puneetlath is eligible for the Bug assigner, not assigning anyone new. |
Current assignee @puneetlath is eligible for the External assigner, not assigning anyone new. |
Job added to Upwork: https://www.upwork.com/jobs/~019572d1017d216d70 |
Triggered auto assignment to Contributor-plus team member for initial proposal review - @sobitneupane ( |
Current assignee @puneetlath is eligible for the External assigner, not assigning anyone new. |
I think when component is class we should render it before we clone elements diff --git a/src/components/Form.js b/src/components/Form.js
index 72ee4afc6b..7a61bb81df 100644
--- a/src/components/Form.js
+++ b/src/components/Form.js
@@ -193,6 +193,11 @@ class Form extends React.Component {
const nestedChildren = new child.type(child.props);
if (!React.isValidElement(nestedChildren) || !lodashGet(nestedChildren, 'props.children')) {
+ if (nestedChildren.render) {
+ return React.cloneElement(child, {
+ children: this.childrenWrapperWithProps(lodashGet(nestedChildren.render(), 'props.children')),
+ });
+ }
return child;
}
|
@fedirjh just capturing what we've discussed in Slack so far: when I try with the WorkspaceNewRoom page that doesn't quite work. But doing However, we have a new problem when we do that where the validation function isn't called when the Class input is changed/blurred (it is called for the functional component). |
This comment was marked as outdated.
This comment was marked as outdated.
@puneetlath I just test @fedirjh proposal's. It seems working just fine for the class component but I think the changes that they made are too much to trace. I am more inclined if can just make small changes to handle the missing I'll leave it to you to decide. |
@mollfpr basically I made change to this code block , the other part I just split the code for rendering form input to this is the code block I made changes if (_.isFunction(child.type)) {
const nestedChildren = new child.type(child.props);
if (!React.isValidElement(nestedChildren) || !lodashGet(nestedChildren, 'props.children')) {
return child;
}
return React.cloneElement(nestedChildren, {
children: this.childrenWrapperWithProps(lodashGet(nestedChildren, 'props.children')),
});
} these are the changes if (_.isFunction(child.type)) {
let nestedChildren = new child.type(child.props);
// If the custom component has a render method, use it to get the nested children
if (_.isFunction(nestedChildren.render)) {
nestedChildren = nestedChildren.render();
}
// If the custom component has children,
if (lodashGet(nestedChildren, 'props.children')) {
return React.cloneElement(nestedChildren, {
children: this.childrenWrapperWithProps(lodashGet(nestedChildren, 'props.children')),
});
}
// If the custom component has a single child, use it
if (React.isValidElement(nestedChildren)) {
return this.inputWrapperWithProps(nestedChildren);
}
// If the custom component has no children, return the component as is
return child;
} |
puneetlath Is it still open for posting proposal? |
@sandipanghos Yes, I believe that, you can submit proposal until one proposal is selected by the reviewers |
Yes, as long as the |
THANKS |
THANKS |
Updated Proposalcc @puneetlath , @mollfpr
Solution 1diff --git a/src/components/Form.js b/src/components/Form.js
index 72ee4afc6b..fe4a7506a4 100644
--- a/src/components/Form.js
+++ b/src/components/Form.js
@@ -190,12 +190,17 @@ class Form extends React.Component {
// Look for any inputs nested in a custom component, e.g AddressForm or IdentityForm
if (_.isFunction(child.type)) {
- const nestedChildren = new child.type(child.props);
+ const childNode = new child.type(child.props);
+ const nestedChildren = _.isFunction(childNode.render) ? childNode.render() : childNode;
- if (!React.isValidElement(nestedChildren) || !lodashGet(nestedChildren, 'props.children')) {
+ if (!React.isValidElement(nestedChildren) && !lodashGet(nestedChildren, 'props.children')) {
return child;
}
+ if (React.isValidElement(nestedChildren)) {
+ return this.childrenWrapperWithProps(nestedChildren);
+ }
+
return React.cloneElement(nestedChildren, {
children: this.childrenWrapperWithProps(lodashGet(nestedChildren, 'props.children')),
});
Solution 2 // Look for any inputs nested in a custom component, e.g AddressForm or IdentityForm
if (_.isFunction(child.type)) {
const childNode = new child.type(child.props);
const nestedChildren = _.isFunction(childNode.render) ? childNode.render() : childNode;
if (React.isValidElement(nestedChildren) || lodashGet(nestedChildren, 'props.children')) {
return this.childrenWrapperWithProps(nestedChildren);
}
return child;
} Solution 3 // Look for any inputs nested in a custom component, e.g AddressForm or IdentityForm
if (_.isFunction(child.type)) {
const nestedChildren = ((nested = new child.type(child.props)) => (_.isFunction(nested.render)
? nested.render()
: nested))();
if (React.isValidElement(nestedChildren) || lodashGet(nestedChildren, 'props.children')) {
return this.childrenWrapperWithProps(nestedChildren);
}
return child;
} |
Thanks, @sobitneupane! Yeah, it’s kinda awkward but I’ll let @puneetlath decide 👍 |
@fedirjh proposal Solution 2 looks good to me. Maybe add a comment about the cc @puneetlath |
📣 @mollfpr You have been assigned to this job by @puneetlath! |
@sobitneupane yes I think it makes sense for @mollfpr to be the C+ on this one. Thanks! @mollfpr @fedirjh I agree proposal 2 (with an explaining comment). It's nice and clean. @fedirjh how would you like to implement that solution plus refactoring the Then after you've done that, I'll update the form validation as described here. But for your PR, we shouldn't change any of the form functionality. Just update it to use the |
I think it's a great idea. We also can test this issue with the refactor. |
@puneetlath That's fair . I am ready to implement that + Refactoring the |
📣 @fedirjh You have been assigned to this job by @puneetlath! |
@puneetlath while refactoring App/src/pages/ReportSettingsPage.js Lines 194 to 201 in aa16054
|
WorkspaceNewRoomPage.mov |
@puneetlath , @mollfpr PR is ready #13713 |
@puneetlath, @mollfpr, @fedirjh Whoops! This issue is 2 days overdue. Let's get this updated quick! |
The PR is in production. Starting the regression period! |
@mollfpr can you apply here? https://www.upwork.com/jobs/~019572d1017d216d70 |
@puneetlath I think the bounty is updated to $2k ref here and the PR is eligible for the bonus. |
Upwork job price has been updated to $2000 |
@puneetlath applied! |
@puneetlath accepted 👍 |
All paid with 50% bonus. Thanks y'all! |
Problem
Our Form component is built to handle nested components and custom components within the form. That functionality is handled here. It seems, however, if the nested component is a Class component that the children of the class component aren't detected by the Form component. If the nested component is a Functional component, then it seems to work just fine. You can see this example here where I added
Form
to the WorkspaceNewRoom page and added two similar test components, one functional and one class based. The functional component is found by the form but the class based one isn't. Context Slack discussion: here.Solution
Update this Form functionality so that it is able to find and recognize custom class-based sub-components.
Upwork Automation - Do Not Edit
The text was updated successfully, but these errors were encountered: