mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Hide "default" catalog entity detail items when extension describes so
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
ff1ab54e0f
commit
9ef5eb66e2
@ -28,9 +28,7 @@ import extensionPageParametersInjectable from "../renderer/routes/extension-page
|
||||
import { pipeline } from "@ogre-tools/fp";
|
||||
import { getExtensionRoutePath } from "../renderer/routes/get-extension-route-path";
|
||||
import { navigateToRouteInjectionToken } from "../common/front-end-routing/navigate-to-route-injection-token";
|
||||
import type {
|
||||
CatalogEntityDetailRegistration,
|
||||
} from "../renderer/components/+catalog/catalog-entity-detail-items/extension-registration";
|
||||
import type { CatalogEntityDetailRegistration } from "../renderer/components/+catalog/catalog-entity-detail-items/extension-registration";
|
||||
|
||||
export class LensRendererExtension extends LensExtension {
|
||||
globalPages: registries.PageRegistration[] = [];
|
||||
|
||||
@ -18,6 +18,7 @@ import catalogEntityDetailItemsInjectable from "./catalog-entity-detail-items/ca
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import type { CatalogEntityDetailItem } from "./catalog-entity-detail-items/catalog-entity-detail-item-injection-token";
|
||||
import type { IComputedValue } from "mobx";
|
||||
import showDefaultCatalogEntityDetailItemsInjectable from "./show-default-catalog-entity-detail-items.injectable";
|
||||
|
||||
export interface CatalogEntityDetailsProps<T extends CatalogEntity> {
|
||||
entity: T;
|
||||
@ -26,16 +27,18 @@ export interface CatalogEntityDetailsProps<T extends CatalogEntity> {
|
||||
}
|
||||
|
||||
interface Dependencies {
|
||||
detailItems: IComputedValue<CatalogEntityDetailItem<any>[]>;
|
||||
detailItems: IComputedValue<CatalogEntityDetailItem<CatalogEntity>[]>;
|
||||
showDefaultCatalogEntityDetailItems: IComputedValue<boolean>;
|
||||
}
|
||||
|
||||
@observer
|
||||
class NonInjectedCatalogEntityDetails<T extends CatalogEntity> extends Component<CatalogEntityDetailsProps<T> & Dependencies> {
|
||||
renderContent(entity: T) {
|
||||
const { onRun, hideDetails } = this.props;
|
||||
const { onRun, hideDetails, showDefaultCatalogEntityDetailItems } = this.props;
|
||||
|
||||
return (
|
||||
<>
|
||||
{showDefaultCatalogEntityDetailItems.get() && (
|
||||
<div className="flex">
|
||||
<div className={styles.entityIcon}>
|
||||
<Avatar
|
||||
@ -79,6 +82,7 @@ class NonInjectedCatalogEntityDetails<T extends CatalogEntity> extends Component
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="box grow">
|
||||
{this.props.detailItems.get().map(({ components: { Details }}, index) => <Details entity={entity} key={index} />)}
|
||||
</div>
|
||||
@ -104,12 +108,20 @@ class NonInjectedCatalogEntityDetails<T extends CatalogEntity> extends Component
|
||||
}
|
||||
}
|
||||
|
||||
const InjectedCatalogEntityDetails = withInjectables<Dependencies, CatalogEntityDetailsProps<CatalogEntity>>(
|
||||
const InjectedCatalogEntityDetails = withInjectables<
|
||||
Dependencies,
|
||||
CatalogEntityDetailsProps<CatalogEntity>
|
||||
>(
|
||||
NonInjectedCatalogEntityDetails,
|
||||
|
||||
{
|
||||
getProps: (di, props) => ({
|
||||
detailItems: di.inject(catalogEntityDetailItemsInjectable, props.entity),
|
||||
|
||||
showDefaultCatalogEntityDetailItems: di.inject(
|
||||
showDefaultCatalogEntityDetailItemsInjectable,
|
||||
props.entity,
|
||||
),
|
||||
...props,
|
||||
}),
|
||||
},
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import { computed } from "mobx";
|
||||
import type { CatalogEntity } from "../../../common/catalog";
|
||||
import catalogEntityDetailItemsInjectable from "./catalog-entity-detail-items/catalog-entity-detail-items.injectable";
|
||||
|
||||
// TODO: Extract "default" entity detail items from components to same level than other items are
|
||||
const showDefaultCatalogEntityDetailItemsInjectable = getInjectable({
|
||||
id: "show-default-catalog-entity-detail-items",
|
||||
|
||||
instantiate: (di, catalogEntity: CatalogEntity) => {
|
||||
const catalogEntityDetailItems = di.inject(
|
||||
catalogEntityDetailItemsInjectable,
|
||||
catalogEntity,
|
||||
);
|
||||
|
||||
return computed(() =>
|
||||
!catalogEntityDetailItems.get().find((item) => item.orderNumber < -999),
|
||||
);
|
||||
},
|
||||
|
||||
lifecycle: lifecycleEnum.keyedSingleton({
|
||||
getInstanceKey: (di, catalogEntity: CatalogEntity) =>
|
||||
`${catalogEntity.kind}/${catalogEntity.apiVersion}`,
|
||||
}),
|
||||
});
|
||||
|
||||
export default showDefaultCatalogEntityDetailItemsInjectable;
|
||||
Loading…
Reference in New Issue
Block a user