mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix tests from rebase
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
5d1609e0e4
commit
3def62cd8d
33 files changed
+457
-449
No files matched your search
@@ -86,7 +86,7 @@ export class AddSecretDialog extends React.Component<AddSecretDialogProps> {
|
||||
};
|
||||
|
||||
private getDataFromFields = (fields: SecretTemplateField[] = [], processValue: (val: string) => string = (val => val)) => {
|
||||
return iter.pipeline(fields)
|
||||
return iter.pipeline(fields.values())
|
||||
.filterMap(({ key, value }) => (
|
||||
value
|
||||
? [key, processValue(value)] as const
|
||||
|
||||
@@ -137,10 +137,8 @@ class NonInjectedDeploymentDetails extends React.Component<DeploymentDetailsProp
|
||||
labelsOnly
|
||||
>
|
||||
{
|
||||
deployment.getConditions().map(condition => {
|
||||
const { type, message, lastTransitionTime, status } = condition;
|
||||
|
||||
return (
|
||||
deployment.getConditions()
|
||||
.map(({ type, message, lastTransitionTime, status }) => (
|
||||
<Badge
|
||||
key={type}
|
||||
label={type}
|
||||
@@ -153,10 +151,8 @@ class NonInjectedDeploymentDetails extends React.Component<DeploymentDetailsProp
|
||||
{`Last transition time: ${lastTransitionTime}`}
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
/>
|
||||
);
|
||||
})
|
||||
)} />
|
||||
))
|
||||
}
|
||||
</DrawerItem>
|
||||
<PodDetailsTolerations workload={deployment}/>
|
||||
|
||||
@@ -30,104 +30,108 @@ export interface IconProps extends React.HTMLAttributes<any> {
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
export const Icon = Object.assign(
|
||||
withTooltip((props: IconProps) => {
|
||||
const ref = createRef<HTMLAnchorElement>();
|
||||
export function isSvg(content: string): boolean {
|
||||
// data-url for raw svg-icon
|
||||
return String(content).includes("svg+xml");
|
||||
}
|
||||
|
||||
const {
|
||||
// skip passing props to icon's html element
|
||||
className, href, link, material, svg, size, smallest, small, big,
|
||||
disabled, sticker, active, focusable, children,
|
||||
interactive, onClick, onKeyDown,
|
||||
...elemProps
|
||||
} = props;
|
||||
const isInteractive = interactive ?? !!(onClick || href || link);
|
||||
const RawIcon = withTooltip((props: IconProps) => {
|
||||
const ref = createRef<HTMLAnchorElement>();
|
||||
|
||||
const boundOnClick = (event: React.MouseEvent) => {
|
||||
if (!disabled) {
|
||||
onClick?.(event);
|
||||
const {
|
||||
// skip passing props to icon's html element
|
||||
className, href, link, material, svg, size, smallest, small, big,
|
||||
disabled, sticker, active,
|
||||
focusable = true,
|
||||
children,
|
||||
interactive, onClick, onKeyDown,
|
||||
...elemProps
|
||||
} = props;
|
||||
const isInteractive = interactive ?? !!(onClick || href || link);
|
||||
|
||||
const boundOnClick = (event: React.MouseEvent) => {
|
||||
if (!disabled) {
|
||||
onClick?.(event);
|
||||
}
|
||||
};
|
||||
const boundOnKeyDown = (event: React.KeyboardEvent<any>) => {
|
||||
switch (event.nativeEvent.code) {
|
||||
case "Space":
|
||||
|
||||
// fallthrough
|
||||
case "Enter": {
|
||||
ref.current?.click();
|
||||
event.preventDefault();
|
||||
break;
|
||||
}
|
||||
};
|
||||
const boundOnKeyDown = (event: React.KeyboardEvent<any>) => {
|
||||
switch (event.nativeEvent.code) {
|
||||
case "Space":
|
||||
|
||||
// fallthrough
|
||||
case "Enter": {
|
||||
ref.current?.click();
|
||||
event.preventDefault();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
onKeyDown?.(event);
|
||||
};
|
||||
|
||||
let iconContent: ReactNode;
|
||||
const iconProps: Partial<IconProps> = {
|
||||
className: cssNames("Icon", className,
|
||||
{ svg, material, interactive: isInteractive, disabled, sticker, active, focusable },
|
||||
!size ? { smallest, small, big } : {},
|
||||
),
|
||||
onClick: isInteractive ? boundOnClick : undefined,
|
||||
onKeyDown: isInteractive ? boundOnKeyDown : undefined,
|
||||
tabIndex: isInteractive && focusable && !disabled ? 0 : undefined,
|
||||
style: size ? { "--size": size + (isNumber(size) ? "px" : "") } as React.CSSProperties : undefined,
|
||||
...elemProps,
|
||||
};
|
||||
|
||||
// render as inline svg-icon
|
||||
if (typeof svg === "string") {
|
||||
const dataUrlPrefix = "data:image/svg+xml;base64,";
|
||||
const svgIconDataUrl = svg.startsWith(dataUrlPrefix) ? svg : require(`./${svg}.svg`);
|
||||
const svgIconText = typeof svgIconDataUrl == "string" // decode xml from data-url
|
||||
? decode(svgIconDataUrl.replace(dataUrlPrefix, "")) : "";
|
||||
|
||||
iconContent = <span className="icon" dangerouslySetInnerHTML={{ __html: svgIconText }} />;
|
||||
}
|
||||
|
||||
// render as material-icon
|
||||
if (typeof material === "string") {
|
||||
iconContent = <span className="icon" data-icon-name={material}>{material}</span>;
|
||||
}
|
||||
onKeyDown?.(event);
|
||||
};
|
||||
|
||||
// wrap icon's content passed from decorator
|
||||
iconProps.children = (
|
||||
<>
|
||||
{iconContent}
|
||||
let iconContent: ReactNode;
|
||||
const iconProps: Partial<IconProps> = {
|
||||
className: cssNames("Icon", className,
|
||||
{ svg, material, interactive: isInteractive, disabled, sticker, active, focusable },
|
||||
!size ? { smallest, small, big } : {},
|
||||
),
|
||||
onClick: isInteractive ? boundOnClick : undefined,
|
||||
onKeyDown: isInteractive ? boundOnKeyDown : undefined,
|
||||
tabIndex: isInteractive && focusable && !disabled ? 0 : undefined,
|
||||
style: size ? { "--size": size + (isNumber(size) ? "px" : "") } as React.CSSProperties : undefined,
|
||||
...elemProps,
|
||||
};
|
||||
|
||||
// render as inline svg-icon
|
||||
if (typeof svg === "string") {
|
||||
const dataUrlPrefix = "data:image/svg+xml;base64,";
|
||||
const svgIconDataUrl = svg.startsWith(dataUrlPrefix) ? svg : require(`./${svg}.svg`);
|
||||
const svgIconText = typeof svgIconDataUrl == "string" // decode xml from data-url
|
||||
? decode(svgIconDataUrl.replace(dataUrlPrefix, ""))
|
||||
: "";
|
||||
|
||||
iconContent = <span className="icon" dangerouslySetInnerHTML={{ __html: svgIconText }} />;
|
||||
}
|
||||
|
||||
// render as material-icon
|
||||
if (typeof material === "string") {
|
||||
iconContent = <span className="icon" data-icon-name={material}>{material}</span>;
|
||||
}
|
||||
|
||||
// wrap icon's content passed from decorator
|
||||
iconProps.children = (
|
||||
<>
|
||||
{iconContent}
|
||||
{children}
|
||||
</>
|
||||
);
|
||||
|
||||
// render icon type
|
||||
if (link) {
|
||||
const { className, children } = iconProps;
|
||||
|
||||
return (
|
||||
<NavLink
|
||||
className={className}
|
||||
to={link}
|
||||
ref={ref}
|
||||
>
|
||||
{children}
|
||||
</>
|
||||
</NavLink>
|
||||
);
|
||||
}
|
||||
|
||||
// render icon type
|
||||
if (link) {
|
||||
const { className, children } = iconProps;
|
||||
if (href) {
|
||||
return (
|
||||
<a
|
||||
{...iconProps}
|
||||
href={href}
|
||||
ref={ref}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<NavLink
|
||||
className={className}
|
||||
to={link}
|
||||
ref={ref}
|
||||
>
|
||||
{children}
|
||||
</NavLink>
|
||||
);
|
||||
}
|
||||
return <i {...iconProps} ref={ref} />;
|
||||
});
|
||||
|
||||
if (href) {
|
||||
return (
|
||||
<a
|
||||
{...iconProps}
|
||||
href={href}
|
||||
ref={ref}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return <i {...iconProps} ref={ref} />;
|
||||
}),
|
||||
{
|
||||
// data-url for raw svg-icon
|
||||
isSvg: (content: string) => String(content).includes("svg+xml"),
|
||||
},
|
||||
);
|
||||
export const Icon = Object.assign(RawIcon, { isSvg });
|
||||
@@ -28,7 +28,10 @@ import createEditResourceTabInjectable from "../dock/edit-resource/edit-resource
|
||||
import hideDetailsInjectable from "../kube-detail-params/hide-details.injectable";
|
||||
|
||||
// TODO: Make tooltips free of side effects by making it deterministic
|
||||
jest.mock("../tooltip");
|
||||
jest.mock("../tooltip/tooltip");
|
||||
jest.mock("../tooltip/withTooltip", () => ({
|
||||
withTooltip: (target: any) => target,
|
||||
}));
|
||||
|
||||
class SomeTestExtension extends LensRendererExtension {
|
||||
constructor(
|
||||
|
||||
@@ -104,18 +104,14 @@ const NonInjectedKubeObjectMeta = observer(({
|
||||
{ownerRefs?.length > 0 && (
|
||||
<DrawerItem name="Controlled By" hidden={isHidden("ownerReferences")}>
|
||||
{
|
||||
ownerRefs.map(ref => {
|
||||
const { name, kind } = ref;
|
||||
const ownerDetailsUrl = getDetailsUrl(apiManager.lookupApiLink(ref, object));
|
||||
|
||||
return (
|
||||
<p key={name}>
|
||||
{kind}
|
||||
{" "}
|
||||
<Link to={ownerDetailsUrl}>{name}</Link>
|
||||
</p>
|
||||
);
|
||||
})
|
||||
ownerRefs.map(ref => (
|
||||
<p key={ref.name}>
|
||||
{`${ref.kind} `}
|
||||
<Link to={getDetailsUrl(apiManager.lookupApiLink(ref, object))}>
|
||||
{ref.name}
|
||||
</Link>
|
||||
</p>
|
||||
))
|
||||
}
|
||||
</DrawerItem>
|
||||
)}
|
||||
|
||||
@@ -164,6 +164,7 @@ class NonInjectedSelect<
|
||||
value = null,
|
||||
options,
|
||||
isMulti,
|
||||
id: inputId,
|
||||
onChange,
|
||||
...props
|
||||
} = this.props;
|
||||
@@ -192,6 +193,7 @@ class NonInjectedSelect<
|
||||
}),
|
||||
...styles,
|
||||
}}
|
||||
inputId={inputId}
|
||||
filterOption={defaultFilter} // This is done because the default filter crashes on symbols
|
||||
isMulti={isMulti}
|
||||
options={convertedOptions}
|
||||
|
||||
@@ -9,11 +9,12 @@ import React from "react";
|
||||
import { cssNames } from "../../utils";
|
||||
import { withTooltip } from "../tooltip";
|
||||
|
||||
export interface StatusBrickProps extends React.HTMLAttributes<any> {
|
||||
export interface StatusBrickProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
}
|
||||
|
||||
export const StatusBrick = withTooltip(({ className, ...elemProps }: StatusBrickProps) => (
|
||||
<div
|
||||
className={cssNames("StatusBrick", className)}
|
||||
{...elemProps} />
|
||||
{...elemProps}
|
||||
/>
|
||||
));
|
||||
@@ -2,23 +2,48 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { SetRequired } from "type-fest";
|
||||
import type { Mutable, SetRequired } from "type-fest";
|
||||
import catalogCategoryRegistryInjectable from "../../../common/catalog/category-registry.injectable";
|
||||
import fileSystemProvisionerStoreInjectable from "../../../extensions/extension-loader/file-system-provisioner-store/file-system-provisioner-store.injectable";
|
||||
import { lensExtensionDependencies } from "../../../extensions/lens-extension";
|
||||
import { LensRendererExtension } from "../../../extensions/lens-renderer-extension";
|
||||
import catalogEntityRegistryInjectable from "../../api/catalog/entity/registry.injectable";
|
||||
import getExtensionPageParametersInjectable from "../../routes/get-extension-page-parameters.injectable";
|
||||
import navigateToRouteInjectable from "../../routes/navigate-to-route.injectable";
|
||||
import routesInjectable from "../../routes/routes.injectable";
|
||||
import type { ApplicationBuilder } from "./get-application-builder";
|
||||
|
||||
export class TestExtension extends LensRendererExtension {}
|
||||
|
||||
export const getRendererExtensionFake = ({ id, ...rest }: SetRequired<Partial<LensRendererExtension>, "id">) => {
|
||||
const instance = new TestExtension({
|
||||
id,
|
||||
absolutePath: "irrelevant",
|
||||
isBundled: false,
|
||||
isCompatible: false,
|
||||
isEnabled: false,
|
||||
manifest: { name: id, version: "some-version" },
|
||||
manifestPath: "irrelevant",
|
||||
});
|
||||
export type FakeExtensionData = SetRequired<Partial<LensRendererExtension>, "id" | "name">;
|
||||
|
||||
Object.assign(instance, rest);
|
||||
export const getRendererExtensionFakeFor = (builder: ApplicationBuilder) => (
|
||||
function getRendererExtensionFake({ id, name, ...rest }: FakeExtensionData) {
|
||||
const instance = new TestExtension({
|
||||
id,
|
||||
absolutePath: "irrelevant",
|
||||
isBundled: false,
|
||||
isCompatible: false,
|
||||
isEnabled: false,
|
||||
manifest: {
|
||||
name,
|
||||
version: "1.0.0",
|
||||
},
|
||||
manifestPath: "irrelevant",
|
||||
});
|
||||
|
||||
Object.assign(instance, rest);
|
||||
|
||||
(instance as Mutable<LensRendererExtension>)[lensExtensionDependencies] = {
|
||||
categoryRegistry: builder.dis.rendererDi.inject(catalogCategoryRegistryInjectable),
|
||||
entityRegistry: builder.dis.rendererDi.inject(catalogEntityRegistryInjectable),
|
||||
fileSystemProvisionerStore: builder.dis.rendererDi.inject(fileSystemProvisionerStoreInjectable),
|
||||
getExtensionPageParameters: builder.dis.rendererDi.inject(getExtensionPageParametersInjectable),
|
||||
navigateToRoute: builder.dis.rendererDi.inject(navigateToRouteInjectable),
|
||||
routes: builder.dis.rendererDi.inject(routesInjectable),
|
||||
};
|
||||
|
||||
return instance;
|
||||
}
|
||||
);
|
||||
|
||||
return instance;
|
||||
};
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
import type { ReactNode } from "react";
|
||||
import React, { useState } from "react";
|
||||
import hoistNonReactStatics from "hoist-non-react-statics";
|
||||
import type { TooltipProps } from "./tooltip";
|
||||
import { Tooltip } from "./tooltip";
|
||||
import { isReactNode } from "../../utils/isReactNode";
|
||||
@@ -21,11 +20,15 @@ export interface TooltipDecoratorProps {
|
||||
* useful for displaying tooltips even when the target is "disabled"
|
||||
*/
|
||||
tooltipOverrideDisabled?: boolean;
|
||||
id?: string | undefined;
|
||||
id?: string;
|
||||
children?: SingleOrMany<React.ReactNode>;
|
||||
}
|
||||
|
||||
export function withTooltip<TargetProps extends Pick<TooltipDecoratorProps, "id" | "children">>(Target: React.FunctionComponent<TargetProps>): React.FunctionComponent<TargetProps & TooltipDecoratorProps> {
|
||||
export function withTooltip<TargetProps>(
|
||||
Target: TargetProps extends Pick<TooltipDecoratorProps, "id" | "children">
|
||||
? React.FunctionComponent<TargetProps>
|
||||
: never,
|
||||
): React.FunctionComponent<TargetProps & TooltipDecoratorProps> {
|
||||
const DecoratedComponent = (props: TargetProps & TooltipDecoratorProps) => {
|
||||
// TODO: Remove side-effect to allow deterministic unit testing
|
||||
const [defaultTooltipId] = useState(uniqueId("tooltip_target_"));
|
||||
@@ -62,7 +65,7 @@ export function withTooltip<TargetProps extends Pick<TooltipDecoratorProps, "id"
|
||||
}
|
||||
|
||||
return (
|
||||
<Target id={targetId} {...targetProps as TargetProps}>
|
||||
<Target id={targetId} {...targetProps as any}>
|
||||
{targetChildren}
|
||||
</Target>
|
||||
);
|
||||
@@ -70,5 +73,5 @@ export function withTooltip<TargetProps extends Pick<TooltipDecoratorProps, "id"
|
||||
|
||||
DecoratedComponent.displayName = `withTooltip(${Target.displayName || Target.name})`;
|
||||
|
||||
return hoistNonReactStatics(DecoratedComponent, Target);
|
||||
return DecoratedComponent;
|
||||
}
|
||||
@@ -27,8 +27,8 @@ export function cssNames(...classNames: IClassName[]): string {
|
||||
}
|
||||
}
|
||||
|
||||
return iter.pipeline(classNamesEnabled)
|
||||
return iter.pipeline(classNamesEnabled.entries())
|
||||
.filter(([, isActive]) => !!isActive)
|
||||
.map(([className]) => className.trim())
|
||||
.filterMap(([className]) => className.trim())
|
||||
.join(" ");
|
||||
}
|
||||
Reference in new issue
Block a user