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

Make update function injectable for button

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2022-05-30 13:05:58 +03:00
parent 315f0a73da
commit 1f1aa6cd32
3 changed files with 26 additions and 4 deletions

View File

@ -130,7 +130,7 @@ const NonInjectedTopBar = observer(({
onClick={goForward}
disabled={!nextEnabled.get()}
/>
<UpdateButton update={noop} />
<UpdateButton />
</div>
<div className={styles.items}>
{renderRegisteredItems(items.get())}

View File

@ -0,0 +1,20 @@
/**
* 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 { AutoUpdateQuitAndInstalledChannel } from "../../../common/ipc";
import broadcastMessageInjectable from "../../../common/ipc/broadcast-message.injectable";
const updateAppInjectable = getInjectable({
id: "update-app",
instantiate: (di) => {
const broadcast = di.inject(broadcastMessageInjectable);
return () => broadcast(AutoUpdateQuitAndInstalledChannel);
},
});
export default updateAppInjectable;

View File

@ -15,13 +15,14 @@ import { withInjectables } from "@ogre-tools/injectable-react";
import { observer } from "mobx-react";
import appUpdateWarningLevelInjectable from "../../app-update-warning/app-update-warning-level.injectable";
import type { IComputedValue } from "mobx";
import updateAppInjectable from "./update-app.injectable";
interface UpdateButtonProps extends HTMLAttributes<HTMLButtonElement> {
update: () => void;
}
interface Dependencies {
warningLevel?: IComputedValue<"light" | "medium" | "high" | "">;
update: () => void;
}
export const NonInjectedUpdateButton = observer(({ warningLevel, update, id }: UpdateButtonProps & Dependencies) => {
@ -33,7 +34,7 @@ export const NonInjectedUpdateButton = observer(({ warningLevel, update, id }: U
setOpened(!opened);
};
if (!warningLevel) {
if (!warningLevel || !warningLevel.get()) {
return null;
}
@ -41,7 +42,7 @@ export const NonInjectedUpdateButton = observer(({ warningLevel, update, id }: U
<>
<button
data-testid="update-button"
data-warning-level={warningLevel}
data-warning-level={warningLevel.get()}
id={buttonId}
className={cssNames(styles.updateButton, {
[styles.warningHigh]: warningLevel.get() === "high",
@ -75,6 +76,7 @@ export const UpdateButton = withInjectables<Dependencies, UpdateButtonProps>(Non
return {
...props,
warningLevel: di.inject(appUpdateWarningLevelInjectable),
update: di.inject(updateAppInjectable),
};
},
});