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

Set editing profile index correctly when deleting profile #1560

Merged
merged 5 commits into from
Nov 4, 2024

Conversation

khaitruong922
Copy link

@khaitruong922 khaitruong922 commented Nov 4, 2024

Fixes #1556

Let's call editing profile index x and deleted profile index y

Currently we does not handle:

  • x < y: The default profile and editing profile will be reset to the first profile, however when reload the page, it still has the value before reset. Additionally, the radio button does not represent the default profile correctly. Calling _setProfileIndex with the same x value will resolve this.
  • x > y: The editing profile index is not shifted up, therefore it moves into below profile. When the editing profile is the last index, it will cause index error, and we cannot add more profiles after that. The issue happens because when we add a profile, the editing profile index is set to last index.

List indexes are also updated correctly after deletion.

@khaitruong922 khaitruong922 requested a review from a team as a code owner November 4, 2024 16:32
jamesmaa
jamesmaa previously approved these changes Nov 4, 2024
@jamesmaa jamesmaa dismissed their stale review November 4, 2024 16:49

Sorry didn't read it carefully. Have a question or two in a bit

Copy link
Collaborator

@jamesmaa jamesmaa left a comment

Choose a reason for hiding this comment

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

Sorry have some q's

@@ -261,6 +261,10 @@ export class ProfileController {
// Update profile index
if (settingsProfileIndex === profileIndex) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (settingsProfileIndex === profileIndex) {
if (settingsProfileIndex >= profileIndex) {

Isn't this math accounted for above? Line 231

if (profileCurrentNew >= profileIndex) {
            profileCurrentNew = Math.min(profileCurrentNew - 1, this._profiles.length - 1);
            modifications.push({
                action: 'set',
                path: 'profileCurrent',
                value: profileCurrentNew,
            });
        }
        

@@ -261,6 +261,10 @@ export class ProfileController {
// Update profile index
if (settingsProfileIndex === profileIndex) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also what's the difference between settingsProfileIndex and profileIndex?

Copy link
Author

Choose a reason for hiding this comment

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

settingsProfileIndex is editing profile index, profileIndex is the index to be deleted. Maybe should rename this?

Copy link
Collaborator

@jamesmaa jamesmaa left a comment

Choose a reason for hiding this comment

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

yeah maybe renaming variables in this file as a separate PR would be good

@jamesmaa jamesmaa added this pull request to the merge queue Nov 4, 2024
Merged via the queue into yomidevs:master with commit afd0b67 Nov 4, 2024
11 checks passed
Copy link

github-actions bot commented Nov 4, 2024

Playwright test results

passed  4 passed
flaky  1 flaky

Details

stats  5 tests across 4 suites
duration  2 minutes, 39 seconds
commit  afd0b67

Flaky tests

chromium › integration.spec.js › anki add

@Kuuuube Kuuuube added kind/bug The issue or PR is regarding a bug area/ui-ux The issue or PR is related to UI/UX/Design labels Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ui-ux The issue or PR is related to UI/UX/Design kind/bug The issue or PR is regarding a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid profile index error when creating and deleting profiles
3 participants