Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 468
feat(shared): Organization hooks with setData and revalidate#1745
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e20e16a
feat(shared): Expose stable mutate
panteliselef 870b9d4
chore(clerk-js): OrganizationList and switcher with stable mutate
panteliselef 612268a
chore(clerk-js): OrganizationProfile with stable mutate
panteliselef 60474fd
fix(shared): Replace mutate with setCache and revalidate
panteliselef deb7ea4
fix(clerk-js): Replace mutate with setCache and revalidate
panteliselef bf36da8
chore(clerk-js,shared): Replace setCache with setData
panteliselef 67d3c1f
fix(shared): Remove unnecessary complexity in types
panteliselef 31645dc
chore(clerk-js): Update after rebase
panteliselef 06a7d7d
chore(shared): Add comments with context
panteliselef d760fbc
chore(shared): Update changeset
panteliselef File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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 |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@clerk/shared': minor | ||
| --- | ||
| Expose `revalidate` and `setData` for paginated lists of data in organization hooks. | ||
| `const {userMemberships:{revalidate, setData}} = useOrganizationList({userMemberships:true})` |
4 changes: 2 additions & 2 deletions
4 packages/clerk-js/src/ui/components/OrganizationList/UserInvitationList.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
4 changes: 2 additions & 2 deletions
4 packages/clerk-js/src/ui/components/OrganizationList/UserSuggestionList.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
13 changes: 3 additions & 10 deletions
13 packages/clerk-js/src/ui/components/OrganizationProfile/ActiveMembersList.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
2 changes: 1 addition & 1 deletion
2 packages/clerk-js/src/ui/components/OrganizationProfile/RemoveDomainPage.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
12 changes: 9 additions & 3 deletions
12 packages/clerk-js/src/ui/components/OrganizationProfile/RequestToJoinList.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
6 changes: 3 additions & 3 deletions
6 packages/clerk-js/src/ui/components/OrganizationProfile/VerifiedDomainPage.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
6 changes: 3 additions & 3 deletions
6 packages/clerk-js/src/ui/components/OrganizationSwitcher/UserInvitationSuggestionList.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
52 changes: 26 additions & 26 deletions
52 packages/clerk-js/src/ui/components/OrganizationSwitcher/utils.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 |
|---|---|---|
| @@ -17,9 +17,20 @@ export const organizationListParams = { | ||
| export const populateCacheUpdateItem = <T extends { id: string }>( | ||
| updatedItem: T, | ||
| itemsInfinitePages: ClerkPaginatedResponse<T>[], | ||
| itemsInfinitePages: (ClerkPaginatedResponse<T> | undefined)[] | undefined, | ||
| ) => { | ||
| if (typeof itemsInfinitePages === 'undefined') { | ||
| return [{ data: [updatedItem], total_count: 1 }]; | ||
| } | ||
| /** | ||
| * We should "preserve" an undefined page if one is found. For example if swr triggers 2 requests, page 1 & page2, and the request for page2 resolves first, at that point in memory itemsInfinitePages would look like this [undefined, {....}] | ||
| * if SWR says that has fetched 2 pages but the first result of is undefined, we should not return back an array with 1 item as this will end up having cacheKeys that point nowhere. | ||
| */ | ||
| return itemsInfinitePages.map(item => { | ||
| if (typeof item === 'undefined') { | ||
| return item; | ||
| } | ||
| const newData = item.data.map(obj => { | ||
| if (obj.id === updatedItem.id) { | ||
| return { | ||
| @@ -33,38 +44,27 @@ export const populateCacheUpdateItem = <T extends { id: string }>( | ||
| }); | ||
| }; | ||
| export const updateCacheInPlace = | ||
| (userSuggestions: any) => | ||
| <T extends { id: string }>(result: T): any => { | ||
| userSuggestions?.unstable__mutate?.(result, { | ||
| populateCache: populateCacheUpdateItem, | ||
| // Since `accept` gives back the updated information, | ||
| // we don't need to revalidate here. | ||
| revalidate: false, | ||
| }); | ||
| }; | ||
| export const populateCacheRemoveItem = <T extends { id: string }>( | ||
| updatedItem: T, | ||
| itemsInfinitePages: ClerkPaginatedResponse<T>[], | ||
| itemsInfinitePages: (ClerkPaginatedResponse<T> | undefined)[] | undefined, | ||
| ) => { | ||
| const prevTotalCount = itemsInfinitePages[itemsInfinitePages.length - 1].total_count; | ||
| const prevTotalCount = itemsInfinitePages?.[itemsInfinitePages.length - 1]?.total_count; | ||
| return itemsInfinitePages.map(item => { | ||
| if (!prevTotalCount) { | ||
| return undefined; | ||
| } | ||
| /** | ||
| * We should "preserve" an undefined page if one is found. For example if swr triggers 2 requests, page 1 & page2, and the request for page2 resolves first, at that point in memory itemsInfinitePages would look like this [undefined, {....}] | ||
| * if SWR says that has fetched 2 pages but the first result of is undefined, we should not return back an array with 1 item as this will end up having cacheKeys that point nowhere. | ||
| */ | ||
| return itemsInfinitePages?.map(item => { | ||
| if (typeof item === 'undefined') { | ||
panteliselef marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| return item; | ||
| } | ||
| const newData = item.data.filter(obj => { | ||
| return obj.id !== updatedItem.id; | ||
| }); | ||
| return { ...item, data: newData, total_count: prevTotalCount - 1 }; | ||
| }); | ||
| }; | ||
| export const removeItemFromPaginatedCache = | ||
| (userInvitations: any) => | ||
| <T extends { id: string }>(result: T): any => { | ||
| userInvitations?.unstable__mutate?.(result, { | ||
| populateCache: populateCacheRemoveItem, | ||
| // Since `accept` gives back the updated information, | ||
| // we don't need to revalidate here. | ||
| revalidate: false, | ||
| }); | ||
| }; | ||
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
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gentle reminder ☝️