mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
* Add data-origin to status bar items for better observability (#6400) * Passing id to status-bar-items Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Add data-origin prop for status bar items Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Fixing status bar tests Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Update snapshots Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Fix linter Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Rename id -> origin because it is not unique Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> * Release 6.1.14 Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com> Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com> Co-authored-by: Alex Andreev <alex.andreev.email@gmail.com>
70 lines
1.8 KiB
TypeScript
70 lines
1.8 KiB
TypeScript
/**
|
|
* 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 type { IComputedValue } from "mobx";
|
|
import { computed } from "mobx";
|
|
import type { StatusBarItemProps } from "./status-bar-registration";
|
|
import type { StatusBarItem } from "./status-bar-item-injection-token";
|
|
import { statusBarItemInjectionToken } from "./status-bar-item-injection-token";
|
|
import { computedInjectManyInjectable } from "@ogre-tools/injectable-extension-for-mobx";
|
|
|
|
interface StatusItem {
|
|
origin?: string;
|
|
component: React.ComponentType<StatusBarItemProps>;
|
|
}
|
|
|
|
export interface StatusBarItems {
|
|
right: StatusItem[];
|
|
left: StatusItem[];
|
|
}
|
|
|
|
interface Dependencies {
|
|
registrations: IComputedValue<StatusBarItem[]>;
|
|
}
|
|
|
|
function getStatusBarItems({ registrations }: Dependencies): IComputedValue<StatusBarItems> {
|
|
return computed(() => {
|
|
const res: StatusBarItems = {
|
|
left: [],
|
|
right: [],
|
|
};
|
|
|
|
for (const registration of registrations.get()) {
|
|
const { position = "right", component, visible, origin } = registration;
|
|
|
|
if (!visible.get()) {
|
|
continue;
|
|
}
|
|
|
|
res[position].push({
|
|
origin,
|
|
component,
|
|
});
|
|
}
|
|
|
|
// This is done so that the first ones registered are closest to the corner
|
|
res.right.reverse();
|
|
|
|
return res;
|
|
});
|
|
}
|
|
|
|
const statusBarItemsInjectable = getInjectable({
|
|
id: "status-bar-items",
|
|
|
|
instantiate: (di) => {
|
|
const computedInjectMany = di.inject(
|
|
computedInjectManyInjectable,
|
|
);
|
|
|
|
return getStatusBarItems({
|
|
registrations: computedInjectMany(statusBarItemInjectionToken),
|
|
});
|
|
},
|
|
|
|
});
|
|
|
|
export default statusBarItemsInjectable;
|