-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11318 from richard-cox/2.8-limit-bindings
Add conditional depagination by native api, apply to bindings
- Loading branch information
Showing
6 changed files
with
91 additions
and
7 deletions.
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { VuexStoreGetters } from '@shell/types/store/vuex'; | ||
import { COUNT } from '@shell/config/types'; | ||
import { ActionFindAllArgs } from '@shell/types/store/dashboard-store.types'; | ||
|
||
type conditionalDepaginateArgs ={ | ||
ctx: { rootGetters: VuexStoreGetters}, | ||
args: { type: string, opt: ActionFindAllArgs}, | ||
}; | ||
type conditionalDepaginateFn = (args: conditionalDepaginateArgs) => boolean | ||
|
||
/** | ||
* Conditionally determine if a resource should use naive kube pagination api to fetch all results | ||
* (not just first page) | ||
*/ | ||
export const conditionalDepaginate = ( | ||
depaginate?: conditionalDepaginateFn | boolean, | ||
depaginateArgs?: conditionalDepaginateArgs | ||
): boolean => { | ||
if (typeof depaginate === 'function') { | ||
return !!depaginateArgs ? depaginate(depaginateArgs) : false; | ||
} | ||
|
||
return depaginate as boolean; | ||
}; | ||
|
||
/** | ||
* Setup a function that will determine if a resource should use native kube pagination api to fetch all resources | ||
* (not just the first page) | ||
*/ | ||
export const configureConditionalDepaginate = ( | ||
{ maxResourceCount, isNorman = false }: { maxResourceCount: number, isNorman: boolean }, | ||
): conditionalDepaginateFn => { | ||
return (fnArgs: conditionalDepaginateArgs ): boolean => { | ||
const { rootGetters } = fnArgs.ctx; | ||
const { type } = fnArgs.args; | ||
const safeType = isNorman ? `management.cattle.io.${ type }` : type; | ||
|
||
const inStore = rootGetters['currentStore'](safeType); | ||
const resourceCounts = rootGetters[`${ inStore }/all`](COUNT)[0]?.counts[safeType]; | ||
const resourceCount = resourceCounts?.summary?.count; | ||
|
||
return resourceCount !== undefined ? resourceCount < maxResourceCount : false; | ||
}; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Properties on all findX actions | ||
*/ | ||
export type ActionCoreFindArgs = { | ||
force?: boolean, | ||
} | ||
|
||
/** | ||
* Args used for findAll action | ||
*/ | ||
export interface ActionFindAllArgs extends ActionCoreFindArgs { | ||
watch?: boolean, | ||
namespaced?: string[], | ||
incremental?: boolean, | ||
hasManualRefresh?: boolean, | ||
limit?: number, | ||
/** | ||
* Iterate over all pages and return all resources. | ||
* | ||
* This is done via the native kube pagination api, not steve | ||
*/ | ||
depaginate?: boolean, | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Unfortunately there's no current way to type the vuex store, however we have ts files that references it | ||
// Until we bring that in, this file can contain the interfaces and types used by ts files in place of `any` | ||
|
||
/** | ||
* Generic interface for Vuex getters | ||
*/ | ||
export interface VuexStoreGetters { | ||
[name: string]: Function; | ||
} |