From 08f05e229a619efba00a84301f94ff09f76aad7d Mon Sep 17 00:00:00 2001 From: Richard Cox Date: Tue, 23 Jul 2024 12:10:53 +0100 Subject: [PATCH] Paginated Label Select Fixes ### No Options Shown - Ensure all ResourceLabeledSelect attributes reach LabelSelect component - This worked at some point, but $attrs now does not contain values that are defined as component props ### Cannot `Load More` options - `Pages` param Missing in API response - This has been removed, work around added ### Search term isn't matching partial results - ensure exact filter matching is off --- shell/components/form/ResourceLabeledSelect.vue | 14 +++++++++++--- .../labeled-select-utils/labeled-select.utils.ts | 2 +- shell/plugins/dashboard-store/actions.js | 2 +- shell/types/store/pagination.types.ts | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/shell/components/form/ResourceLabeledSelect.vue b/shell/components/form/ResourceLabeledSelect.vue index da4e54578f1..d2fd1b8ca89 100644 --- a/shell/components/form/ResourceLabeledSelect.vue +++ b/shell/components/form/ResourceLabeledSelect.vue @@ -126,11 +126,17 @@ export default defineComponent({ computed: { labelSelectAttributes() { + // This component is a wrapper for LabelSelect, so pass through everything + const allAttrs = { + ...this.$attrs, // Attributes (other than props) + ...this.$props, // Attributes that are props + }; + return this.paginate ? { - ...this.$attrs, + ...allAttrs, ...this.paginatedResourceSettings?.labelSelectOptions || {} } : { - ...this.$attrs, + ...allAttrs, ...this.allResourcesSettings?.labelSelectOptions || {} }; }, @@ -156,7 +162,9 @@ export default defineComponent({ } const { filter } = opts; - const filters = !!filter ? [PaginationParamFilter.createSingleField({ field: 'metadata.name', value: filter })] : []; + const filters = !!filter ? [PaginationParamFilter.createSingleField({ + field: 'metadata.name', value: filter, exact: false + })] : []; const defaultOptions: LabelSelectPaginationFunctionOptions = { opts, filters, diff --git a/shell/components/form/labeled-select-utils/labeled-select.utils.ts b/shell/components/form/labeled-select-utils/labeled-select.utils.ts index e47761ad7e2..04dab0e9c41 100644 --- a/shell/components/form/labeled-select-utils/labeled-select.utils.ts +++ b/shell/components/form/labeled-select-utils/labeled-select.utils.ts @@ -109,7 +109,7 @@ export async function labelSelectPaginationFunction({ return { page: resPage, - pages: res.pages, + pages: res.pages || Math.ceil(res.count / (pageSize || Number.MAX_SAFE_INTEGER)), total: res.count }; } catch (err) { diff --git a/shell/plugins/dashboard-store/actions.js b/shell/plugins/dashboard-store/actions.js index ae1a0fa3c01..ab063bed970 100644 --- a/shell/plugins/dashboard-store/actions.js +++ b/shell/plugins/dashboard-store/actions.js @@ -419,7 +419,7 @@ export default { }, result: { count: out.count, - pages: out.pages, + pages: out.pages || Math.ceil(out.count / (opt.pagination.pageSize || Number.MAX_SAFE_INTEGER)), timestamp: new Date().getTime() } } : undefined, diff --git a/shell/types/store/pagination.types.ts b/shell/types/store/pagination.types.ts index 02da890fb10..716c7c3d9ff 100644 --- a/shell/types/store/pagination.types.ts +++ b/shell/types/store/pagination.types.ts @@ -227,7 +227,7 @@ export class PaginationParamFilter extends PaginationParam { /** * Convenience method when you just want an instance of {@link PaginationParamFilter} with a simple `filter=x=y` param */ - static createSingleField(field: { field?: string; value: string; equals?: boolean; }): PaginationParam { + static createSingleField(field: { field?: string; value: string; equals?: boolean; exact?: boolean }): PaginationParam { return new PaginationParamFilter({ fields: [new PaginationFilterField(field)] }); }