Skip to content
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
77 changes: 77 additions & 0 deletions pages/03-core/in-iframe.page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { omit } from "lodash";

import ColumnLayout from "@cloudscape-design/components/column-layout";

import CoreChart from "../../lib/components/internal-do-not-use/core-chart";
import { dateFormatter } from "../common/formatters";
import { useChartSettings } from "../common/page-settings";
import { Page } from "../common/templates";

export default function () {
const { chartProps } = useChartSettings();
return (
<Page title="Charts inside iframe test page" iframe={{}}>
<ColumnLayout columns={2}>
<CoreChart
{...omit(chartProps.pie, "ref")}
ariaLabel="Line chart"
options={{
chart: { height: 300 },
series: [
{
name: "Running",
type: "line",
data: [
{ x: new Date("2020-01-01").getTime(), y: 44 },
{ x: new Date("2020-01-02").getTime(), y: 55 },
{ x: new Date("2020-01-03").getTime(), y: 60 },
],
},
{
name: "Failed",
type: "line",
data: [
{ x: new Date("2020-01-01").getTime(), y: 22 },
{ x: new Date("2020-01-02").getTime(), y: 15 },
{ x: new Date("2020-01-03").getTime(), y: 30 },
],
},
{
name: "In-progress",
type: "line",
data: [
{ x: new Date("2020-01-01").getTime(), y: 34 },
{ x: new Date("2020-01-02").getTime(), y: 30 },
{ x: new Date("2020-01-03").getTime(), y: 10 },
],
},
],
xAxis: [{ type: "datetime", valueFormatter: dateFormatter }],
}}
/>

<CoreChart
{...omit(chartProps.pie, "ref")}
ariaLabel="Pie chart"
options={{
chart: { height: 300 },
series: [
{
name: "Resource count",
type: "pie",
data: [
{ name: "Running", y: 34 },
{ name: "Failed", y: 30 },
{ name: "In-progress", y: 10 },
],
},
],
}}
/>
</ColumnLayout>
</Page>
);
}
57 changes: 25 additions & 32 deletions pages/06-visual-tests/in-iframe.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,34 @@ import { omit } from "lodash";
import CoreChart from "../../lib/components/internal-do-not-use/core-chart";
import { useChartSettings } from "../common/page-settings";
import { Page } from "../common/templates";
import { IframeWrapper } from "../utils/iframe-wrapper";

export default function () {
const { chartProps } = useChartSettings();
return (
<Page title="Chart inside iframe visual regression page">
<IframeWrapper
AppComponent={() => {
const { chartProps } = useChartSettings();
return (
<CoreChart
{...omit(chartProps.pie, "ref")}
ariaLabel="Pie chart"
options={{
series: [
{
name: "Resource count",
type: "pie",
data: [
{ name: "Running", y: 60 },
{ name: "Failed", y: 30 },
{ name: "In-progress", y: 10 },
],
},
],
}}
callback={(api) => {
setTimeout(() => {
if (api.chart.series) {
const point = api.chart.series[0].data.find((p) => p.y === 10)!;
api.highlightChartPoint(point);
}
}, 0);
}}
/>
);
<Page title="Chart inside iframe visual regression page" iframe={{}}>
<CoreChart
{...omit(chartProps.pie, "ref")}
ariaLabel="Pie chart"
options={{
series: [
{
name: "Resource count",
type: "pie",
data: [
{ name: "Running", y: 60 },
{ name: "Failed", y: 30 },
{ name: "In-progress", y: 10 },
],
},
],
}}
callback={(api) => {
setTimeout(() => {
if (api.chart.series) {
const point = api.chart.series[0].data.find((p) => p.y === 10)!;
api.highlightChartPoint(point);
}
}, 0);
}}
/>
</Page>
Expand Down
28 changes: 17 additions & 11 deletions pages/common/templates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Header from "@cloudscape-design/components/header";
import SpaceBetween from "@cloudscape-design/components/space-between";

import AppContext from "../app/app-context";
import { IframeWrapper } from "../utils/iframe-wrapper";
import { ScreenshotArea } from "./screenshot-area";

import styles from "./styles.module.scss";
Expand Down Expand Up @@ -48,12 +49,14 @@ export function Page({
settings,
children,
screenshotArea = true,
iframe,
}: {
title: React.ReactNode;
subtitle?: React.ReactNode;
settings?: React.ReactNode;
children: React.ReactNode;
screenshotArea?: boolean;
iframe?: { id?: string };
}) {
const { urlParams } = useContext(AppContext);
const [toolsOpen, setToolsOpen] = useState(!urlParams.screenshotMode);
Expand All @@ -70,24 +73,27 @@ export function Page({
},
});
}

const content = (
<Box>
<h1>{title}</h1>
{subtitle && !urlParams.screenshotMode && (
<Box variant="p" margin={{ bottom: "xs" }}>
{subtitle}
</Box>
)}
<Box>{screenshotArea ? <ScreenshotArea>{children}</ScreenshotArea> : children}</Box>
</Box>
);

return (
<AppLayout
headerSelector="#h"
navigationHide={true}
activeDrawerId={toolsOpen ? "settings" : null}
onDrawerChange={({ detail }) => setToolsOpen(!!detail.activeDrawerId)}
drawers={drawers}
content={
<Box>
<h1>{title}</h1>
{subtitle && !urlParams.screenshotMode && (
<Box variant="p" margin={{ bottom: "xs" }}>
{subtitle}
</Box>
)}
<Box>{screenshotArea ? <ScreenshotArea>{children}</ScreenshotArea> : children}</Box>
</Box>
}
content={iframe ? <IframeWrapper {...iframe} AppComponent={() => content} /> : content}
/>
);
}
Expand Down
Loading