-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kludge "isEnabledForCluster" work again for workload overview details
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
- Loading branch information
Showing
9 changed files
with
1,805 additions
and
71 deletions.
There are no files selected for viewing
1,539 changes: 1,539 additions & 0 deletions
1,539
...snapshots__/disable-workloads-overview-details-when-cluster-is-not-relevant.test.tsx.snap
Large diffs are not rendered by default.
Oops, something went wrong.
114 changes: 114 additions & 0 deletions
114
...ew/extension-api/disable-workloads-overview-details-when-cluster-is-not-relevant.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/** | ||
* Copyright (c) OpenLens Authors. All rights reserved. | ||
* Licensed under MIT License. See LICENSE in root directory for more information. | ||
*/ | ||
import type { AsyncFnMock } from "@async-fn/jest"; | ||
import asyncFn from "@async-fn/jest"; | ||
import type { RenderResult } from "@testing-library/react"; | ||
import type { ApplicationBuilder } from "../../../../../renderer/components/test-utils/get-application-builder"; | ||
import type { KubernetesCluster } from "../../../../../common/catalog-entities"; | ||
import { getApplicationBuilder } from "../../../../../renderer/components/test-utils/get-application-builder"; | ||
import { getExtensionFakeFor } from "../../../../../renderer/components/test-utils/get-extension-fake"; | ||
import extensionShouldBeEnabledForClusterFrameInjectable from "../../../../../renderer/extension-loader/extension-should-be-enabled-for-cluster-frame.injectable"; | ||
import apiManagerInjectable from "../../../../../common/k8s-api/api-manager/manager.injectable"; | ||
import navigateToWorkloadsOverviewInjectable from "../../../../../common/front-end-routing/routes/cluster/workloads/overview/navigate-to-workloads-overview.injectable"; | ||
import React from "react"; | ||
|
||
describe("disable workloads overview details when cluster is not relevant", () => { | ||
let builder: ApplicationBuilder; | ||
let rendered: RenderResult; | ||
let isEnabledForClusterMock: AsyncFnMock< | ||
(cluster: KubernetesCluster) => boolean | ||
>; | ||
|
||
beforeEach(async () => { | ||
builder = getApplicationBuilder(); | ||
|
||
builder.beforeApplicationStart(({ mainDi }) => { | ||
mainDi.override(apiManagerInjectable, () => ({})); | ||
}); | ||
|
||
const rendererDi = builder.dis.rendererDi; | ||
|
||
rendererDi.unoverride(extensionShouldBeEnabledForClusterFrameInjectable); | ||
|
||
builder.setEnvironmentToClusterFrame(); | ||
|
||
const getExtensionFake = getExtensionFakeFor(builder); | ||
|
||
isEnabledForClusterMock = asyncFn(); | ||
|
||
const testExtension = getExtensionFake({ | ||
id: "test-extension-id", | ||
name: "test-extension", | ||
|
||
rendererOptions: { | ||
isEnabledForCluster: isEnabledForClusterMock, | ||
|
||
kubeWorkloadsOverviewItems: [ | ||
{ | ||
components: { | ||
Details: () => ( | ||
<div data-testid="some-detail-component">Some detail component</div> | ||
), | ||
}, | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
rendered = await builder.render(); | ||
|
||
const navigateToWorkloadsOverview = rendererDi.inject( | ||
navigateToWorkloadsOverviewInjectable, | ||
); | ||
|
||
navigateToWorkloadsOverview(); | ||
|
||
builder.extensions.enable(testExtension); | ||
}); | ||
|
||
describe("given not yet known if extension should be enabled for the cluster, when navigating", () => { | ||
it("renders", () => { | ||
expect(rendered.baseElement).toMatchSnapshot(); | ||
}); | ||
|
||
it("does not show the detail", () => { | ||
const actual = rendered.queryByTestId("some-detail-component"); | ||
|
||
expect(actual).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
describe("given extension shouldn't be enabled for the cluster, when navigating", () => { | ||
beforeEach(async () => { | ||
await isEnabledForClusterMock.resolve(false); | ||
}); | ||
|
||
it("renders", () => { | ||
expect(rendered.baseElement).toMatchSnapshot(); | ||
}); | ||
|
||
it("does not show the detail", () => { | ||
const actual = rendered.queryByTestId("some-detail-component"); | ||
|
||
expect(actual).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
describe("given extension should be enabled for the cluster, when navigating", () => { | ||
beforeEach(async () => { | ||
await isEnabledForClusterMock.resolve(true); | ||
}); | ||
|
||
it("renders", () => { | ||
expect(rendered.baseElement).toMatchSnapshot(); | ||
}); | ||
|
||
it("shows the detail", () => { | ||
const actual = rendered.getByTestId("some-detail-component"); | ||
|
||
expect(actual).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
68 changes: 0 additions & 68 deletions
68
src/renderer/components/+workloads-overview/detail-components.injectable.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...kloads-overview/workload-overview-details/implementations/overview-statuses.injectable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Copyright (c) OpenLens Authors. All rights reserved. | ||
* Licensed under MIT License. See LICENSE in root directory for more information. | ||
*/ | ||
import { getInjectable } from "@ogre-tools/injectable"; | ||
import { workloadOverviewDetailInjectionToken } from "../workload-overview-detail-injection-token"; | ||
import { OverviewStatuses } from "../../overview-statuses"; | ||
import { computed } from "mobx"; | ||
|
||
const overviewStatusesInjectable = getInjectable({ | ||
id: "overview-statuses", | ||
|
||
instantiate: () => ({ | ||
Component: OverviewStatuses, | ||
enabled: computed(() => true), | ||
orderNumber: 10, | ||
}), | ||
|
||
injectionToken: workloadOverviewDetailInjectionToken, | ||
}); | ||
|
||
export default overviewStatusesInjectable; |
22 changes: 22 additions & 0 deletions
22
...orkloads-overview/workload-overview-details/implementations/workload-events.injectable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Copyright (c) OpenLens Authors. All rights reserved. | ||
* Licensed under MIT License. See LICENSE in root directory for more information. | ||
*/ | ||
import { getInjectable } from "@ogre-tools/injectable"; | ||
import { workloadOverviewDetailInjectionToken } from "../workload-overview-detail-injection-token"; | ||
import { computed } from "mobx"; | ||
import { WorkloadEvents } from "../../../../initializers/workload-events"; | ||
|
||
const workloadEventsInjectable = getInjectable({ | ||
id: "workload-events", | ||
|
||
instantiate: () => ({ | ||
Component: WorkloadEvents, | ||
enabled: computed(() => true), | ||
orderNumber: 300, | ||
}), | ||
|
||
injectionToken: workloadOverviewDetailInjectionToken, | ||
}); | ||
|
||
export default workloadEventsInjectable; |
18 changes: 18 additions & 0 deletions
18
...+workloads-overview/workload-overview-details/workload-overview-detail-injection-token.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Copyright (c) OpenLens Authors. All rights reserved. | ||
* Licensed under MIT License. See LICENSE in root directory for more information. | ||
*/ | ||
import { getInjectionToken } from "@ogre-tools/injectable"; | ||
import type { IComputedValue } from "mobx"; | ||
import type React from "react"; | ||
|
||
interface WorkloadOverviewDetail { | ||
orderNumber: number; | ||
Component: React.ElementType<{}>; | ||
enabled: IComputedValue<boolean>; | ||
} | ||
|
||
export const workloadOverviewDetailInjectionToken = | ||
getInjectionToken<WorkloadOverviewDetail>({ | ||
id: "workload-overview-detail-injection-token", | ||
}); |
57 changes: 57 additions & 0 deletions
57
...ads-overview/workload-overview-details/workload-overview-detail-registrator.injectable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Copyright (c) OpenLens Authors. All rights reserved. | ||
* Licensed under MIT License. See LICENSE in root directory for more information. | ||
*/ | ||
import { getInjectable } from "@ogre-tools/injectable"; | ||
import { computed } from "mobx"; | ||
import getRandomIdInjectable from "../../../../common/utils/get-random-id.injectable"; | ||
import type { LensRendererExtension } from "../../../../extensions/lens-renderer-extension"; | ||
import extensionShouldBeEnabledForClusterFrameInjectable from "../../../extension-loader/extension-should-be-enabled-for-cluster-frame.injectable"; | ||
import { workloadOverviewDetailInjectionToken } from "./workload-overview-detail-injection-token"; | ||
import { extensionRegistratorInjectionToken } from "../../../../extensions/extension-loader/extension-registrator-injection-token"; | ||
|
||
const workloadOverviewDetailRegistratorInjectable = getInjectable({ | ||
id: "workload-overview-detail-registrator", | ||
|
||
instantiate: (di) => { | ||
const getRandomId = di.inject(getRandomIdInjectable); | ||
|
||
const getExtensionShouldBeEnabledForClusterFrame = ( | ||
extension: LensRendererExtension, | ||
) => | ||
di.inject(extensionShouldBeEnabledForClusterFrameInjectable, extension); | ||
|
||
return (ext) => { | ||
const extension = ext as LensRendererExtension; | ||
|
||
const extensionShouldBeEnabledForClusterFrame = | ||
getExtensionShouldBeEnabledForClusterFrame(extension); | ||
|
||
return extension.kubeWorkloadsOverviewItems.map((registration) => { | ||
const id = `workload-overview-detail-from-${ | ||
extension.sanitizedExtensionId | ||
}-${getRandomId()}`; | ||
|
||
return getInjectable({ | ||
id, | ||
|
||
instantiate: () => ({ | ||
Component: registration.components.Details, | ||
|
||
enabled: computed(() => | ||
extensionShouldBeEnabledForClusterFrame.value.get(), | ||
), | ||
|
||
orderNumber: 200 - (registration.priority || 50), | ||
}), | ||
|
||
injectionToken: workloadOverviewDetailInjectionToken, | ||
}); | ||
}); | ||
}; | ||
}, | ||
|
||
injectionToken: extensionRegistratorInjectionToken, | ||
}); | ||
|
||
export default workloadOverviewDetailRegistratorInjectable; |
30 changes: 30 additions & 0 deletions
30
...nts/+workloads-overview/workload-overview-details/workload-overview-details.injectable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Copyright (c) OpenLens Authors. All rights reserved. | ||
* Licensed under MIT License. See LICENSE in root directory for more information. | ||
*/ | ||
import { getInjectable } from "@ogre-tools/injectable"; | ||
import { computed } from "mobx"; | ||
import { filter, map, sortBy } from "lodash/fp"; | ||
import { computedInjectManyInjectable } from "@ogre-tools/injectable-extension-for-mobx"; | ||
import { workloadOverviewDetailInjectionToken } from "./workload-overview-detail-injection-token"; | ||
import { pipeline } from "@ogre-tools/fp"; | ||
|
||
const workloadOverviewDetailsInjectable = getInjectable({ | ||
id: "workload-overview-details", | ||
|
||
instantiate: (di) => { | ||
const computedInjectMany = di.inject(computedInjectManyInjectable); | ||
const details = computedInjectMany(workloadOverviewDetailInjectionToken); | ||
|
||
return computed(() => | ||
pipeline( | ||
details.get(), | ||
filter((detail) => detail.enabled.get()), | ||
sortBy((detail) => detail.orderNumber), | ||
map((detail) => detail.Component), | ||
), | ||
); | ||
}, | ||
}); | ||
|
||
export default workloadOverviewDetailsInjectable; |