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

Converting MesherySetting component from Class to Functional based #8701

Closed
wants to merge 7 commits into from

Conversation

Cvr421
Copy link

@Cvr421 Cvr421 commented Sep 9, 2023

Notes for Reviewers
Converting class based component to functional based component

This PR fixes #8674

Signed commits
Yes, I signed my commits.

@welcome
Copy link

welcome bot commented Sep 9, 2023

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.
Be sure to double-check that you have signed your commits. Here are instructions for making signing an implicit activity while performing a commit.

@github-actions github-actions bot added the component/ui User Interface label Sep 9, 2023
@Cvr421
Copy link
Author

Cvr421 commented Sep 9, 2023

Hii @Rajdip019 Please review this PR

// eslint-disable-next-line no-unused-vars
const handleError = (msg) => (error) => {
props.updateProgress({ showProgress : false });
const notify = props.notify;
Copy link
Contributor

@Rajdip019 Rajdip019 Sep 9, 2023

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

useEffect(() => {
const fetchData = async () => {
try {
const modelsResponse = await getModelsDetail();
Copy link
Contributor

@Rajdip019 Rajdip019 Sep 9, 2023

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.

JSON.stringify(props.meshAdapters) !== JSON.stringify(meshAdapters)
) {

k8sconfig (props.k8sconfig)
Copy link
Contributor

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?

Copy link
Author

@Cvr421 Cvr421 Sep 10, 2023

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

@Rajdip019
Copy link
Contributor

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

@Cvr421 Cvr421 changed the title Converting class to functional based component Converting MesherySetting component from Class to Functional based Sep 10, 2023
@Cvr421
Copy link
Author

Cvr421 commented Sep 10, 2023

@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

@Cvr421
Copy link
Author

Cvr421 commented Sep 11, 2023

@Rajdip019 I have made the changes that are requested by you . Please review

Class based Component behaviour / Current behaviour

Classs.componene.2.mp4

Functional based component behaviour

Functional.Based.component.mp4

@Rajdip019
Copy link
Contributor

LGTM

@sudhanshutech
Copy link
Member

@Cvr421 have you also build meshery right after the changes?

@Cvr421
Copy link
Author

Cvr421 commented Sep 12, 2023

@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 .
First i run the make server on localhost 9081 and then make ui on localhost 3000

JSON.stringify(props.meshAdapters) !== JSON.stringify(meshAdapters)
) {

k8sconfig (props.k8sconfig)
Copy link
Contributor

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

Copy link
Author

@Cvr421 Cvr421 Sep 13, 2023

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);
Copy link
Contributor

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

Copy link
Author

@Cvr421 Cvr421 Sep 13, 2023

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 .


k8sconfig (props.k8sconfig)
meshAdapters (props.meshAdapters)
grafana (props.grafana)
Copy link
Contributor

Choose a reason for hiding this comment

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

what does this do ?

Copy link
Author

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)

handleError = (msg) => (error) => {
this.props.updateProgress({ showProgress : false });
const notify = this.props.notify;
// eslint-disable-next-line no-unused-vars
Copy link
Contributor

Choose a reason for hiding this comment

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

dont disable lint rules

Copy link
Author

@Cvr421 Cvr421 Sep 13, 2023

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 ?

Copy link
Contributor

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.

Copy link
Author

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

Copy link
Author

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 .

const {
tabVal, subTabVal, k8sconfig, meshAdapters,
} = this.state;
if (props.router.route != newRoute)props.router.push(newRoute)
Copy link
Contributor

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

Copy link
Author

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

@@ -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)))
Copy link
Contributor

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

Copy link
Author

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

@Cvr421
Copy link
Author

Cvr421 commented Sep 13, 2023

Hii @aabidsofi19 i have updated the withRouter with useRouter .

@Cvr421
Copy link
Author

Cvr421 commented Sep 19, 2023

@aabidsofi19 Please review this PR . And let me know your thoughts .

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>
Cvr421 and others added 3 commits October 25, 2023 18:34
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>
@Cvr421
Copy link
Author

Cvr421 commented Oct 30, 2023

@aabidsofi19 Can you please review this PR and let me know your thoughts . Its been Opened from very long time .

Copy link

stale bot commented Dec 12, 2023

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.

@stale stale bot added the issue/stale Issue has not had any activity for an extended period of time label Dec 12, 2023
Copy link

stale bot commented Dec 22, 2023

This issue is being automatically closed due to inactivity. However, you may choose to reopen this issue.

@stale stale bot closed this Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/ui User Interface issue/stale Issue has not had any activity for an extended period of time
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[UI] Convert MesherySettings.js form Class-based to a functional component
4 participants