Repository navigation
DataViews: Add onReset prop for view persistence reset #75093
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
Changes from all commits
7bfe139
9268ac6
63351fe
d6dbe5b
94af1b4
58c9cc8
4295d7d
42c5f6b
6b04e37
94fe802
a1ee3f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,9 +14,7 @@ import { | |
| __experimentalToggleGroupControlOption as ToggleGroupControlOption, | ||
| __experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon, | ||
| SelectControl, | ||
| __experimentalGrid as Grid, | ||
| __experimentalHeading as Heading, | ||
| __experimentalText as Text, | ||
| privateApis as componentsPrivateApis, | ||
| } from '@wordpress/components'; | ||
| import { __, _x } from '@wordpress/i18n'; | ||
|
|
@@ -247,53 +245,44 @@ function ItemsPerPageControl() { | |
| ); | ||
| } | ||
|
|
||
| function SettingsSection( { | ||
| title, | ||
| description, | ||
| children, | ||
| }: { | ||
| title: string; | ||
| description?: string; | ||
| children: React.ReactNode; | ||
| } ) { | ||
| function ResetViewButton() { | ||
| const { onReset } = useContext( DataViewsContext ); | ||
|
|
||
| // Don't render if no persistence support (onReset is undefined) | ||
| if ( onReset === undefined ) { | ||
| return null; | ||
| } | ||
|
|
||
| const isDisabled = onReset === false; | ||
|
|
||
| return ( | ||
| <Grid columns={ 12 } className="dataviews-settings-section" gap={ 4 }> | ||
|
youknowriad marked this conversation as resolved.
Resolved
|
||
| <div className="dataviews-settings-section__sidebar"> | ||
| <Heading | ||
| level={ 2 } | ||
| className="dataviews-settings-section__title" | ||
| > | ||
| { title } | ||
| </Heading> | ||
| { description && ( | ||
| <Text | ||
| variant="muted" | ||
| className="dataviews-settings-section__description" | ||
| > | ||
| { description } | ||
| </Text> | ||
| ) } | ||
| </div> | ||
| <Grid | ||
| columns={ 8 } | ||
| gap={ 4 } | ||
| className="dataviews-settings-section__content" | ||
| > | ||
| { children } | ||
| </Grid> | ||
| </Grid> | ||
| <Button | ||
|
Contributor
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. Should we use the Button component from the
Contributor
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. This would have a lot of impacts (We'd need to support user color profiles ... which is currently broken if you use cc @aduth as we discussed this elsewhere, see how this seemingly naive suggestion would have broken things. |
||
| variant="tertiary" | ||
| size="compact" | ||
| disabled={ isDisabled } | ||
| accessibleWhenDisabled | ||
| className="dataviews-view-config__reset-button" | ||
| onClick={ () => { | ||
| if ( typeof onReset === 'function' ) { | ||
| onReset(); | ||
| } | ||
| } } | ||
| > | ||
| { __( 'Reset view' ) } | ||
| </Button> | ||
| ); | ||
| } | ||
|
|
||
| export function DataviewsViewConfigDropdown() { | ||
| const { view } = useContext( DataViewsContext ); | ||
| const { view, onReset } = useContext( DataViewsContext ); | ||
| const popoverId = useInstanceId( | ||
| _DataViewsViewConfig, | ||
| 'dataviews-view-config-dropdown' | ||
| ); | ||
| const activeLayout = VIEW_LAYOUTS.find( | ||
| ( layout ) => layout.type === view.type | ||
| ); | ||
| const isModified = typeof onReset === 'function'; | ||
| return ( | ||
| <Dropdown | ||
| expandOnMobile | ||
|
|
@@ -303,14 +292,22 @@ export function DataviewsViewConfigDropdown() { | |
| } } | ||
| renderToggle={ ( { onToggle, isOpen } ) => { | ||
| return ( | ||
| <Button | ||
| size="compact" | ||
| icon={ cog } | ||
| label={ _x( 'View options', 'View is used as a noun' ) } | ||
| onClick={ onToggle } | ||
| aria-expanded={ isOpen ? 'true' : 'false' } | ||
| aria-controls={ popoverId } | ||
| /> | ||
| <div className="dataviews-view-config__toggle-wrapper"> | ||
| <Button | ||
| size="compact" | ||
| icon={ cog } | ||
| label={ _x( | ||
| 'View options', | ||
| 'View is used as a noun' | ||
| ) } | ||
| onClick={ onToggle } | ||
| aria-expanded={ isOpen ? 'true' : 'false' } | ||
| aria-controls={ popoverId } | ||
| /> | ||
| { isModified && ( | ||
| <span className="dataviews-view-config__modified-indicator" /> | ||
| ) } | ||
| </div> | ||
| ); | ||
| } } | ||
| renderContent={ () => ( | ||
|
|
@@ -323,11 +320,25 @@ export function DataviewsViewConfigDropdown() { | |
| className="dataviews-view-config" | ||
| gap="xl" | ||
| > | ||
| <SettingsSection title={ __( 'Appearance' ) }> | ||
| <Stack | ||
| direction="row" | ||
| justify="space-between" | ||
| align="center" | ||
| className="dataviews-view-config__header" | ||
| > | ||
| <Heading | ||
| level={ 2 } | ||
| className="dataviews-settings-section__title" | ||
| > | ||
| { __( 'Appearance' ) } | ||
| </Heading> | ||
| <ResetViewButton /> | ||
| </Stack> | ||
| <Stack direction="column" gap="lg"> | ||
| <Stack | ||
| direction="row" | ||
| gap="sm" | ||
| className="is-divided-in-two" | ||
| className="dataviews-view-config__sort-controls" | ||
| > | ||
| <SortFieldControl /> | ||
| <SortDirectionControl /> | ||
|
|
@@ -338,7 +349,7 @@ export function DataviewsViewConfigDropdown() { | |
| <InfiniteScrollToggle /> | ||
| <ItemsPerPageControl /> | ||
| <PropertiesSection /> | ||
| </SettingsSection> | ||
| </Stack> | ||
| </Stack> | ||
| </DropdownContentWrapper> | ||
| ) } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.