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

[BUG]: Not clear how to get around the error message about unsaved changes #20927

Open
natashabag opened this issue Aug 31, 2024 · 8 comments
Open
Assignees
Labels
bug Label to indicate an issue is a regression Impact: Medium Will improve quality-of-life for at least 30% of users. Work: Medium The means to find the solution is clear, but it isn't at good-first-issue level yet.

Comments

@natashabag
Copy link

natashabag commented Aug 31, 2024

Describe the bug

Not clear how to get around the error message about unsaved changes. When the changes to a story have been unsaved for some reason, user is unable to get back to the story, and make some changes. For example, normal user won't be able to navigate to the tab that had been closed as instructed per error message. The message should be more clear where to go and how to get back access to the story if it's possible.

URL of the page where the issue is observed.

https://www.oppiatestserver.org/story_editor/of7BrmztCbX1

Steps To Reproduce

Preconditions: user has to be granted manager's access to Fractions, and curriculum admin

  1. Log in
  2. Go to Topics and Skills Dashboard
  3. Locate Fractions
  4. Select a story
  5. Make a minor update to the story title
  6. Close out the tab without saving the changes
  7. Go back to the same story
  8. Observe

Expected Behavior

The message should be more clear. Or user should be granted access to the story regardless unsaved changes.

Screenshots/Videos

bughunt.mov
Screenshot 2024-08-30 at 9 38 29 PM

What device are you using?

Desktop

Operating System

MacOS

What browsers are you seeing the problem on?

Chrome, Firefox

Browser version

Chrome 126.0.6478.57, Firefox 127.0

Additional context

No response

Tips for developers

Before addressing the bug, please identify which PR caused the issue (you can follow the steps here). If you identify the PR, comment on the issue with a link to it. If not, mention the commit hash of the oldest commit you saw the bug on (and the month and year it was made in).

Then, please leave a comment with details of the approach that you plan to take to fix the issue (see example).

Note: If this is your first Oppia issue, please make sure to follow our guidelines for choosing an issue and setting things up. You will also need to show a demo of the fix working correctly on your local machine. Thanks!

@natashabag natashabag added bug Label to indicate an issue is a regression triage needed labels Aug 31, 2024
@natashabag natashabag changed the title [BUG]: Not clear how to get around an error message about unsaved changes [BUG]: Not clear how to get around the error message about unsaved changes Aug 31, 2024
@Kanupriyaoppia
Copy link
Collaborator

I also faced similar problem during exploration creation (testing)

@ujjwalpathaak
Copy link
Contributor

Screenshot 2024-10-21 at 11 20 42 PM
this is one of the object stored in localStorage for story entity -

numberOfOpenedTabs - it shows the number of times that particular URL was visited not the actual count of tabs as When i refresed the count increased, but never reduces!

Possible Solutions ( wrt the orignal thought while writing it ) -

  1. Rename numberOfOpenedTabs - A more accurate name could be tabOpenCount or pageVisitCount to represent the metric correctly.
  2. Add Destructor Logic - We need logic to decrement the count when a tab is closed to reflect the actual number of open tabs.

Also what behaviour is expected to resolve the issue?

  1. Give an option to the used to Discard changes and proceed to the page.
  2. Or recover the unsaved version (Explore how we can persist unsaved changes, possibly using localStorage or sessionStorage). This requires further exploration to determine the best approach for recovering unsaved states after reload or navigation.

@ujjwalpathaak
Copy link
Contributor

Hey @natashabag,
Can you suggest anyone who could help me with my doubts as mentioned above, so that I can maybe start making an approach.

@seanlip
Copy link
Member

seanlip commented Oct 28, 2024

Hi @ujjwalpathaak, sorry for the late reply. Thank you for digging into this and sharing your findings!

I think that the name numberOfOpenedTabs isn't really different from tabOpenCount, so I don't think we need to rename it. However, I do agree with you that we need to add destructor logic. Is there a way to do this in a foolproof way (such that we are guaranteed to call the destructor and decrement the count before the page is closed)?

I think that the general aim behind this feature is to avoid the same person making edits to the same entity in multiple tabs (which can happen by accident), so I'm not sure that either of your two suggestions at the bottom would resolve the issue (since both of them will allow editing the same entity in multiple tabs). I think a successful resolution here would ensure that the message is not shown when it is not supposed to be -- let's explore that first, and if it's not possible to do that with certainty, we could look into other options for the product behaviour.

Hope this helps, and feel free to ask if you have follow-up questions -- thanks!

@seanlip seanlip added Work: Medium The means to find the solution is clear, but it isn't at good-first-issue level yet. Impact: Medium Will improve quality-of-life for at least 30% of users. labels Nov 1, 2024
@ujjwalpathaak
Copy link
Contributor

ujjwalpathaak commented Nov 6, 2024

Hey @seanlip,
Currently in story-editor-page.component.ts

    this.windowRef.nativeWindow.addEventListener(
      'beforeunload',
      this.onClosingStoryEditorBrowserTab
    );

is being used to bind the onClosingStoryEditorBrowserTab() func to tab closing event.

for the same thing in skill-editor-page.component.ts

    this.windowRef.nativeWindow.addEventListener('beforeunload', event => {
      this.onClosingSkillEditorBrowserTab();
    });

is being used ~ which works correctly.

I think the issue is that using a regular function in story-editor-page.component.ts causes the event to lose the component’s lexical scope. In contrast, in skill-editor-page.component.ts, the arrow function preserves the lexical scope, which keeps access to storyEditorStateService and localStorageService intact in the beforeunload event.

I used an arrow func in story-editor-page.component.ts which is giving me satisfactory results.

Screen.Recording.2024-11-06.at.9.59.47.AM.webm

Have a look at the video. It shows that the feature to handle unsaved changes when closing tabs is now working well. It allows a new tab to access the page, and when I increase the tab count to 3 and then lower it to 2, the values in localStorage also update accordingly.

@seanlip
Copy link
Member

seanlip commented Nov 11, 2024

OK, thanks @ujjwalpathaak. I have one question: is the original issue always reproducible in the story editor with 100% certainty, or does it only happen sometimes? If the former, then your solution seems likely to be correct, but I just wanted to double-check this.

@ujjwalpathaak
Copy link
Contributor

Hey @seanlip,
I only have access to macOS at the moment. I tried to reproduce the issue with - Chrome, Safari & Firefox.
The problem was consistent across all the three browsers, and the solution proposed seemed to work for em.

@seanlip
Copy link
Member

seanlip commented Nov 12, 2024

@ujjwalpathaak Sounds good, thanks. I'm assigning you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Label to indicate an issue is a regression Impact: Medium Will improve quality-of-life for at least 30% of users. Work: Medium The means to find the solution is clear, but it isn't at good-first-issue level yet.
Projects
Status: Todo
Development

No branches or pull requests

4 participants