1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Add WelcomeBanner.width extension API (#3663)

* Allow to add WelcomeBannerRegistration.width and use that to caculate to width of Banner container

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>

* Export at const

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
This commit is contained in:
chh 2021-08-24 10:05:08 +03:00 committed by GitHub
parent 4219f3c907
commit 54ac311933
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 17 deletions

View File

@ -30,6 +30,10 @@ export interface WelcomeBannerRegistration {
* The banner component to be shown on the welcome screen. * The banner component to be shown on the welcome screen.
*/ */
Banner?: React.ComponentType Banner?: React.ComponentType
/**
* The banner width in px.
*/
width?: number
} }
export class WelcomeBannerRegistry extends BaseRegistry<WelcomeBannerRegistration> { } export class WelcomeBannerRegistry extends BaseRegistry<WelcomeBannerRegistration> { }

View File

@ -24,6 +24,7 @@ import { render, screen } from "@testing-library/react";
import "@testing-library/jest-dom/extend-expect"; import "@testing-library/jest-dom/extend-expect";
import { Welcome } from "../welcome"; import { Welcome } from "../welcome";
import { TopBarRegistry, WelcomeMenuRegistry, WelcomeBannerRegistry } from "../../../../extensions/registries"; import { TopBarRegistry, WelcomeMenuRegistry, WelcomeBannerRegistry } from "../../../../extensions/registries";
import { defaultWidth } from "../welcome";
describe("<Welcome/>", () => { describe("<Welcome/>", () => {
beforeEach(() => { beforeEach(() => {
@ -69,4 +70,30 @@ describe("<Welcome/>", () => {
expect(screen.queryByTestId(testId)).toBeInTheDocument(); expect(screen.queryByTestId(testId)).toBeInTheDocument();
expect(container.getElementsByClassName("logo").length).toBe(0); expect(container.getElementsByClassName("logo").length).toBe(0);
}); });
it("calculates max width from WelcomeBanner.width registered in WelcomeBannerRegistry", async () => {
WelcomeBannerRegistry.getInstance().getItems = jest.fn().mockImplementationOnce(() => [
{
width: 100,
Banner: () => <div />
},
{
width: 800,
Banner: () => <div />
}
]);
render(<Welcome />);
expect(screen.queryByTestId("welcome-banner-container")).toHaveStyle({
// should take the max width of the banners (if > defaultWidth)
width: `800px`,
});
expect(screen.queryByTestId("welcome-text-container")).toHaveStyle({
width: `${defaultWidth}px`
});
expect(screen.queryByTestId("welcome-menu-container")).toHaveStyle({
width: `${defaultWidth}px`
});
});
}); });

View File

@ -25,10 +25,6 @@
height: 100%; height: 100%;
z-index: 1; z-index: 1;
.box {
width: 320px;
}
h2 { h2 {
color: var(--textColorAccent); color: var(--textColorAccent);
font-weight: 600; font-weight: 600;
@ -41,7 +37,6 @@
} }
ul { ul {
width: 200px;
margin-top: 20px; margin-top: 20px;
li { li {

View File

@ -29,21 +29,35 @@ import { WelcomeMenuRegistry } from "../../../extensions/registries";
import { WelcomeTopbar } from "../cluster-manager/welcome-topbar"; import { WelcomeTopbar } from "../cluster-manager/welcome-topbar";
import { WelcomeBannerRegistry } from "../../../extensions/registries"; import { WelcomeBannerRegistry } from "../../../extensions/registries";
export const defaultWidth = 320;
@observer @observer
export class Welcome extends React.Component { export class Welcome extends React.Component {
render() { render() {
const welcomeBanner = WelcomeBannerRegistry.getInstance().getItems(); const welcomeBanner = WelcomeBannerRegistry.getInstance().getItems();
// if there is banner with specified width, use it to calculate the width of the container
const maxWidth = welcomeBanner.reduce((acc, curr) => {
const currWidth = curr.width ?? 0;
if (acc > currWidth) {
return acc;
}
return currWidth;
}, defaultWidth);
return ( return (
<> <>
<WelcomeTopbar/> <WelcomeTopbar/>
<div className="flex justify-center Welcome align-center"> <div className="flex justify-center Welcome align-center">
<div className="box"> <div style={{ width: `${maxWidth}px` }} data-testid="welcome-banner-container">
{welcomeBanner.length > 0 ? ( {welcomeBanner.length > 0 ? (
<Carousel <Carousel
stopAutoPlayOnHover={true} stopAutoPlayOnHover={true}
indicators={welcomeBanner.length > 1} indicators={welcomeBanner.length > 1}
autoPlay={true} autoPlay={true}
navButtonsAlwaysInvisible={true}
> >
{welcomeBanner.map((item, index) => {welcomeBanner.map((item, index) =>
<item.Banner key={index} /> <item.Banner key={index} />
@ -51,21 +65,25 @@ export class Welcome extends React.Component {
</Carousel> </Carousel>
) : <Icon svg="logo-lens" className="logo" />} ) : <Icon svg="logo-lens" className="logo" />}
<h2>Welcome to {productName} 5!</h2> <div className="flex justify-center">
<div style={{ width: `${defaultWidth}px` }} data-testid="welcome-text-container">
<h2>Welcome to {productName} 5!</h2>
<p> <p>
To get you started we have auto-detected your clusters in your kubeconfig file and added them to the catalog, your centralized view for managing all your cloud-native resources. To get you started we have auto-detected your clusters in your kubeconfig file and added them to the catalog, your centralized view for managing all your cloud-native resources.
<br/><br/> <br /><br />
If you have any questions or feedback, please join our <a href={slackUrl} target="_blank" rel="noreferrer" className="link">Lens Community slack channel</a>. If you have any questions or feedback, please join our <a href={slackUrl} target="_blank" rel="noreferrer" className="link">Lens Community slack channel</a>.
</p> </p>
<ul className="box"> <ul className="block" style={{ width: `${defaultWidth}px` }} data-testid="welcome-menu-container">
{WelcomeMenuRegistry.getInstance().getItems().map((item, index) => ( {WelcomeMenuRegistry.getInstance().getItems().map((item, index) => (
<li key={index} className="flex grid-12" onClick={() => item.click()}> <li key={index} className="flex grid-12" onClick={() => item.click()}>
<Icon material={item.icon} className="box col-1" /> <a className="box col-10">{typeof item.title === "string" ? item.title : item.title()}</a> <Icon material="navigate_next" className="box col-1" /> <Icon material={item.icon} className="box col-1" /> <a className="box col-10">{typeof item.title === "string" ? item.title : item.title()}</a> <Icon material="navigate_next" className="box col-1" />
</li> </li>
))} ))}
</ul> </ul>
</div>
</div>
</div> </div>
</div> </div>
</> </>