Skip to content

Commit

Permalink
backport fix for local/api filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-cox committed Dec 5, 2024
1 parent eb96204 commit 3907b29
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 26 deletions.
21 changes: 16 additions & 5 deletions shell/mixins/resource-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,18 @@ export default {
props: {
/**
* Add additional filtering to the rows
*
* Should only be used when we have all results, otherwise we're filtering a page which already has been filtered...
*/
filterRows: {
localFilter: {
type: Function,
default: null,
},

/**
* Add additional filtering to the pagination api request
*/
apiFilter: {
type: Function,
default: null,
},
Expand All @@ -91,11 +101,8 @@ export default {
return rows;
}
} else {
return rows;
return this.localFilter ? this.localFilter(rows) : rows;
}

// return this.filterRows ? this.filterRows(rows) : rows;
return [];
}

return [];
Expand Down Expand Up @@ -172,6 +179,10 @@ export default {
force: this.paginating !== null // Fix for manual refresh (before ripped out).
};

if (this.apiFilter) {
opt.paginating = this.apiFilter(opt.pagination);
}

this['paginating'] = true;

const that = this;
Expand Down
65 changes: 54 additions & 11 deletions shell/pages/home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import { defineComponent } from 'vue';
import { mapPref, AFTER_LOGIN_ROUTE, READ_WHATS_NEW, HIDE_HOME_PAGE_CARDS } from '@shell/store/prefs';
import { Banner } from '@components/Banner';
import BannerGraphic from '@shell/components/BannerGraphic';
import IndentedPanel from '@shell/components/IndentedPanel';
import BannerGraphic from '@shell/components/BannerGraphic.vue';
import IndentedPanel from '@shell/components/IndentedPanel.vue';
import PaginatedResourceTable, { FetchPageSecondaryResourcesOpts, FetchSecondaryResourcesOpts } from '@shell/components/PaginatedResourceTable.vue';
import { BadgeState } from '@components/BadgeState';
import CommunityLinks from '@shell/components/CommunityLinks';
import SingleClusterInfo from '@shell/components/SingleClusterInfo';
import CommunityLinks from '@shell/components/CommunityLinks.vue';
import SingleClusterInfo from '@shell/components/SingleClusterInfo.vue';
import { mapGetters, mapState } from 'vuex';
import { MANAGEMENT, CAPI } from '@shell/config/types';
import { NAME as MANAGER } from '@shell/config/product/manager';
Expand All @@ -19,14 +19,16 @@ import PageHeaderActions from '@shell/mixins/page-actions';
import { getVendor } from '@shell/config/private-label';
import { mapFeature, MULTI_CLUSTER } from '@shell/store/features';
import { BLANK_CLUSTER } from '@shell/store/store-types.js';
import { paginationFilterClusters } from '@shell/utils/cluster';
import { filterHiddenLocalCluster, filterOnlyKubernetesClusters, paginationFilterClusters } from '@shell/utils/cluster';
import TabTitle from '@shell/components/TabTitle.vue';
import { ActionFindPageArgs } from '@shell/types/store/dashboard-store.types';
import { RESET_CARDS_ACTION, SET_LOGIN_ACTION } from '@shell/config/page-actions';
import { STEVE_NAME_COL, STEVE_STATE_COL } from '@shell/config/pagination-table-headers';
import { PaginationParamFilter, FilterArgs, PaginationFilterField } from '@shell/types/store/pagination.types';
import { PaginationParamFilter, FilterArgs, PaginationFilterField, PaginationArgs } from '@shell/types/store/pagination.types';
import ProvCluster from '@shell/models/provisioning.cattle.io.cluster';
import devConsole from 'utils/dev-console';
import { sameContents } from 'utils/array';
export default defineComponent({
name: 'Home',
Expand All @@ -45,8 +47,6 @@ export default defineComponent({
mixins: [PageHeaderActions],
data() {
const paginationRequestFilters = paginationFilterClusters(this.$store);
return {
HIDE_HOME_PAGE_CARDS,
fullVersion: getVersionInfo(this.$store).fullVersion,
Expand All @@ -64,8 +64,6 @@ export default defineComponent({
],
vendor: getVendor(),
paginationRequestFilters,
provClusterSchema: this.$store.getters['management/schemaFor'](CAPI.RANCHER_CLUSTER),
canViewMgmtClusters: !!this.$store.getters['management/schemaFor'](MANAGEMENT.CLUSTER),
Expand Down Expand Up @@ -423,6 +421,48 @@ export default defineComponent({
if (retry === 0 && res?.type === 'error' && res?.status === 500) {
await this.closeSetLoginBanner(retry + 1);
}
},
/**
* Filter out hidden clusters from list of all clusters
*/
filterRowsLocal(rows: any[]) {
devConsole.warn('filterRowsLocal', rows, filterHiddenLocalCluster(filterOnlyKubernetesClusters(rows || [], this.$store), this.$store));
return filterHiddenLocalCluster(filterOnlyKubernetesClusters(rows || [], this.$store), this.$store);
},
/**
* Filter out hidden clusters via api
*/
filterRowsApi(pagination: PaginationArgs): PaginationArgs {
if (!pagination.filters) {
pagination.filters = [];
}
// Pending API Support https://github.com/rancher/rancher/issues/48011
const existingFilters = pagination.filters;
const requiredFilters = paginationFilterClusters(this.$store, false);
for (let i = 0; i < requiredFilters.length; i++) {
const required = requiredFilters[i];
for (let j = 0; j < existingFilters.length; j++) {
const candidate = existingFilters[j];
if (
required.fields.length === candidate.fields.length &&
sameContents(required.fields.map((e) => e.field), candidate.fields.map((e) => e.field))
) {
Object.assign(candidate, required);
break;
}
}
pagination.filters.push(required);
}
return pagination;
}
}
});
Expand Down Expand Up @@ -500,6 +540,7 @@ export default defineComponent({
class="col span-12"
>
<!-- // TODO: RC (home page/side bar) TEST with pagination off and on. check loading indicator when pagination off -->
<!-- TODO: RC namespaced: false now doesn't work -->
<PaginatedResourceTable
:schema="provClusterSchema"
:table-actions="false"
Expand All @@ -509,8 +550,10 @@ export default defineComponent({
:pagination-headers="paginationHeaders"
context="home"

:local-filter="filterRowsLocal"
:api-filter="filterRowsApi"

:namespaced="false"
:request-filters="paginationRequestFilters"
manualRefreshButtonSize="sm"
:fetchSecondaryResources="fetchSecondaryResources"
:fetchPageSecondaryResources="fetchPageSecondaryResources"
Expand Down
33 changes: 23 additions & 10 deletions shell/utils/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ import { PaginationFilterField, PaginationParamFilter } from '@shell/types/store
* @param {*} store
* @returns PaginationParam[]
*/
export function paginationFilterClusters(store) {
export function paginationFilterClusters(store, filterMgmtCluster = true) {
// TODO: RC (home page/side bar) TEST both facets
const paginationRequestFilters = [];
const pFilterOnlyKubernetesClusters = paginationFilterOnlyKubernetesClusters(store);
const pFilterHiddenLocalCluster = paginationFilterHiddenLocalCluster(store);

if (pFilterOnlyKubernetesClusters) {
paginationRequestFilters.push(pFilterOnlyKubernetesClusters);
}
// Commenting out for the moment. This is broken for non-paginated world
// filterOnlyKubernetesClusters expects a mgmt cluster, however in the home page it's given a prov cluster
// note - filterHiddenLocalCluster works because it uses model isLocal which is on both cluster types
// const pFilterOnlyKubernetesClusters = paginationFilterOnlyKubernetesClusters(store);
// if (pFilterOnlyKubernetesClusters) {
// paginationRequestFilters.push(pFilterOnlyKubernetesClusters);
// }
const pFilterHiddenLocalCluster = paginationFilterHiddenLocalCluster(store, filterMgmtCluster);

if (pFilterHiddenLocalCluster) {
paginationRequestFilters.push(pFilterHiddenLocalCluster);
}
Expand All @@ -34,7 +38,7 @@ export function paginationFilterClusters(store) {
* @param {*} store
* @returns PaginationParam | null
*/
export function paginationFilterHiddenLocalCluster(store) {
export function paginationFilterHiddenLocalCluster(store, filterMgmtCluster = true) {
const hideLocalSetting = store.getters['management/byId'](MANAGEMENT.SETTING, SETTING.HIDE_LOCAL_CLUSTER) || {};
const value = hideLocalSetting.value || hideLocalSetting.default || 'false';
const hideLocal = value === 'true';
Expand All @@ -43,12 +47,21 @@ export function paginationFilterHiddenLocalCluster(store) {
return null;
}

return PaginationParamFilter.createMultipleFields([
const filter = filterMgmtCluster ? [
new PaginationFilterField({
field: `spec.internal`, // Pending API support https://github.com/rancher/rancher/issues/48011
value: false,
}),
]);
})
] : [
new PaginationFilterField({
field: `id`,
value: 'fleet-local/local',
exact: true,
equals: false,
})
];

return PaginationParamFilter.createMultipleFields(filter);
}

/**
Expand Down

0 comments on commit 3907b29

Please sign in to comment.