[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Page MenuHomePhabricator

Use localStorage instead of a user preference for saving whether the infobox is expanded or collapsed
Closed, ResolvedPublic3 Estimated Story Points

Description

Why remove the user preference

Since T290941: Preserve open/collapsed state of the accordion [M], IPInfo has used a user preference to save the expanded state of the infobox.

In general, we should be conservative about adding user preferences, as outlined in:

A preference for remembering UI state seems to contravene these guidelines. (NB IPInfo also adds a few other user preferences, but the others are mandated by legal requirements (T291582) or temporary (T292802).)

We do have a URL parameter openInfobox that forces the infobox to be open, which is used when clicking through from the IPInfo popup (T293723), and could also be added when sharing URLs.

User localStorage instead

Removing the preference would mean that the infobox would no longer default to open, without the URL parameter. We should instead do this in local storage.

localStorage is documented here: https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage

Using localStorage in MediaWiki is documented here: https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.storage - note that mw.storage has no expiry, and localStorage has limited space.

Acceptance criteria
  • A user preference is no longer set true when the infobox is expanded
  • The user preference is set false when the infobox is collapsed, as this removes it from the database. This should be commented clearly in the code.
  • A key is added to mw.storage when the infobox is expanded
  • The key is removed from mw.storage when the infobox is collapsed
  • A comment is added, that if we ever remove this feature, we should call mw.storage.remove(<our-key>) here to free up space
  • mw.storage is checked when deciding whether the infobox should be expanded or collapsed. (The URL parameter openInfobox should still take precedence.)
What changes will the user see?
  • There is currently a bug where there can be a delay between the database being updated with the user preference, and the next page refresh. This bug will be fixed.
  • The preference for an expanded/collapsed infobox will only persist as long as localStorage persists
  • Before this task, the preference was saved per user; after, it will persist across users until the browser is closed

Event Timeline

Tchanders renamed this task from Remove the user preference for saving whether the infobox is expanded or collapsed to Use localStorage instead of a user preference for saving whether the infobox is expanded or collapsed.Mar 24 2022, 4:35 PM
Tchanders updated the task description. (Show Details)

@Niharika I've added a section to explain the differences from the user's perspective

Change 777786 had a related patch set uploaded (by STran; author: STran):

[mediawiki/extensions/IPInfo@master] Use localStorage instead of user options for infobox state

https://gerrit.wikimedia.org/r/777786

Testing this is still affected by T305650, so it might be better to test it after that one

Change 777786 merged by jenkins-bot:

[mediawiki/extensions/IPInfo@master] Use localStorage instead of user options for infobox state

https://gerrit.wikimedia.org/r/777786

Did regression on the expand and collapse of the IP info box on supported browsers(IE, Chrome, FF, Safari, Opera, Edge)
the user preference is sustained most times.

Screen Shot 2022-04-11 at 3.00.14 PM.png (1×2 px, 693 KB)

Screen Shot 2022-04-11 at 2.49.42 PM.png (1×2 px, 535 KB)

I lightly suspect the clean up might not be working as intended. Without the server being aware of a default value, I think setting 0 is either doing nothing, or actively inserting new rows for everyone. I'm not sure how it would be resulting in removing existing rows for users that stored a non-default/non-zero value in the past. Might be worth double checking that this has the desired effect on the database table.

If I understand correctly, the change did not account for transitioning it. That seems fine (it's a small effort to open it again), but that also means the existing data could presumably be removed in one go from the server-side without deferring this to the client. This is something one would need for localStorage, but not for user.options. E.g. we could run a single DELETE query for this in beta and (if in prod) in prod as well. Alternatively, one could wait for T300371 to take care of it as that task is likely to result in any change to user options to naturally delete any rows for invalid/unknown keys.

Without the server being aware of a default value, I think setting 0 is either doing nothing, or actively inserting new rows for everyone.

Ah yes, we shouldn't have removed the default in the patch (setting the default value would remove the row). As it is, it is throwing the warning but shouldn't be inserting new rows.

We added this into the app rather than just running a query in production, since in theory the extension could be being used by third parties (however, it's probably unlikely, given how new it is, plus the need for a maxmind subscription).

We could add the default value back until T305838: Remove line to clean up old user preference, or just do T305838 now, given the unlikeliness of this being used outside Wikimedia, plus the existence of T300371: Drop now unused user preferences from production database(s).