Add defaultProps.catalogEntityStore

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
This commit is contained in:
Hung-Han (Henry) Chen committed 2021-10-05 08:53:44 +03:00
1 parent c0532865c6
commit f0b8479e5c
2 files changed
+21 -7

No files matched your search

@@ -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() {
+8 -2
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 ?? {};