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

fix: Make funnel metrics discovery work in iframe #2995

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
63 changes: 63 additions & 0 deletions pages/funnel-analytics/app-layout-iframe-wizard.page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import React, { useState } from 'react';

import AppLayout from '~components/app-layout';
import BreadcrumbGroup from '~components/breadcrumb-group';
import { setFunnelMetrics } from '~components/internal/analytics';
import ScreenreaderOnly from '~components/internal/components/screenreader-only';

import labels from '../app-layout/utils/labels';
import { IframeWrapper } from '../utils/iframe-wrapper';
import ScreenshotArea from '../utils/screenshot-area';
import { MockedFunnelMetrics } from './mock-funnel';
import { WizardFlow } from './shared/wizard-flow';

setFunnelMetrics(MockedFunnelMetrics);

function InnerApp() {
const [mounted, setMounted] = useState(true);
return (
<AppLayout
ariaLabels={labels}
contentType="wizard"
breadcrumbs={
<BreadcrumbGroup
items={[
{ text: 'System', href: '#' },
{ text: 'Components', href: '#components' },
{
text: 'Create Resource',
href: '#components/breadcrumb-group',
},
]}
ariaLabel="Breadcrumbs"
/>
}
navigationHide={true}
toolsHide={true}
content={mounted ? <WizardFlow onUnmount={() => setMounted(false)} /> : 'no wizard'}
/>
);
}

export default function () {
return (
<ScreenshotArea gutters={false}>
<AppLayout
data-testid="main-layout"
ariaLabels={labels}
toolsHide={true}
disableContentPaddings={true}
content={
<>
<ScreenreaderOnly>
<h1>All content lives in iframe</h1>
</ScreenreaderOnly>
<IframeWrapper id="inner-iframe" AppComponent={InnerApp} />
</>
}
/>
</ScreenshotArea>
);
}
148 changes: 148 additions & 0 deletions pages/funnel-analytics/shared/wizard-flow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import React, { useState } from 'react';

import Container from '~components/container';
import FormField from '~components/form-field';
import Header from '~components/header';
import Input from '~components/input';
import Link from '~components/link';
import SpaceBetween from '~components/space-between';
import Wizard, { WizardProps } from '~components/wizard';

import { i18nStrings } from '../../wizard/common';

import styles from '../../wizard/styles.scss';

interface WizardFlowProps {
onUnmount?: () => void;
}

export function WizardFlow({ onUnmount }: WizardFlowProps) {
const [value, setValue] = useState('');
const [value2, setValue2] = useState('');
const [value3, setValue3] = useState('');
const [value4, setValue4] = useState('');

const [errorText, setErrorText] = useState('');
const [activeStepIndex, setActiveStepIndex] = useState(0);
const steps: WizardProps.Step[] = [
{
title: 'Step 1',
errorText,
content: (
<SpaceBetween size="s">
<Container
header={<Header>Container 1 - header</Header>}
analyticsMetadata={{
instanceIdentifier: 'step1-container1',
}}
>
<SpaceBetween size="s">
<FormField
info={
<Link data-testid="external-link" external={true} href="#">
Learn more
</Link>
}
errorText={value === 'error' ? 'Trigger error' : ''}
label="Field 1"
>
<Input
data-testid="field1"
value={value}
onChange={event => {
setValue(event.detail.value);
}}
/>
</FormField>
<FormField label="Field 2">
<Input
data-testid="field2"
value={value2}
onChange={event => {
setValue2(event.detail.value);
}}
/>
</FormField>
</SpaceBetween>
</Container>
<Container
header={<Header>Container 2 - header</Header>}
analyticsMetadata={{ instanceIdentifier: 'step1-container2' }}
>
<SpaceBetween size="s">
<FormField label="Field 3">
<Input
data-testid="field3"
value={value3}
onChange={event => {
setValue3(event.detail.value);
}}
/>
</FormField>
<FormField label="Field 4">
<Input
data-testid="field4"
value={value4}
onChange={event => {
setValue4(event.detail.value);
}}
/>
</FormField>
</SpaceBetween>
</Container>
</SpaceBetween>
),
analyticsMetadata: { instanceIdentifier: 'step-1' },
},
{
title: 'Step 2',
isOptional: true,
errorText,
content: (
<div className={styles['step-content']}>
<div id="content-text">Content 2</div>
</div>
),
analyticsMetadata: { instanceIdentifier: 'step-2' },
},
{
title: 'Step 3',
info: <Link variant="info">Info</Link>,
errorText: 'Simulated final step error',
content: (
<div className={styles['step-content']}>
{Array.from(Array(15).keys()).map(key => (
<div key={key} className={styles['content-item']}>
Item {key}
</div>
))}
</div>
),
analyticsMetadata: { instanceIdentifier: 'step-3' },
},
];

return (
<Wizard
analyticsMetadata={{
instanceIdentifier: 'multi-page-demo',
flowType: 'create',
}}
i18nStrings={i18nStrings}
steps={steps}
activeStepIndex={activeStepIndex}
onNavigate={e => {
if (value === 'error') {
setErrorText('There is an error');
} else {
setErrorText('');
setActiveStepIndex(e.detail.requestedStepIndex);
}
}}
onCancel={onUnmount}
onSubmit={onUnmount}
/>
);
}
149 changes: 4 additions & 145 deletions pages/funnel-analytics/static-multi-page-flow.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,135 +2,18 @@
// SPDX-License-Identifier: Apache-2.0
import React, { useState } from 'react';

import {
AppLayout,
BreadcrumbGroup,
Container,
FormField,
Header,
Input,
Link,
SpaceBetween,
Wizard,
WizardProps,
} from '~components';
import AppLayout from '~components/app-layout';
import BreadcrumbGroup from '~components/breadcrumb-group';
import { setFunnelMetrics } from '~components/internal/analytics';

import labels from '../app-layout/utils/labels';
import { i18nStrings } from '../wizard/common';
import { MockedFunnelMetrics } from './mock-funnel';

import styles from '../wizard/styles.scss';
import { WizardFlow } from './shared/wizard-flow';

setFunnelMetrics(MockedFunnelMetrics);

export default function MultiPageCreate() {
const [mounted, setMounted] = useState(true);
const [value, setValue] = useState('');
const [value2, setValue2] = useState('');
const [value3, setValue3] = useState('');
const [value4, setValue4] = useState('');

const [errorText, setErrorText] = useState('');
const [activeStepIndex, setActiveStepIndex] = useState(0);

const steps: WizardProps.Step[] = [
{
title: 'Step 1',
errorText,
content: (
<SpaceBetween size="s">
<Container
header={<Header>Container 1 - header</Header>}
analyticsMetadata={{
instanceIdentifier: 'step1-container1',
}}
>
<SpaceBetween size="s">
<FormField
info={
<Link data-testid="external-link" external={true} href="#">
Learn more
</Link>
}
errorText={value === 'error' ? 'Trigger error' : ''}
label="Field 1"
>
<Input
data-testid="field1"
value={value}
onChange={event => {
setValue(event.detail.value);
}}
/>
</FormField>
<FormField label="Field 2">
<Input
data-testid="field2"
value={value2}
onChange={event => {
setValue2(event.detail.value);
}}
/>
</FormField>
</SpaceBetween>
</Container>
<Container
header={<Header>Container 2 - header</Header>}
analyticsMetadata={{ instanceIdentifier: 'step1-container2' }}
>
<SpaceBetween size="s">
<FormField label="Field 3">
<Input
data-testid="field3"
value={value3}
onChange={event => {
setValue3(event.detail.value);
}}
/>
</FormField>
<FormField label="Field 4">
<Input
data-testid="field4"
value={value4}
onChange={event => {
setValue4(event.detail.value);
}}
/>
</FormField>
</SpaceBetween>
</Container>
</SpaceBetween>
),
analyticsMetadata: { instanceIdentifier: 'step-1' },
},
{
title: 'Step 2',
isOptional: true,
errorText,
content: (
<div className={styles['step-content']}>
<div id="content-text">Content 2</div>
</div>
),
analyticsMetadata: { instanceIdentifier: 'step-2' },
},
{
title: 'Step 3',
info: <Link variant="info">Info</Link>,
errorText: 'Simulated final step error',
content: (
<div className={styles['step-content']}>
{Array.from(Array(15).keys()).map(key => (
<div key={key} className={styles['content-item']}>
Item {key}
</div>
))}
</div>
),
analyticsMetadata: { instanceIdentifier: 'step-3' },
},
];

return (
<AppLayout
Expand All @@ -154,31 +37,7 @@ export default function MultiPageCreate() {
<button data-testid="unmount" onClick={() => setMounted(false)}>
Unmount
</button>
{mounted && (
<Wizard
analyticsMetadata={{
instanceIdentifier: 'multi-page-demo',
flowType: 'create',
}}
i18nStrings={i18nStrings}
steps={steps}
activeStepIndex={activeStepIndex}
onNavigate={e => {
if (value === 'error') {
setErrorText('There is an error');
} else {
setErrorText('');
setActiveStepIndex(e.detail.requestedStepIndex);
}
}}
onCancel={() => {
setMounted(false);
}}
onSubmit={() => {
setMounted(false);
}}
/>
)}
{mounted && <WizardFlow onUnmount={() => setMounted(false)} />}
</>
}
/>
Expand Down
Loading
Loading