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
|
<hr
|
||||||
class="small"
|
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>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
|
|||||||
@ -74,7 +74,7 @@ describe("preferences - navigation to extension specific preferences", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("doesn't show preferences from unrelated extension", () => {
|
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();
|
expect(actual).toBeNull();
|
||||||
});
|
});
|
||||||
|
|||||||
@ -2,49 +2,35 @@
|
|||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { pipeline } from "@ogre-tools/fp";
|
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||||
import { getInjectable, getInjectionToken } from "@ogre-tools/injectable";
|
import type { IComputedValue } from "mobx";
|
||||||
import { filter, overSome } from "lodash/fp";
|
|
||||||
import { computed } from "mobx";
|
import { computed } from "mobx";
|
||||||
|
|
||||||
import rendererExtensionsInjectable from "../../../extensions/renderer-extensions.injectable";
|
import rendererExtensionsInjectable from "../../../extensions/renderer-extensions.injectable";
|
||||||
import type { LensRendererExtension } from "../../../extensions/lens-renderer-extension";
|
|
||||||
import type { RegisteredAppPreference } from "./app-preferences/app-preference-registration";
|
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({
|
const extensionsPreferenceItemsInjectable = getInjectable({
|
||||||
id: "extension-preference-items",
|
id: "extension-preference-items",
|
||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di, extensionId: string): IComputedValue<RegisteredAppPreference[]> => {
|
||||||
const extensions = di.inject(rendererExtensionsInjectable);
|
const extensions = di.inject(rendererExtensionsInjectable);
|
||||||
|
const extension = extensions.get().find((extension) => extension.id === extensionId);
|
||||||
|
|
||||||
return computed(() => {
|
return computed(() => {
|
||||||
const enabledExtensions = extensions.get();
|
if (!extension) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
return pipeline(
|
return extension.appPreferences
|
||||||
di.injectMany(extensionPreferenceItemInjectionToken),
|
.filter(preference => !preference.showInPreferencesTab)
|
||||||
|
.map(preference => ({
|
||||||
filter((item) =>
|
id: preference.id,
|
||||||
overSome([
|
...preference,
|
||||||
isNonExtensionItem,
|
}));
|
||||||
isEnabledExtensionItemFor(enabledExtensions),
|
|
||||||
])(item),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
lifecycle: lifecycleEnum.transient,
|
||||||
});
|
});
|
||||||
|
|
||||||
const isNonExtensionItem = (item: ExtensionPreferenceItem) => !item.extension;
|
|
||||||
|
|
||||||
const isEnabledExtensionItemFor =
|
|
||||||
(enabledExtensions: LensRendererExtension[]) => (item: ExtensionPreferenceItem) =>
|
|
||||||
!!enabledExtensions.find((extension) => extension === item.extension);
|
|
||||||
|
|
||||||
export default extensionsPreferenceItemsInjectable;
|
export default extensionsPreferenceItemsInjectable;
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import type { RegisteredAppPreference } from "./app-preferences/app-preference-r
|
|||||||
import { ExtensionSettings } from "./extension-settings";
|
import { ExtensionSettings } from "./extension-settings";
|
||||||
import { Preferences } from "./preferences";
|
import { Preferences } from "./preferences";
|
||||||
import extensionsPreferenceItemsInjectable from "./extension-preference-items.injectable";
|
import extensionsPreferenceItemsInjectable from "./extension-preference-items.injectable";
|
||||||
|
import currentPathParametersInjectable from "../../routes/current-path-parameters.injectable";
|
||||||
|
|
||||||
interface Dependencies {
|
interface Dependencies {
|
||||||
preferenceItems: IComputedValue<RegisteredAppPreference[]>;
|
preferenceItems: IComputedValue<RegisteredAppPreference[]>;
|
||||||
@ -36,8 +37,13 @@ export const Extensions = withInjectables<Dependencies>(
|
|||||||
observer(NonInjectedExtensions),
|
observer(NonInjectedExtensions),
|
||||||
|
|
||||||
{
|
{
|
||||||
getProps: (di) => ({
|
getProps: (di) => {
|
||||||
preferenceItems: di.inject(extensionsPreferenceItemsInjectable),
|
const pathParameters = di.inject(currentPathParametersInjectable);
|
||||||
}),
|
const extensionId = pathParameters.get().extensionId;
|
||||||
|
|
||||||
|
return {
|
||||||
|
preferenceItems: di.inject(extensionsPreferenceItemsInjectable, extensionId),
|
||||||
|
};
|
||||||
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user