Improve Table typing and remove annotations on callbacks

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton committed 2021-06-07 11:30:28 -04:00
1 parent 22c9d03edb
commit defb0ea0dd
55 files changed
+498 -490

No files matched your search

@@ -33,6 +33,7 @@ import { crdStore } from "../+custom-resources/crd.store";
import { CrdResourceDetails } from "../+custom-resources";
import { KubeObjectMenu } from "./kube-object-menu";
import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry";
import { CustomResourceDefinition } from "../../api/endpoints";
/**
* Used to store `object.selfLink` to show more info about resource in the details panel.
@@ -99,15 +100,7 @@ export class KubeObjectDetails extends React.Component {
}
@computed get object() {
const store = apiManager.getStore(this.path);
if (store) {
return store.getByPath(this.path);
}
}
@computed get isCrdInstance() {
return !!crdStore.getByObject(this.object);
return apiManager.getStore(this.path)?.getByPath(this.path);
}
@disposeOnUnmount
@@ -137,7 +130,7 @@ export class KubeObjectDetails extends React.Component {
});
render() {
const { object, isLoading, loadingError, isCrdInstance } = this;
const { object, isLoading, loadingError } = this;
const isOpen = !!(object || isLoading || loadingError);
let title = "";
let details: React.ReactNode[];
@@ -150,7 +143,7 @@ export class KubeObjectDetails extends React.Component {
return <item.components.Details object={object} key={`object-details-${index}`}/>;
});
if (isCrdInstance && details.length === 0) {
if (object instanceof CustomResourceDefinition && details.length === 0) {
details.push(<CrdResourceDetails object={object}/>);
}
}
@@ -30,21 +30,22 @@ import { KubeObjectMenu } from "./kube-object-menu";
import { kubeSelectedUrlParam, showDetails } from "./kube-object-details";
import { kubeWatchApi } from "../../api/kube-watch-api";
import { clusterContext } from "../context";
import { FilterType, pageFilters } from "../item-object-list/page-filters.store";
export interface KubeObjectListLayoutProps extends ItemListLayoutProps {
store: KubeObjectStore;
dependentStores?: KubeObjectStore[];
export interface KubeObjectListLayoutProps<K extends KubeObject> extends ItemListLayoutProps<K> {
store: KubeObjectStore<K>;
dependentStores?: KubeObjectStore<KubeObject>[];
}
const defaultProps: Partial<KubeObjectListLayoutProps> = {
const defaultProps: Partial<KubeObjectListLayoutProps<KubeObject>> = {
onDetails: (item: KubeObject) => showDetails(item.selfLink),
};
@observer
export class KubeObjectListLayout extends React.Component<KubeObjectListLayoutProps> {
export class KubeObjectListLayout<K extends KubeObject> extends React.Component<KubeObjectListLayoutProps<K>> {
static defaultProps = defaultProps as object;
constructor(props: KubeObjectListLayoutProps) {
constructor(props: KubeObjectListLayoutProps<K>) {
super(props);
makeObservable(this);
}
@@ -76,7 +77,18 @@ export class KubeObjectListLayout extends React.Component<KubeObjectListLayoutPr
items={items}
preloadStores={false} // loading handled in kubeWatchApi.subscribeStores()
detailsItem={this.selectedItem}
renderItemMenu={(item: KubeObject) => <KubeObjectMenu object={item} />} // safe because we are dealing with KubeObjects here
renderItemMenu={(item: K) => <KubeObjectMenu object={item} />} // safe because we are dealing with KubeObjects here
filterCallbacks={{
[FilterType.NAMESPACE]: items => {
const filterValues = pageFilters.getValues(FilterType.NAMESPACE);
if (filterValues.length > 0) {
return items.filter(item => filterValues.includes(item.getNs()));
}
return items;
},
}}
/>
);
}