Skip to content

Commit

Permalink
Iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-cox committed Dec 2, 2024
1 parent 419cc30 commit 42b3845
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
28 changes: 17 additions & 11 deletions shell/components/nav/TopLevelMenu.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ type MgmtCluster = {
type ProvCluster = {
[key: string]: any
}

/**
* Order
* 1. Specific Local Cluster
* 2. Ready
* 3. Name
* 1. local cluster - https://github.com/rancher/dashboard/issues/10975
* 2. working clusters
* 3. name
*/
const DEFAULT_SORT: Array<PaginationSort> = [
// Put local cluster at top of list - https://github.com/rancher/dashboard/issues/10975
// {
// asc: true,
// field: 'spec.internal', // Pending API support https://github.com/rancher/rancher/issues/48011
Expand Down Expand Up @@ -143,6 +143,9 @@ export abstract class BaseTopLevelMenuHelper {
}
}

/**
* Helper designed to supply paginated results for the top level menu cluster resources
*/
export class TopLevelMenuHelperPagination extends BaseTopLevelMenuHelper implements TopLevelMenuHelper {
private args?: UpdateArgs;

Expand All @@ -152,9 +155,6 @@ export class TopLevelMenuHelperPagination extends BaseTopLevelMenuHelper impleme

private commonClusterFilters: PaginationParam[];

/**
*
*/
constructor({ $store }: {
$store: VuexStore,
}) {
Expand All @@ -167,7 +167,8 @@ export class TopLevelMenuHelperPagination extends BaseTopLevelMenuHelper impleme
this.clustersPinnedWrapper = new PaginationWrapper({
$store,
onUpdate: () => {
// TODO: RC trigger on websocket update (only need 1 trigger for this cluster type)
// trigger on websocket update (only need 1 trigger for this cluster type)
// https://github.com/rancher/rancher/issues/40773 / https://github.com/rancher/dashboard/issues/12734
if (this.args) {
this.update(this.args);
}
Expand All @@ -183,7 +184,8 @@ export class TopLevelMenuHelperPagination extends BaseTopLevelMenuHelper impleme
this.clustersOthersWrapper = new PaginationWrapper({
$store,
onUpdate: (res) => {
// TODO: RC trigger on websocket update (only need 1 trigger for this cluster type)
// trigger on websocket update (only need 1 trigger for this cluster type)
// https://github.com/rancher/rancher/issues/40773 / https://github.com/rancher/dashboard/issues/12734
if (this.args) {
this.update(this.args);
}
Expand All @@ -199,7 +201,8 @@ export class TopLevelMenuHelperPagination extends BaseTopLevelMenuHelper impleme
this.provClusterWrapper = new PaginationWrapper({
$store,
onUpdate: (res) => {
// TODO: RC trigger on websocket update
// trigger on websocket update (only need 1 trigger for this cluster type)
// https://github.com/rancher/rancher/issues/40773 / https://github.com/rancher/dashboard/issues/12734
if (this.args) {
this.update(this.args);
}
Expand Down Expand Up @@ -277,7 +280,7 @@ export class TopLevelMenuHelperPagination extends BaseTopLevelMenuHelper impleme
}

if (excludePinned) {
// cluster id is NOT 1 AND NOT 2 OR 3 OR 4...
// cluster id is NOT 1 AND NOT 2 AND NOT 3 AND NOT 4...
filters.push(...pinnedIds.map((id) => PaginationParamFilter.createSingleField({
field: 'id', equals: false, value: id
})));
Expand Down Expand Up @@ -364,6 +367,9 @@ export class TopLevelMenuHelperPagination extends BaseTopLevelMenuHelper impleme
}
}

/**
* Helper designed to supply non-pagainted results for the top level menu cluster resources
*/
export class TopLevelMenuHelperLegacy extends BaseTopLevelMenuHelper implements TopLevelMenuHelper {
private hasProvCluster: boolean;

Expand Down
3 changes: 1 addition & 2 deletions shell/components/nav/TopLevelMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { TopLevelMenuHelperPagination, TopLevelMenuHelperLegacy } from 'componen
import devConsole from 'utils/dev-console';
import { debounce } from 'lodash';
// TODO: RC wire in socket updates to pagination wrapper
// TODO: RC test search properly
// TODO: RC loading indicators?
Expand All @@ -46,7 +45,7 @@ export default {
const provClusters = !canPagination && hasProvCluster ? this.$store.getters[`management/all`](CAPI.RANCHER_CLUSTER) : [];
const mgmtClusters = !canPagination ? this.$store.getters[`management/all`](MANAGEMENT.CLUSTER) : [];
devConsole.warn(provClusters, mgmtClusters);
devConsole.warn(provClusters, mgmtClusters); // TODO: RC search for all of these
return {
shown: false,
Expand Down
14 changes: 13 additions & 1 deletion shell/utils/pagination-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,22 @@ interface Result<T> {
pagination: StorePagination
}

/**
* This is a helper class that will assist in fetching a resource
* - Handle if the resource can be fetched by the new pagination api
* - Make a request to get a page (including classify)
* - Provide updates when the resource changes
*
* This is designed to work in places where we don't/can't store the resource in the store
* - There already exists a resource we don't want to overwrite
* - We're transient and want something nicer than just cluster/request
*/
class PaginationWrapper<T = any> {
private $store: VuexStore;
private enabledFor: PaginationResourceContext;
private onUpdate: (out: Result<T>) => void; // TODO: RC wire in to web socket (when new socket stuff is available)

// Blocked on https://github.com/rancher/rancher/issues/40773 / https://github.com/rancher/dashboard/issues/12734
private onUpdate: (out: Result<T>) => void;

public isEnabled: boolean;

Expand Down

0 comments on commit 42b3845

Please sign in to comment.