Skip to content

Email Aliases: error message for GenerateAlias #29153

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

Merged
merged 11 commits into from
May 22, 2025
Merged

Conversation

arthuredelstein
Copy link
Collaborator

@arthuredelstein arthuredelstein commented May 21, 2025

  • mojom file definition
  • updated UI implementation
  • unit tests
  • storybook

Resolves brave/brave-browser#46222

- mojom file definition
- updated UI implementation
- unit tests
- storybook
@arthuredelstein arthuredelstein requested a review from a team as a code owner May 21, 2025 05:48
@github-actions github-actions bot added the CI/storybook-url Deploy storybook and provide a unique URL for each build label May 21, 2025
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@@ -51,7 +51,7 @@ interface EmailAliasesService {
CancelAuthenticationOrLogout();

// Generate a proposed email alias.
GenerateAlias() => (string alias_email);
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe you could use a union for this? It represents the "only one of these should be present" state a bit better :)

union GenerateAliasResult {
    string alias;
    string error;
}

...

GenerateAlias() => (GenerateAliasResult result);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Copy link
Collaborator

Choose a reason for hiding this comment

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

on the cpp side (future PR) we should use struct traits to convert this into base::expected as the union is kind of clunky and base::expected is preferred for error handling

Comment on lines 221 to 222
const aliasEmailBox = screen.getByText('emailAliasesAliasLabel')
.closest('div')?.nextElementSibling
Copy link
Contributor

Choose a reason for hiding this comment

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

hey I worry that this selector is going to be a bit brittle if we change the HTML - maybe we should add a data-test-id to the element?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor

@fallaciousreasoning fallaciousreasoning left a comment

Choose a reason for hiding this comment

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

Nearly there - just another comment on the mojom and a couple of getLocale calls 😄

Comment on lines 154 to 155
const [generateAliasResult, setGenerateAliasResult] =
React.useState<GenerateAliasResult | null>(null)
Copy link
Contributor

Choose a reason for hiding this comment

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

this is completely a matter of personal preference so up to you but I'd normally type this as:

const [generateAliasResult, setGenerateAliasResult] =
    React.useState<GenerateAliasResult>()

// generateAliasResult is `GenerateAliasResult | undefined`

and then use undefined instead of null

up to you 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

works for me; fixed

mockEmailAliasesService.generateAlias = jest.fn().mockImplementation(
() => Promise.resolve('new@brave.com'))
() => Promise.resolve({ result: { errorMessage: null, aliasEmail } }))
Copy link
Collaborator

Choose a reason for hiding this comment

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

@fallaciousreasoning is this the correct mapping from mojo interface for optional? It will still have the property and just be null vs not having the property at all?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch. Somehow the typescript linter wasn't catching this until I explicitly added the type there. Actually it maps to

/**
 * @typedef { {
 *   aliasEmail: (!string|undefined),
 *   errorMessage: (!string|undefined),
 * } }
 */
export const GenerateAliasResult = {};

So I needed to use undefined rather than null. I have pushed a fix

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

I have a vague idea that the property has to be present, it just also has to be undefined.

@arthuredelstein arthuredelstein requested a review from bridiver May 22, 2025 16:35
@arthuredelstein
Copy link
Collaborator Author

For @brave/string-reviewers-team -- here's a screenshot of the string in use:
image

Copy link
Collaborator

@mkarolin mkarolin left a comment

Choose a reason for hiding this comment

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

strings++

Copy link
Contributor

@fallaciousreasoning fallaciousreasoning left a comment

Choose a reason for hiding this comment

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

lgtm

@arthuredelstein arthuredelstein merged commit 8420ae5 into master May 22, 2025
18 checks passed
@arthuredelstein arthuredelstein deleted the issues/46222 branch May 22, 2025 22:58
@github-actions github-actions bot added this to the 1.81.x - Nightly milestone May 22, 2025
@brave-builds
Copy link
Collaborator

Released in v1.81.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/storybook-url Deploy storybook and provide a unique URL for each build
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Email Aliases: implement GenerateAlias error message
5 participants