mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
chore: Upgrade versions of @ogre-tools/* to 15.3.0
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
7dc0ce7192
commit
ba8f7f916d
27 files changed
+5445
-17542
No files matched your search
@@ -72,7 +72,7 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
||||
});
|
||||
});
|
||||
di.override(spawnInjectable, () => spawnMock);
|
||||
di.override(randomUUIDInjectable, () => () => "deadbeef");
|
||||
di.override(randomUUIDInjectable, () => () => "dead-foo-bar-foo-beef");
|
||||
|
||||
di.override(processEnvInjectable, () => ({
|
||||
SOME_ENV_VAR: "some-env-value",
|
||||
@@ -110,7 +110,7 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
||||
});
|
||||
|
||||
it("should send the command via stdin", () => {
|
||||
expect(stdinValue).toBe(`'/some/process/exec/path' -p '"deadbeef" + JSON.stringify(process.env) + "deadbeef"'`);
|
||||
expect(stdinValue).toBe(`'/some/process/exec/path' -p '"deadfoobarfoobeef" + JSON.stringify(process.env) + "deadfoobarfoobeef"'`);
|
||||
});
|
||||
|
||||
it("should close stdin", () => {
|
||||
@@ -167,7 +167,7 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
||||
...expectedEnv,
|
||||
};
|
||||
|
||||
shellStdout.emit("data", Buffer.from(`some-other-datadeadbeef${JSON.stringify(fakeInnerEnv)}deadbeefsome-third-other-data`));
|
||||
shellStdout.emit("data", Buffer.from(`some-other-datadeadfoobarfoobeef${JSON.stringify(fakeInnerEnv)}deadfoobarfoobeefsome-third-other-data`));
|
||||
});
|
||||
|
||||
describe("when process successfully exits", () => {
|
||||
@@ -216,7 +216,7 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
||||
});
|
||||
|
||||
it("should send the command via stdin", () => {
|
||||
expect(stdinValue).toBe(` '/some/process/exec/path' -p '"deadbeef" + JSON.stringify(process.env) + "deadbeef"'`);
|
||||
expect(stdinValue).toBe(` '/some/process/exec/path' -p '"deadfoobarfoobeef" + JSON.stringify(process.env) + "deadfoobarfoobeef"'`);
|
||||
});
|
||||
|
||||
it("should close stdin", () => {
|
||||
@@ -273,7 +273,7 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
||||
...expectedEnv,
|
||||
};
|
||||
|
||||
shellStdout.emit("data", Buffer.from(`some-other-datadeadbeef${JSON.stringify(fakeInnerEnv)}deadbeefsome-third-other-data`));
|
||||
shellStdout.emit("data", Buffer.from(`some-other-datadeadfoobarfoobeef${JSON.stringify(fakeInnerEnv)}deadfoobarfoobeefsome-third-other-data`));
|
||||
});
|
||||
|
||||
describe("when process successfully exits", () => {
|
||||
@@ -312,7 +312,7 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
||||
[
|
||||
"-l",
|
||||
"-c",
|
||||
`'/some/process/exec/path' -p '"deadbeef" + JSON.stringify(process.env) + "deadbeef"'`,
|
||||
`'/some/process/exec/path' -p '"deadfoobarfoobeef" + JSON.stringify(process.env) + "deadfoobarfoobeef"'`,
|
||||
],
|
||||
expect.objectContaining({
|
||||
env: expectedEnv,
|
||||
@@ -378,7 +378,7 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
||||
...expectedEnv,
|
||||
};
|
||||
|
||||
shellStdout.emit("data", Buffer.from(`some-other-datadeadbeef${JSON.stringify(fakeInnerEnv)}deadbeefsome-third-other-data`));
|
||||
shellStdout.emit("data", Buffer.from(`some-other-datadeadfoobarfoobeef${JSON.stringify(fakeInnerEnv)}deadfoobarfoobeefsome-third-other-data`));
|
||||
});
|
||||
|
||||
describe("when process successfully exits", () => {
|
||||
@@ -425,7 +425,7 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
||||
});
|
||||
|
||||
it("should send the command via stdin", () => {
|
||||
expect(stdinValue).toBe(`Command '/some/process/exec/path' -p '\\"deadbeef\\" + JSON.stringify(process.env) + \\"deadbeef\\"'`);
|
||||
expect(stdinValue).toBe(`Command '/some/process/exec/path' -p '\\"deadfoobarfoobeef\\" + JSON.stringify(process.env) + \\"deadfoobarfoobeef\\"'`);
|
||||
});
|
||||
|
||||
it("should close stdin", () => {
|
||||
@@ -482,7 +482,7 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
||||
...expectedEnv,
|
||||
};
|
||||
|
||||
shellStdout.emit("data", Buffer.from(`some-other-datadeadbeef${JSON.stringify(fakeInnerEnv)}deadbeefsome-third-other-data`));
|
||||
shellStdout.emit("data", Buffer.from(`some-other-datadeadfoobarfoobeef${JSON.stringify(fakeInnerEnv)}deadfoobarfoobeefsome-third-other-data`));
|
||||
});
|
||||
|
||||
describe("when process successfully exits", () => {
|
||||
|
||||
@@ -2,105 +2,100 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { DiContainerForInjection } from "@ogre-tools/injectable";
|
||||
|
||||
import {
|
||||
getInjectable,
|
||||
instantiationDecoratorToken,
|
||||
lifecycleEnum,
|
||||
} from "@ogre-tools/injectable";
|
||||
|
||||
import { injectionDecoratorToken, getInjectable } from "@ogre-tools/injectable";
|
||||
import assert from "assert";
|
||||
import { isFunction } from "lodash/fp";
|
||||
import emitTelemetryInjectable from "./emit-telemetry.injectable";
|
||||
|
||||
import type { WhiteListItem } from "./telemetry-white-list-for-functions.injectable";
|
||||
import telemetryWhiteListForFunctionsInjectable from "./telemetry-white-list-for-functions.injectable";
|
||||
import logErrorInjectable from "../../../common/log-error.injectable";
|
||||
import { isFunction, isString } from "@k8slens/utilities";
|
||||
|
||||
const telemetryDecoratorInjectable = getInjectable({
|
||||
id: "telemetry-decorator",
|
||||
|
||||
instantiate: (diForDecorator) => ({
|
||||
decorate:
|
||||
(instantiateToBeDecorated: any) =>
|
||||
(di: DiContainerForInjection, instantiationParameter: any) => {
|
||||
const instance = instantiateToBeDecorated(di, instantiationParameter);
|
||||
decorate: (instantiateToBeDecorated) =>
|
||||
(di, instantiationParameter) => {
|
||||
const instance = instantiateToBeDecorated(di, instantiationParameter);
|
||||
|
||||
if (isFunction(instance)) {
|
||||
return (...args: any[]) => {
|
||||
const currentContext = di.context.at(-1);
|
||||
if (isFunction(instance)) {
|
||||
return (...args: unknown[]) => {
|
||||
const currentContext = di.context.at(-1);
|
||||
|
||||
assert(currentContext);
|
||||
assert(currentContext);
|
||||
|
||||
const emitTelemetry = diForDecorator.inject(
|
||||
emitTelemetryInjectable,
|
||||
);
|
||||
const emitTelemetry = diForDecorator.inject(emitTelemetryInjectable);
|
||||
const logError = diForDecorator.inject(logErrorInjectable);
|
||||
const whiteList = diForDecorator.inject(telemetryWhiteListForFunctionsInjectable);
|
||||
|
||||
const logError = diForDecorator.inject(logErrorInjectable);
|
||||
const { isWhiteListed, getParams } = findWhiteListEntry(whiteList, currentContext.injectable.id);
|
||||
|
||||
const whiteList = diForDecorator.inject(
|
||||
telemetryWhiteListForFunctionsInjectable,
|
||||
);
|
||||
if (isWhiteListed) {
|
||||
let params;
|
||||
|
||||
const whiteListMap = getWhiteListMap(whiteList);
|
||||
|
||||
const whiteListed = whiteListMap.get(currentContext.injectable.id);
|
||||
|
||||
if (whiteListed) {
|
||||
let params;
|
||||
|
||||
try {
|
||||
params = whiteListed.getParams(...args);
|
||||
} catch (e) {
|
||||
params = {
|
||||
error:
|
||||
try {
|
||||
params = getParams(...args);
|
||||
} catch (e) {
|
||||
params = {
|
||||
error:
|
||||
"Tried to produce params for telemetry, but getParams() threw an error",
|
||||
};
|
||||
};
|
||||
|
||||
logError(
|
||||
`Tried to produce params for telemetry of "${currentContext.injectable.id}", but getParams() threw an error`,
|
||||
e,
|
||||
);
|
||||
}
|
||||
|
||||
emitTelemetry({
|
||||
action: currentContext.injectable.id,
|
||||
params,
|
||||
});
|
||||
logError(
|
||||
`Tried to produce params for telemetry of "${currentContext.injectable.id}", but getParams() threw an error`,
|
||||
e,
|
||||
);
|
||||
}
|
||||
|
||||
return instance(...args);
|
||||
};
|
||||
}
|
||||
emitTelemetry({
|
||||
action: currentContext.injectable.id,
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
return instance;
|
||||
},
|
||||
return instance(...args);
|
||||
};
|
||||
}
|
||||
|
||||
return instance;
|
||||
},
|
||||
}),
|
||||
|
||||
decorable: false,
|
||||
// Todo: this is required because of imperfect typing in injectable.
|
||||
lifecycle: lifecycleEnum.singleton,
|
||||
injectionToken: instantiationDecoratorToken,
|
||||
injectionToken: injectionDecoratorToken,
|
||||
});
|
||||
|
||||
const getWhiteListMap = (whiteList: WhiteListItem[]) =>
|
||||
new Map(
|
||||
whiteList.map((item) =>
|
||||
typeof item === "string"
|
||||
? [
|
||||
item,
|
||||
{
|
||||
getParams: () => undefined,
|
||||
},
|
||||
]
|
||||
: [
|
||||
item.id,
|
||||
{
|
||||
getParams: item.getParams,
|
||||
},
|
||||
],
|
||||
),
|
||||
);
|
||||
type WhiteListEntry = {
|
||||
isWhiteListed: true;
|
||||
getParams: (...args: unknown[]) => Record<string, any> | undefined;
|
||||
} | {
|
||||
isWhiteListed: false;
|
||||
getParams?: undefined;
|
||||
};
|
||||
|
||||
|
||||
const findWhiteListEntry = (whiteList: WhiteListItem[], id: string): WhiteListEntry => {
|
||||
for (const entry of whiteList) {
|
||||
if (isString(entry)) {
|
||||
if (entry === id) {
|
||||
return {
|
||||
isWhiteListed: true,
|
||||
getParams: () => undefined,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
if (entry.id === id) {
|
||||
return {
|
||||
isWhiteListed: true,
|
||||
getParams: entry.getParams,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
isWhiteListed: false,
|
||||
};
|
||||
};
|
||||
|
||||
export default telemetryDecoratorInjectable;
|
||||
@@ -37,7 +37,7 @@ class NonInjectedSidebarItem extends React.Component<
|
||||
}
|
||||
|
||||
get id(): string {
|
||||
return this.registration.id;
|
||||
return this.item.id;
|
||||
}
|
||||
|
||||
@computed get expanded(): boolean {
|
||||
@@ -52,8 +52,8 @@ class NonInjectedSidebarItem extends React.Component<
|
||||
return this.props.item.isActive.get();
|
||||
}
|
||||
|
||||
get registration() {
|
||||
return this.props.item.registration;
|
||||
get item() {
|
||||
return this.props.item;
|
||||
}
|
||||
|
||||
toggleExpand = () => {
|
||||
@@ -71,7 +71,7 @@ class NonInjectedSidebarItem extends React.Component<
|
||||
|
||||
return (
|
||||
<ul className={cssNames(styles.subMenu, { [styles.active]: this.isActive })}>
|
||||
{this.props.item.children.map(item => <SidebarItem key={item.registration.id} item={item} />)}
|
||||
{this.props.item.children.map(item => <SidebarItem key={item.id} item={item} />)}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
@@ -82,7 +82,7 @@ class NonInjectedSidebarItem extends React.Component<
|
||||
className={styles.SidebarItem}
|
||||
data-testid={`sidebar-item-${this.id}`}
|
||||
data-is-active-test={this.isActive}
|
||||
data-parent-id-test={this.registration.parentId}
|
||||
data-parent-id-test={this.item.parentId}
|
||||
>
|
||||
<NavLink
|
||||
to={""}
|
||||
@@ -95,13 +95,13 @@ class NonInjectedSidebarItem extends React.Component<
|
||||
if (this.isExpandable) {
|
||||
this.toggleExpand();
|
||||
} else {
|
||||
this.registration.onClick();
|
||||
this.item.onClick();
|
||||
}
|
||||
}}
|
||||
data-testid={`sidebar-item-link-for-${this.id}`}
|
||||
>
|
||||
{this.registration.getIcon?.()}
|
||||
<span>{this.registration.title}</span>
|
||||
{this.item.getIcon?.()}
|
||||
<span>{this.item.title}</span>
|
||||
{this.isExpandable && (
|
||||
<Icon
|
||||
className={styles.expandIcon}
|
||||
|
||||
@@ -5,18 +5,9 @@
|
||||
import { getInjectable, getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { IComputedValue } from "mobx";
|
||||
import { computed } from "mobx";
|
||||
import { pipeline } from "@ogre-tools/fp";
|
||||
import { computedInjectManyInjectable } from "@ogre-tools/injectable-extension-for-mobx";
|
||||
import {
|
||||
filter,
|
||||
flatMap,
|
||||
identity,
|
||||
invokeMap,
|
||||
isEmpty,
|
||||
map,
|
||||
orderBy,
|
||||
some,
|
||||
} from "lodash/fp";
|
||||
import { byOrderNumber } from "../../../common/utils/composable-responsibilities/orderable/orderable";
|
||||
import type { SetRequired } from "type-fest";
|
||||
|
||||
export interface SidebarItemRegistration {
|
||||
id: string;
|
||||
@@ -33,10 +24,8 @@ export const sidebarItemsInjectionToken = getInjectionToken<
|
||||
IComputedValue<SidebarItemRegistration[]>
|
||||
>({ id: "sidebar-items-injection-token" });
|
||||
|
||||
export interface HierarchicalSidebarItem {
|
||||
registration: SidebarItemRegistration;
|
||||
export interface HierarchicalSidebarItem extends SetRequired<SidebarItemRegistration, "isActive" | "isVisible"> {
|
||||
children: HierarchicalSidebarItem[];
|
||||
isActive: IComputedValue<boolean>;
|
||||
}
|
||||
|
||||
const sidebarItemsInjectable = getInjectable({
|
||||
@@ -44,54 +33,42 @@ const sidebarItemsInjectable = getInjectable({
|
||||
|
||||
instantiate: (di) => {
|
||||
const computedInjectMany = di.inject(computedInjectManyInjectable);
|
||||
|
||||
const sidebarItemRegistrations = computedInjectMany(sidebarItemsInjectionToken);
|
||||
|
||||
return computed((): HierarchicalSidebarItem[] => {
|
||||
const registrations = pipeline(
|
||||
sidebarItemRegistrations.get(),
|
||||
flatMap(dereference),
|
||||
);
|
||||
const registrations = sidebarItemRegistrations
|
||||
.get()
|
||||
.flatMap(reg => reg.get());
|
||||
|
||||
const getSidebarItemsHierarchy = (registrations: SidebarItemRegistration[]) => {
|
||||
const _getSidebarItemsHierarchy = (parentId: string | null): HierarchicalSidebarItem[] =>
|
||||
pipeline(
|
||||
registrations,
|
||||
|
||||
filter((item) => item.parentId === parentId),
|
||||
|
||||
map((registration) => {
|
||||
const children = _getSidebarItemsHierarchy(registration.id);
|
||||
const impl = (parentId: string | null): HierarchicalSidebarItem[] => (
|
||||
registrations
|
||||
.filter((item) => item.parentId === parentId)
|
||||
.map(({
|
||||
isActive = computed(() => false),
|
||||
isVisible = computed(() => true),
|
||||
...registration
|
||||
}) => {
|
||||
const children = impl(registration.id);
|
||||
|
||||
return {
|
||||
registration,
|
||||
...registration,
|
||||
children,
|
||||
|
||||
isVisible,
|
||||
isActive: computed(() => {
|
||||
if (isEmpty(children)) {
|
||||
return registration.isActive ? registration.isActive.get() : false;
|
||||
if (children.length === 0) {
|
||||
return isActive.get();
|
||||
}
|
||||
|
||||
return pipeline(
|
||||
children,
|
||||
invokeMap("isActive.get"),
|
||||
some(identity),
|
||||
);
|
||||
return children.some(child => child.isActive.get());
|
||||
}),
|
||||
};
|
||||
}),
|
||||
})
|
||||
.filter(({ isVisible }) => isVisible.get())
|
||||
.sort(byOrderNumber)
|
||||
);
|
||||
|
||||
filter(item => item.registration.isVisible?.get() ?? true),
|
||||
|
||||
(items) =>
|
||||
orderBy(
|
||||
["registration.orderNumber"],
|
||||
["asc"],
|
||||
items,
|
||||
),
|
||||
);
|
||||
|
||||
return _getSidebarItemsHierarchy(null);
|
||||
return impl(null);
|
||||
};
|
||||
|
||||
return getSidebarItemsHierarchy(registrations);
|
||||
@@ -99,7 +76,4 @@ const sidebarItemsInjectable = getInjectable({
|
||||
},
|
||||
});
|
||||
|
||||
const dereference = (items: IComputedValue<SidebarItemRegistration[]>) =>
|
||||
items.get();
|
||||
|
||||
export default sidebarItemsInjectable;
|
||||
@@ -35,7 +35,7 @@ const NonInjectedSidebar = observer(({
|
||||
.map(hierarchicalSidebarItem => (
|
||||
<SidebarItem
|
||||
item={hierarchicalSidebarItem}
|
||||
key={hierarchicalSidebarItem.registration.id}
|
||||
key={hierarchicalSidebarItem.id}
|
||||
/>
|
||||
))
|
||||
}
|
||||
|
||||
@@ -34,21 +34,17 @@ export const TabLayout = observer(
|
||||
|
||||
{hasTabs && (
|
||||
<Tabs center>
|
||||
{tabs.map(({ registration, isActive }) => {
|
||||
const active = isActive.get();
|
||||
|
||||
return (
|
||||
<Tab
|
||||
onClick={registration.onClick}
|
||||
key={registration.id}
|
||||
label={registration.title}
|
||||
active={active}
|
||||
data-is-active-test={active}
|
||||
data-testid={`tab-link-for-${registration.id}`}
|
||||
value={undefined}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
{tabs.map(({ onClick, id, title, isActive }) => (
|
||||
<Tab
|
||||
onClick={onClick}
|
||||
key={id}
|
||||
label={title}
|
||||
active={isActive.get()}
|
||||
data-is-active-test={isActive.get()}
|
||||
data-testid={`tab-link-for-${id}`}
|
||||
value={undefined}
|
||||
/>
|
||||
))}
|
||||
</Tabs>
|
||||
)}
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ function VirtualListInner<T extends { getId(): string } | string>({
|
||||
? renderList(fixedHeight)
|
||||
: (
|
||||
<AutoSizer disableWidth>
|
||||
{({ height }) => renderList(height)}
|
||||
{({ height = 0 }) => renderList(height)}
|
||||
</AutoSizer>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user