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

Fix withInjectables props

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2022-05-27 14:01:48 +03:00
parent 9acc2c9f9c
commit 613e98cd2f

View File

@ -12,17 +12,19 @@ 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 { withInjectables } from "@ogre-tools/injectable-react";
import appUpdateWarningInjectable from "../../app-update-warning/app-update-warning.injectable"; import { observer } from "mobx-react";
import appUpdateWarningLevelInjectable from "../../app-update-warning/app-update-warning-level.injectable";
import type { IComputedValue } from "mobx";
interface UpdateButtonProps extends HTMLAttributes<HTMLButtonElement> { interface UpdateButtonProps extends HTMLAttributes<HTMLButtonElement> {
update: () => void; update: () => void;
} }
interface Dependencies { interface Dependencies {
warningLevel?: "light" | "medium" | "high" | ""; warningLevel?: IComputedValue<"light" | "medium" | "high" | "">;
} }
export function NonInjectedUpdateButton({ warningLevel, update, id }: UpdateButtonProps & Dependencies) { export const NonInjectedUpdateButton = observer(({ 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);
@ -42,8 +44,8 @@ export function NonInjectedUpdateButton({ warningLevel, update, id }: UpdateButt
data-warning-level={warningLevel} data-warning-level={warningLevel}
id={buttonId} id={buttonId}
className={cssNames(styles.updateButton, { className={cssNames(styles.updateButton, {
[styles.warningHigh]: warningLevel === "high", [styles.warningHigh]: warningLevel.get() === "high",
[styles.warningMedium]: warningLevel === "medium", [styles.warningMedium]: warningLevel.get() === "medium",
})} })}
> >
Update Update
@ -66,15 +68,13 @@ export function NonInjectedUpdateButton({ warningLevel, update, id }: UpdateButt
</Menu> </Menu>
</> </>
); );
} });
export const UpdateButton = withInjectables<Dependencies, UpdateButtonProps>(NonInjectedUpdateButton, { export const UpdateButton = withInjectables<Dependencies, UpdateButtonProps>(NonInjectedUpdateButton, {
getProps: (di, props) => { getProps: (di, props) => {
const store = di.inject(appUpdateWarningInjectable);
return { return {
...props, ...props,
warningLevel: store.warningLevel, warningLevel: di.inject(appUpdateWarningLevelInjectable),
}; };
}, },
}); });