mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Consolidate navigating to preferences
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
8dca046495
commit
a7f300a010
@ -13,7 +13,10 @@ const navigateToPreferencesInjectable = getInjectable({
|
||||
const navigateToRoute = di.inject(navigateToRouteInjectionToken);
|
||||
const preferencesRoute = di.inject(preferencesRouteInjectable);
|
||||
|
||||
return () => navigateToRoute(preferencesRoute);
|
||||
return (tabId?: string) =>
|
||||
navigateToRoute(preferencesRoute, {
|
||||
parameters: tabId ? { preferenceTabId: tabId } : {},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -3,17 +3,15 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import preferencesRouteInjectable from "./preferences-route.injectable";
|
||||
import { navigateToRouteInjectionToken } from "../../../common/front-end-routing/navigate-to-route-injection-token";
|
||||
import navigateToPreferencesInjectable from "../../../common/front-end-routing/routes/preferences/navigate-to-preferences.injectable";
|
||||
|
||||
const navigateToApplicationPreferencesInjectable = getInjectable({
|
||||
id: "navigate-to-application-preferences",
|
||||
|
||||
instantiate: (di) => {
|
||||
const navigateToRoute = di.inject(navigateToRouteInjectionToken);
|
||||
const route = di.inject(preferencesRouteInjectable);
|
||||
const navigateToPreferences = di.inject(navigateToPreferencesInjectable);
|
||||
|
||||
return () => navigateToRoute(route, { parameters: { preferenceTabId: "app" }});
|
||||
return () => navigateToPreferences("app");
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -3,17 +3,15 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import preferencesRouteInjectable from "./preferences-route.injectable";
|
||||
import { navigateToRouteInjectionToken } from "../../../common/front-end-routing/navigate-to-route-injection-token";
|
||||
import navigateToPreferencesInjectable from "../../../common/front-end-routing/routes/preferences/navigate-to-preferences.injectable";
|
||||
|
||||
const navigateToEditorPreferencesInjectable = getInjectable({
|
||||
id: "navigate-to-editor-preferences",
|
||||
|
||||
instantiate: (di) => {
|
||||
const navigateToRoute = di.inject(navigateToRouteInjectionToken);
|
||||
const route = di.inject(preferencesRouteInjectable);
|
||||
const navigateToPreferences = di.inject(navigateToPreferencesInjectable);
|
||||
|
||||
return () => navigateToRoute(route, { parameters: { preferenceTabId: "editor" }});
|
||||
return () => navigateToPreferences("editor");
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -3,17 +3,15 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import preferencesRouteInjectable from "./preferences-route.injectable";
|
||||
import { navigateToRouteInjectionToken } from "../../../common/front-end-routing/navigate-to-route-injection-token";
|
||||
import navigateToPreferencesInjectable from "../../../common/front-end-routing/routes/preferences/navigate-to-preferences.injectable";
|
||||
|
||||
const navigateToKubernetesPreferencesInjectable = getInjectable({
|
||||
id: "navigate-to-kubernetes-preferences",
|
||||
|
||||
instantiate: (di) => {
|
||||
const navigateToRoute = di.inject(navigateToRouteInjectionToken);
|
||||
const route = di.inject(preferencesRouteInjectable);
|
||||
const navigateToPreferences = di.inject(navigateToPreferencesInjectable);
|
||||
|
||||
return () => navigateToRoute(route, { parameters: { preferenceTabId: "kubernetes" }});
|
||||
return () => navigateToPreferences("kubernetes");
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -3,17 +3,15 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { navigateToRouteInjectionToken } from "../../../common/front-end-routing/navigate-to-route-injection-token";
|
||||
import preferencesRouteInjectable from "./preferences-route.injectable";
|
||||
import navigateToPreferencesInjectable from "../../../common/front-end-routing/routes/preferences/navigate-to-preferences.injectable";
|
||||
|
||||
const navigateToProxyPreferencesInjectable = getInjectable({
|
||||
id: "navigate-to-proxy-preferences",
|
||||
|
||||
instantiate: (di) => {
|
||||
const navigateToRoute = di.inject(navigateToRouteInjectionToken);
|
||||
const route = di.inject(preferencesRouteInjectable);
|
||||
const navigateToPreferences = di.inject(navigateToPreferencesInjectable);
|
||||
|
||||
return () => navigateToRoute(route, { parameters: { preferenceTabId: "proxy" }});
|
||||
return () => navigateToPreferences("proxy");
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -3,17 +3,15 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { navigateToRouteInjectionToken } from "../../../common/front-end-routing/navigate-to-route-injection-token";
|
||||
import preferencesRouteInjectable from "./preferences-route.injectable";
|
||||
import navigateToPreferencesInjectable from "../../../common/front-end-routing/routes/preferences/navigate-to-preferences.injectable";
|
||||
|
||||
const navigateToTelemetryPreferencesInjectable = getInjectable({
|
||||
id: "navigate-to-telemetry-preferences",
|
||||
|
||||
instantiate: (di) => {
|
||||
const navigateToRoute = di.inject(navigateToRouteInjectionToken);
|
||||
const route = di.inject(preferencesRouteInjectable);
|
||||
const navigateToPreferences = di.inject(navigateToPreferencesInjectable);
|
||||
|
||||
return () => navigateToRoute(route, { parameters: { preferenceTabId: "telemetry" }});
|
||||
return () => navigateToPreferences("telemetry");
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -3,17 +3,15 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { navigateToRouteInjectionToken } from "../../../common/front-end-routing/navigate-to-route-injection-token";
|
||||
import preferencesRouteInjectable from "./preferences-route.injectable";
|
||||
import navigateToPreferencesInjectable from "../../../common/front-end-routing/routes/preferences/navigate-to-preferences.injectable";
|
||||
|
||||
const navigateToTerminalPreferencesInjectable = getInjectable({
|
||||
id: "navigate-to-terminal-preferences",
|
||||
|
||||
instantiate: (di) => {
|
||||
const navigateToRoute = di.inject(navigateToRouteInjectionToken);
|
||||
const route = di.inject(preferencesRouteInjectable);
|
||||
const navigateToPreferences = di.inject(navigateToPreferencesInjectable);
|
||||
|
||||
return () => navigateToRoute(route, { parameters: { preferenceTabId: "terminal" }});
|
||||
return () => navigateToPreferences("terminal");
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -1,44 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { pipeline } from "@ogre-tools/fp";
|
||||
import { getInjectable, getInjectionToken } from "@ogre-tools/injectable";
|
||||
import { computedInjectManyInjectable } from "@ogre-tools/injectable-extension-for-mobx";
|
||||
import { filter, orderBy } from "lodash/fp";
|
||||
import type { IComputedValue } from "mobx";
|
||||
import { computed } from "mobx";
|
||||
|
||||
export const preferenceNavigationItemInjectionToken =
|
||||
getInjectionToken<PreferenceNavigationItem>({
|
||||
id: "preference-navigation-item-injection-token",
|
||||
});
|
||||
|
||||
export interface PreferenceNavigationItem {
|
||||
id: string;
|
||||
label: string;
|
||||
isActive: IComputedValue<boolean>;
|
||||
isVisible: IComputedValue<boolean>;
|
||||
navigate: () => void;
|
||||
orderNumber: number;
|
||||
parent: string;
|
||||
}
|
||||
|
||||
const preferenceNavigationItemsInjectable = getInjectable({
|
||||
id: "preference-navigation-items",
|
||||
|
||||
instantiate: (di) => {
|
||||
const computedInjectMany = di.inject(computedInjectManyInjectable);
|
||||
const navigationItems = computedInjectMany(preferenceNavigationItemInjectionToken);
|
||||
|
||||
return computed((): PreferenceNavigationItem[] =>
|
||||
pipeline(
|
||||
navigationItems.get(),
|
||||
filter((item) => !!item.isVisible.get()),
|
||||
(items) => orderBy([(item) => item.orderNumber], ["asc"], items),
|
||||
),
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
export default preferenceNavigationItemsInjectable;
|
||||
@ -11,8 +11,8 @@ import navigateToAddClusterInjectable from "../../../common/front-end-routing/ro
|
||||
import navigateToExtensionsInjectable from "../../../common/front-end-routing/routes/extensions/navigate-to-extensions.injectable";
|
||||
import navigateToEntitySettingsInjectable from "../../../common/front-end-routing/routes/entity-settings/navigate-to-entity-settings.injectable";
|
||||
import navigateToClusterViewInjectable from "../../../common/front-end-routing/routes/cluster-view/navigate-to-cluster-view.injectable";
|
||||
import navigateToPreferenceTabIdInjectable from "./navigate-to-preference-tab-id.injectable";
|
||||
import catalogEntityRegistryInjectable from "../../api/catalog/entity/registry.injectable";
|
||||
import navigateToPreferencesInjectable from "../../../common/front-end-routing/routes/preferences/navigate-to-preferences.injectable";
|
||||
|
||||
const bindProtocolAddRouteHandlersInjectable = getInjectable({
|
||||
id: "bind-protocol-add-route-handlers",
|
||||
@ -25,7 +25,7 @@ const bindProtocolAddRouteHandlersInjectable = getInjectable({
|
||||
navigateToExtensions: di.inject(navigateToExtensionsInjectable),
|
||||
navigateToEntitySettings: di.inject(navigateToEntitySettingsInjectable),
|
||||
navigateToClusterView: di.inject(navigateToClusterViewInjectable),
|
||||
navigateToPreferenceTabId: di.inject(navigateToPreferenceTabIdInjectable),
|
||||
navigateToPreferences: di.inject(navigateToPreferencesInjectable),
|
||||
entityRegistry: di.inject(catalogEntityRegistryInjectable),
|
||||
}),
|
||||
});
|
||||
|
||||
@ -28,7 +28,7 @@ interface Dependencies {
|
||||
navigateToExtensions: () => void;
|
||||
navigateToEntitySettings: NavigateToEntitySettings;
|
||||
navigateToClusterView: NavigateToClusterView;
|
||||
navigateToPreferenceTabId: (tabId: string) => void;
|
||||
navigateToPreferences: (tabId: string) => void;
|
||||
entityRegistry: CatalogEntityRegistry;
|
||||
}
|
||||
|
||||
@ -40,13 +40,13 @@ export const bindProtocolAddRouteHandlers = ({
|
||||
navigateToExtensions,
|
||||
navigateToEntitySettings,
|
||||
navigateToClusterView,
|
||||
navigateToPreferenceTabId,
|
||||
navigateToPreferences,
|
||||
entityRegistry,
|
||||
}: Dependencies) => () => {
|
||||
lensProtocolRouterRenderer
|
||||
.addInternalHandler("/preferences", ({ search: { highlight: tabId }}) => {
|
||||
if (tabId) {
|
||||
navigateToPreferenceTabId(tabId);
|
||||
navigateToPreferences(tabId);
|
||||
}
|
||||
})
|
||||
.addInternalHandler("/", ({ tail }) => {
|
||||
|
||||
@ -1,30 +0,0 @@
|
||||
/**
|
||||
* 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 preferenceNavigationItemsInjectable from "../../components/+preferences/preferences-navigation/preference-navigation-items.injectable";
|
||||
import navigateToPreferencesInjectable from "../../../common/front-end-routing/routes/preferences/navigate-to-preferences.injectable";
|
||||
|
||||
const navigateToPreferenceTabIdInjectable = getInjectable({
|
||||
id: "navigate-to-preference-tab-id",
|
||||
|
||||
instantiate: (di) => {
|
||||
const preferenceNavigationItems = di.inject(preferenceNavigationItemsInjectable);
|
||||
const navigateToPreferences = di.inject(navigateToPreferencesInjectable);
|
||||
|
||||
return (tabId: string) => {
|
||||
const targetTab = preferenceNavigationItems.get().find(item => item.id === tabId);
|
||||
|
||||
if (targetTab) {
|
||||
targetTab.navigate();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
navigateToPreferences();
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default navigateToPreferenceTabIdInjectable;
|
||||
Loading…
Reference in New Issue
Block a user