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

Refactor removing devices #2881

Merged
merged 5 commits into from
Feb 26, 2025
Merged

Refactor removing devices #2881

merged 5 commits into from
Feb 26, 2025

Conversation

lmuntaner
Copy link
Collaborator

@lmuntaner lmuntaner commented Feb 25, 2025

Motivation

We want to add a confirmation screen instead of an alert when removing devices.

To do that, we'll need to use the same pattern as adding a recovery phrase from the manage page. This means, passing a function that will be triggered with the user interaction instead of calling the function in the Authenticator.

In this PR, I refactor the code so that in a subsequent PR I'll be able to render a new page and then send the user back to the manage page.

Changes

  • New fields in the Authenticator: device and canBeRemoved.
  • New helper onRemoveDevice that calls deleteDevice.
  • New parameter onRemoveDevice accordingly.

Tests

  • No new tests because there is no new functionality.
  • Tested locally.

🟡 Some screens were changed

@lmuntaner lmuntaner marked this pull request as ready for review February 25, 2025 16:27
@lmuntaner lmuntaner requested a review from sea-snake February 25, 2025 16:27
@lmuntaner
Copy link
Collaborator Author

@sea-snake please review

}: {
authenticator: DedupAuthenticator;
index: number;
i18n: I18n;
icon?: TemplateResult;
onRemoveDevice: (device: DeviceData) => void;
Copy link
Contributor

@sea-snake sea-snake Feb 25, 2025

Choose a reason for hiding this comment

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

If the device is passed into authenticatorItem already as argument and there is only a single device passed in, there's no need for the device argument in onRemoveDevice since the parent component already knows the device that should be removed.

On another note, an argument for onRemove would only make sense if the delete button on device A could delete device B e.g. with a dropdown to choose as user.

I would suggest keeping the method abstract:

Suggested change
onRemoveDevice: (device: DeviceData) => void;
onRemove: () => void;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wasn't thinking on the "best practice" to be honest. Thanks!

settings.push({
action: "remove",
caption: "Remove",
fn: () => onRemoveDevice(device),
Copy link
Contributor

@sea-snake sea-snake Feb 25, 2025

Choose a reason for hiding this comment

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

In line with above:

Suggested change
fn: () => onRemoveDevice(device),
fn: onRemove,

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep

@@ -124,26 +127,33 @@ export const authenticatorItem = ({
dupCount,
warn,
info,
remove,
device,
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless authenticatorItem needs to render the device, it shouldn't need it as argument.

Suggested change
device,

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yep

@@ -96,7 +99,7 @@ export const authenticatorsSection = ({
<div class="c-action-list">
<ul>
${authenticators.map((authenticator, index) =>
authenticatorItem({ authenticator, index, i18n })
authenticatorItem({ authenticator, index, i18n, onRemoveDevice })
Copy link
Contributor

Choose a reason for hiding this comment

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

As suggested earlier, from a UI perspective we only have one thing to remove within the authenticatorItem component, so the following should suffice.

Suggested change
authenticatorItem({ authenticator, index, i18n, onRemoveDevice })
authenticatorItem({ authenticator, index, i18n, onRemove: () => onRemoveDevice(authenticator. device) })

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure

@lmuntaner lmuntaner force-pushed the lm-refactor-remove-device branch from 02afe04 to 2f7f536 Compare February 25, 2025 18:52
@lmuntaner lmuntaner requested a review from sea-snake February 25, 2025 18:52
@lmuntaner
Copy link
Collaborator Author

@sea-snake ready for another review

@lmuntaner lmuntaner force-pushed the lm-refactor-remove-device branch from 2f7f536 to 89a7cfd Compare February 26, 2025 06:13
@lmuntaner lmuntaner added this pull request to the merge queue Feb 26, 2025
Merged via the queue into main with commit b48baa0 Feb 26, 2025
67 checks passed
@lmuntaner lmuntaner deleted the lm-refactor-remove-device branch February 26, 2025 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants