1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Update ogre-tools for improved types of withInjectables (#4587)

This commit is contained in:
Janne Savolainen 2021-12-17 17:28:26 +02:00 committed by GitHub
parent 96309814dc
commit a711499bb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 68 additions and 80 deletions

View File

@ -196,8 +196,8 @@
"@hapi/call": "^8.0.1", "@hapi/call": "^8.0.1",
"@hapi/subtext": "^7.0.3", "@hapi/subtext": "^7.0.3",
"@kubernetes/client-node": "^0.16.1", "@kubernetes/client-node": "^0.16.1",
"@ogre-tools/injectable": "^1.4.1", "@ogre-tools/injectable": "1.5.0",
"@ogre-tools/injectable-react": "^1.4.1", "@ogre-tools/injectable-react": "1.5.2",
"@sentry/electron": "^2.5.4", "@sentry/electron": "^2.5.4",
"@sentry/integrations": "^6.15.0", "@sentry/integrations": "^6.15.0",
"abort-controller": "^3.0.0", "abort-controller": "^3.0.0",

View File

@ -49,34 +49,28 @@ import type { LensExtensionId } from "../../../extensions/lens-extension";
import installOnDropInjectable from "./install-on-drop/install-on-drop.injectable"; import installOnDropInjectable from "./install-on-drop/install-on-drop.injectable";
import { supportedExtensionFormats } from "./supported-extension-formats"; import { supportedExtensionFormats } from "./supported-extension-formats";
interface Props { interface Dependencies {
dependencies: { userExtensions: IComputedValue<InstalledExtension[]>;
userExtensions: IComputedValue<InstalledExtension[]>; enableExtension: (id: LensExtensionId) => void;
enableExtension: (id: LensExtensionId) => void; disableExtension: (id: LensExtensionId) => void;
disableExtension: (id: LensExtensionId) => void; confirmUninstallExtension: (extension: InstalledExtension) => Promise<void>;
confirmUninstallExtension: (extension: InstalledExtension) => Promise<void>; installFromInput: (input: string) => Promise<void>;
installFromInput: (input: string) => Promise<void>; installFromSelectFileDialog: () => Promise<void>;
installFromSelectFileDialog: () => Promise<void>; installOnDrop: (files: File[]) => Promise<void>;
installOnDrop: (files: File[]) => Promise<void>;
};
} }
@observer @observer
class NonInjectedExtensions extends React.Component<Props> { class NonInjectedExtensions extends React.Component<Dependencies> {
@observable installPath = ""; @observable installPath = "";
constructor(props: Props) { constructor(props: Dependencies) {
super(props); super(props);
makeObservable(this); makeObservable(this);
} }
get dependencies() {
return this.props.dependencies;
}
componentDidMount() { componentDidMount() {
disposeOnUnmount(this, [ disposeOnUnmount(this, [
reaction(() => this.dependencies.userExtensions.get().length, (curSize, prevSize) => { reaction(() => this.props.userExtensions.get().length, (curSize, prevSize) => {
if (curSize > prevSize) { if (curSize > prevSize) {
disposeOnUnmount(this, [ disposeOnUnmount(this, [
when(() => !ExtensionInstallationStateStore.anyInstalling, () => this.installPath = ""), when(() => !ExtensionInstallationStateStore.anyInstalling, () => this.installPath = ""),
@ -87,10 +81,10 @@ class NonInjectedExtensions extends React.Component<Props> {
} }
render() { render() {
const userExtensions = this.dependencies.userExtensions.get(); const userExtensions = this.props.userExtensions.get();
return ( return (
<DropFileInput onDropFiles={this.dependencies.installOnDrop}> <DropFileInput onDropFiles={this.props.installOnDrop}>
<SettingLayout className="Extensions" contentGaps={false}> <SettingLayout className="Extensions" contentGaps={false}>
<section> <section>
<h1>Extensions</h1> <h1>Extensions</h1>
@ -106,8 +100,8 @@ class NonInjectedExtensions extends React.Component<Props> {
<Install <Install
supportedFormats={supportedExtensionFormats} supportedFormats={supportedExtensionFormats}
onChange={value => (this.installPath = value)} onChange={value => (this.installPath = value)}
installFromInput={() => this.dependencies.installFromInput(this.installPath)} installFromInput={() => this.props.installFromInput(this.installPath)}
installFromSelectFileDialog={this.dependencies.installFromSelectFileDialog} installFromSelectFileDialog={this.props.installFromSelectFileDialog}
installPath={this.installPath} installPath={this.installPath}
/> />
@ -115,9 +109,9 @@ class NonInjectedExtensions extends React.Component<Props> {
<InstalledExtensions <InstalledExtensions
extensions={userExtensions} extensions={userExtensions}
enable={this.dependencies.enableExtension} enable={this.props.enableExtension}
disable={this.dependencies.disableExtension} disable={this.props.disableExtension}
uninstall={this.dependencies.confirmUninstallExtension} uninstall={this.props.confirmUninstallExtension}
/> />
</section> </section>
</SettingLayout> </SettingLayout>
@ -126,10 +120,10 @@ class NonInjectedExtensions extends React.Component<Props> {
} }
} }
export const Extensions = withInjectables<Dependencies>(
export const Extensions = withInjectables(NonInjectedExtensions, { NonInjectedExtensions,
getProps: di => ({ {
dependencies: { getProps: (di) => ({
userExtensions: di.inject(userExtensionsInjectable), userExtensions: di.inject(userExtensionsInjectable),
enableExtension: di.inject(enableExtensionInjectable), enableExtension: di.inject(enableExtensionInjectable),
disableExtension: di.inject(disableExtensionInjectable), disableExtension: di.inject(disableExtensionInjectable),
@ -140,6 +134,6 @@ export const Extensions = withInjectables(NonInjectedExtensions, {
installFromSelectFileDialog: di.inject( installFromSelectFileDialog: di.inject(
installFromSelectFileDialogInjectable, installFromSelectFileDialogInjectable,
), ),
}, }),
}), },
}); );

View File

@ -32,38 +32,28 @@ import hideDetailsInjectable from "./dependencies/hide-details.injectable";
import kubeObjectMenuItemsInjectable from "./dependencies/kube-object-menu-items/kube-object-menu-items.injectable"; import kubeObjectMenuItemsInjectable from "./dependencies/kube-object-menu-items/kube-object-menu-items.injectable";
import apiManagerInjectable from "./dependencies/api-manager.injectable"; import apiManagerInjectable from "./dependencies/api-manager.injectable";
// TODO: Replace with KubeObjectMenuProps2 export interface KubeObjectMenuProps<TKubeObject extends KubeObject> extends MenuActionsProps {
export interface KubeObjectMenuProps<TKubeObject> extends MenuActionsProps {
object: TKubeObject | null | undefined; object: TKubeObject | null | undefined;
editable?: boolean; editable?: boolean;
removable?: boolean; removable?: boolean;
} }
interface KubeObjectMenuProps2 extends MenuActionsProps { interface Dependencies {
object: KubeObject | null | undefined; apiManager: ApiManager;
editable?: boolean; kubeObjectMenuItems: React.ElementType[];
removable?: boolean; clusterName: string;
hideDetails: () => void;
dependencies: { editResourceTab: (kubeObject: KubeObject) => void;
apiManager: ApiManager;
kubeObjectMenuItems: React.ElementType[];
clusterName: string;
hideDetails: () => void;
editResourceTab: (kubeObject: KubeObject) => void;
};
} }
class NonInjectedKubeObjectMenu extends React.Component<KubeObjectMenuProps2> { class NonInjectedKubeObjectMenu<TKubeObject extends KubeObject> extends React.Component<KubeObjectMenuProps<TKubeObject> & Dependencies> {
get dependencies() {
return this.props.dependencies;
}
get store() { get store() {
const { object } = this.props; const { object } = this.props;
if (!object) return null; if (!object) return null;
return this.props.dependencies.apiManager.getStore(object.selfLink); return this.props.apiManager.getStore(object.selfLink);
} }
get isEditable() { get isEditable() {
@ -76,13 +66,13 @@ class NonInjectedKubeObjectMenu extends React.Component<KubeObjectMenuProps2> {
@boundMethod @boundMethod
async update() { async update() {
this.props.dependencies.hideDetails(); this.props.hideDetails();
this.props.dependencies.editResourceTab(this.props.object); this.props.editResourceTab(this.props.object);
} }
@boundMethod @boundMethod
async remove() { async remove() {
this.props.dependencies.hideDetails(); this.props.hideDetails();
const { object, removeAction } = this.props; const { object, removeAction } = this.props;
if (removeAction) await removeAction(); if (removeAction) await removeAction();
@ -103,7 +93,7 @@ class NonInjectedKubeObjectMenu extends React.Component<KubeObjectMenuProps2> {
return ( return (
<p> <p>
Remove {object.kind} <b>{breadcrumb}</b> from <b>{this.dependencies.clusterName}</b>? Remove {object.kind} <b>{breadcrumb}</b> from <b>{this.props.clusterName}</b>?
</p> </p>
); );
} }
@ -111,7 +101,7 @@ class NonInjectedKubeObjectMenu extends React.Component<KubeObjectMenuProps2> {
getMenuItems(): React.ReactChild[] { getMenuItems(): React.ReactChild[] {
const { object, toolbar } = this.props; const { object, toolbar } = this.props;
return this.props.dependencies.kubeObjectMenuItems.map((MenuItem, index) => ( return this.props.kubeObjectMenuItems.map((MenuItem, index) => (
<MenuItem object={object} toolbar={toolbar} key={`menu-item-${index}`} /> <MenuItem object={object} toolbar={toolbar} key={`menu-item-${index}`} />
)); ));
} }
@ -134,19 +124,23 @@ class NonInjectedKubeObjectMenu extends React.Component<KubeObjectMenuProps2> {
} }
} }
export const KubeObjectMenu = withInjectables(NonInjectedKubeObjectMenu, { export function KubeObjectMenu<T extends KubeObject>(
getProps: (di, props) => ({ props: KubeObjectMenuProps<T>,
dependencies: { ) {
clusterName: di.inject(clusterNameInjectable), return withInjectables<Dependencies, KubeObjectMenuProps<T>>(
apiManager: di.inject(apiManagerInjectable), NonInjectedKubeObjectMenu,
editResourceTab: di.inject(editResourceTabInjectable), {
hideDetails: di.inject(hideDetailsInjectable), getProps: (di, props) => ({
clusterName: di.inject(clusterNameInjectable),
apiManager: di.inject(apiManagerInjectable),
editResourceTab: di.inject(editResourceTabInjectable),
hideDetails: di.inject(hideDetailsInjectable),
kubeObjectMenuItems: di.inject(kubeObjectMenuItemsInjectable, { kubeObjectMenuItems: di.inject(kubeObjectMenuItemsInjectable, {
kubeObject: props.object, kubeObject: props.object,
}),
...props,
}), }),
}, },
)(props);
...props, }
}),
});

View File

@ -979,19 +979,19 @@
dependencies: dependencies:
lodash "^4.17.21" lodash "^4.17.21"
"@ogre-tools/injectable-react@^1.4.1": "@ogre-tools/injectable-react@1.5.2":
version "1.4.1" version "1.5.2"
resolved "https://registry.yarnpkg.com/@ogre-tools/injectable-react/-/injectable-react-1.4.1.tgz#48d8633462189939292596a66631d6717e39e47f" resolved "https://registry.yarnpkg.com/@ogre-tools/injectable-react/-/injectable-react-1.5.2.tgz#7df925ca5abda86210f527333774ddbf027f0693"
integrity sha512-SRk3QXvFCEQk4MeVG8TAomGcOt0Pf06hZ5kBh+iNIug3FLYeyWagH6OSVylZRu4u2Izd89J0taS1GmSfYDoHaA== integrity sha512-n26NyGLYjwyIbfwsLj1tg0uNPK6SI/H0vGisMNpNfrcdci2QiLQBSKemnLMMRn7LF/+JhA/NQClTetiMkcSCuw==
dependencies: dependencies:
"@ogre-tools/fp" "^1.4.0" "@ogre-tools/fp" "^1.4.0"
"@ogre-tools/injectable" "^1.4.1" "@ogre-tools/injectable" "^1.5.0"
lodash "^4.17.21" lodash "^4.17.21"
"@ogre-tools/injectable@^1.4.1": "@ogre-tools/injectable@1.5.0", "@ogre-tools/injectable@^1.5.0":
version "1.4.1" version "1.5.0"
resolved "https://registry.yarnpkg.com/@ogre-tools/injectable/-/injectable-1.4.1.tgz#45414c6e13c870d7d84f4fa8e0dd67b33f6cc23e" resolved "https://registry.yarnpkg.com/@ogre-tools/injectable/-/injectable-1.5.0.tgz#edf911f360e73bb5f10ac669f147108d1465fc45"
integrity sha512-vX4QXS/2d3g7oUenOKcv3mZRnJ5XewUMPsSsELjCyhL2caJlD0eB9J7y3y0eeFu/I18L8GC3DRs9o3QNshwN5Q== integrity sha512-k0Wgc8QqB+p/gHcWPVWJV8N8xX5cMpagEjZ1C5bPVeRyB+73od/yHgb1HOgL2pPzlE6qOtTdkiUrWuTAoqnqUw==
dependencies: dependencies:
"@ogre-tools/fp" "^1.4.0" "@ogre-tools/fp" "^1.4.0"
lodash "^4.17.21" lodash "^4.17.21"