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

Give an UpdateButton injectables

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2022-05-24 15:16:25 +03:00
parent acb119af94
commit 1fd3487f3f

View File

@ -11,13 +11,18 @@ import { Menu, MenuItem } from "../menu";
import { cssNames } from "../../utils"; import { cssNames } from "../../utils";
import type { IconProps } from "../icon"; import type { IconProps } from "../icon";
import { Icon } from "../icon"; import { Icon } from "../icon";
import { withInjectables } from "@ogre-tools/injectable-react";
import appUpdateWarningInjectable from "../../app-freshness/app-update-warning.injectable";
interface UpdateButtonProps extends HTMLAttributes<HTMLButtonElement> { interface UpdateButtonProps extends HTMLAttributes<HTMLButtonElement> {
warningLevel?: "light" | "medium" | "high";
update: () => void; update: () => void;
} }
export function UpdateButton({ warningLevel, update, id }: UpdateButtonProps) { interface Dependencies {
warningLevel?: "light" | "medium" | "high" | "";
}
export function NonInjectedUpdateButton({ warningLevel, update, id }: UpdateButtonProps & Dependencies) {
const buttonId = id ?? "update-lens-button"; const buttonId = id ?? "update-lens-button";
const menuIconProps: IconProps = { material: "update", small: true }; const menuIconProps: IconProps = { material: "update", small: true };
const [opened, setOpened] = useState(false); const [opened, setOpened] = useState(false);
@ -62,3 +67,14 @@ export function UpdateButton({ warningLevel, update, id }: UpdateButtonProps) {
</> </>
); );
} }
export const UpdateButton = withInjectables<Dependencies, UpdateButtonProps>(NonInjectedUpdateButton, {
getProps: (di, props) => {
const store = di.inject(appUpdateWarningInjectable);
return {
...props,
warningLevel: store.warningLevel,
};
},
});