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:
parent
c0532865c6
commit
f0b8479e5c
@ -20,7 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { computed, IReactionDisposer, makeObservable, observable, reaction } from "mobx";
|
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 { CatalogEntity } from "../../api/catalog-entity";
|
||||||
import type { CatalogEntityOnRunHook } from "../../api/catalog-entity-registry";
|
import type { CatalogEntityOnRunHook } from "../../api/catalog-entity-registry";
|
||||||
import { ItemStore } from "../../../common/item.store";
|
import { ItemStore } from "../../../common/item.store";
|
||||||
@ -29,10 +29,18 @@ import { autoBind } from "../../../common/utils";
|
|||||||
import { CatalogEntityItem } from "./catalog-entity-item";
|
import { CatalogEntityItem } from "./catalog-entity-item";
|
||||||
|
|
||||||
export class CatalogEntityStore extends ItemStore<CatalogEntityItem<CatalogEntity>> {
|
export class CatalogEntityStore extends ItemStore<CatalogEntityItem<CatalogEntity>> {
|
||||||
constructor() {
|
#catalogEntityRegistry: CatalogEntityRegistry;
|
||||||
|
|
||||||
|
constructor(catalogEntityRegistry?: CatalogEntityRegistry) {
|
||||||
super();
|
super();
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
autoBind(this);
|
autoBind(this);
|
||||||
|
|
||||||
|
if (catalogEntityRegistry) {
|
||||||
|
this.#catalogEntityRegistry = catalogEntityRegistry;
|
||||||
|
} else {
|
||||||
|
this.#catalogEntityRegistry = _catalogEntityRegistry;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@observable activeCategory?: CatalogCategory;
|
@observable activeCategory?: CatalogCategory;
|
||||||
@ -40,10 +48,10 @@ export class CatalogEntityStore extends ItemStore<CatalogEntityItem<CatalogEntit
|
|||||||
|
|
||||||
@computed get entities() {
|
@computed get entities() {
|
||||||
if (!this.activeCategory) {
|
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() {
|
@computed get selectedItem() {
|
||||||
@ -51,7 +59,7 @@ export class CatalogEntityStore extends ItemStore<CatalogEntityItem<CatalogEntit
|
|||||||
}
|
}
|
||||||
|
|
||||||
getCatalogEntityOnRunHook(catalogEntityUid: CatalogEntity["metadata"]["uid"]): CatalogEntityOnRunHook | undefined {
|
getCatalogEntityOnRunHook(catalogEntityUid: CatalogEntity["metadata"]["uid"]): CatalogEntityOnRunHook | undefined {
|
||||||
return catalogEntityRegistry.getOnRunHook(catalogEntityUid);
|
return this.#catalogEntityRegistry.getOnRunHook(catalogEntityUid);
|
||||||
}
|
}
|
||||||
|
|
||||||
watch() {
|
watch() {
|
||||||
|
|||||||
@ -56,7 +56,10 @@ enum sortBy {
|
|||||||
|
|
||||||
const css = makeCss(styles);
|
const css = makeCss(styles);
|
||||||
|
|
||||||
interface Props extends RouteComponentProps<CatalogViewRouteParam> {}
|
interface Props extends RouteComponentProps<CatalogViewRouteParam> {
|
||||||
|
catalogEntityStore: CatalogEntityStore;
|
||||||
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class Catalog extends React.Component<Props> {
|
export class Catalog extends React.Component<Props> {
|
||||||
@observable private catalogEntityStore?: CatalogEntityStore;
|
@observable private catalogEntityStore?: CatalogEntityStore;
|
||||||
@ -66,8 +69,11 @@ export class Catalog extends React.Component<Props> {
|
|||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
super(props);
|
super(props);
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
this.catalogEntityStore = new CatalogEntityStore();
|
this.catalogEntityStore = props.catalogEntityStore;
|
||||||
}
|
}
|
||||||
|
static defaultProps = {
|
||||||
|
catalogEntityStore: new CatalogEntityStore(),
|
||||||
|
};
|
||||||
|
|
||||||
get routeActiveTab(): string {
|
get routeActiveTab(): string {
|
||||||
const { group, kind } = this.props.match.params ?? {};
|
const { group, kind } = this.props.match.params ?? {};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user