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

Split layout / view options. Use active layout icon for the layout button #63205

Merged
merged 3 commits into from
Jul 9, 2024
Merged
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
153 changes: 81 additions & 72 deletions packages/dataviews/src/view-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { ChangeEvent } from 'react';
import {
Button,
privateApis as componentsPrivateApis,
__experimentalHStack as HStack,
} from '@wordpress/components';
import { __, _x } from '@wordpress/i18n';
import { memo } from '@wordpress/element';
Expand Down Expand Up @@ -75,51 +76,34 @@ function ViewTypeMenu( {
if ( _availableViews.length === 1 ) {
return null;
}
const activeView = _availableViews.find( ( v ) => view.type === v.type );
return (
<DropdownMenu
trigger={
<DropdownMenuItem
suffix={
<span aria-hidden="true">{ activeView?.label }</span>
return _availableViews.map( ( availableView ) => {
return (
<DropdownMenuRadioItem
key={ availableView.type }
value={ availableView.type }
name="view-actions-available-view"
checked={ availableView.type === view.type }
hideOnClick
onChange={ ( e: ChangeEvent< HTMLInputElement > ) => {
switch ( e.target.value ) {
case 'list':
case 'grid':
case 'table':
return onChangeView( {
...view,
type: e.target.value,
layout: {},
} );
}
>
<DropdownMenuItemLabel>
{ __( 'Layout' ) }
</DropdownMenuItemLabel>
</DropdownMenuItem>
}
>
{ _availableViews.map( ( availableView ) => {
return (
<DropdownMenuRadioItem
key={ availableView.type }
value={ availableView.type }
name="view-actions-available-view"
checked={ availableView.type === view.type }
hideOnClick
onChange={ ( e: ChangeEvent< HTMLInputElement > ) => {
switch ( e.target.value ) {
case 'list':
case 'grid':
case 'table':
return onChangeView( {
...view,
type: e.target.value,
layout: {},
} );
}
throw new Error( 'Invalid dataview' );
} }
>
<DropdownMenuItemLabel>
{ availableView.label }
</DropdownMenuItemLabel>
</DropdownMenuRadioItem>
);
} ) }
</DropdownMenu>
);
throw new Error( 'Invalid dataview' );
} }
>
<DropdownMenuItemLabel>
{ availableView.label }
</DropdownMenuItemLabel>
</DropdownMenuRadioItem>
);
} );
}

const PAGE_SIZE_VALUES = [ 10, 20, 50, 100 ];
Expand Down Expand Up @@ -305,35 +289,60 @@ function _ViewActions< Item >( {
onChangeView,
supportedLayouts,
}: ViewActionsProps< Item > ) {
const activeView = VIEW_LAYOUTS.find( ( v ) => view.type === v.type );
return (
<DropdownMenu
trigger={
<Button
size="compact"
icon={ cog }
label={ _x( 'View options', 'View is used as a noun' ) }
/>
}
>
<DropdownMenuGroup>
<ViewTypeMenu
view={ view }
onChangeView={ onChangeView }
supportedLayouts={ supportedLayouts }
/>
<SortMenu
fields={ fields }
view={ view }
onChangeView={ onChangeView }
/>
<FieldsVisibilityMenu
fields={ fields }
view={ view }
onChangeView={ onChangeView }
/>
<PageSizeMenu view={ view } onChangeView={ onChangeView } />
</DropdownMenuGroup>
</DropdownMenu>
<>
<HStack
spacing={ 1 }
expanded={ false }
style={ { flexShrink: 0 } }
>
<DropdownMenu
trigger={
<Button
size="compact"
icon={ activeView?.icon }
label={ __( 'Layout' ) }
/>
}
>
<ViewTypeMenu
view={ view }
onChangeView={ onChangeView }
supportedLayouts={ supportedLayouts }
/>
</DropdownMenu>
<DropdownMenu
trigger={
<Button
size="compact"
icon={ cog }
label={ _x(
'View options',
'View is used as a noun'
) }
/>
}
>
<DropdownMenuGroup>
<SortMenu
fields={ fields }
view={ view }
onChangeView={ onChangeView }
/>
<FieldsVisibilityMenu
fields={ fields }
view={ view }
onChangeView={ onChangeView }
/>
<PageSizeMenu
view={ view }
onChangeView={ onChangeView }
/>
</DropdownMenuGroup>
</DropdownMenu>
</HStack>
</>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ test.describe( 'Dataviews List Layout', () => {
page.getByRole( 'button', { name: 'Reset' } )
).toBeFocused();

await page.keyboard.press( 'Tab' );
await expect(
page.getByRole( 'button', { name: 'Layout' } )
).toBeFocused();

await page.keyboard.press( 'Tab' );
await expect(
page.getByRole( 'button', { name: 'View options' } )
Expand All @@ -69,6 +74,7 @@ test.describe( 'Dataviews List Layout', () => {
await page.keyboard.press( 'Tab' );
await page.keyboard.press( 'Tab' );
await page.keyboard.press( 'Tab' );
await page.keyboard.press( 'Tab' );

// Make sure the items have loaded before reaching for the 1st item in the list.
await expect( page.getByRole( 'grid' ) ).toBeVisible();
Expand Down Expand Up @@ -98,6 +104,7 @@ test.describe( 'Dataviews List Layout', () => {
await page.keyboard.press( 'Tab' );
await page.keyboard.press( 'Tab' );
await page.keyboard.press( 'Tab' );
await page.keyboard.press( 'Tab' );

// Make sure the items have loaded before reaching for the 1st item in the list.
await expect( page.getByRole( 'grid' ) ).toBeVisible();
Expand All @@ -121,6 +128,7 @@ test.describe( 'Dataviews List Layout', () => {
await page.keyboard.press( 'Tab' );
await page.keyboard.press( 'Tab' );
await page.keyboard.press( 'Tab' );
await page.keyboard.press( 'Tab' );

// Make sure the items have loaded before reaching for the 1st item in the list.
await expect( page.getByRole( 'grid' ) ).toBeVisible();
Expand Down Expand Up @@ -162,6 +170,7 @@ test.describe( 'Dataviews List Layout', () => {
await page.keyboard.press( 'Tab' );
await page.keyboard.press( 'Tab' );
await page.keyboard.press( 'Tab' );
await page.keyboard.press( 'Tab' );

// Make sure the items have loaded before reaching for the 1st item in the list.
await expect( page.getByRole( 'grid' ) ).toBeVisible();
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/specs/site-editor/new-templates-list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ test.describe( 'Templates', () => {
test( 'Field visibility', async ( { admin, page } ) => {
await admin.visitSiteEditor( { postType: 'wp_template' } );

await page.getByRole( 'button', { name: 'View options' } ).click();
await page.getByRole( 'menuitem', { name: 'Layout' } ).click();
await page.getByRole( 'button', { name: 'Layout' } ).click();
await page.getByRole( 'menuitemradio', { name: 'Table' } ).click();

await page.getByRole( 'button', { name: 'Description' } ).click();
Expand Down
8 changes: 2 additions & 6 deletions test/performance/specs/site-editor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,11 @@ test.describe( 'Site Editor Performance', () => {
// If it's there, switch to the list layout before running the test.
// See https://github.com/WordPress/gutenberg/pull/59792
const isDataViewsUI = await page
.getByRole( 'button', { name: 'View options' } )
.getByRole( 'button', { name: 'Layout' } )
.isVisible();
if ( isDataViewsUI ) {
await page
.getByRole( 'button', { name: 'View options' } )
.click();
await page
.getByRole( 'menuitem' )
.filter( { has: page.getByText( 'Layout' ) } )
.getByRole( 'button', { name: 'Layout' } )
.click();
await page
.getByRole( 'menuitemradio' )
Expand Down
Loading