-
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 c5a8373
Showing
24 changed files
with
337 additions
and
110 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
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,75 @@ | ||
// 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" | ||
notifications="test notifications" | ||
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.findNotifications()).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" | ||
notifications="test notifications" | ||
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.findNotifications()).toBeFalsy(); | ||
expect(wrapper.findTools()).toBeFalsy(); | ||
expect(wrapper.findContentRegion()).toBeTruthy(); | ||
}); | ||
}); | ||
}); |
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
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> | ||
); | ||
} |
9 changes: 9 additions & 0 deletions
9
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,9 @@ | ||
/* | ||
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; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/app-layout/visual-refresh-toolbar/skeleton/slot-skeletons.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,23 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import React from 'react'; | ||
|
||
import { AppLayoutNotificationsImplementationProps } from '../notifications'; | ||
import { AppLayoutToolbarImplementationProps } from '../toolbar'; | ||
import { BreadcrumbsSlot } from './breadcrumbs'; | ||
import { NotificationsSlot, 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> | ||
) | ||
); | ||
|
||
export const NotificationsSkeleton = React.forwardRef<HTMLElement, AppLayoutNotificationsImplementationProps>( | ||
(props: AppLayoutNotificationsImplementationProps, ref) => <NotificationsSlot ref={ref} /> | ||
); |
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.