mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Refactor watches to use native k8s api (#2095)
* fix lint Signed-off-by: Roman <ixrock@gmail.com> * fixes & refactoring Signed-off-by: Roman <ixrock@gmail.com> * fix lint, micro-refactoring Signed-off-by: Roman <ixrock@gmail.com> * more refactoring, clean up, responding to comments Signed-off-by: Roman <ixrock@gmail.com> * fix: remove extra check for cluster.allowedApi from processing buffered watch-api events Signed-off-by: Roman <ixrock@gmail.com> * refactoring, detaching NamespaceStore from KubeObjectStore Signed-off-by: Roman <ixrock@gmail.com> * fix: wait for contextReady in NamespaceStore Signed-off-by: Roman <ixrock@gmail.com> * refactoring & fixes Signed-off-by: Roman <ixrock@gmail.com> * fix lint Signed-off-by: Roman <ixrock@gmail.com> * fixes: reloading context stores on NamespaceSelect-change Signed-off-by: Roman <ixrock@gmail.com> * optimize loading all resources when "all namespaces" selected -> single request per resource (when have rights) Signed-off-by: Roman <ixrock@gmail.com> * use native k8s api watches Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * retry watch when it makes sense Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * workaround for browser connection limits Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * use always random subdomain for getResponse Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * resubscribe stores on contextNamespace change Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * modify watch event before calling callback Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> Co-authored-by: Roman <ixrock@gmail.com>
This commit is contained in:
1 parent
6ded5e73fa
commit
035dd470ef
34 files changed
+414
-599
No files matched your search
@@ -38,6 +38,7 @@ interface IHeaderPlaceholders {
|
||||
export interface ItemListLayoutProps<T extends ItemObject = ItemObject> {
|
||||
tableId?: string;
|
||||
className: IClassName;
|
||||
items?: T[];
|
||||
store: ItemStore<T>;
|
||||
dependentStores?: ItemStore[];
|
||||
preloadStores?: boolean;
|
||||
@@ -138,7 +139,8 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
|
||||
const { store, dependentStores } = this.props;
|
||||
const stores = Array.from(new Set([store, ...dependentStores]));
|
||||
|
||||
stores.forEach(store => store.loadAll(namespaceStore.getContextNamespaces()));
|
||||
// load context namespaces by default (see also: `<NamespaceSelectFilter/>`)
|
||||
stores.forEach(store => store.loadAll(namespaceStore.contextNamespaces));
|
||||
}
|
||||
|
||||
private filterCallbacks: { [type: string]: ItemsFilter } = {
|
||||
@@ -179,11 +181,7 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
|
||||
|
||||
@computed get filters() {
|
||||
let { activeFilters } = pageFilters;
|
||||
const { isClusterScoped, isSearchable, searchFilters } = this.props;
|
||||
|
||||
if (isClusterScoped) {
|
||||
activeFilters = activeFilters.filter(({ type }) => type !== FilterType.NAMESPACE);
|
||||
}
|
||||
const { isSearchable, searchFilters } = this.props;
|
||||
|
||||
if (!(isSearchable && searchFilters)) {
|
||||
activeFilters = activeFilters.filter(({ type }) => type !== FilterType.SEARCH);
|
||||
@@ -217,7 +215,9 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
|
||||
}
|
||||
});
|
||||
|
||||
return this.applyFilters(filterItems, allItems);
|
||||
const items = this.props.items ?? allItems;
|
||||
|
||||
return this.applyFilters(filterItems, items);
|
||||
}
|
||||
|
||||
@autobind()
|
||||
@@ -337,8 +337,8 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
|
||||
}
|
||||
|
||||
renderInfo() {
|
||||
const { allItems, items, isReady, userSettings, filters } = this;
|
||||
const allItemsCount = allItems.length;
|
||||
const { items, isReady, userSettings, filters } = this;
|
||||
const allItemsCount = this.props.store.getTotalCount();
|
||||
const itemsCount = items.length;
|
||||
const isFiltered = isReady && filters.length > 0;
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { computed, observable, reaction } from "mobx";
|
||||
import { autobind } from "../../utils";
|
||||
import { namespaceStore } from "../+namespaces/namespace.store";
|
||||
import { searchUrlParam } from "../input/search-input-url";
|
||||
|
||||
export enum FilterType {
|
||||
@@ -24,32 +23,6 @@ export class PageFiltersStore {
|
||||
|
||||
constructor() {
|
||||
this.syncWithGlobalSearch();
|
||||
this.syncWithContextNamespace();
|
||||
}
|
||||
|
||||
protected syncWithContextNamespace() {
|
||||
const disposers = [
|
||||
reaction(() => this.getValues(FilterType.NAMESPACE), filteredNs => {
|
||||
if (filteredNs.length !== namespaceStore.getContextNamespaces().length) {
|
||||
namespaceStore.setContext(filteredNs);
|
||||
}
|
||||
}),
|
||||
namespaceStore.onContextChange(namespaces => {
|
||||
const filteredNs = this.getValues(FilterType.NAMESPACE);
|
||||
const isChanged = namespaces.length !== filteredNs.length;
|
||||
|
||||
if (isChanged) {
|
||||
this.filters.replace([
|
||||
...this.filters.filter(({ type }) => type !== FilterType.NAMESPACE),
|
||||
...namespaces.map(ns => ({ type: FilterType.NAMESPACE, value: ns })),
|
||||
]);
|
||||
}
|
||||
}, {
|
||||
fireImmediately: true
|
||||
})
|
||||
];
|
||||
|
||||
return () => disposers.forEach(dispose => dispose());
|
||||
}
|
||||
|
||||
protected syncWithGlobalSearch() {
|
||||
|
||||
Reference in new issue
Block a user