mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
loading k8s resources into stores per selected namespaces -- part 3
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
1 parent
f71829ff14
commit
51bdfc131b
5 files changed
+127
-84
No files matched your search
@@ -17,58 +17,56 @@ import { cronJobStore } from "../+workloads-cronjobs/cronjob.store";
|
||||
import { Events } from "../+events";
|
||||
import { KubeObjectStore } from "../../kube-object.store";
|
||||
import { isAllowedResource } from "../../../common/rbac";
|
||||
import { namespaceStore } from "../+namespaces/namespace.store";
|
||||
|
||||
interface Props extends RouteComponentProps<IWorkloadsOverviewRouteParams> {
|
||||
}
|
||||
|
||||
@observer
|
||||
export class WorkloadsOverview extends React.Component<Props> {
|
||||
@observable isLoading = false;
|
||||
@observable isUnmounting = false;
|
||||
|
||||
async componentDidMount() {
|
||||
const stores: KubeObjectStore[] = [];
|
||||
const stores: KubeObjectStore[] = [
|
||||
isAllowedResource("pods") && podsStore,
|
||||
isAllowedResource("deployments") && deploymentStore,
|
||||
isAllowedResource("daemonsets") && daemonSetStore,
|
||||
isAllowedResource("statefulsets") && statefulSetStore,
|
||||
isAllowedResource("statefulsets") && statefulSetStore,
|
||||
isAllowedResource("replicasets") && replicaSetStore,
|
||||
isAllowedResource("jobs") && jobStore,
|
||||
isAllowedResource("cronjobs") && cronJobStore,
|
||||
isAllowedResource("events") && eventStore,
|
||||
].filter(Boolean);
|
||||
|
||||
if (isAllowedResource("pods")) {
|
||||
stores.push(podsStore);
|
||||
const unsubscribeMap = new Map<KubeObjectStore, Function>(
|
||||
stores.map(store => [store, Function])
|
||||
);
|
||||
|
||||
const loadStores = async () => {
|
||||
this.isLoading = true;
|
||||
for (const store of stores) {
|
||||
if (this.isUnmounting) break;
|
||||
try {
|
||||
store.reset();
|
||||
await store.loadAll();
|
||||
unsubscribeMap.get(store)(); // unsubscribe previous watcher
|
||||
unsubscribeMap.set(store, store.subscribe());
|
||||
} catch (error) {
|
||||
console.error("loading store error", error);
|
||||
}
|
||||
}
|
||||
this.isLoading = false;
|
||||
}
|
||||
|
||||
if (isAllowedResource("deployments")) {
|
||||
stores.push(deploymentStore);
|
||||
}
|
||||
namespaceStore.onContextChange(loadStores, {
|
||||
fireImmediately: true,
|
||||
});
|
||||
|
||||
if (isAllowedResource("daemonsets")) {
|
||||
stores.push(daemonSetStore);
|
||||
}
|
||||
|
||||
if (isAllowedResource("statefulsets")) {
|
||||
stores.push(statefulSetStore);
|
||||
}
|
||||
|
||||
if (isAllowedResource("replicasets")) {
|
||||
stores.push(replicaSetStore);
|
||||
}
|
||||
|
||||
if (isAllowedResource("jobs")) {
|
||||
stores.push(jobStore);
|
||||
}
|
||||
|
||||
if (isAllowedResource("cronjobs")) {
|
||||
stores.push(cronJobStore);
|
||||
}
|
||||
|
||||
if (isAllowedResource("events")) {
|
||||
stores.push(eventStore);
|
||||
}
|
||||
|
||||
const unsubscribeList: Array<() => void> = [];
|
||||
|
||||
for (const store of stores) {
|
||||
await store.loadAll();
|
||||
unsubscribeList.push(store.subscribe());
|
||||
}
|
||||
|
||||
await when(() => this.isUnmounting);
|
||||
unsubscribeList.forEach(dispose => dispose());
|
||||
await when(() => this.isUnmounting && !this.isLoading);
|
||||
unsubscribeMap.forEach(dispose => dispose());
|
||||
unsubscribeMap.clear();
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
@@ -79,11 +77,11 @@ export class WorkloadsOverview extends React.Component<Props> {
|
||||
return (
|
||||
<>
|
||||
<OverviewStatuses/>
|
||||
{ isAllowedResource("events") && <Events
|
||||
{isAllowedResource("events") && <Events
|
||||
compact
|
||||
hideFilters
|
||||
className="box grow"
|
||||
/> }
|
||||
/>}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user