-
Notifications
You must be signed in to change notification settings - Fork 2
BA-2267: generate edit username #221
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| export { default as withTokenSetup } from './withTokenSetup' | ||
| export { default as withProviders } from './withProviders' | ||
| export { default as withMutationResolver } from './withMutationResolver' |
67 changes: 67 additions & 0 deletions
67
packages/components/.storybook/decorators/withMutationResolver.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import React, { useEffect } from 'react' | ||
|
|
||
| import { createTestEnvironment } from '@baseapp-frontend/graphql' | ||
|
|
||
| import type { StoryContext, StoryFn } from '@storybook/react' | ||
| import { Observable, OperationDescriptor } from 'relay-runtime' | ||
| import { MockPayloadGenerator } from 'relay-test-utils' | ||
| import { MockResolvers } from 'relay-test-utils/lib/RelayMockPayloadGenerator' | ||
|
|
||
| export type DynamicMockResolvers = (operation: OperationDescriptor) => MockResolvers | ||
|
|
||
| const withMutationResolver = (Story: StoryFn, context: StoryContext) => { | ||
| const { environment, queueOperationResolver } = context.parameters | ||
| .relayMockEnvironment as ReturnType<typeof createTestEnvironment> | ||
|
|
||
| const mockResolvers = context.parameters.mockResolvers || undefined | ||
| const dynamicMockResolvers: DynamicMockResolvers = | ||
| context.parameters.dynamicMockResolvers || undefined | ||
| const mutationError: string = context.parameters.mutationError || undefined | ||
|
|
||
| useEffect(() => { | ||
| const originalExecuteMutation = environment.executeMutation | ||
|
|
||
| environment.executeMutation = (request) => { | ||
| if (!mutationError) { | ||
| if (dynamicMockResolvers) { | ||
| environment.mock.queueOperationResolver(() => { | ||
| return MockPayloadGenerator.generate( | ||
| request.operation, | ||
| dynamicMockResolvers(request.operation), | ||
| ) | ||
| }) | ||
| } else if (mockResolvers) { | ||
| environment.mock.queueOperationResolver(() => { | ||
| return MockPayloadGenerator.generate(request.operation, mockResolvers) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| const observable = originalExecuteMutation.call(environment, request) | ||
|
|
||
| return Observable.create((sink) => { | ||
| if (mutationError) { | ||
| setTimeout(() => { | ||
| sink.error(new Error(mutationError)) | ||
| }, 100) | ||
| } else { | ||
| observable.subscribe({ | ||
| complete: () => { | ||
| setTimeout(() => { | ||
| sink.complete() | ||
| }, 100) | ||
| }, | ||
| }) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| return () => { | ||
| environment.executeMutation = originalExecuteMutation | ||
| } | ||
| }, [environment, queueOperationResolver]) | ||
|
|
||
| return <Story /> | ||
| } | ||
|
|
||
| export default withMutationResolver | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions
22
packages/components/modules/profiles/common/graphql/fragments/ProfilesList.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { graphql } from 'react-relay' | ||
|
|
||
| export const ProfilesListFragment = graphql` | ||
| fragment ProfilesListFragment on User | ||
| @argumentDefinitions(count: { type: "Int", defaultValue: 10 }, cursor: { type: "String" }) | ||
| @refetchable(queryName: "profilesListRefetchable") { | ||
| id | ||
| profiles(first: $count, after: $cursor) @connection(key: "ProfilesListFragment_profiles") { | ||
| edges { | ||
| cursor | ||
| node { | ||
| id | ||
| ...ProfileItemFragment | ||
| } | ||
| } | ||
| pageInfo { | ||
| hasNextPage | ||
| endCursor | ||
| } | ||
| } | ||
| } | ||
| ` |
28 changes: 28 additions & 0 deletions
28
packages/components/modules/profiles/common/graphql/fragments/UserMembersList.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { graphql } from 'react-relay' | ||
|
|
||
| export const UserMembersListFragment = graphql` | ||
| fragment UserMembersListFragment on Profile | ||
| @refetchable(queryName: "userMembersListPaginationRefetchable") | ||
| @argumentDefinitions( | ||
| count: { type: "Int", defaultValue: 10 } | ||
| cursor: { type: "String" } | ||
| orderBy: { type: "String" } | ||
| q: { type: "String" } | ||
| ) { | ||
| canChangeRole: hasPerm(perm: "baseapp_profiles.change_profileuserrole") | ||
| ...ProfileItemFragment | ||
| members(first: $count, after: $cursor, orderBy: $orderBy, q: $q) | ||
| @connection(key: "UserMembersFragment_members", filters: ["orderBy", "q"]) { | ||
| totalCount | ||
| edges { | ||
| node { | ||
| ...MemberItemFragment | ||
| } | ||
| } | ||
| pageInfo { | ||
| endCursor | ||
| hasNextPage | ||
| } | ||
| } | ||
| } | ||
| ` |
9 changes: 9 additions & 0 deletions
9
packages/components/modules/profiles/common/graphql/queries/ProfileSettingsRelayTest.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { graphql } from 'react-relay' | ||
|
|
||
| export const ProfileSettingsRelayTest = graphql` | ||
| query ProfileSettingsRelayTestQuery @relay_test_operation { | ||
| profile: node(id: "test-id") { | ||
| ...ProfileComponentFragment | ||
| } | ||
| } | ||
| ` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/components/modules/profiles/web/ProfileSettingsComponent/__storybook__/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { useLazyLoadQuery } from 'react-relay' | ||
|
|
||
| import { ProfileSettingsRelayTestQuery as QueryType } from '../../../../../__generated__/ProfileSettingsRelayTestQuery.graphql' | ||
| import { ProfileSettingsRelayTest } from '../../../common/graphql/queries/ProfileSettingsRelayTest' | ||
| import ProfileSettingsComponent from '../index' | ||
| import { ProfileSettingsComponentProps } from '../types' | ||
|
|
||
| const ProfileSettingsComponentWithQuery = (props: ProfileSettingsComponentProps) => { | ||
| const profileRef = useLazyLoadQuery<QueryType>(ProfileSettingsRelayTest, {}) | ||
|
|
||
| return <ProfileSettingsComponent {...props} profile={profileRef.profile} /> | ||
| } | ||
|
|
||
| export default ProfileSettingsComponentWithQuery |
30 changes: 30 additions & 0 deletions
30
...es/components/modules/profiles/web/ProfileSettingsComponent/__storybook__/mockResolver.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| export const mockResolvers = { | ||
| Node: () => ({ | ||
| __typename: 'Profile', | ||
| id: '1', | ||
| name: 'Profile 1', | ||
| biography: 'Profile 1 biography', | ||
| image: null, | ||
| bannerImage: null, | ||
| canChange: true, | ||
| canDelete: true, | ||
| urlPath: { | ||
| path: '/profile/1', | ||
| }, | ||
| owner: { | ||
| phoneNumber: '1234567890', | ||
| }, | ||
| }), | ||
| Mutation: () => ({ | ||
| profileUpdate: { | ||
| errors: null, | ||
| }, | ||
| }), | ||
| } | ||
pt-tsl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export const mockResolversWithMutationError = { | ||
| ...mockResolvers, | ||
| Mutation: () => ({ | ||
| profileUpdate: {}, | ||
| }), | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.