Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a feature flag to select the desired UI design #1814

Merged
merged 8 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions chart/kubeapps/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -699,3 +699,5 @@ featureFlags:
# - name: second-cluster
# apiServiceURL: https://second-cluster:6443
# certificateAuthorityData: LS0tLS1CRUdJ...
# ui is a WIP feature for the migration to Clarity design system.
ui: hex
1 change: 1 addition & 0 deletions dashboard/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ RUN yarn install --frozen-lockfile

RUN mkdir /app/src
RUN curl -L https://unpkg.com/@bitnami/hex@3.2.0/dist/hex.min.css > /app/src/hex.min.css
RUN curl -L https://unpkg.com/@clr/ui@3.1.4/clr-ui.min.css > /app/src/clr-ui.min.css

COPY . /app
RUN yarn run build
Expand Down
4 changes: 3 additions & 1 deletion dashboard/public/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"oauthLoginURI": "/oauth2/start",
"oauthLogoutURI": "/oauth2/sign_out",
"featureFlags": {
"operators": true
"operators": true,
"additionalClusters": [],
"ui": "hex"
}
}
2 changes: 1 addition & 1 deletion dashboard/src/components/AppList/AppList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const defaultProps: any = {
getCustomResources: jest.fn(),
customResources: [],
csvs: [],
featureFlags: { operators: true, additionalClusters: [] },
featureFlags: { operators: true, additionalClusters: [], ui: "hex" },
};

context("when changing props", () => {
Expand Down
10 changes: 7 additions & 3 deletions dashboard/src/components/Catalog/Catalog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const defaultProps = {
kubeappsNamespace: "kubeapps",
csvs: [],
getCSVs: jest.fn(),
featureFlags: { operators: false, additionalClusters: [] },
featureFlags: { operators: false, additionalClusters: [], ui: "hex" },
};

it("propagates the filter from the props", () => {
Expand Down Expand Up @@ -66,7 +66,7 @@ describe("componentDidMount", () => {
{...defaultProps}
getCSVs={getCSVs}
namespace={namespace}
featureFlags={{ operators: true, additionalClusters: [] }}
featureFlags={{ ...defaultProps.featureFlags, operators: true }}
/>,
);
expect(getCSVs).toHaveBeenCalledWith(namespace);
Expand All @@ -77,7 +77,11 @@ describe("componentDidUpdate", () => {
it("re-fetches csvs if the namespace changes", () => {
const getCSVs = jest.fn();
const wrapper = shallow(
<Catalog {...defaultProps} getCSVs={getCSVs} featureFlags={{ operators: true, additionalClusters: [] }} />,
<Catalog
{...defaultProps}
getCSVs={getCSVs}
featureFlags={{ ...defaultProps.featureFlags, operators: true }}
/>,
);
wrapper.setProps({ namespace: "a-different-one" });
expect(getCSVs).toHaveBeenCalledWith("a-different-one");
Expand Down
8 changes: 6 additions & 2 deletions dashboard/src/components/Header/Header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const defaultProps = {
setNamespace: jest.fn(),
createNamespace: jest.fn(),
getNamespace: jest.fn(),
featureFlags: { operators: false, additionalClusters: [], ui: "hex" },
};
it("renders the header links and titles", () => {
const wrapper = shallow(<Header {...defaultProps} />);
Expand All @@ -38,7 +39,10 @@ it("renders the header links and titles", () => {
describe("settings", () => {
it("renders settings", () => {
const wrapper = shallow(
<Header {...defaultProps} featureFlags={{ operators: false, additionalClusters: [] }} />,
<Header
{...defaultProps}
featureFlags={{ ...defaultProps.featureFlags, operators: false }}
/>,
);
const settingsbar = wrapper.find(".header__nav__submenu").first();
const items = settingsbar.find("NavLink").map(p => p.props());
Expand All @@ -54,7 +58,7 @@ describe("settings", () => {

it("renders operators link", () => {
const wrapper = shallow(
<Header {...defaultProps} featureFlags={{ operators: true, additionalClusters: [] }} />,
<Header {...defaultProps} featureFlags={{ ...defaultProps.featureFlags, operators: true }} />,
);
const settingsbar = wrapper.find(".header__nav__submenu").first();
const items = settingsbar.find("NavLink").map(p => p.props());
Expand Down
7 changes: 3 additions & 4 deletions dashboard/src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { app } from "../../shared/url";
import "./Header.css";
import HeaderLink from "./HeaderLink";
import NamespaceSelector from "./NamespaceSelector";
import UISelector from "./UISelector";

interface IHeaderProps {
authenticated: boolean;
Expand All @@ -31,10 +32,6 @@ interface IHeaderState {
}

class Header extends React.Component<IHeaderProps, IHeaderState> {
public static defaultProps = {
featureFlags: { operators: false, additionalClusters: [] },
};

constructor(props: any) {
super(props);

Expand All @@ -61,6 +58,7 @@ class Header extends React.Component<IHeaderProps, IHeaderState> {
authenticated: showNav,
createNamespace,
getNamespace,
featureFlags,
} = this.props;
const header = `header ${this.state.mobileOpen ? "header-open" : ""}`;
const submenu = `header__nav__submenu ${
Expand All @@ -70,6 +68,7 @@ class Header extends React.Component<IHeaderProps, IHeaderState> {
const reposPath = `/config/ns/${cluster.currentNamespace}/repos`;
return (
<section className="gradient-135-brand type-color-reverse type-color-reverse-anchor-reset">
<UISelector UI={featureFlags.ui} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me here - does this actually make a selector appear in the UI? I assume not since we've got a feature flag to select which UI... so what does this component do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, I called this "selector" because the component is in charge of selecting the css file to load (but maybe another name is more suitable?). The selection is made automatically based on the configuration so the user just sees the configured UI. You will see an example in the next PR.

<div className="container">
<header className={header}>
<div className="header__logo">
Expand Down
7 changes: 7 additions & 0 deletions dashboard/src/components/Header/UISelector/Clarity.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as React from "react";

import "../../../clr-ui.min.css";

const CSSSelector: React.FC = () => null;

export default CSSSelector;
7 changes: 7 additions & 0 deletions dashboard/src/components/Header/UISelector/HEx.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as React from "react";

import "../../../hex.min.css";

const CSSSelector: React.FC = () => null;

export default CSSSelector;
17 changes: 17 additions & 0 deletions dashboard/src/components/Header/UISelector/UISelector.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as React from "react";

const HEx = React.lazy(() => import("./HEx"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see it matches the filename, but was that a typo? (the 'E' rather than 'e')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, the design system is called "HEx": https://design.bitnami.com/

const Clarity = React.lazy(() => import("./Clarity"));

export interface IUISelectorProps {
UI: string;
}

const UISelector: React.FC<IUISelectorProps> = props => (
<React.Suspense fallback={null}>
{props.UI === "hex" && <HEx />}
{props.UI === "clarity" && <Clarity />}
</React.Suspense>
);

export default UISelector;
3 changes: 3 additions & 0 deletions dashboard/src/components/Header/UISelector/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import UISelector from "./UISelector";

export default UISelector;
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const defaultState = {
auth: defaultAuthState,
router: { location: emptyLocation },
config: {
featureFlags: { operators: true, additionalClusters: [] },
featureFlags: { operators: true, additionalClusters: [], ui: "hex" },
},
clusters: {
currentCluster: "default",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const makeStore = (
namespace: "",
appVersion: "",
oauthLogoutURI: "",
featureFlags: { operators: false, additionalClusters: [] },
featureFlags: { operators: false, additionalClusters: [], ui: "hex" },
};
return mockStore({ auth, config });
};
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/containers/RoutesContainer/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ interface IRoutesProps extends IRouteComponentPropsAndRouteProps {

class Routes extends React.Component<IRoutesProps> {
public static defaultProps = {
featureFlags: { operators: false, additionalClusters: [] },
featureFlags: { operators: false, additionalClusters: [], ui: "hex" },
};
public render() {
const reposPath = "/config/ns/:namespace/repos";
Expand Down
1 change: 0 additions & 1 deletion dashboard/src/index.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@import url("https://fonts.googleapis.com/css?family=Fira+Sans:300,400,700|Hind:300,400,700");
@import "hex.min.css";

body {
margin: 0;
Expand Down
19 changes: 11 additions & 8 deletions dashboard/src/reducers/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,17 @@ describe("clusterReducer", () => {
oauthLogoutURI: "",
featureFlags: {
operators: false,
additionalClusters: [{
name: "additionalCluster1",
apiServiceURL: "https://not-used-by-dashboard.example.com/",
}, {
name: "additionalCluster2",
apiServiceURL: "https://not-used-by-dashboard.example.com/",
}],
}
additionalClusters: [
{
name: "additionalCluster1",
apiServiceURL: "https://not-used-by-dashboard.example.com/",
},
{
name: "additionalCluster2",
apiServiceURL: "https://not-used-by-dashboard.example.com/",
},
],
},
} as IConfig;
it("adds the additional clusters to the clusters state", () => {
expect(
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/reducers/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const clusterReducer = (
clusters[cluster.name] = {
currentNamespace: "default",
namespaces: [],
}
};
});
return {
...state,
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/reducers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const initialState: IConfigState = {
authProxyEnabled: false,
oauthLoginURI: "",
oauthLogoutURI: "",
featureFlags: { operators: true, additionalClusters: [] },
featureFlags: { operators: true, additionalClusters: [], ui: "hex" },
};

const configReducer = (state: IConfigState = initialState, action: ConfigAction): IConfigState => {
Expand Down
4 changes: 2 additions & 2 deletions dashboard/src/shared/Auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ describe("Auth", () => {
oauthLogoutURI,
namespace: "ns",
appVersion: "2",
featureFlags: { operators: false, additionalClusters: [] },
featureFlags: { operators: false, additionalClusters: [], ui: "hex" },
});

expect(mockedAssign).toBeCalledWith(oauthLogoutURI);
Expand All @@ -188,7 +188,7 @@ describe("Auth", () => {
oauthLogoutURI: "",
namespace: "ns",
appVersion: "2",
featureFlags: { operators: false, additionalClusters: [] },
featureFlags: { operators: false, additionalClusters: [], ui: "hex" },
});

expect(mockedAssign).toBeCalledWith("/oauth2/sign_out");
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/shared/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface IAdditionalCluster {
export interface IFeatureFlags {
operators: boolean;
additionalClusters: IAdditionalCluster[];
ui: string;
}

// IConfig is the configuration for Kubeapps
Expand Down