mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
feat: Introduce minimal dock tabs
Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
This commit is contained in:
parent
b6e44424b7
commit
7892d76b5d
@ -32,9 +32,13 @@
|
||||
"peerDependencies": {
|
||||
"@k8slens/feature-core": "^6.5.0-alpha.0",
|
||||
"@k8slens/ui-components": "^1.0.0-alpha.0",
|
||||
"@ogre-tools/fp": "^15.1.2",
|
||||
"@ogre-tools/injectable": "^15.1.2",
|
||||
"@ogre-tools/injectable-extension-for-auto-registration": "^15.1.2",
|
||||
"@ogre-tools/fp": "^15.1.2",
|
||||
"@ogre-tools/injectable-extension-for-mobx": "^15.1.2",
|
||||
"@ogre-tools/injectable-react": "^15.1.2",
|
||||
"mobx": "^6.8.0",
|
||||
"mobx-react": "^7.6.0",
|
||||
"lodash": "^4.17.21",
|
||||
"react": "^17"
|
||||
},
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`dock when rendered renders 1`] = `
|
||||
exports[`DockHost, given rendered given implementations of dock tabs emerge renders 1`] = `
|
||||
<body>
|
||||
<div>
|
||||
<div
|
||||
@ -18,28 +18,11 @@ exports[`dock when rendered renders 1`] = `
|
||||
<div
|
||||
class="flex align-center"
|
||||
>
|
||||
<span
|
||||
class="overflow-hidden text-ellipsis"
|
||||
>
|
||||
Some title
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="Tab flex gaps align-center"
|
||||
data-some-dock-tab-test="true"
|
||||
>
|
||||
<div
|
||||
class="label"
|
||||
>
|
||||
<div
|
||||
class="flex align-center"
|
||||
>
|
||||
<span
|
||||
class="overflow-hidden text-ellipsis"
|
||||
>
|
||||
Some other title
|
||||
</span>
|
||||
Some content
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -61,3 +44,30 @@ exports[`dock when rendered renders 1`] = `
|
||||
</div>
|
||||
</body>
|
||||
`;
|
||||
|
||||
exports[`DockHost, given rendered given no implementations of dock tabs, renders 1`] = `
|
||||
<body>
|
||||
<div>
|
||||
<div
|
||||
class="Dock isOpen"
|
||||
>
|
||||
<div
|
||||
class="flex align-center tabs-container"
|
||||
/>
|
||||
<div
|
||||
class="flex align-center toolbar gaps box grow pl-0"
|
||||
>
|
||||
<div
|
||||
class="dock-menu box grow"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
class="tab-content"
|
||||
style="flex-basis: 420px;"
|
||||
>
|
||||
Some content
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
`;
|
||||
|
||||
11
packages/business-features/dock/src/dock-tab.ts
Normal file
11
packages/business-features/dock/src/dock-tab.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import type React from "react";
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
|
||||
export type DockTab = {
|
||||
id: string;
|
||||
Component: React.ComponentType;
|
||||
};
|
||||
|
||||
export const dockTabInjectionToken = getInjectionToken<DockTab>({
|
||||
id: "dock-tab-injection-token",
|
||||
});
|
||||
@ -1,29 +1,63 @@
|
||||
import { createContainer, DiContainer } from "@ogre-tools/injectable";
|
||||
import { runInAction } from "mobx";
|
||||
import { createContainer, DiContainer, getInjectable } from "@ogre-tools/injectable";
|
||||
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
|
||||
import { registerInjectableReact } from "@ogre-tools/injectable-react";
|
||||
import { renderFor } from "@k8slens/test-utils";
|
||||
import { DockHost } from "./dock/dock-host";
|
||||
import React from "react";
|
||||
import type { RenderResult } from "@testing-library/react";
|
||||
import { dockTabInjectionToken } from "./dock-tab";
|
||||
import { Discover, discoverFor } from "@k8slens/react-testing-library-discovery";
|
||||
import { registerFeature } from "@k8slens/feature-core";
|
||||
import { dockFeature } from "./feature";
|
||||
|
||||
describe("dock", () => {
|
||||
describe("DockHost, given rendered", () => {
|
||||
let di: DiContainer;
|
||||
let rendered: RenderResult;
|
||||
let discover: Discover;
|
||||
|
||||
beforeEach(() => {
|
||||
di = createContainer("some-container");
|
||||
|
||||
// registerFeature(di, dockFeature);
|
||||
registerMobX(di);
|
||||
registerInjectableReact(di);
|
||||
runInAction(() => {
|
||||
registerFeature(di, dockFeature);
|
||||
});
|
||||
|
||||
describe("when rendered", () => {
|
||||
let rendered: RenderResult;
|
||||
|
||||
beforeEach(() => {
|
||||
const render = renderFor(di);
|
||||
|
||||
rendered = render(<DockHost />);
|
||||
discover = discoverFor(() => rendered);
|
||||
});
|
||||
|
||||
it("given no implementations of dock tabs, renders", () => {
|
||||
expect(rendered.baseElement).toMatchSnapshot();
|
||||
});
|
||||
|
||||
describe("given implementations of dock tabs emerge", () => {
|
||||
beforeEach(() => {
|
||||
const dockInjectable = getInjectable({
|
||||
id: "some-dock-tab",
|
||||
|
||||
instantiate: () => ({
|
||||
id: "some-dock-tab",
|
||||
Component: () => <div data-some-dock-tab-test>Some content</div>,
|
||||
}),
|
||||
|
||||
injectionToken: dockTabInjectionToken,
|
||||
});
|
||||
|
||||
runInAction(() => {
|
||||
di.register(dockInjectable);
|
||||
});
|
||||
});
|
||||
|
||||
it("renders", () => {
|
||||
expect(rendered.baseElement).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("renders the dock tab", () => {
|
||||
discover.getSingleElement("some-dock-tab");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,21 +1,24 @@
|
||||
import type { IComputedValue } from "mobx";
|
||||
import { observer } from "mobx-react";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import React from "react";
|
||||
import { Tab } from "./tab";
|
||||
import { Div, Span } from "@k8slens/ui-components";
|
||||
import { Div, Map } from "@k8slens/ui-components";
|
||||
import dockTabsInjectable from "./dock-tabs.injectable";
|
||||
import type { DockTab } from "../dock-tab";
|
||||
|
||||
export const DockHost = () => (
|
||||
const NonInjectedDockHost = observer(({ dockTabs }: Dependencies) => (
|
||||
<Div _className={["Dock", { isOpen: true }]}>
|
||||
<Div _flexParent={{ centeredVertically: true }} className="tabs-container">
|
||||
<Map items={dockTabs.get()}>
|
||||
{({ Component }) => (
|
||||
<Tab>
|
||||
<Div _flexParent={{ centeredVertically: true }}>
|
||||
<Span _wordWrap>Some title</Span>
|
||||
</Div>
|
||||
</Tab>
|
||||
|
||||
<Tab>
|
||||
<Div _flexParent={{ centeredVertically: true }}>
|
||||
<Span _wordWrap>Some other title</Span>
|
||||
<Component />
|
||||
</Div>
|
||||
</Tab>
|
||||
)}
|
||||
</Map>
|
||||
</Div>
|
||||
|
||||
<Div
|
||||
@ -34,4 +37,19 @@ export const DockHost = () => (
|
||||
Some content
|
||||
</div>
|
||||
</Div>
|
||||
));
|
||||
|
||||
interface Dependencies {
|
||||
dockTabs: IComputedValue<DockTab[]>;
|
||||
}
|
||||
|
||||
export const DockHost = withInjectables<Dependencies>(
|
||||
NonInjectedDockHost,
|
||||
|
||||
{
|
||||
getProps: (di, props) => ({
|
||||
dockTabs: di.inject(dockTabsInjectable),
|
||||
...props,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { computedInjectManyInjectable } from "@ogre-tools/injectable-extension-for-mobx";
|
||||
import { dockTabInjectionToken } from "../dock-tab";
|
||||
|
||||
const dockTabsInjectable = getInjectable({
|
||||
id: "dock-tabs",
|
||||
|
||||
instantiate: (di) => {
|
||||
const computedInjectMany = di.inject(computedInjectManyInjectable);
|
||||
|
||||
return computedInjectMany(dockTabInjectionToken);
|
||||
},
|
||||
});
|
||||
|
||||
export default dockTabsInjectable;
|
||||
@ -4,13 +4,13 @@ import {
|
||||
rendererExtensionApi as Renderer,
|
||||
commonExtensionApi as Common,
|
||||
registerLensCore,
|
||||
metricsFeature
|
||||
metricsFeature,
|
||||
} from "@k8slens/core/renderer";
|
||||
import { autoRegister } from "@ogre-tools/injectable-extension-for-auto-registration";
|
||||
import { registerFeature } from "@k8slens/feature-core";
|
||||
import {
|
||||
applicationFeature,
|
||||
startApplicationInjectionToken
|
||||
startApplicationInjectionToken,
|
||||
} from "@k8slens/application";
|
||||
import { createContainer } from "@ogre-tools/injectable";
|
||||
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
|
||||
@ -18,6 +18,7 @@ import { registerInjectableReact } from "@ogre-tools/injectable-react";
|
||||
import { messagingFeatureForRenderer } from "@k8slens/messaging-for-renderer";
|
||||
import { keyboardShortcutsFeature } from "@k8slens/keyboard-shortcuts";
|
||||
import { reactApplicationFeature } from "@k8slens/react-application";
|
||||
import { dockFeature } from "@k8slens/dock";
|
||||
|
||||
const environment = "renderer";
|
||||
|
||||
@ -36,7 +37,8 @@ runInAction(() => {
|
||||
messagingFeatureForRenderer,
|
||||
keyboardShortcutsFeature,
|
||||
reactApplicationFeature,
|
||||
metricsFeature
|
||||
metricsFeature,
|
||||
dockFeature,
|
||||
);
|
||||
|
||||
autoRegister({
|
||||
|
||||
Loading…
Reference in New Issue
Block a user