mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Remove dead code
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
4fbc14225f
commit
e5c3132688
@ -1,27 +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 { computed } from "mobx";
|
|
||||||
import { frontEndRouteInjectionToken } from "../../../front-end-route-injection-token";
|
|
||||||
import type { Route } from "../../../front-end-route-injection-token";
|
|
||||||
|
|
||||||
interface ExtensionPreferenceRouteParams {
|
|
||||||
extensionId: string;
|
|
||||||
tabId?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const extensionPreferencesRouteInjectable = getInjectable({
|
|
||||||
id: "extension-preferences-route",
|
|
||||||
|
|
||||||
instantiate: (): Route<ExtensionPreferenceRouteParams> => ({
|
|
||||||
path: "/preferences/extension/:extensionId/:tabId?",
|
|
||||||
clusterFrame: false,
|
|
||||||
isEnabled: computed(() => true),
|
|
||||||
}),
|
|
||||||
|
|
||||||
injectionToken: frontEndRouteInjectionToken,
|
|
||||||
});
|
|
||||||
|
|
||||||
export default extensionPreferencesRouteInjectable;
|
|
||||||
@ -1,26 +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 extensionPreferencesRouteInjectable from "./extension-preferences-route.injectable";
|
|
||||||
import { navigateToRouteInjectionToken } from "../../../navigate-to-route-injection-token";
|
|
||||||
|
|
||||||
const navigateToExtensionPreferencesInjectable = getInjectable({
|
|
||||||
id: "navigate-to-extension-preferences",
|
|
||||||
|
|
||||||
instantiate: (di) => {
|
|
||||||
const navigateToRoute = di.inject(navigateToRouteInjectionToken);
|
|
||||||
const route = di.inject(extensionPreferencesRouteInjectable);
|
|
||||||
|
|
||||||
return (extensionId: string, tabId?: string) => navigateToRoute(route, {
|
|
||||||
parameters: {
|
|
||||||
extensionId,
|
|
||||||
tabId,
|
|
||||||
},
|
|
||||||
withoutAffectingBackButton: true,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default navigateToExtensionPreferencesInjectable;
|
|
||||||
@ -11,4 +11,3 @@ export interface AppPreferenceTabRegistration {
|
|||||||
orderNumber?: number;
|
orderNumber?: number;
|
||||||
visible?: IComputedValue<boolean>;
|
visible?: IComputedValue<boolean>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,19 +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 rendererExtensionsInjectable from "../../../../extensions/renderer-extensions.injectable";
|
|
||||||
import { getAppPreferences } from "./get-app-preferences";
|
|
||||||
|
|
||||||
const appPreferencesInjectable = getInjectable({
|
|
||||||
id: "app-preferences",
|
|
||||||
|
|
||||||
instantiate: (di) =>
|
|
||||||
getAppPreferences({
|
|
||||||
extensions: di.inject(rendererExtensionsInjectable),
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
export default appPreferencesInjectable;
|
|
||||||
@ -1,29 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import type { IComputedValue } from "mobx";
|
|
||||||
import { computed } from "mobx";
|
|
||||||
import type { LensRendererExtension } from "../../../../extensions/lens-renderer-extension";
|
|
||||||
import type { AppPreferenceRegistration, RegisteredAppPreference } from "./app-preference-registration";
|
|
||||||
|
|
||||||
interface Dependencies {
|
|
||||||
extensions: IComputedValue<LensRendererExtension[]>;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getRegisteredItem(item: AppPreferenceRegistration): RegisteredAppPreference {
|
|
||||||
return {
|
|
||||||
id: item.id || item.title.toLowerCase().replace(/[^0-9a-zA-Z]+/g, "-"),
|
|
||||||
...item,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export const getAppPreferences = ({ extensions }: Dependencies) => {
|
|
||||||
return computed(() => (
|
|
||||||
extensions.get()
|
|
||||||
.flatMap((extension) => extension.appPreferences)
|
|
||||||
.map(getRegisteredItem)
|
|
||||||
));
|
|
||||||
};
|
|
||||||
@ -1,52 +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 { filter, map } from "lodash/fp";
|
|
||||||
import { extensionRegistratorInjectionToken } from "../../../extensions/extension-loader/extension-registrator-injection-token";
|
|
||||||
import type { LensRendererExtension } from "../../../extensions/lens-renderer-extension";
|
|
||||||
import { pipeline } from "@ogre-tools/fp";
|
|
||||||
import { extensionPreferenceItemInjectionToken } from "./extension-preference-items-injection-token";
|
|
||||||
|
|
||||||
const extensionPreferenceItemRegistratorInjectable = getInjectable({
|
|
||||||
id: "extension-preference-item-registrator",
|
|
||||||
|
|
||||||
instantiate:
|
|
||||||
() =>
|
|
||||||
(ext) => {
|
|
||||||
const extension = ext as LensRendererExtension;
|
|
||||||
|
|
||||||
return pipeline(
|
|
||||||
extension.appPreferences,
|
|
||||||
|
|
||||||
filter(
|
|
||||||
(registration) => !registration.showInPreferencesTab,
|
|
||||||
),
|
|
||||||
|
|
||||||
map((registration) => {
|
|
||||||
const id = `extension-preferences-item-${registration.id}-for-extension-${extension.sanitizedExtensionId}`;
|
|
||||||
|
|
||||||
return getInjectable({
|
|
||||||
id,
|
|
||||||
injectionToken: extensionPreferenceItemInjectionToken,
|
|
||||||
|
|
||||||
instantiate: () => ({
|
|
||||||
id: registration.id || id,
|
|
||||||
title: registration.title,
|
|
||||||
extension,
|
|
||||||
|
|
||||||
components: {
|
|
||||||
Hint: registration.components.Hint,
|
|
||||||
Input: registration.components.Input,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
injectionToken: extensionRegistratorInjectionToken,
|
|
||||||
});
|
|
||||||
|
|
||||||
export default extensionPreferenceItemRegistratorInjectable;
|
|
||||||
@ -1,17 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
|
||||||
import type { LensRendererExtension } from "../../../extensions/lens-renderer-extension";
|
|
||||||
import type { RegisteredAppPreference } from "./app-preferences/app-preference-registration";
|
|
||||||
|
|
||||||
interface ExtensionPreferenceItem extends RegisteredAppPreference {
|
|
||||||
extension: LensRendererExtension;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const extensionPreferenceItemInjectionToken = getInjectionToken<ExtensionPreferenceItem>({
|
|
||||||
id: "extension-preference-item-injection-token",
|
|
||||||
});
|
|
||||||
|
|
||||||
@ -1,35 +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 { computed } from "mobx";
|
|
||||||
import extensionPreferencesRouteInjectable from "../../../common/front-end-routing/routes/preferences/extension/extension-preferences-route.injectable";
|
|
||||||
import rendererExtensionsInjectable from "../../../extensions/renderer-extensions.injectable";
|
|
||||||
import routePathParametersInjectable from "../../routes/route-path-parameters.injectable";
|
|
||||||
import { getExtensionPreferenceItems } from "./get-extension-preference-items";
|
|
||||||
|
|
||||||
const extensionPreferencesModelInjectable = getInjectable({
|
|
||||||
id: "extension-preferences-model",
|
|
||||||
|
|
||||||
instantiate: (di) => {
|
|
||||||
const route = di.inject(extensionPreferencesRouteInjectable);
|
|
||||||
const pathParameters = di.inject(routePathParametersInjectable, route);
|
|
||||||
const extensions = di.inject(rendererExtensionsInjectable);
|
|
||||||
|
|
||||||
return computed(() => {
|
|
||||||
const { extensionId, tabId } = pathParameters.get();
|
|
||||||
const targetExtension = extensions.get().find((extension) => extension.sanitizedExtensionId === extensionId);
|
|
||||||
const targetAppTab = targetExtension?.appPreferenceTabs.find(tab => tab.id === tabId);
|
|
||||||
const preferencePageTitle = targetAppTab?.title || `${targetExtension?.manifest.name || "Extension"} preferences`;
|
|
||||||
|
|
||||||
return {
|
|
||||||
extensionName: targetExtension?.manifest.name,
|
|
||||||
preferenceItems: getExtensionPreferenceItems(targetExtension, tabId),
|
|
||||||
preferencePageTitle,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default extensionPreferencesModelInjectable;
|
|
||||||
@ -1,21 +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 { routeSpecificComponentInjectionToken } from "../../routes/route-specific-component-injection-token";
|
|
||||||
import extensionPreferencesRouteInjectable from "../../../common/front-end-routing/routes/preferences/extension/extension-preferences-route.injectable";
|
|
||||||
import { Extensions } from "./extensions";
|
|
||||||
|
|
||||||
const extensionPreferencesRouteComponentInjectable = getInjectable({
|
|
||||||
id: "extension-preferences-route-component",
|
|
||||||
|
|
||||||
instantiate: (di) => ({
|
|
||||||
route: di.inject(extensionPreferencesRouteInjectable),
|
|
||||||
Component: Extensions,
|
|
||||||
}),
|
|
||||||
|
|
||||||
injectionToken: routeSpecificComponentInjectionToken,
|
|
||||||
});
|
|
||||||
|
|
||||||
export default extensionPreferencesRouteComponentInjectable;
|
|
||||||
@ -1,51 +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 { filter, map } from "lodash/fp";
|
|
||||||
import { extensionRegistratorInjectionToken } from "../../../extensions/extension-loader/extension-registrator-injection-token";
|
|
||||||
import type { LensRendererExtension } from "../../../extensions/lens-renderer-extension";
|
|
||||||
import { pipeline } from "@ogre-tools/fp";
|
|
||||||
import { telemetryPreferenceItemInjectionToken } from "./telemetry-preference-items.injectable";
|
|
||||||
|
|
||||||
const extensionTelemetryPreferenceItemRegistratorInjectable = getInjectable({
|
|
||||||
id: "extension-telemetry-preference-item-registrator",
|
|
||||||
|
|
||||||
instantiate:
|
|
||||||
() =>
|
|
||||||
(ext) => {
|
|
||||||
const extension = ext as LensRendererExtension;
|
|
||||||
|
|
||||||
return pipeline(
|
|
||||||
extension.appPreferences,
|
|
||||||
|
|
||||||
filter(
|
|
||||||
(registration) => registration.showInPreferencesTab === "telemetry",
|
|
||||||
),
|
|
||||||
|
|
||||||
map((registration) => {
|
|
||||||
const id = `telemetry-preferences-item-${registration.id}-for-extension-${extension.sanitizedExtensionId}`;
|
|
||||||
|
|
||||||
return getInjectable({
|
|
||||||
id,
|
|
||||||
injectionToken: telemetryPreferenceItemInjectionToken,
|
|
||||||
|
|
||||||
instantiate: () => ({
|
|
||||||
id: registration.id || id,
|
|
||||||
title: registration.title,
|
|
||||||
|
|
||||||
components: {
|
|
||||||
Hint: registration.components.Hint,
|
|
||||||
Input: registration.components.Input,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
injectionToken: extensionRegistratorInjectionToken,
|
|
||||||
});
|
|
||||||
|
|
||||||
export default extensionTelemetryPreferenceItemRegistratorInjectable;
|
|
||||||
@ -1,57 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
|
||||||
import type { IComputedValue } from "mobx";
|
|
||||||
import { observer } from "mobx-react";
|
|
||||||
import React from "react";
|
|
||||||
import type { RegisteredAppPreference } from "./app-preferences/app-preference-registration";
|
|
||||||
import extensionPreferencesModelInjectable from "./extension-preference-model.injectable";
|
|
||||||
import { ExtensionPreferenceBlock } from "../../../features/preferences/renderer/compliance-for-legacy-extension-api/extension-preference-block";
|
|
||||||
|
|
||||||
interface Dependencies {
|
|
||||||
model: IComputedValue<{
|
|
||||||
preferenceItems: RegisteredAppPreference[];
|
|
||||||
extensionName?: string;
|
|
||||||
preferencePageTitle?: string;
|
|
||||||
}>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const NonInjectedExtensions = ({ model }: Dependencies) => {
|
|
||||||
const { extensionName, preferenceItems, preferencePageTitle } = model.get();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<section id="extensions">
|
|
||||||
<h2 data-testid="extension-preferences-page-title">
|
|
||||||
{preferencePageTitle}
|
|
||||||
</h2>
|
|
||||||
{!extensionName && (
|
|
||||||
<div
|
|
||||||
className="flex items-center"
|
|
||||||
data-testid="error-for-extension-not-being-present"
|
|
||||||
>
|
|
||||||
No extension found
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{preferenceItems.map((preferenceItem, index) => (
|
|
||||||
<ExtensionPreferenceBlock
|
|
||||||
key={`${preferenceItem.id}-${index}`}
|
|
||||||
registration={preferenceItem}
|
|
||||||
data-testid={`extension-preference-item-for-${preferenceItem.id}`}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</section>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const Extensions = withInjectables<Dependencies>(
|
|
||||||
observer(NonInjectedExtensions),
|
|
||||||
|
|
||||||
{
|
|
||||||
getProps: (di) => ({
|
|
||||||
model: di.inject(extensionPreferencesModelInjectable),
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import type { LensRendererExtension } from "../../../extensions/lens-renderer-extension";
|
|
||||||
import type { RegisteredAppPreference } from "./app-preferences/app-preference-registration";
|
|
||||||
|
|
||||||
export function getExtensionPreferenceItems(extension?: LensRendererExtension, tabId?: string): RegisteredAppPreference[] {
|
|
||||||
if (!extension) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const preferences = extension.appPreferences.map(preference => ({
|
|
||||||
id: preference.id || preference.title,
|
|
||||||
...preference,
|
|
||||||
}));
|
|
||||||
|
|
||||||
if (tabId) {
|
|
||||||
return preferences.filter(preference => preference.showInPreferencesTab == tabId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return preferences.filter(preference => !preference.showInPreferencesTab);
|
|
||||||
}
|
|
||||||
@ -1,68 +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 { computed } from "mobx";
|
|
||||||
import { map } from "lodash/fp";
|
|
||||||
|
|
||||||
import routeIsActiveInjectable from "../../../routes/route-is-active.injectable";
|
|
||||||
import { preferenceNavigationItemInjectionToken } from "./preference-navigation-items.injectable";
|
|
||||||
|
|
||||||
import type { LensRendererExtension } from "../../../../extensions/lens-renderer-extension";
|
|
||||||
import { extensionRegistratorInjectionToken } from "../../../../extensions/extension-loader/extension-registrator-injection-token";
|
|
||||||
import { pipeline } from "@ogre-tools/fp";
|
|
||||||
import extensionPreferencesRouteInjectable from "../../../../common/front-end-routing/routes/preferences/extension/extension-preferences-route.injectable";
|
|
||||||
import navigateToExtensionPreferencesInjectable from "../../../../common/front-end-routing/routes/preferences/extension/navigate-to-extension-preferences.injectable";
|
|
||||||
import type { LensExtension } from "../../../../extensions/lens-extension";
|
|
||||||
import routePathParametersInjectable from "../../../routes/route-path-parameters.injectable";
|
|
||||||
|
|
||||||
const extensionSpecificTabNavigationItemRegistratorInjectable = getInjectable({
|
|
||||||
id: "extension-specific-tab-preferences-navigation-items",
|
|
||||||
|
|
||||||
instantiate: (di) => {
|
|
||||||
return (ext: LensExtension) => {
|
|
||||||
const extension = ext as LensRendererExtension;
|
|
||||||
const navigateToExtensionPreferences = di.inject(
|
|
||||||
navigateToExtensionPreferencesInjectable,
|
|
||||||
);
|
|
||||||
const route = di.inject(extensionPreferencesRouteInjectable);
|
|
||||||
const routeIsActive = di.inject(routeIsActiveInjectable, route);
|
|
||||||
const pathParameters = di.inject(routePathParametersInjectable, route);
|
|
||||||
|
|
||||||
return pipeline(
|
|
||||||
extension.appPreferenceTabs,
|
|
||||||
|
|
||||||
map((tab) => {
|
|
||||||
const id = `extension-${extension.sanitizedExtensionId}-nav-item-${tab.id}`;
|
|
||||||
const isActive = computed(() => routeIsActive.get() && pathParameters.get().tabId === tab.id);
|
|
||||||
|
|
||||||
return getInjectable({
|
|
||||||
id,
|
|
||||||
injectionToken: preferenceNavigationItemInjectionToken,
|
|
||||||
instantiate: () => ({
|
|
||||||
id,
|
|
||||||
label: tab.title,
|
|
||||||
parent: "general",
|
|
||||||
orderNumber: tab.orderNumber || 100,
|
|
||||||
navigate: () => navigateToExtensionPreferences(extension.sanitizedExtensionId, tab.id),
|
|
||||||
|
|
||||||
isVisible: computed(() => {
|
|
||||||
if (!tab.visible) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return tab.visible.get();
|
|
||||||
}),
|
|
||||||
|
|
||||||
isActive,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
};
|
|
||||||
},
|
|
||||||
injectionToken: extensionRegistratorInjectionToken,
|
|
||||||
});
|
|
||||||
|
|
||||||
export default extensionSpecificTabNavigationItemRegistratorInjectable;
|
|
||||||
@ -1,56 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
import React from "react";
|
|
||||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
|
||||||
import type { IComputedValue } from "mobx";
|
|
||||||
import type { PreferenceNavigationItem } from "./preference-navigation-items.injectable";
|
|
||||||
import { Icon } from "../../icon";
|
|
||||||
import { PreferencesNavigationTab } from "./preference-navigation-tab";
|
|
||||||
import preferenceNavigationItemsForGroupInjectable from "./preference-navigation-items-for-group.injectable";
|
|
||||||
import { observer } from "mobx-react";
|
|
||||||
|
|
||||||
interface Dependencies {
|
|
||||||
navigationItems: IComputedValue<PreferenceNavigationItem[]>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const NonInjectedExtensionsNavGroup = observer((props: Dependencies) => {
|
|
||||||
if (!props.navigationItems.get().length) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div data-testid="extension-settings">
|
|
||||||
<hr/>
|
|
||||||
<div className="header flex items-center">
|
|
||||||
<Icon
|
|
||||||
material="extension"
|
|
||||||
smallest
|
|
||||||
className="mr-3"
|
|
||||||
/>
|
|
||||||
{" "}
|
|
||||||
Extensions
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
{props.navigationItems.get().map(item => (
|
|
||||||
<PreferencesNavigationTab
|
|
||||||
key={item.id}
|
|
||||||
item={item}
|
|
||||||
data-testid={`tab-link-for-${item.id}`}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
export const ExtensionsNavGroup = withInjectables<Dependencies>(
|
|
||||||
NonInjectedExtensionsNavGroup,
|
|
||||||
|
|
||||||
{
|
|
||||||
getProps: (di) => ({
|
|
||||||
navigationItems: di.inject(preferenceNavigationItemsForGroupInjectable, "extensions"),
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
@ -1,57 +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 { computed } from "mobx";
|
|
||||||
import extensionPreferencesRouteInjectable from "../../../../common/front-end-routing/routes/preferences/extension/extension-preferences-route.injectable";
|
|
||||||
import navigateToExtensionPreferencesInjectable from "../../../../common/front-end-routing/routes/preferences/extension/navigate-to-extension-preferences.injectable";
|
|
||||||
import { extensionRegistratorInjectionToken } from "../../../../extensions/extension-loader/extension-registrator-injection-token";
|
|
||||||
import type { LensRendererExtension } from "../../../../extensions/lens-renderer-extension";
|
|
||||||
import routeIsActiveInjectable from "../../../routes/route-is-active.injectable";
|
|
||||||
import routePathParametersInjectable from "../../../routes/route-path-parameters.injectable";
|
|
||||||
import { preferenceNavigationItemInjectionToken } from "./preference-navigation-items.injectable";
|
|
||||||
|
|
||||||
const extensionPreferencesNavigationItemRegistratorInjectable = getInjectable({
|
|
||||||
id: "extension-preferences-navigation-item",
|
|
||||||
|
|
||||||
instantiate: (di) => {
|
|
||||||
return (ext) => {
|
|
||||||
const extension = ext as LensRendererExtension;
|
|
||||||
const navigateToExtensionPreferences = di.inject(
|
|
||||||
navigateToExtensionPreferencesInjectable,
|
|
||||||
);
|
|
||||||
|
|
||||||
const extensionHasPreferences = extension.appPreferences.length > 0;
|
|
||||||
const extensionHasGeneralPreferences = extension.appPreferences.some(preferences =>
|
|
||||||
!preferences.showInPreferencesTab,
|
|
||||||
);
|
|
||||||
const isVisible = computed(() => extensionHasPreferences && extensionHasGeneralPreferences);
|
|
||||||
const extensionRoute = di.inject(extensionPreferencesRouteInjectable);
|
|
||||||
const pathParameters = di.inject(routePathParametersInjectable, extensionRoute);
|
|
||||||
const routeIsActive = di.inject(routeIsActiveInjectable, extensionRoute);
|
|
||||||
const isActive = computed(() => routeIsActive.get() && pathParameters.get().extensionId === extension.sanitizedExtensionId);
|
|
||||||
const id = `extension-preferences-navigation-item-${extension.sanitizedExtensionId}`;
|
|
||||||
|
|
||||||
const injectable = getInjectable({
|
|
||||||
id,
|
|
||||||
injectionToken: preferenceNavigationItemInjectionToken,
|
|
||||||
instantiate: () => ({
|
|
||||||
id: `extension-${extension.sanitizedExtensionId}`,
|
|
||||||
label: `${extension.name}`,
|
|
||||||
navigate: () => navigateToExtensionPreferences(extension.sanitizedExtensionId),
|
|
||||||
isActive,
|
|
||||||
isVisible,
|
|
||||||
orderNumber: 20,
|
|
||||||
parent: "extensions",
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
return [injectable];
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
injectionToken: extensionRegistratorInjectionToken,
|
|
||||||
});
|
|
||||||
|
|
||||||
export default extensionPreferencesNavigationItemRegistratorInjectable;
|
|
||||||
@ -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,
|
|
||||||
lifecycleEnum,
|
|
||||||
} from "@ogre-tools/injectable";
|
|
||||||
import { computed } from "mobx";
|
|
||||||
import type { PreferenceNavigationItem } from "./preference-navigation-items.injectable";
|
|
||||||
import preferenceNavigationItemsInjectable from "./preference-navigation-items.injectable";
|
|
||||||
|
|
||||||
const preferenceNavigationItemsForGroupInjectable = getInjectable({
|
|
||||||
id: "preference-navigation-items-for-group",
|
|
||||||
|
|
||||||
instantiate: (di, group: string) => {
|
|
||||||
const preferenceNavigationItems = di.inject(preferenceNavigationItemsInjectable);
|
|
||||||
|
|
||||||
return computed((): PreferenceNavigationItem[] =>
|
|
||||||
preferenceNavigationItems.get().filter((item) => item.parent == group),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
lifecycle: lifecycleEnum.keyedSingleton({
|
|
||||||
getInstanceKey: (di, group: string) => group,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
export default preferenceNavigationItemsForGroupInjectable;
|
|
||||||
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
import { observer } from "mobx-react";
|
|
||||||
import React from "react";
|
|
||||||
import { Tab } from "../../tabs";
|
|
||||||
import type { PreferenceNavigationItem } from "./preference-navigation-items.injectable";
|
|
||||||
|
|
||||||
interface PreferenceNavigationTabProps extends React.DOMAttributes<HTMLElement> {
|
|
||||||
item: PreferenceNavigationItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const PreferencesNavigationTab = observer(({ item }: PreferenceNavigationTabProps) => (
|
|
||||||
<Tab
|
|
||||||
value={item}
|
|
||||||
label={item.label}
|
|
||||||
data-testid={`tab-link-for-${item.id}`}
|
|
||||||
active={item.isActive.get()}
|
|
||||||
/>
|
|
||||||
));
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
import { getInjectable, getInjectionToken } from "@ogre-tools/injectable";
|
|
||||||
import { computedInjectManyInjectable } from "@ogre-tools/injectable-extension-for-mobx";
|
|
||||||
import type { AppPreferenceRegistration } from "./app-preferences/app-preference-registration";
|
|
||||||
|
|
||||||
export const telemetryPreferenceItemInjectionToken = getInjectionToken<AppPreferenceRegistration>({
|
|
||||||
id: "telemetry-preference-item-injection-token",
|
|
||||||
});
|
|
||||||
|
|
||||||
const telemetryPreferenceItemsInjectable = getInjectable({
|
|
||||||
id: "telemetry-preference-items",
|
|
||||||
|
|
||||||
instantiate: (di) => {
|
|
||||||
const computedInjectMany = di.inject(computedInjectManyInjectable);
|
|
||||||
|
|
||||||
return computedInjectMany(telemetryPreferenceItemInjectionToken);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default telemetryPreferenceItemsInjectable;
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user