1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Add defaultProps.catalogEntityStore

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
This commit is contained in:
Hung-Han (Henry) Chen 2021-10-05 08:53:44 +03:00
parent c0532865c6
commit f0b8479e5c
No known key found for this signature in database
GPG Key ID: 54B44603D251B788
2 changed files with 21 additions and 7 deletions

View File

@ -20,7 +20,7 @@
*/
import { computed, IReactionDisposer, makeObservable, observable, reaction } from "mobx";
import { catalogEntityRegistry } from "../../api/catalog-entity-registry";
import { catalogEntityRegistry as _catalogEntityRegistry, CatalogEntityRegistry } from "../../api/catalog-entity-registry";
import type { CatalogEntity } from "../../api/catalog-entity";
import type { CatalogEntityOnRunHook } from "../../api/catalog-entity-registry";
import { ItemStore } from "../../../common/item.store";
@ -29,10 +29,18 @@ import { autoBind } from "../../../common/utils";
import { CatalogEntityItem } from "./catalog-entity-item";
export class CatalogEntityStore extends ItemStore<CatalogEntityItem<CatalogEntity>> {
constructor() {
#catalogEntityRegistry: CatalogEntityRegistry;
constructor(catalogEntityRegistry?: CatalogEntityRegistry) {
super();
makeObservable(this);
autoBind(this);
if (catalogEntityRegistry) {
this.#catalogEntityRegistry = catalogEntityRegistry;
} else {
this.#catalogEntityRegistry = _catalogEntityRegistry;
}
}
@observable activeCategory?: CatalogCategory;
@ -40,10 +48,10 @@ export class CatalogEntityStore extends ItemStore<CatalogEntityItem<CatalogEntit
@computed get entities() {
if (!this.activeCategory) {
return catalogEntityRegistry.filteredItems.map(entity => new CatalogEntityItem(entity));
return this.#catalogEntityRegistry.filteredItems.map(entity => new CatalogEntityItem(entity));
}
return catalogEntityRegistry.getItemsForCategory(this.activeCategory, { filtered: true }).map(entity => new CatalogEntityItem(entity));
return this.#catalogEntityRegistry.getItemsForCategory(this.activeCategory, { filtered: true }).map(entity => new CatalogEntityItem(entity));
}
@computed get selectedItem() {
@ -51,7 +59,7 @@ export class CatalogEntityStore extends ItemStore<CatalogEntityItem<CatalogEntit
}
getCatalogEntityOnRunHook(catalogEntityUid: CatalogEntity["metadata"]["uid"]): CatalogEntityOnRunHook | undefined {
return catalogEntityRegistry.getOnRunHook(catalogEntityUid);
return this.#catalogEntityRegistry.getOnRunHook(catalogEntityUid);
}
watch() {

View File

@ -56,7 +56,10 @@ enum sortBy {
const css = makeCss(styles);
interface Props extends RouteComponentProps<CatalogViewRouteParam> {}
interface Props extends RouteComponentProps<CatalogViewRouteParam> {
catalogEntityStore: CatalogEntityStore;
}
@observer
export class Catalog extends React.Component<Props> {
@observable private catalogEntityStore?: CatalogEntityStore;
@ -66,8 +69,11 @@ export class Catalog extends React.Component<Props> {
constructor(props: Props) {
super(props);
makeObservable(this);
this.catalogEntityStore = new CatalogEntityStore();
this.catalogEntityStore = props.catalogEntityStore;
}
static defaultProps = {
catalogEntityStore: new CatalogEntityStore(),
};
get routeActiveTab(): string {
const { group, kind } = this.props.match.params ?? {};