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

chore(ui,ui-react-core): Add type guard utils #3291

Merged
merged 6 commits into from
Jan 27, 2023
Merged

chore(ui,ui-react-core): Add type guard utils #3291

merged 6 commits into from
Jan 27, 2023

Conversation

ioanabrooks
Copy link
Contributor

@ioanabrooks ioanabrooks commented Jan 11, 2023

Description of changes

This change adds the following type guard utils:

  • isObject
  • isString
  • isUndefined
    in an effort to make some progress towards removing lodash dependency.

Notes:

  • isString is equivalent to the lodash implementation as it is used by inAppMessagging inside of handleMessageAction util to check the validity of the URL we receive from the message payload delivered by Pinpoint via Amplify JS, and we want to cover edge case as much as possible since we have no control over what is sent over.
  • isObject diverges from lodash implementation based on internal usage [when checking is something is an object we also check it's not an array so excluding arrays from this util is a quality of life improvement, additionally the likelihood of functions occurring based on current usage at least is low].

Issue #, if available

Description of how you validated changes

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.

@ioanabrooks ioanabrooks requested a review from a team as a code owner January 11, 2023 20:12
@changeset-bot
Copy link

changeset-bot bot commented Jan 11, 2023

🦋 Changeset detected

Latest commit: 4069dba

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@aws-amplify/ui-react-core Patch
@aws-amplify/ui Patch
@aws-amplify/ui-react-native Patch
@aws-amplify/ui-react Patch
@aws-amplify/ui-vue Patch
@aws-amplify/ui-angular Patch

Not sure what this means? Click here to learn what changesets are.

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

0618
0618 previously approved these changes Jan 11, 2023
Copy link
Contributor

@0618 0618 left a comment

Choose a reason for hiding this comment

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

LGTM

packages/react-core/src/utils/index.ts Show resolved Hide resolved
@ioanabrooks ioanabrooks temporarily deployed to ci January 11, 2023 20:32 — with GitHub Actions Inactive
@ioanabrooks ioanabrooks temporarily deployed to ci January 11, 2023 20:32 — with GitHub Actions Inactive
@ioanabrooks ioanabrooks temporarily deployed to ci January 11, 2023 20:32 — with GitHub Actions Inactive
@ioanabrooks ioanabrooks temporarily deployed to ci January 11, 2023 20:32 — with GitHub Actions Inactive
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.

Thanks for doing this!

What do you think of moving these in to a top level utils folder and putting them in to their own files? Currently the helpers folder is coupled to connected component utils/helpers. IMO it would make sense to keep these in their own folder since they are more generic, and to leave helpers as is to keep a separation of concerns (in particular since the connected component helpers/utils are most likely not living in the UI package long term)

packages/ui/src/helpers/typeGuards.ts Outdated Show resolved Hide resolved
packages/ui/src/helpers/typeGuards.ts Outdated Show resolved Hide resolved
packages/ui/src/helpers/typeGuards.ts Outdated Show resolved Hide resolved
@0618 0618 mentioned this pull request Jan 11, 2023
4 tasks
dbanksdesign
dbanksdesign previously approved these changes Jan 19, 2023
Copy link
Contributor

@dbanksdesign dbanksdesign left a comment

Choose a reason for hiding this comment

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

LGTM! Tentative approval for @calebpollman's comment on TS strict not liking isUndefined

@@ -11,7 +11,7 @@ export function areEmptyArrays<T>(...values: T[]): boolean {
}

function isEmptyObject<T>(value: T): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe for a future PR, should these functions like isEmptyObject be in the UI package so other frameworks can use it?

@@ -0,0 +1,59 @@
import { isObject, isString, isUndefined } from '../typeGuards';

describe('isObject', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yay unit tests!!

packages/ui/src/helpers/typeGuards.ts Outdated Show resolved Hide resolved
packages/ui/src/helpers/typeGuards.ts Outdated Show resolved Hide resolved
@ioanabrooks ioanabrooks dismissed stale reviews from dbanksdesign and 0618 via 5753ff3 January 25, 2023 20:23
@ioanabrooks ioanabrooks temporarily deployed to ci January 25, 2023 20:45 — with GitHub Actions Inactive
@ioanabrooks ioanabrooks temporarily deployed to ci January 25, 2023 20:45 — with GitHub Actions Inactive
@ioanabrooks ioanabrooks temporarily deployed to ci January 25, 2023 20:45 — with GitHub Actions Inactive
@ioanabrooks ioanabrooks temporarily deployed to ci January 25, 2023 20:45 — with GitHub Actions Inactive
dbanksdesign
dbanksdesign previously approved these changes Jan 25, 2023
Copy link
Contributor

@dbanksdesign dbanksdesign left a comment

Choose a reason for hiding this comment

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

LGTM! I'm fine either way about the isObject being the exact lodash method or not.

0618
0618 previously approved these changes Jan 25, 2023
@0618 0618 dismissed their stale review January 26, 2023 16:59

Wait for Caleb's approval

@ioanabrooks ioanabrooks temporarily deployed to ci January 26, 2023 20:12 — with GitHub Actions Inactive
@ioanabrooks ioanabrooks temporarily deployed to ci January 26, 2023 20:12 — with GitHub Actions Inactive
@ioanabrooks ioanabrooks temporarily deployed to ci January 26, 2023 20:12 — with GitHub Actions Inactive
@ioanabrooks ioanabrooks temporarily deployed to ci January 26, 2023 20:12 — with GitHub Actions Inactive
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.

🚢 🚢 🚢

@ioanabrooks ioanabrooks merged commit 9ce2d01 into main Jan 27, 2023
@ioanabrooks ioanabrooks deleted the type-guards branch January 27, 2023 17:44
@github-actions github-actions bot mentioned this pull request Jan 27, 2023
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.

6 participants