-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Render breadcrumbs slot in the skeleton state
- Loading branch information
1 parent
672e7f8
commit 6f91db5
Showing
20 changed files
with
273 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
/* eslint-disable simple-import-sort/imports */ | ||
import React from 'react'; | ||
|
||
import { describeEachAppLayout, renderComponent } from './utils'; | ||
import AppLayout from '../../../lib/components/app-layout'; | ||
import BreadcrumbGroup from '../../../lib/components/breadcrumb-group'; | ||
import { getFunnelKeySelector } from '../../internal/analytics/selectors'; | ||
|
||
let widgetMockEnabled = false; | ||
function createWidgetizedComponentMock(Implementation: React.ComponentType, Skeleton: React.ComponentType) { | ||
return () => { | ||
return function Widgetized(props: any) { | ||
if (!widgetMockEnabled) { | ||
return <Implementation {...props} />; | ||
} | ||
if (Skeleton) { | ||
return <Skeleton {...props} />; | ||
} | ||
return null; | ||
}; | ||
}; | ||
} | ||
|
||
jest.mock('../../../lib/components/internal/widgets', () => ({ | ||
createWidgetizedComponent: createWidgetizedComponentMock, | ||
})); | ||
|
||
describeEachAppLayout({ themes: ['refresh-toolbar'] }, () => { | ||
it('renders complete component by default', () => { | ||
const { wrapper } = renderComponent( | ||
<AppLayout | ||
navigation="test nav" | ||
breadcrumbs={<BreadcrumbGroup items={[{ text: 'Home', href: '' }]} />} | ||
tools="test tools" | ||
/> | ||
); | ||
expect(wrapper.findToolbar()).toBeTruthy(); | ||
expect(wrapper.findNavigation()).toBeTruthy(); | ||
expect(wrapper.findBreadcrumbs()).toBeTruthy(); | ||
expect(wrapper.find(getFunnelKeySelector('funnel-name'))).toBeTruthy(); | ||
expect(wrapper.findTools()).toBeTruthy(); | ||
expect(wrapper.findContentRegion()).toBeTruthy(); | ||
}); | ||
|
||
describe('in loading state', () => { | ||
beforeEach(() => { | ||
widgetMockEnabled = true; | ||
}); | ||
afterEach(() => { | ||
widgetMockEnabled = false; | ||
}); | ||
|
||
it('renders skeleton parts only', () => { | ||
const { wrapper } = renderComponent( | ||
<AppLayout | ||
navigation="test nav" | ||
breadcrumbs={<BreadcrumbGroup items={[{ text: 'Home', href: '' }]} />} | ||
tools="test tools" | ||
/> | ||
); | ||
expect(wrapper.findToolbar()).toBeFalsy(); | ||
expect(wrapper.findNavigation()).toBeFalsy(); | ||
expect(wrapper.findBreadcrumbs()).toBeFalsy(); | ||
expect(wrapper.find(getFunnelKeySelector('funnel-name'))).toBeTruthy(); | ||
expect(wrapper.findTools()).toBeFalsy(); | ||
expect(wrapper.findContentRegion()).toBeTruthy(); | ||
}); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
src/app-layout/visual-refresh-toolbar/skeleton/breadcrumbs/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import React from 'react'; | ||
|
||
import { BreadcrumbGroupImplementation } from '../../../../breadcrumb-group/implementation'; | ||
import { BreadcrumbGroupProps } from '../../../../breadcrumb-group/interfaces'; | ||
import { BreadcrumbsSlotContext } from '../../contexts'; | ||
|
||
import styles from './styles.css.js'; | ||
|
||
interface BreadcrumbsSlotProps { | ||
ownBreadcrumbs: React.ReactNode; | ||
discoveredBreadcrumbs: BreadcrumbGroupProps | null; | ||
} | ||
|
||
export function BreadcrumbsSlot({ ownBreadcrumbs, discoveredBreadcrumbs }: BreadcrumbsSlotProps) { | ||
return ( | ||
<BreadcrumbsSlotContext.Provider value={{ isInToolbar: true }}> | ||
<div className={styles['breadcrumbs-own']}>{ownBreadcrumbs}</div> | ||
{discoveredBreadcrumbs && ( | ||
<div className={styles['breadcrumbs-discovered']}> | ||
<BreadcrumbGroupImplementation | ||
{...discoveredBreadcrumbs} | ||
data-awsui-discovered-breadcrumbs={true} | ||
__injectAnalyticsComponentMetadata={true} | ||
/> | ||
</div> | ||
)} | ||
</BreadcrumbsSlotContext.Provider> | ||
); | ||
} |
13 changes: 13 additions & 0 deletions
13
src/app-layout/visual-refresh-toolbar/skeleton/breadcrumbs/styles.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
// backward compatibility before this commit: 7a4b7b3e3b1d50830383805a8f4ab6cd93c9701f | ||
.breadcrumbs-own:not(:empty) + .breadcrumbs-discovered { | ||
display: none; | ||
} | ||
|
||
.block-body-scroll { | ||
overflow: hidden; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/app-layout/visual-refresh-toolbar/skeleton/toolbar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import React from 'react'; | ||
|
||
import { AppLayoutToolbarImplementationProps } from '../toolbar'; | ||
import { BreadcrumbsSlot } from './breadcrumbs'; | ||
import { ToolbarSlot } from './slot-wrappers'; | ||
|
||
export const ToolbarSkeleton = React.forwardRef<HTMLElement, AppLayoutToolbarImplementationProps>( | ||
({ appLayoutInternals }: AppLayoutToolbarImplementationProps, ref) => ( | ||
<ToolbarSlot ref={ref}> | ||
<BreadcrumbsSlot | ||
ownBreadcrumbs={appLayoutInternals.breadcrumbs} | ||
discoveredBreadcrumbs={appLayoutInternals.discoveredBreadcrumbs} | ||
/> | ||
</ToolbarSlot> | ||
) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.