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

Cleaning up

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2023-03-15 10:36:29 +03:00
parent da8c11fdb6
commit f302ee3af5
4 changed files with 8 additions and 23 deletions

View File

@ -13,7 +13,6 @@ import { renderFor } from "../../test-utils/renderFor";
import { ClusterIconSetting } from "../icon-settings";
import { screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import type { ChangedClusterPreference } from "../cluster-settings-menu-injection-token";
import { clusterIconSettingsMenuInjectionToken } from "../cluster-settings-menu-injection-token";
import { runInAction } from "mobx";
@ -46,10 +45,8 @@ const newMenuItem = getInjectable({
instantiate: () => ({
id: "test-menu-item",
title: "Hello World",
onClick: () => {
const data: ChangedClusterPreference = ["clusterName", "New cluster name"];
return data;
onClick: (preferences) => {
preferences.clusterName = "Hello World";
},
}),
@ -63,8 +60,6 @@ describe("Icon settings", () => {
beforeEach(() => {
di = getDiForUnitTesting();
// registerMobX(di);
const render = renderFor(di);
rendered = render(

View File

@ -3,8 +3,6 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { ClusterPreferences } from "../../../common/cluster-types";
import type { ChangedClusterPreference } from "./cluster-settings-menu-injection-token";
import { clusterIconSettingsMenuInjectionToken } from "./cluster-settings-menu-injection-token";
const clusterIconSettingsMenuClearItem = getInjectable({
@ -13,15 +11,13 @@ const clusterIconSettingsMenuClearItem = getInjectable({
instantiate: () => ({
id: "clear-icon-menu-item",
title: "Clear",
disabled: (preferences: ClusterPreferences) => !preferences.icon,
onClick: () => {
disabled: (preferences) => !preferences.icon,
onClick: (preferences) => {
/**
* NOTE: this needs to be `null` rather than `undefined` so that we can
* tell the difference between it not being there and being cleared.
*/
const data: ChangedClusterPreference = ["icon", null];
return data;
preferences.icon = null;
},
}),

View File

@ -5,13 +5,11 @@
import { getInjectionToken } from "@ogre-tools/injectable";
import type { ClusterPreferences } from "../../../common/cluster-types";
export type ChangedClusterPreference = [keyof ClusterPreferences, any];
export interface ClusterIconMenuItem {
id: string;
title: string;
disabled?: (preferences: ClusterPreferences) => boolean;
onClick: (preferences: ClusterPreferences) => ChangedClusterPreference;
onClick: (preferences: ClusterPreferences) => void;
}
export const clusterIconSettingsMenuInjectionToken = getInjectionToken<ClusterIconMenuItem>({

View File

@ -15,7 +15,7 @@ import { FilePicker, OverSizeLimitStyle } from "../file-picker";
import { MenuActions, MenuItem } from "../menu";
import type { ShowNotification } from "../notifications";
import showErrorNotificationInjectable from "../notifications/show-error-notification.injectable";
import type { ChangedClusterPreference, ClusterIconMenuItem } from "./cluster-settings-menu-injection-token";
import type { ClusterIconMenuItem } from "./cluster-settings-menu-injection-token";
import { clusterIconSettingsMenuInjectionToken } from "./cluster-settings-menu-injection-token";
export interface ClusterIconSettingProps {
@ -55,10 +55,6 @@ const NonInjectedClusterIconSetting = observer((props: ClusterIconSettingProps &
?.click();
};
const save = ([kind, value]: ChangedClusterPreference) => {
cluster.preferences[kind] = value;
};
return (
<div ref={element}>
<div className="file-loader flex flex-row items-center">
@ -89,7 +85,7 @@ const NonInjectedClusterIconSetting = observer((props: ClusterIconSettingProps &
</MenuItem>
{props.menuItems.get().map(item => (
<MenuItem
onClick={() => save(item.onClick(cluster.preferences))}
onClick={() => item.onClick(cluster.preferences)}
key={item.id}
disabled={item.disabled?.(cluster.preferences)}>
{item.title}