Skip to content

feat(react): add useMessageProps hook for In-App Messaging #2340

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

Conversation

cshfang
Copy link
Member

@cshfang cshfang commented Jul 25, 2022

This PR adds a hook for use with In-App Messaging components (to be added in future PRs)

Description of how you validated changes

Tested with sample app and yarn test

Checklist

  • PR description included
  • yarn test passes
  • Tests are updated
  • No side effects or sideEffects field updated
  • Relevant documentation is changed or added (and PR referenced)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@cshfang cshfang requested a review from a team as a code owner July 25, 2022 22:33
@changeset-bot
Copy link

changeset-bot bot commented Jul 25, 2022

⚠️ No Changeset found

Latest commit: 0446497

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@cshfang cshfang requested a review from calebpollman July 25, 2022 22:33
Copy link
Contributor

@reesscot reesscot left a comment

Choose a reason for hiding this comment

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

LGTM, just had a few miscellaneous comments

styleParams: { payloadStyle, overrideStyle },
});

expect(output).toMatchSnapshot();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: rather than rely on comparing the snapshot to the test code and relying on humans not to just update the snapshot, what do you think of expecting it to match an expectedStyle object we can read right here. That would make me more confident in the test.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think part of why we just opted for snapshots here was it was already the case with the RN versions of these utils. Imho, we should lean on snapshot tests for a quick (and often large) tree output and trust that our contributors respect them and make updates only after they have validated the changes are intentional. Personally, I find that to be the exact same exercise as just updating some expectedStyle object but I do understand your concern. But I will add a task to re-evaluate this approach holistically and swap out snapshot tests all at once if the team is unconvinced 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

That's fair.

/**
* Resolved message types
*/
export interface MessageComponentStyles {
Copy link
Contributor

Choose a reason for hiding this comment

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

These are the styles provided from pinpoint, right? Should we add a comment describing why these styles are the only ones that can be overwritten?

Copy link
Member Author

Choose a reason for hiding this comment

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

These aren't all coming from Pinpoint (e.g. image and close button styles aren't coming from payload). I think they represent (almost?) everything that is displayed in a message component, however, so we are actually allowing a lot of overriding via styles. Maybe the comment can be shored up (admittedly, it was copied from the React Native version of this hook)

import { MessagePayloadStyle } from '@aws-amplify/ui-react-core';
import React from 'react';

// import { ImageDimensions } from '../useMessageImage';
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: unused import

styles: MessageComponentStyles | null;
}

export interface MessageStyleParams {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this extra interface necessary, or could getMessageStyles just take a single argument of type StyleParams? I guess the question is, are you expecting to receive add more properties here?

Copy link
Member Author

Choose a reason for hiding this comment

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

A large part of doing this was simply to maintain parity with the React Native counterpart. We could scrap it and just inline the StyleParams typing in the function arguments but it is probably cleaner and more easily extensible (should we decide we do need to add more arguments especially as we add more complex components e.g. Carousel - even though I don't anticipate it yet).

Copy link
Contributor

@katieklein katieklein left a comment

Choose a reason for hiding this comment

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

lgtm. qq - should the useMessageImage commented code be included in this PR?

@cshfang
Copy link
Member Author

cshfang commented Jul 26, 2022

lgtm. qq - should the useMessageImage commented code be included in this PR?

Ideally, probably not. But we know that the PR for that is in flight also and this code needs to be added anyway. There's no real reason this commit would be all that useful on its own.

Chris Fang added 2 commits July 25, 2022 19:10
…shfang/amplify-ui into in-app-messaging/add-use-message-props
Copy link
Member

@calebpollman calebpollman left a comment

Choose a reason for hiding this comment

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

Left some suggestions but LGTM overall

import { MessagePayloadStyle } from '@aws-amplify/ui-react-core';
import React from 'react';

// import { ImageDimensions } from '../useMessageImage';
Copy link
Member

Choose a reason for hiding this comment

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

Think we can delete this line, web useMessageImage does not return ImageDimensions

@cshfang cshfang merged commit 6379c3f into aws-amplify:in-app-messaging/main Jul 27, 2022
@cshfang cshfang deleted the in-app-messaging/add-use-message-props branch July 27, 2022 16:56
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.

4 participants