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

DataViews: Use Dropdown for views config dialog #65314

Merged
merged 1 commit into from
Sep 13, 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
48 changes: 23 additions & 25 deletions packages/dataviews/src/components/dataviews-view-config/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { ChangeEvent } from 'react';
*/
import {
Button,
Popover,
Dropdown,
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
__experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon,
Expand All @@ -24,7 +24,7 @@ import {
BaseControl,
} from '@wordpress/components';
import { __, _x, sprintf } from '@wordpress/i18n';
import { memo, useContext, useState, useMemo } from '@wordpress/element';
import { memo, useContext, useMemo } from '@wordpress/element';
import { chevronDown, chevronUp, cog, seen, unseen } from '@wordpress/icons';
import warning from '@wordpress/warning';

Expand Down Expand Up @@ -549,34 +549,32 @@ function _DataViewsViewConfig( {
setDensity: React.Dispatch< React.SetStateAction< number > >;
defaultLayouts?: SupportedLayouts;
} ) {
const [ isShowingViewPopover, setIsShowingViewPopover ] =
useState< boolean >( false );

return (
<>
<ViewTypeMenu defaultLayouts={ defaultLayouts } />
<div>
<Button
size="compact"
icon={ cog }
label={ _x( 'View options', 'View is used as a noun' ) }
onClick={ () => setIsShowingViewPopover( true ) }
/>
{ isShowingViewPopover && (
<Popover
placement="bottom-end"
onClose={ () => {
setIsShowingViewPopover( false );
} }
focusOnMount
>
<DataviewsViewConfigContent
density={ density }
setDensity={ setDensity }
<Dropdown
popoverProps={ { placement: 'bottom-end', offset: 9 } }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be extracted as a constant object, to avoid passing a new instance every re-render

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also done in #65373

contentClassName="dataviews-view-config"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dataviews-view-config classname is already used for the VStack in the DataviewsViewConfigContent, which causes some styles to be unexpectedly applied to two elements at the same time. We should probably remove this instance.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also fixed in #65373

renderToggle={ ( { onToggle } ) => {
return (
<Button
size="compact"
icon={ cog }
label={ _x(
'View options',
'View is used as a noun'
) }
onClick={ onToggle }
/>
</Popover>
);
} }
renderContent={ () => (
<DataviewsViewConfigContent
density={ density }
setDensity={ setDensity }
/>
) }
</div>
/>
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
.dataviews-view-config {
width: 320px;
/* stylelint-disable-next-line property-no-unknown -- the linter needs to be updated to accepted the container-type property */
container-type: inline-size;
padding: $grid-unit-20;
font-size: $default-font-size;
line-height: $default-line-height;
.components-popover__content {
Copy link
Contributor

@ciampo ciampo Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using internal component classnames can really hinder our ability to make changes to the components without causing unintended breaking changes.

In this case, we can use the DropdownContentWrapper component, which is used specifically to set custom padding for dropdown content. I will open a separate PR to make the change

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your follow up! I wasn't aware of DropdownContentWrapper.

width: 320px;
/* stylelint-disable-next-line property-no-unknown -- the linter needs to be updated to accepted the container-type property */
container-type: inline-size;
padding: $grid-unit-20;
font-size: $default-font-size;
line-height: $default-line-height;
}
}

.dataviews-view-config__sort-direction .components-toggle-group-control-option-base {
text-transform: uppercase;
}
Expand Down
Loading