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

feat: add warning on reload and tab exit (#474) #555

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

aapatil2004
Copy link

This is how it looks when we user tries to reload filling partial information
image
And this is how it looks when user tries to leave the site
leave

Implemented using Windows before unload feature

@aapatil2004 aapatil2004 requested a review from a team as a code owner December 14, 2024 04:33
@aapatil2004 aapatil2004 changed the title Implemented warning on reload and exiting tab #474 Implemented warning on reload and tab exit (#474) Dec 14, 2024
@aapatil2004 aapatil2004 changed the title Implemented warning on reload and tab exit (#474) feat: add warning on reload and tab exit (#474) Dec 14, 2024
Copy link
Member

@alexgarel alexgarel left a comment

Choose a reason for hiding this comment

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

Thanks @aapatil2004 for the good work. I have some remarks, that are more cleaning up, I imagine.


useEffect(() => {
const handleBeforeUnload = (event) => {
if(taxonomyName || ownerName || branchName || description) { // Show warning only if the form is dirty
Copy link
Member

Choose a reason for hiding this comment

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

Not sure but, why don't you use isFormDirty here ?

If it does not work because of dependencies, you may remove its definition.

useEffect(() => {
const handleBeforeUnload = (event) => {
if(taxonomyName || ownerName || branchName || description) { // Show warning only if the form is dirty
console.log("event warning back triggered");
Copy link
Member

Choose a reason for hiding this comment

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

We should remove console.log before merging.

Copy link
Member

@alexgarel alexgarel left a comment

Choose a reason for hiding this comment

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

I have another problem with you implementation: it does not work if I click on a link in the application (click on the logo).

Is there a way to also handle it ?
getUserConfirmation (see here) seems the way to go to handle this.

@alexgarel
Copy link
Member

I have another problem with you implementation: it does not work if I click on a link in the application (click on the logo).

Just to be clear: your implementation does well for part of the cases, we must add the case of application internal navigation (which is also important).

Copy link
Member

@alexgarel alexgarel left a comment

Choose a reason for hiding this comment

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

Thanks @aapatil2004 for your work, I have some issues though. I let you give a look at my comments.

@@ -22,7 +22,7 @@ export type OpenAPIConfig = {

export const OpenAPI: OpenAPIConfig = {
// TODO: Used to keep API_URL backward compatible with existing code, update API_URL when possible
BASE: API_URL.substring(0, API_URL.length - 1),
BASE: typeof API_URL === 'string' ? API_URL.substring(0, API_URL.length - 1) : '',
Copy link
Member

Choose a reason for hiding this comment

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

@aapatil2004 this file is auto-generated, so I think this change will be removed on next generation.

I think it's ok because, as seen, it should never be the case that API_URL is not defined. (wee could maybe add a check at another place to have a meaningful error).

You can live it as is in this PR though.

Comment on lines -189 to -196
<FormHelperText
sx={{ width: "75%", textAlign: "center", maxWidth: "600px" }}
>
Explain what is your goal with this new project, what changes are
you going to bring. Remember to privilege small projects (do big
project as a succession of small one).
</FormHelperText>

Copy link
Member

Choose a reason for hiding this comment

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

Why did you remove this ?

Comment on lines -137 to -141
error={isOwnerNameInvalid(ownerName)}
helperText={
isOwnerNameInvalid(ownerName) &&
"Special characters are not allowed"
}
Copy link
Member

Choose a reason for hiding this comment

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

Why did you remove the checks ?

Comment on lines -153 to -159
<FormHelperText
sx={{ width: "75%", textAlign: "center", maxWidth: "600px" }}
>
Please use your Github account username if possible, or eventually
your id on open food facts slack (so that we can contact you)
</FormHelperText>

Copy link
Member

Choose a reason for hiding this comment

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

why did you remove this ?

Comment on lines -161 to -165
error={isInvalidBranchName}
helperText={
isInvalidBranchName &&
"Special characters, capital letters and white spaces are not allowed"
}
Copy link
Member

Choose a reason for hiding this comment

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

why did you remove this ?

}
return false;
const handleFieldChange = (setter) => (event) => {
setter(event.target.value);
};
Copy link
Member

Choose a reason for hiding this comment

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

this check is important, why was it removed ?

Comment on lines +50 to +51
const handleNavigation = (url: string) => {
if (taxonomyName || ownerName || description) {
Copy link
Member

Choose a reason for hiding this comment

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

We will need to have this kind of confirmation for other pages so we can't check that this way. This check should remain local to the startproject page. Maybe you can do this by first registering a needsConfirm state and check it here, that way we could implement this on more pages with different checks.

Also

@@ -85,7 +100,7 @@ export const ResponsiveAppBar = () => {
page.url ? (
<MenuItem
key={page.translationKey}
onClick={handleCloseNavMenu}
onClick={() => handleNavigation(`/${page.url}`)} // Use handleNavigation
Copy link
Member

Choose a reason for hiding this comment

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

I think the method of using BrowserRouter getUserConfirmation proposed in this article might be better (because more central). Did you try it ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

2 participants