Repository navigation
Dashboard: show ghost widgets visually & allow easy removal #78502
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
328c55c
Dashboard: render message for missing widgets
simison 53b3548
Simplify without util
simison 62c9cbb
Use Icon
simison ed8ccec
Simplify without Stack
simison 0a389cd
Use UI Icon
simison 2ca7803
Use UI Icon for all icons
simison ce576c8
Show loading state while widgets are resolving
simison a379a5c
Fix test
simison bed5ada
Remove "remove" button
simison a6a3e74
Use suppresssions.json
simison 1ed3f7a
Fix
simison 4b57739
Fix test
simison 8d9494f
Prettier
simison ae99b76
Review
simison File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -80,6 +80,8 @@ | |
| margin-block-end: 0; | ||
| } | ||
|
|
||
| .loading { | ||
| .loading, | ||
| .unavailable { | ||
| height: 100%; | ||
| } | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ import type { ReactNode } from 'react'; | |
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { Icon as WCIcon, Spinner } from '@wordpress/components'; | ||
| import { Spinner } from '@wordpress/components'; | ||
| import { | ||
| Component, | ||
| Suspense, | ||
|
|
@@ -16,9 +16,8 @@ import { | |
| useMemo, | ||
| } from '@wordpress/element'; | ||
| import { __ } from '@wordpress/i18n'; | ||
| // Dashboard is still experimental. | ||
| // eslint-disable-next-line @wordpress/use-recommended-components | ||
| import { Card, Stack, Notice, VisuallyHidden } from '@wordpress/ui'; | ||
| import { plugins } from '@wordpress/icons'; | ||
| import { Card, Icon, Stack, Notice, Text, VisuallyHidden } from '@wordpress/ui'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
|
|
@@ -69,6 +68,37 @@ function LoadingOverlay() { | |
| ); | ||
| } | ||
|
|
||
| interface UnavailableWidgetProps { | ||
| widgetTypeName: string; | ||
| } | ||
|
|
||
| function UnavailableWidget( { widgetTypeName }: UnavailableWidgetProps ) { | ||
| return ( | ||
| <> | ||
| <Card.Header> | ||
| <span | ||
| className={ styles.widgetChromeHeaderIcon } | ||
| aria-hidden="true" | ||
| > | ||
| <Icon icon={ plugins } /> | ||
| </span> | ||
| </Card.Header> | ||
| <Card.Content className={ styles.widgetChromeContent }> | ||
| <Stack | ||
| direction="column" | ||
| justify="center" | ||
| align="center" | ||
| gap="md" | ||
| className={ styles.unavailable } | ||
| > | ||
| <Text>{ __( 'Widget is no longer available.' ) }</Text> | ||
| <Text render={ <code /> }>{ widgetTypeName }</Text> | ||
| </Stack> | ||
| </Card.Content> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| interface HeaderProps { | ||
| titleId: string; | ||
| widgetType: WidgetType; | ||
|
|
@@ -87,7 +117,7 @@ function Header( { titleId, widgetType }: HeaderProps ) { | |
| className={ styles.widgetChromeHeaderIcon } | ||
| aria-hidden="true" | ||
| > | ||
| <WCIcon icon={ widgetType.icon } /> | ||
| <Icon icon={ widgetType.icon } /> | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| </span> | ||
| ) } | ||
| <Card.Title id={ titleId } render={ <h3 /> }> | ||
|
|
@@ -119,7 +149,8 @@ export interface WidgetChromeProps { | |
| */ | ||
| export const WidgetChrome = forwardRef< HTMLDivElement, WidgetChromeProps >( | ||
| function WidgetChrome( { widget, index, className }, ref ) { | ||
| const { widgetTypes, editMode } = useDashboardInternalContext(); | ||
| const { widgetTypes, isResolvingWidgetTypes, editMode } = | ||
| useDashboardInternalContext(); | ||
| const widgetType = widgetTypes.find( ( t ) => t.name === widget.type ); | ||
| const titleId = useId(); | ||
|
|
||
|
|
@@ -133,7 +164,38 @@ export const WidgetChrome = forwardRef< HTMLDivElement, WidgetChromeProps >( | |
| ); | ||
|
|
||
| if ( ! widgetType ) { | ||
| return null; | ||
| if ( isResolvingWidgetTypes ) { | ||
| return ( | ||
| <WidgetContextProvider value={ contextValue }> | ||
| <Card.Root | ||
| render={ <section /> } | ||
| ref={ ref } | ||
| className={ clsx( styles.widgetChrome, className ) } | ||
| aria-busy="true" | ||
| aria-label={ __( 'Loading' ) } | ||
| > | ||
| <Card.Content | ||
| className={ styles.widgetChromeContent } | ||
| > | ||
| <LoadingOverlay /> | ||
| </Card.Content> | ||
| </Card.Root> | ||
| </WidgetContextProvider> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <WidgetContextProvider value={ contextValue }> | ||
| <Card.Root | ||
| render={ <section /> } | ||
| ref={ ref } | ||
| className={ clsx( styles.widgetChrome, className ) } | ||
| aria-label={ __( 'Missing widget' ) } | ||
| > | ||
| <UnavailableWidget widgetTypeName={ widget.type } /> | ||
| </Card.Root> | ||
| </WidgetContextProvider> | ||
| ); | ||
| } | ||
|
|
||
| // `presentation` encodes two independent axes. `full-bleed` hides | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
Iconfrom@wordpress/uiwas already done in #78440, but then I accidentally reverted it in rebase of another PR.So this just returns it back to the previous state; could do a separate PR, but it seems fine here too.