/** * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ import styles from "./styles.module.scss"; import type { HTMLAttributes } from "react"; import React, { useState } from "react"; import { Menu, MenuItem } from "../menu"; import { cssNames } from "../../utils"; import type { IconProps } from "../icon"; import { Icon } from "../icon"; import { withInjectables } from "@ogre-tools/injectable-react"; import { observer } from "mobx-react"; import updateWarningLevelInjectable from "../../../common/application-update/update-warning-level/update-warning-level.injectable"; import type { IComputedValue } from "mobx"; import { computed } from "mobx"; import restartAndInstallUpdateInjectable from "./restart-and-install-update.injectable"; interface UpdateButtonProps extends HTMLAttributes { } interface Dependencies { warningLevel: IComputedValue<"light" | "medium" | "high" | "">; update: () => void; } export const NonInjectedUpdateButton = observer(({ warningLevel, update, id }: UpdateButtonProps & Dependencies) => { const buttonId = id ?? "update-lens-button"; const menuIconProps: IconProps = { material: "update", small: true }; const [opened, setOpened] = useState(false); const toggle = () => { setOpened(!opened); }; if (!warningLevel.get()) { return null; } return ( <> Relaunch to Update Lens ); }); export const UpdateButton = withInjectables(NonInjectedUpdateButton, { getProps: (di, props) => { const warnignLevel = di.inject(updateWarningLevelInjectable); return { ...props, warningLevel: computed(() => warnignLevel.value.get()), update: di.inject(restartAndInstallUpdateInjectable), }; }, });