Skip to content

Commit

Permalink
enhacements
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Aug 7, 2024
1 parent d332d33 commit 006fb8c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 49 deletions.
74 changes: 36 additions & 38 deletions packages/dataviews/src/components/dataviews-view-config/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Popover,
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
__experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon,
SelectControl,
__experimentalItemGroup as ItemGroup,
__experimentalItem as Item,
Expand All @@ -29,7 +30,7 @@ import warning from '@wordpress/warning';
/**
* Internal dependencies
*/
import { SORTING_DIRECTIONS, sortLabelsShort } from '../../constants';
import { SORTING_DIRECTIONS, sortIcons, sortLabels } from '../../constants';
import { VIEW_LAYOUTS, getMandatoryFields } from '../../dataviews-layouts';
import type { SupportedLayouts } from '../../types';
import DataViewsContext from '../dataviews-context';
Expand Down Expand Up @@ -60,9 +61,9 @@ function ViewTypeMenu( {
<Button
size="compact"
icon={ activeView?.icon }
label={ __( 'Layout' ) }
label={ __( 'Layout' ) }
/>
}
}
>
{ availableLayouts.map( ( layout ) => {
const config = VIEW_LAYOUTS.find( ( v ) => v.type === layout );
Expand Down Expand Up @@ -168,10 +169,11 @@ function SortDirectionControl() {
>
{ SORTING_DIRECTIONS.map( ( direction ) => {
return (
<ToggleGroupControlOption
<ToggleGroupControlOptionIcon
key={ direction }
value={ direction }
label={ sortLabelsShort[ direction ] }
icon={ sortIcons[ direction ] }
label={ sortLabels[ direction ] }
/>
);
} ) }
Expand Down Expand Up @@ -270,7 +272,7 @@ function SettingsSection( {
children,
}: {
title: string;
description: string;
description?: string;
children: React.ReactNode;
} ) {
return (
Expand All @@ -282,12 +284,14 @@ function SettingsSection( {
>
{ title }
</Heading>
<Text
variant="muted"
className="dataviews-settings-section__description"
>
{ description }
</Text>
{ description && (
<Text
variant="muted"
className="dataviews-settings-section__description"
>
{ description }
</Text>
) }
</div>
<Grid
columns={ 8 }
Expand All @@ -303,20 +307,14 @@ function SettingsSection( {
function DataviewsViewConfigContent() {
return (
<VStack className="dataviews-view-config" spacing={ 6 }>
<SettingsSection
title={ __( 'Appearance' ) }
description={ __( 'Customize the display of data' ) }
>
<SettingsSection title={ __( 'Appearance' ) }>
<HStack expanded className="is-divided-in-two">
<SortFieldControl />
<SortDirectionControl />
</HStack>
<ItemsPerPageControl />
</SettingsSection>
<SettingsSection
title={ __( 'Properties' ) }
description={ __( 'Manage property order and display' ) }
>
<SettingsSection title={ __( 'Properties' ) }>
<FieldControl />
</SettingsSection>
</VStack>
Expand All @@ -332,25 +330,25 @@ function _DataViewsViewConfig( {
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
>
<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 />
</Popover>
) }
</div>
</Popover>
) }
</div>
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.dataviews-view-config {
width: 363px;
width: 320px;
container-type: inline-size;
padding: $grid-unit-20;
}
Expand Down
15 changes: 5 additions & 10 deletions packages/dataviews/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* WordPress dependencies
*/
import { __, _x } from '@wordpress/i18n';
import { __ } from '@wordpress/i18n';
import { arrowDown, arrowUp } from '@wordpress/icons';

/**
* Internal dependencies
Expand Down Expand Up @@ -58,15 +59,9 @@ export const sortLabels = {
asc: __( 'Sort ascending' ),
desc: __( 'Sort descending' ),
};
export const sortLabelsShort = {
asc: _x(
'Asc',
'Short label for ascending sorting, should be at most 6 characters'
),
desc: _x(
'Desc',
'Short label for descending sorting, should be at most 6 characters'
),
export const sortIcons = {
asc: arrowUp,
desc: arrowDown,
};

// View layouts.
Expand Down

0 comments on commit 006fb8c

Please sign in to comment.