Skip to content

Commit

Permalink
Move PaginatedResourceTable and ResourceLabeledSelect to type file, i…
Browse files Browse the repository at this point in the history
…mproving naming
  • Loading branch information
richard-cox committed Jan 23, 2025
1 parent bec8e7a commit c19aabe
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 73 deletions.
12 changes: 2 additions & 10 deletions shell/components/PaginatedResourceTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
import { defineComponent } from 'vue';
import ResourceFetch from '@shell/mixins/resource-fetch';
import ResourceTable from '@shell/components/ResourceTable.vue';
import { StorePaginationResult } from '@shell/types/store/pagination.types';
export type FetchSecondaryResourcesOpts = { canPaginate: boolean }
export type FetchSecondaryResourcesReturns = Promise<any>
export type FetchSecondaryResources = (opts: FetchSecondaryResourcesOpts) => FetchSecondaryResourcesReturns
export type FetchPageSecondaryResourcesOpts = { canPaginate: boolean, force: boolean, page: any[], pagResult: StorePaginationResult }
export type FetchPageSecondaryResources = (opts: FetchPageSecondaryResourcesOpts) => Promise<any>
/**
* This is meant to enable ResourceList like capabilities outside of List pages / components
Expand Down Expand Up @@ -59,7 +51,7 @@ export default defineComponent({
*
* This will fetch them ALL and will be run in a non-server-side pagination world
*
* of type FetchSecondaryResources
* of type PagTableFetchSecondaryResources
*/
fetchSecondaryResources: {
type: Function,
Expand All @@ -73,7 +65,7 @@ export default defineComponent({
*
* called from shell/mixins/resource-fetch-api-pagination.js
*
* of type FetchPageSecondaryResources
* of type PagTableFetchPageSecondaryResources
*/
fetchPageSecondaryResources: {
type: Function,
Expand Down
53 changes: 4 additions & 49 deletions shell/components/form/ResourceLabeledSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,8 @@ import { PropType, defineComponent } from 'vue';
import LabeledSelect from '@shell/components/form/LabeledSelect.vue';
import { PaginationParamFilter } from '@shell/types/store/pagination.types';
import { labelSelectPaginationFunction, LabelSelectPaginationFunctionOptions } from '@shell/components/form/labeled-select-utils/labeled-select.utils';
import { LabelSelectPaginateFn, LabelSelectPaginateFnOptions, LabelSelectPaginateFnResponse } from '@shell/types/components/labeledSelect';
type PaginateTypeOverridesFn = (opts: LabelSelectPaginationFunctionOptions) => LabelSelectPaginationFunctionOptions;
interface SharedSettings {
/**
* Provide specific LabelSelect options for this mode (paginated / not paginated)
*/
labelSelectOptions?: { [key: string]: any },
/**
* Map, filter, tweak, etc the resources to show in the LabelSelect
*/
updateResources?: (resources: any[]) => any[]
}
/**
* Settings to use when the LabelSelect is paginating
*/
export interface ResourceLabeledSelectPaginateSettings extends SharedSettings {
/**
* Override the convenience function which fetches a page of results
*/
overrideRequest?: LabelSelectPaginateFn,
/**
* Override the default settings used in the convenience function to fetch a page of results
*/
requestSettings?: PaginateTypeOverridesFn,
}
/**
* Settings to use when the LabelSelect is fetching all resources (not paginating)
*/
export type ResourceLabeledSelectSettings = SharedSettings
/**
* Force a specific mode
*/
export enum RESOURCE_LABEL_SELECT_MODE {
/**
* Fetch all resources
*/
ALL_RESOURCES = 'ALL', // eslint-disable-line no-unused-vars
/**
* Determine if all resources are fetched given system settings
*/
DYNAMIC = 'DYNAMIC', // eslint-disable-line no-unused-vars
}
import { LabelSelectPaginateFnOptions, LabelSelectPaginateFnResponse } from '@shell/types/components/labeledSelect';
import { RESOURCE_LABEL_SELECT_MODE, ResourceLabeledSelectPaginateSettings, ResourceLabeledSelectSettings } from '@shell/types/components/resourceLabeledSelect';
/**
* Convenience wrapper around the LabelSelect component to support pagination
Expand Down Expand Up @@ -91,15 +46,15 @@ export default defineComponent({
},
/**
* Specific settings to use when we're showing all results
* Specific settings to use when we're showing all results in the drop down
*/
allResourcesSettings: {
type: Object as PropType<ResourceLabeledSelectSettings>,
default: null,
},
/**
* Specific settings to use when we're showing paginated results
* Specific settings to use when we're showing paginated results in the drop down
*/
paginatedResourceSettings: {
type: Object as PropType<ResourceLabeledSelectPaginateSettings>,
Expand Down
2 changes: 1 addition & 1 deletion shell/list/networking.k8s.io.ingress.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default {
methods: {
/**
* of type FetchSecondaryResources
* of type PagTableFetchSecondaryResources
*/
async fetchSecondaryResources(opts) {
// pathExistsInSchema requires schema networking.k8s.io.ingress to have resources fields via schema definition but none were found. has the schema 'fetchResourceFields' been called?
Expand Down
9 changes: 5 additions & 4 deletions shell/list/node.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import PaginatedResourceTable, { FetchPageSecondaryResourcesOpts, FetchSecondaryResourcesOpts, FetchSecondaryResourcesReturns } from '@shell/components/PaginatedResourceTable.vue';
import PaginatedResourceTable from '@shell/components/PaginatedResourceTable.vue';
import Tag from '@shell/components/Tag.vue';
import { Banner } from '@components/Banner';
import { PODS } from '@shell/config/table-headers';
Expand All @@ -19,6 +19,7 @@ import { GROUP_RESOURCES, mapPref } from '@shell/store/prefs';
import { COLUMN_BREAKPOINTS } from '@shell/types/store/type-map';
import { mapGetters } from 'vuex';
import { PagTableFetchPageSecondaryResourcesOpts, PagTableFetchSecondaryResourcesOpts, PagTableFetchSecondaryResourcesReturns } from '@shell/types/components/paginatedResourceTable';
export default defineComponent({
name: 'ListNode',
Expand Down Expand Up @@ -186,9 +187,9 @@ export default defineComponent({
},
/**
* of type FetchSecondaryResources
* of type PagTableFetchSecondaryResources
*/
async fetchSecondaryResources({ canPaginate }: FetchSecondaryResourcesOpts): FetchSecondaryResourcesReturns {
async fetchSecondaryResources({ canPaginate }: PagTableFetchSecondaryResourcesOpts): PagTableFetchSecondaryResourcesReturns {
if (canPaginate) {
return;
}
Expand Down Expand Up @@ -221,7 +222,7 @@ export default defineComponent({
*
* So when we have a page.... use those entries as filters when fetching the other resources
*/
async fetchPageSecondaryResources({ canPaginate, force, page }: FetchPageSecondaryResourcesOpts) {
async fetchPageSecondaryResources({ canPaginate, force, page }: PagTableFetchPageSecondaryResourcesOpts) {
if (!page?.length) {
return;
}
Expand Down
9 changes: 5 additions & 4 deletions shell/list/persistentvolume.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<script lang="ts">
import { defineComponent } from 'vue';
import PaginatedResourceTable, { FetchPageSecondaryResourcesOpts, FetchSecondaryResourcesOpts, FetchSecondaryResourcesReturns } from '@shell/components/PaginatedResourceTable.vue';
import PaginatedResourceTable from '@shell/components/PaginatedResourceTable.vue';
import { PVC } from '@shell/config/types';
import { ActionFindPageArgs } from '@shell/types/store/dashboard-store.types';
import { FilterArgs, PaginationFilterField, PaginationParamFilter } from '@shell/types/store/pagination.types';
import { PagTableFetchPageSecondaryResourcesOpts, PagTableFetchSecondaryResourcesOpts, PagTableFetchSecondaryResourcesReturns } from '@shell/types/components/paginatedResourceTable';
export default defineComponent({
name: 'ListPersistentVolume',
Expand Down Expand Up @@ -39,9 +40,9 @@ export default defineComponent({
methods: {
/**
* of type FetchSecondaryResources
* of type PagTableFetchSecondaryResources
*/
async fetchSecondaryResources({ canPaginate }: FetchSecondaryResourcesOpts): FetchSecondaryResourcesReturns {
async fetchSecondaryResources({ canPaginate }: PagTableFetchSecondaryResourcesOpts): PagTableFetchSecondaryResourcesReturns {
if (canPaginate) {
return;
}
Expand All @@ -54,7 +55,7 @@ export default defineComponent({
*
* So when we have a page.... use those entries as filters when fetching the other resources
*/
async fetchPageSecondaryResources({ canPaginate, force, page }: FetchPageSecondaryResourcesOpts) {
async fetchPageSecondaryResources({ canPaginate, force, page }: PagTableFetchPageSecondaryResourcesOpts) {
if (!page?.length) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion shell/list/service.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default {
methods: {
/**
* of type FetchSecondaryResources
* of type PagTableFetchSecondaryResources
*/
async fetchSecondaryResources(opts) {
const inStore = this.$store.getters['currentStore']();
Expand Down
9 changes: 5 additions & 4 deletions shell/pages/home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { mapPref, AFTER_LOGIN_ROUTE, READ_WHATS_NEW, HIDE_HOME_PAGE_CARDS } from
import { Banner } from '@components/Banner';
import BannerGraphic from '@shell/components/BannerGraphic.vue';
import IndentedPanel from '@shell/components/IndentedPanel.vue';
import PaginatedResourceTable, { FetchPageSecondaryResourcesOpts, FetchSecondaryResourcesOpts, FetchSecondaryResourcesReturns } from '@shell/components/PaginatedResourceTable.vue';
import PaginatedResourceTable from '@shell/components/PaginatedResourceTable.vue';
import { BadgeState } from '@components/BadgeState';
import CommunityLinks from '@shell/components/CommunityLinks.vue';
import SingleClusterInfo from '@shell/components/SingleClusterInfo.vue';
Expand All @@ -28,6 +28,7 @@ import { STEVE_NAME_COL, STEVE_STATE_COL } from '@shell/config/pagination-table-
import { PaginationParamFilter, FilterArgs, PaginationFilterField, PaginationArgs } from '@shell/types/store/pagination.types';
import ProvCluster from '@shell/models/provisioning.cattle.io.cluster';
import { sameContents } from '@shell/utils/array';
import { PagTableFetchPageSecondaryResourcesOpts, PagTableFetchSecondaryResourcesOpts, PagTableFetchSecondaryResourcesReturns } from '@shell/types/components/paginatedResourceTable';
export default defineComponent({
name: 'Home',
Expand Down Expand Up @@ -238,9 +239,9 @@ export default defineComponent({
methods: {
/**
* Of type FetchSecondaryResources
* Of type PagTableFetchSecondaryResources
*/
fetchSecondaryResources(opts: FetchSecondaryResourcesOpts): FetchSecondaryResourcesReturns {
fetchSecondaryResources(opts: PagTableFetchSecondaryResourcesOpts): PagTableFetchSecondaryResourcesReturns {
if (opts.canPaginate) {
return Promise.resolve({});
}
Expand Down Expand Up @@ -271,7 +272,7 @@ export default defineComponent({
async fetchPageSecondaryResources({
canPaginate, force, page, pagResult
}: FetchPageSecondaryResourcesOpts) {
}: PagTableFetchPageSecondaryResourcesOpts) {
if (!canPaginate || !page?.length) {
this.clusterCount = 0;
Expand Down
26 changes: 26 additions & 0 deletions shell/types/components/paginatedResourceTable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { StorePaginationResult } from '@shell/types/store/pagination.types';

/**
* see {@link PagTableFetchSecondaryResources}
*/
export type PagTableFetchSecondaryResourcesOpts = { canPaginate: boolean }
/**
* see {@link PagTableFetchSecondaryResources}
*/
export type PagTableFetchSecondaryResourcesReturns = Promise<any>
/**
* Function to fetch resources that are required to supplement information needed by rows in a PaginatedResourceTable
*
* Used in scenarios where ALL resources are expected
*/
export type PagTableFetchSecondaryResources = (opts: PagTableFetchSecondaryResourcesOpts) => PagTableFetchSecondaryResourcesReturns

/**
* see {@link PagTableFetchPageSecondaryResources}
*/
export type PagTableFetchPageSecondaryResourcesOpts = { canPaginate: boolean, force: boolean, page: any[], pagResult: StorePaginationResult }
/**
* Function to fetch resources that are required to supplement information needed by a single page in a PaginatedResourceTable
*/
export type PagTableFetchPageSecondaryResources = (opts: PagTableFetchPageSecondaryResourcesOpts) => Promise<any>

Check failure on line 26 in shell/types/components/paginatedResourceTable.ts

View workflow job for this annotation

GitHub Actions / lint

Too many blank lines at the end of file. Max of 0 allowed
48 changes: 48 additions & 0 deletions shell/types/components/resourceLabeledSelect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { LabelSelectPaginationFunctionOptions } from '@shell/components/form/labeled-select-utils/labeled-select.utils';
import { LabelSelectPaginateFn } from '@shell/types/components/labeledSelect';

type PaginateTypeOverridesFn = (opts: LabelSelectPaginationFunctionOptions) => LabelSelectPaginationFunctionOptions;

interface SharedSettings {
/**
* Provide specific LabelSelect options for this mode (paginated / not paginated)
*/
labelSelectOptions?: { [key: string]: any },
/**
* Map, filter, tweak, etc the resources to show in the LabelSelect
*/
updateResources?: (resources: any[]) => any[]
}

/**
* Settings to use when the LabelSelect is paginating
*/
export interface ResourceLabeledSelectPaginateSettings extends SharedSettings {
/**
* Override the convenience function which fetches a page of results
*/
overrideRequest?: LabelSelectPaginateFn,
/**
* Override the default settings used in the convenience function to fetch a page of results
*/
requestSettings?: PaginateTypeOverridesFn,
}

/**
* Settings to use when the LabelSelect is fetching all resources (not paginating)
*/
export type ResourceLabeledSelectSettings = SharedSettings

/**
* Force a specific mode
*/
export enum RESOURCE_LABEL_SELECT_MODE {
/**
* Fetch all resources
*/
ALL_RESOURCES = 'ALL', // eslint-disable-line no-unused-vars
/**
* Determine if all resources are fetched given system settings
*/
DYNAMIC = 'DYNAMIC', // eslint-disable-line no-unused-vars
}

Check failure on line 48 in shell/types/components/resourceLabeledSelect.ts

View workflow job for this annotation

GitHub Actions / lint

Newline required at end of file but not found

0 comments on commit c19aabe

Please sign in to comment.