group-settings: Handle invalid urls correctly.

There were couple of problems in our handling of invalid or
incomplete URLs-
- The browser back button behavior breaks if someone enters
url with invalid group ID, incorrect group name.
- On typing group edit URLs with invalid group ID, an error
was raised and the URLs remained the same with just opening
the groups overlay with "Your" tab selected in left panel.
- On typing group edit URLs with incorrect right side tab or
without any right side tab, we showed "general" section, which
is fine, but the URL was still incorrect.

This commit fixes the above mentioned problems-
- URLs with invalid group IDs are now handled gracefully
with groups UI opening in the same way as before but the
url is updated to "#groups/your".
- We now update the right side tab to "general" if right
side tab is invalid or there is no right side tab.
- All the URL updates to fix invalid urls are done using
"history.replaceState" to make sure the browser back button
behaves as expected.
- All the code for checking the urls is done in hashchange.js
itself, so we can remove some code from change_state.
This commit is contained in:
Sahil Batra
2024-02-09 19:04:09 +05:30
committed by Tim Abbott
parent eea5ee8923
commit 2fe36cc0d7
5 changed files with 54 additions and 22 deletions

View File

@@ -67,6 +67,10 @@ export function get_user_group_from_id(group_id: number): UserGroup {
return user_group;
}
export function maybe_get_user_group_from_id(group_id: number): UserGroup | undefined {
return user_group_by_id_dict.get(group_id);
}
export function update(event: UserGroupUpdateEvent): void {
const group = get_user_group_from_id(event.group_id);
if (event.data.name !== undefined) {