-
Notifications
You must be signed in to change notification settings - Fork 398
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
CB-5658 CB-5659 fix: pagination resolving #2922
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5bd6122
CB-5658 CB-5659 fix: pagination resolving
Wroud bb6e6e3
Merge branch 'devel' into fix/cb-5658/pagination-resolving
Wroud a170f07
Merge branch 'devel' into fix/cb-5658/pagination-resolving
mr-anton-t 888ccfe
CB-5658 fix resources pages
Wroud 7b48f02
Merge branch 'devel' into fix/cb-5658/pagination-resolving
dariamarutkina 979dc0c
CB-5667 fix: node rename behavior
Wroud d5783af
CB-5658 chore: refactor repeated code
Wroud 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 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 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 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 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 |
---|---|---|
|
@@ -34,7 +34,7 @@ import { isResourceAlias } from './ResourceAlias'; | |
import { ResourceError } from './ResourceError'; | ||
import type { ResourceKey, ResourceKeyFlat } from './ResourceKey'; | ||
import { resourceKeyAlias } from './ResourceKeyAlias'; | ||
import { resourceKeyList } from './ResourceKeyList'; | ||
import { isResourceKeyList, resourceKeyList } from './ResourceKeyList'; | ||
import { resourceKeyListAlias } from './ResourceKeyListAlias'; | ||
import { ResourceOffsetPagination } from './ResourceOffsetPagination'; | ||
|
||
|
@@ -91,41 +91,58 @@ export abstract class CachedResource< | |
this.aliases.add(CachedResourceParamKey, () => defaultKey); | ||
this.aliases.add(CachedResourceListEmptyKey, () => resourceKeyList([])); | ||
this.aliases.add(CachedResourceOffsetPageTargetKey, key => key.options.target); | ||
this.aliases.add(CachedResourceOffsetPageKey, key => { | ||
const keys = []; | ||
const pageInfo = this.offsetPagination.getPageInfo(key); | ||
this.aliases.add( | ||
CachedResourceOffsetPageListKey, | ||
key => key.parent! as any, | ||
(param, key) => { | ||
if (!isResourceKeyList(key)) { | ||
return key as any; | ||
} | ||
|
||
if (pageInfo) { | ||
const from = key.options.offset; | ||
const to = key.options.offset + key.options.limit; | ||
const keys = new Set<any>(); | ||
const pageInfo = this.offsetPagination.getPageInfo(param); | ||
|
||
for (const page of pageInfo.pages) { | ||
if (page.isHasCommonSegment(from, to)) { | ||
keys.push(...page.get(from, to)); | ||
if (pageInfo) { | ||
const from = param.options.offset; | ||
const to = param.options.offset + param.options.limit; | ||
|
||
for (const page of pageInfo.pages) { | ||
if (page.isHasCommonSegment(from, to)) { | ||
for (const pageKey of page.get(from, to)) { | ||
keys.add(pageKey); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return resourceKeyList(key.filter(value => keys.has(value))); | ||
}, | ||
); | ||
this.aliases.add( | ||
CachedResourceOffsetPageKey, | ||
key => key.parent! as any, | ||
(param, key) => { | ||
if (!isResourceKeyList(key)) { | ||
return key as any; | ||
} | ||
|
||
// todo: return single element? | ||
return resourceKeyList([...new Set(keys)]); | ||
}); | ||
this.aliases.add(CachedResourceOffsetPageListKey, key => { | ||
const keys = []; | ||
const pageInfo = this.offsetPagination.getPageInfo(key); | ||
const keys = new Set<any>(); | ||
const pageInfo = this.offsetPagination.getPageInfo(param); | ||
|
||
if (pageInfo) { | ||
const from = key.options.offset; | ||
const to = key.options.offset + key.options.limit; | ||
if (pageInfo) { | ||
const from = param.options.offset; | ||
const to = param.options.offset + param.options.limit; | ||
|
||
for (const page of pageInfo.pages) { | ||
if (page.isHasCommonSegment(from, to)) { | ||
keys.push(...page.get(from, to)); | ||
for (const page of pageInfo.pages) { | ||
if (page.isHasCommonSegment(from, to)) { | ||
for (const pageKey of page.get(from, to)) { | ||
keys.add(pageKey); | ||
} | ||
} | ||
Comment on lines
+135
to
+140
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. we can define helper like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's keep it for now |
||
} | ||
} | ||
} | ||
|
||
return resourceKeyList([...new Set(keys)]); | ||
}); | ||
return resourceKeyList(key.filter(value => keys.has(value))); | ||
}, | ||
); | ||
|
||
// this.logger.spy(this.beforeLoad, 'beforeLoad'); | ||
// this.logger.spy(this.onDataOutdated, 'onDataOutdated'); | ||
|
@@ -329,6 +346,7 @@ export abstract class CachedResource< | |
} | ||
|
||
const pageKey = this.aliases.isAlias(param, CachedResourceOffsetPageKey) || this.aliases.isAlias(param, CachedResourceOffsetPageListKey); | ||
|
||
if (pageKey) { | ||
const pageInfo = this.offsetPagination.getPageInfo(pageKey); | ||
|
||
|
This file contains 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 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 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.
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.
I can see a copy-paste here and a little bit below for all resources with pagination.
Maybe we should add a helper here so it returns the correct
pageKey
and thepage
? So we don't miss this bug when we create a new feature with the exact pagination mechanismThere 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.
now you can use
getOffsetPageKeyInfo
helper