From f0c397c001fe5c43ffdfcf9fcdb1f25a44c403e1 Mon Sep 17 00:00:00 2001 From: Richard Cox Date: Fri, 5 Apr 2024 15:05:09 +0100 Subject: [PATCH 1/9] Update Node list to support server-side pagination - Setup pagination headers for the node type - Define a pattern for fetching custom list secondary resources - Major improvements to the way pagination settings are defined and created - Lots of docs improvements - Handle calling fetch again once fetch is in progress (nuxt caches running request) - Validate filter fields (not all are supported by the vai cache - General pagination fixes --- shell/components/ResourceList/index.vue | 2 +- shell/components/SortableTable/index.vue | 15 - shell/config/product/explorer.js | 64 ++- shell/config/table-headers.js | 2 +- shell/list/node.vue | 291 +++++++++---- shell/mixins/fetch.client.js | 18 +- shell/mixins/resource-fetch-api-pagination.js | 86 ++-- shell/mixins/resource-fetch.js | 14 +- shell/models/cluster/node.js | 4 + shell/plugins/dashboard-store/actions.js | 26 +- shell/plugins/dashboard-store/getters.js | 18 +- shell/plugins/steve/__tests__/getters.test.ts | 2 +- .../steve/accept-or-reject-socket-message.ts | 3 +- shell/plugins/steve/getters.js | 6 +- .../projectAndNamespaceFiltering.utils.ts | 6 +- shell/plugins/steve/steve-pagination-utils.ts | 133 ++++-- shell/types/store/dashboard-store.types.ts | 174 +------- shell/types/store/pagination.types.ts | 403 ++++++++++++++++++ .../store/{type-map.d.ts => type-map.ts} | 15 + shell/utils/array.ts | 28 +- shell/utils/pagination-utils.ts | 20 +- 21 files changed, 956 insertions(+), 374 deletions(-) create mode 100644 shell/types/store/pagination.types.ts rename shell/types/store/{type-map.d.ts => type-map.ts} (50%) diff --git a/shell/components/ResourceList/index.vue b/shell/components/ResourceList/index.vue index b3078a962e..c248037a13 100644 --- a/shell/components/ResourceList/index.vue +++ b/shell/components/ResourceList/index.vue @@ -172,7 +172,7 @@ export default { * This covers case 1 */ pagination(neu, old) { - if (neu && !this.componentWillFetch && this.paginationEqual(neu, old)) { + if (neu && !this.componentWillFetch && !this.paginationEqual(neu, old)) { this.$fetchType(this.resource); } }, diff --git a/shell/components/SortableTable/index.vue b/shell/components/SortableTable/index.vue index 423999381c..034777ed10 100644 --- a/shell/components/SortableTable/index.vue +++ b/shell/components/SortableTable/index.vue @@ -29,21 +29,6 @@ import { getParent } from '@shell/utils/dom'; // NOTE: This is populated by a plugin (formatters.js) to avoid issues with plugins export const FORMATTERS = {}; -export const COLUMN_BREAKPOINTS = { - /** - * Only show column if at tablet width or wider - */ - TABLET: 'tablet', - /** - * Only show column if at laptop width or wider - */ - LAPTOP: 'laptop', - /** - * Only show column if at desktop width or wider - */ - DESKTOP: 'desktop' -}; - // @TODO: // Fixed header/scrolling diff --git a/shell/config/product/explorer.js b/shell/config/product/explorer.js index e0fb117825..2a2aeed23f 100644 --- a/shell/config/product/explorer.js +++ b/shell/config/product/explorer.js @@ -19,7 +19,7 @@ import { STORAGE_CLASS_PROVISIONER, PERSISTENT_VOLUME_SOURCE, HPA_REFERENCE, MIN_REPLICA, MAX_REPLICA, CURRENT_REPLICA, ACCESS_KEY, DESCRIPTION, EXPIRES, EXPIRY_STATE, SUB_TYPE, AGE_NORMAN, SCOPE_NORMAN, PERSISTENT_VOLUME_CLAIM, RECLAIM_POLICY, PV_REASON, WORKLOAD_HEALTH_SCALE, POD_RESTARTS, - DURATION, MESSAGE, REASON, LAST_SEEN_TIME, EVENT_TYPE, OBJECT, ROLE, SECRET_DATA + DURATION, MESSAGE, REASON, LAST_SEEN_TIME, EVENT_TYPE, OBJECT, ROLE, ROLES, VERSION, INTERNAL_EXTERNAL_IP, KUBE_NODE_OS, CPU, RAM, PODS, SECRET_DATA } from '@shell/config/table-headers'; import { DSL } from '@shell/store/type-map'; @@ -27,6 +27,8 @@ import { STEVE_AGE_COL, STEVE_LIST_GROUPS, STEVE_NAMESPACE_COL, STEVE_NAME_COL, STEVE_STATE_COL } from '@shell/config/pagination-table-headers'; +import { COLUMN_BREAKPOINTS } from '@shell/types/store/type-map'; + export const NAME = 'explorer'; export function init(store) { @@ -267,6 +269,66 @@ export function init(store) { STEVE_AGE_COL ]); + headers(NODE, + [ + STATE, + NAME, + ROLES, + VERSION, + INTERNAL_EXTERNAL_IP, + { + ...KUBE_NODE_OS, + breakpoint: COLUMN_BREAKPOINTS.LAPTOP, + getValue: (row) => row.status?.nodeInfo?.operatingSystem + }, + { + ...CPU, + breakpoint: COLUMN_BREAKPOINTS.LAPTOP, + getValue: (row) => row.cpuUsagePercentage + }, { + ...RAM, + breakpoint: COLUMN_BREAKPOINTS.LAPTOP, + getValue: (row) => row.ramUsagePercentage + }, + AGE + ], + [ + STEVE_STATE_COL, + STEVE_NAME_COL, + { + ...ROLES, + sort: false, + search: false + }, + { + ...VERSION, + value: 'status.nodeInfo.kubeletVersion', + getValue: undefined, + sort: ['status.nodeInfo.kubeletVersion'], + search: 'status.nodeInfo.kubeletVersion' + }, { + ...INTERNAL_EXTERNAL_IP, + sort: false, + search: false, + }, { + ...KUBE_NODE_OS, + breakpoint: COLUMN_BREAKPOINTS.LAPTOP, + getValue: undefined + }, { + ...CPU, + breakpoint: COLUMN_BREAKPOINTS.LAPTOP, + getValue: (row) => row.cpuUsagePercentage, + sort: false, + search: false, + }, { + ...RAM, + breakpoint: COLUMN_BREAKPOINTS.LAPTOP, + sort: false, + search: false, + }, + STEVE_AGE_COL + ]); + headers(MANAGEMENT.PSA, [STATE, NAME_COL, { ...DESCRIPTION, width: undefined diff --git a/shell/config/table-headers.js b/shell/config/table-headers.js index 7aa3531abc..98df8540b1 100644 --- a/shell/config/table-headers.js +++ b/shell/config/table-headers.js @@ -1,6 +1,6 @@ import { CATTLE_PUBLIC_ENDPOINTS } from '@shell/config/labels-annotations'; import { NODE as NODE_TYPE } from '@shell/config/types'; -import { COLUMN_BREAKPOINTS } from '@shell/components/SortableTable/index.vue'; +import { COLUMN_BREAKPOINTS } from '@shell/types/store/type-map'; // Note: 'id' is always the last sort, so you don't have to specify it here. diff --git a/shell/list/node.vue b/shell/list/node.vue index 84c25fd388..da8eaf67a7 100644 --- a/shell/list/node.vue +++ b/shell/list/node.vue @@ -1,21 +1,28 @@ -