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
Converting MesherySetting component from Class to Functional based #8701
Conversation
Yay, your first pull request! 👍 A contributor will be by to give feedback soon. In the meantime, you can find updates in the #github-notifications channel in the community Slack. |
Hii @Rajdip019 Please review this PR |
ui/components/MesherySettings.js
Outdated
// eslint-disable-next-line no-unused-vars | ||
const handleError = (msg) => (error) => { | ||
props.updateProgress({ showProgress : false }); | ||
const notify = props.notify; |
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.
use the useNotifications
hook for notifications, not props. Also make sure to remove the withNotify
wrapper
ui/components/MesherySettings.js
Outdated
useEffect(() => { | ||
const fetchData = async () => { | ||
try { | ||
const modelsResponse = await getModelsDetail(); |
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.
Try to use a cleanup function and don't use await inside of a useEffect, place the fetchData
function outside the useEffect.
ui/components/MesherySettings.js
Outdated
JSON.stringify(props.meshAdapters) !== JSON.stringify(meshAdapters) | ||
) { | ||
|
||
k8sconfig (props.k8sconfig) |
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.
What does this line and the next 4 lines do? Can you elaborate a bit?
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.
Actually here we are checking the props.k8sconfig state conditionally that if this condition {(JSON.stringify(props.k8sconfig) !== JSON.stringify(k8sconfig)} is true then props.k8config has changed . and if it's changed then we are updating the k8sconfig local variable. this is the same logic that are mention into class based component . And same for next line
@Cvr421 make sure to change the PR name to something specific. Also, when you do all the required changes can you attach a video of this component working before and after? |
Ya sure |
@Rajdip019 I have made the changes that are requested by you . Please review Class based Component behaviour / Current behaviour Classs.componene.2.mp4Functional based component behaviour Functional.Based.component.mp4 |
LGTM |
@Cvr421 have you also build meshery right after the changes? |
Yes @sudhanshutech i have build meshery number of time to check it is working fine . |
ui/components/MesherySettings.js
Outdated
JSON.stringify(props.meshAdapters) !== JSON.stringify(meshAdapters) | ||
) { | ||
|
||
k8sconfig (props.k8sconfig) |
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.
what does this do , isnt k8sconfig destructured from props
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.
@aabidsofi19
Actually here we are checking the props.k8sconfig state conditionally that if this condition {(JSON.stringify(props.k8sconfig) !== JSON.stringify(k8sconfig)} is true then props.k8config has changed . and if it's changed then we are updating the k8sconfig local variable. this is the same logic that are mention into class based component . And same for next line.
const [scannedPrometheus, setScannedPrometheus] = useState([]); | ||
const [tabVal, setTabVal] = useState(0); | ||
const [subTabVal, setSubTabVal] = useState(0); | ||
const [isMeshConfigured] = useState(k8sconfig.clusterConfigured); |
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 we storing this in state , it is derived from props
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.
@aabidsofi19 storing in state has multiple advantages like increase the Performance Optimization and code readability
But in functional component its recomended to use the state .
I think if you can check the class based component . this is derived form this.state which is act similar has useStates in functional component .
ui/components/MesherySettings.js
Outdated
|
||
k8sconfig (props.k8sconfig) | ||
meshAdapters (props.meshAdapters) | ||
grafana (props.grafana) |
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.
what does this do ?
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.
Here we are updating the local variable k8config . Its the part of first question that you have asked above . about if
this
JSON.stringify(props.meshAdapters) !== JSON.stringify(meshAdapters)
) {
k8sconfig (props.k8sconfig)
ui/components/MesherySettings.js
Outdated
handleError = (msg) => (error) => { | ||
this.props.updateProgress({ showProgress : false }); | ||
const notify = this.props.notify; | ||
// eslint-disable-next-line no-unused-vars |
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.
dont disable lint rules
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.
Actually @aabidsofi19 we are not using this handleError function anywere . so that why i am getting this error
Error: 'handleError' is assigned a value but never used . when restarting the server . that's why i disable lint rules for this function only . can we remove this function ?
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, you can remove the function if it's not being used anywhere. Or you could just comment that out as well marking as not being used.
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, you can remove the function if it's not being used anywhere. Or you could just comment that out as well marking as not being used.
ok
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.
@Rajdip019 @aabidsofi19
I have commented the Unused function as marking as it is not in use .
ui/components/MesherySettings.js
Outdated
const { | ||
tabVal, subTabVal, k8sconfig, meshAdapters, | ||
} = this.state; | ||
if (props.router.route != newRoute)props.router.push(newRoute) |
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.
router should not come from props
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.
ok i'll update this
ui/components/MesherySettings.js
Outdated
@@ -576,5 +520,5 @@ const mapDispatchToProps = (dispatch) => ({ updateProgress : bindActionCreators( | |||
MesherySettings.propTypes = { classes : PropTypes.object, }; | |||
|
|||
export default withStyles(styles, { withTheme : true })( | |||
connect(mapStateToProps, mapDispatchToProps)(withRouter(withNotify(MesherySettings))) | |||
connect(mapStateToProps, mapDispatchToProps)(withRouter((MesherySettings))) |
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.
no need for withRouter ;use useRouter
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.
ok i'll will update this
Hii @aabidsofi19 i have updated the withRouter with useRouter . |
@aabidsofi19 Please review this PR . And let me know your thoughts . |
91fd2aa
to
b007da8
Compare
Resolving git conflict Signed-off-by: Cvr421 <Chandravijayk42187@gmail.com>
Signed-off-by: Cvr421 <Chandravijayk42187@gmail.com>
Signed-off-by: Cvr421 <Chandravijayk42187@gmail.com>
Signed-off-by: Cvr421 <Chandravijayk42187@gmail.com>
b007da8
to
dde3a3f
Compare
Signed-off-by: Chandravijay rai <82499697+Cvr421@users.noreply.github.com>
Signed-off-by: aabidsofi19 <65964225+aabidsofi19@users.noreply.github.com>
Signed-off-by: Chandravijay rai <82499697+Cvr421@users.noreply.github.com>
@aabidsofi19 Can you please review this PR and let me know your thoughts . Its been Opened from very long time . |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue is being automatically closed due to inactivity. However, you may choose to reopen this issue. |
Notes for Reviewers
Converting class based component to functional based component
This PR fixes #8674
Signed commits
Yes, I signed my commits.