mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Show preferences only from specified extension
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
d0bb70452a
commit
098bda1866
@ -145,31 +145,6 @@ exports[`preferences - navigation to extension specific preferences given in pre
|
||||
<hr
|
||||
class="small"
|
||||
/>
|
||||
<section
|
||||
class="small"
|
||||
data-testid="extension-preference-item-for-some-other-preference-item-id"
|
||||
id="some-other-preference-item-id"
|
||||
>
|
||||
<div
|
||||
class="SubTitle"
|
||||
>
|
||||
Test preference item
|
||||
|
||||
</div>
|
||||
<div
|
||||
data-testid="some-other-preference-item-input"
|
||||
/>
|
||||
<div
|
||||
class="hint"
|
||||
>
|
||||
<div
|
||||
data-testid="some-other-preference-item-hint"
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
<hr
|
||||
class="small"
|
||||
/>
|
||||
</section>
|
||||
</div>
|
||||
<div
|
||||
|
||||
@ -74,7 +74,7 @@ describe("preferences - navigation to extension specific preferences", () => {
|
||||
});
|
||||
|
||||
it("doesn't show preferences from unrelated extension", () => {
|
||||
const actual = rendered.getByTestId("extension-preference-item-for-some-other-preference-item-id");
|
||||
const actual = rendered.queryByTestId("extension-preference-item-for-some-other-preference-item-id");
|
||||
|
||||
expect(actual).toBeNull();
|
||||
});
|
||||
|
||||
@ -2,49 +2,35 @@
|
||||
* 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 { filter, overSome } from "lodash/fp";
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import type { IComputedValue } from "mobx";
|
||||
import { computed } from "mobx";
|
||||
|
||||
import rendererExtensionsInjectable from "../../../extensions/renderer-extensions.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",
|
||||
});
|
||||
|
||||
const extensionsPreferenceItemsInjectable = getInjectable({
|
||||
id: "extension-preference-items",
|
||||
|
||||
instantiate: (di) => {
|
||||
instantiate: (di, extensionId: string): IComputedValue<RegisteredAppPreference[]> => {
|
||||
const extensions = di.inject(rendererExtensionsInjectable);
|
||||
const extension = extensions.get().find((extension) => extension.id === extensionId);
|
||||
|
||||
return computed(() => {
|
||||
const enabledExtensions = extensions.get();
|
||||
if (!extension) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return pipeline(
|
||||
di.injectMany(extensionPreferenceItemInjectionToken),
|
||||
|
||||
filter((item) =>
|
||||
overSome([
|
||||
isNonExtensionItem,
|
||||
isEnabledExtensionItemFor(enabledExtensions),
|
||||
])(item),
|
||||
),
|
||||
);
|
||||
return extension.appPreferences
|
||||
.filter(preference => !preference.showInPreferencesTab)
|
||||
.map(preference => ({
|
||||
id: preference.id,
|
||||
...preference,
|
||||
}));
|
||||
});
|
||||
},
|
||||
lifecycle: lifecycleEnum.transient,
|
||||
});
|
||||
|
||||
const isNonExtensionItem = (item: ExtensionPreferenceItem) => !item.extension;
|
||||
|
||||
const isEnabledExtensionItemFor =
|
||||
(enabledExtensions: LensRendererExtension[]) => (item: ExtensionPreferenceItem) =>
|
||||
!!enabledExtensions.find((extension) => extension === item.extension);
|
||||
|
||||
export default extensionsPreferenceItemsInjectable;
|
||||
|
||||
@ -11,6 +11,7 @@ import type { RegisteredAppPreference } from "./app-preferences/app-preference-r
|
||||
import { ExtensionSettings } from "./extension-settings";
|
||||
import { Preferences } from "./preferences";
|
||||
import extensionsPreferenceItemsInjectable from "./extension-preference-items.injectable";
|
||||
import currentPathParametersInjectable from "../../routes/current-path-parameters.injectable";
|
||||
|
||||
interface Dependencies {
|
||||
preferenceItems: IComputedValue<RegisteredAppPreference[]>;
|
||||
@ -36,8 +37,13 @@ export const Extensions = withInjectables<Dependencies>(
|
||||
observer(NonInjectedExtensions),
|
||||
|
||||
{
|
||||
getProps: (di) => ({
|
||||
preferenceItems: di.inject(extensionsPreferenceItemsInjectable),
|
||||
}),
|
||||
getProps: (di) => {
|
||||
const pathParameters = di.inject(currentPathParametersInjectable);
|
||||
const extensionId = pathParameters.get().extensionId;
|
||||
|
||||
return {
|
||||
preferenceItems: di.inject(extensionsPreferenceItemsInjectable, extensionId),
|
||||
};
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user