Skip to content

Commit

Permalink
Several bug fixes (#2061)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andres Martinez Gotor authored Sep 24, 2020
1 parent 78a8c7f commit 747a1a1
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 13 deletions.
6 changes: 6 additions & 0 deletions dashboard/src/components/AppView/AppSecrets/AppSecrets.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
.app-secrets-content {
margin-top: 1.2rem;
margin-right: 1.2rem;
}

.app-secrets-section {
max-height: 10rem;
overflow-y: auto;
}
2 changes: 1 addition & 1 deletion dashboard/src/components/AppView/AppSecrets/AppSecrets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function AppSecrets({ secretRefs }: IResourceTableProps) {
});
}
return (
<section aria-labelledby="app-secrets">
<section aria-labelledby="app-secrets" className="app-secrets-section">
<h5 className="section-title" id="app-secrets">
Application Secrets
</h5>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
width: 100%;
height: 100%;
padding-left: 0.3rem;
overflow-x: auto;
overflow-y: hidden;
}

.secret-datum-icon {
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/components/ChartView/ChartHeader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ it("displays the appVersion", () => {

it("uses the icon", () => {
const wrapper = mount(<ChartHeader {...testProps} />);
const icon = wrapper.find("img").filterWhere(i => i.prop("alt") === "app-icon");
const icon = wrapper.find("img").filterWhere(i => i.prop("alt") === "icon");
expect(icon.exists()).toBe(true);
expect(icon.props()).toMatchObject({ src: "api/assetsvc/test.jpg" });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from "react";

import { mount } from "enzyme";
import { act } from "react-dom/test-utils";
import { defaultStore, mountWrapper } from "shared/specs/mountWrapper";
import { IBasicFormParam } from "shared/types";
import TextParam from "./TextParam";

Expand Down Expand Up @@ -185,3 +186,20 @@ it("should forward the proper value when using a select", () => {
});
expect(handler.mock.calls[0][0]).toMatchObject(event);
});

it("a change in the param property should update the current value", () => {
const wrapper = mountWrapper(
defaultStore,
<TextParam {...stringProps} param={{ ...stringParam, value: "" }} />,
);
const input = wrapper.find("input");
expect(input.prop("value")).toBe("");

wrapper.setProps({
param: {
...stringParam,
value: "foo",
},
});
expect(input.prop("value")).toBe("");
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from "react";
import { isEmpty } from "lodash";
import React, { useEffect, useState } from "react";
import { IBasicFormParam } from "shared/types";

export interface IStringParamProps {
Expand All @@ -12,12 +13,14 @@ export interface IStringParamProps {
}

function TextParam({ id, param, label, inputType, handleBasicFormParamChange }: IStringParamProps) {
const [value, setValue] = React.useState((param.value || "") as any);
let timeout: NodeJS.Timeout;
const [value, setValue] = useState((param.value || "") as any);
const [valueModified, setValueModified] = useState(false);
const [timeout, setThisTimeout] = useState({} as NodeJS.Timeout);
const onChange = (
e: React.FormEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>,
) => {
setValue(e.currentTarget.value);
setValueModified(true);
// Gather changes before submitting
clearTimeout(timeout);
const func = handleBasicFormParamChange(param);
Expand All @@ -28,8 +31,15 @@ function TextParam({ id, param, label, inputType, handleBasicFormParamChange }:
type: e.currentTarget.type,
},
} as React.FormEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>;
timeout = setTimeout(() => func(targetCopy), 500);
setThisTimeout(setTimeout(() => func(targetCopy), 500));
};

useEffect(() => {
if (!isEmpty(param.value) && !valueModified) {
setValue(param.value);
}
}, [valueModified, param.value]);

let input = (
<input
id={id}
Expand Down
24 changes: 24 additions & 0 deletions dashboard/src/components/Icon/Icon.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from "react";
import { act } from "react-dom/test-utils";
import { defaultStore, mountWrapper } from "shared/specs/mountWrapper";
import Icon from "./Icon";

it("should render an icon", () => {
const wrapper = mountWrapper(defaultStore, <Icon icon="foo" />);
expect(wrapper.find("img").prop("src")).toBe("foo");
});

it("should use the default icon if not given", () => {
const wrapper = mountWrapper(defaultStore, <Icon />);
expect(wrapper.find("img").prop("src")).toBe("placeholder.png");
});

it("should fallback to the placeholder if an error happens", () => {
const wrapper = mountWrapper(defaultStore, <Icon icon="foo" />);
expect(wrapper.find("img").prop("src")).toBe("foo");
act(() => {
wrapper.find("img").simulate("error", {});
});
wrapper.update();
expect(wrapper.find("img").prop("src")).toBe("placeholder.png");
});
26 changes: 26 additions & 0 deletions dashboard/src/components/Icon/Icon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React, { useEffect, useState } from "react";

import placeholder from "../../placeholder.png";

export interface IIconProps {
icon?: any;
}

function Icon({ icon }: IIconProps) {
const [srcIcon, setSrcIcon] = useState(placeholder);
const [iconErrored, setIconErrored] = useState(false);
useEffect(() => {
if (srcIcon !== icon && icon && !iconErrored) {
setSrcIcon(icon);
}
}, [srcIcon, icon, iconErrored]);

const onError = () => {
setIconErrored(true);
setSrcIcon(placeholder);
};

return <img src={srcIcon} alt="icon" onError={onError} />;
}

export default Icon;
3 changes: 2 additions & 1 deletion dashboard/src/components/InfoCard/InfoCard.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Icon from "components/Icon/Icon";
import { shallow } from "enzyme";
import * as React from "react";
import { Link } from "react-router-dom";
Expand Down Expand Up @@ -80,7 +81,7 @@ it("should parse a description as JSX.Element", () => {

it("should parse an icon", () => {
const wrapper = shallow(<InfoCard title="foo" info="foobar" />);
expect(wrapper.find("img")).toExist();
expect(wrapper.find(Icon)).toExist();
});

it("should parse a background img", () => {
Expand Down
3 changes: 2 additions & 1 deletion dashboard/src/components/InfoCard/InfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Card, { CardBlock, CardFooter, CardHeader } from "../js/Card";
import Column from "../js/Column";
import Row from "../js/Row";

import Icon from "components/Icon/Icon";
import placeholder from "../../placeholder.png";
import "./InfoCard.css";

Expand Down Expand Up @@ -48,7 +49,7 @@ function InfoCard(props: IInfoCardProps) {
<CardBlock>
<div className="info-card-block">
<div className="card-icon">
<img src={icon} alt="icon" />
<Icon icon={icon} />
</div>
<div className="card-description-wrapper">
<div className="card-description">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ exports[`should render a Card 1`] = `
<div
className="card-icon"
>
<img
alt="icon"
src="an-icon.png"
<Icon
icon="an-icon.png"
/>
</div>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import React from "react";
import { useSelector } from "react-redux";
import { Operators } from "shared/Operators";
import { IStoreState } from "shared/types";
import "./CapabilityLevel.css";

export default function OperatorSummary() {
const { operator, isFetching, csv } = useSelector((state: IStoreState) => state.operators);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ it("fallbacks to the default icon if not set", () => {
expect(
wrapper
.find("img")
.filterWhere(i => i.prop("alt") === "app-icon")
.filterWhere(i => i.prop("alt") === "icon")
.prop("src"),
).toBe("placeholder.png");
});
Expand Down
3 changes: 2 additions & 1 deletion dashboard/src/components/PageHeader/PageHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from "react";

import Icon from "components/Icon/Icon";
import Column from "components/js/Column";
import Row from "components/js/Row";
import olmIcon from "icons/operator-framework.svg";
Expand Down Expand Up @@ -32,7 +33,7 @@ function PageHeader({
<Row>
<Column span={7}>
<div className="kubeapps-title-section">
{icon && <img src={icon} alt="app-icon" />}
{icon && <Icon icon={icon} />}
<div className="kubeapps-title-block">
{titleSize === "lg" ? <h1>{title}</h1> : <h3>{title}</h3>}
{helm && (
Expand Down

0 comments on commit 747a1a1

Please sign in to comment.