Skip to content

Commit

Permalink
Add separator
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Nov 29, 2023
1 parent 546335f commit bb6935b
Showing 1 changed file with 91 additions and 82 deletions.
173 changes: 91 additions & 82 deletions packages/edit-site/src/components/dataviews/view-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,91 +185,100 @@ function HeaderMenu( { dataView, header } ) {
</DropdownSubMenuTrigger>
}
>
{ filter.elements.map( ( element ) => {
let isActive = false;
if ( filterInView ) {
// Intentionally use loose comparison, so it does type conversion.
// This covers the case where a top-level filter for the same field converts a number into a string.
isActive =
element.value == filterInView.value; // eslint-disable-line eqeqeq
}

return (
<DropdownMenuItem
key={ element.value }
suffix={
isActive && <Icon icon={ check } />
}
onSelect={ () => {
dataView.setColumnFilters( [
...otherFilters,
{
[ filter.field +
':' +
filterInView?.operator ]:
isActive
? undefined
: element.value,
},
] );
} }
>
{ element.label }
</DropdownMenuItem>
);
} ) }
{ filter.operators.length > 1 && (
<DropdownSubMenu
trigger={
<DropdownSubMenuTrigger>
{ __( 'Settings' ) }
</DropdownSubMenuTrigger>
}
>
<DropdownMenuCheckboxItem
key="in-filter"
value={ OPERATOR_IN }
checked={
filterInView?.operator ===
OPERATOR_IN
<WithSeparators>
<DropdownMenuGroup>
{ filter.elements.map( ( element ) => {
let isActive = false;
if ( filterInView ) {
// Intentionally use loose comparison, so it does type conversion.
// This covers the case where a top-level filter for the same field converts a number into a string.
/* eslint-disable eqeqeq */
isActive =
element.value ==
filterInView.value;
/* eslint-enable eqeqeq */
}
onSelect={ () =>
dataView.setColumnFilters( [
...otherFilters,
{
[ filter.field +
':' +
OPERATOR_IN ]:
filterInView?.value,
},
] )
}
>
{ __( 'Show matches' ) }
</DropdownMenuCheckboxItem>
<DropdownMenuCheckboxItem
key="not-in-filter"
value={ OPERATOR_NOT_IN }
checked={
filterInView?.operator ===
OPERATOR_NOT_IN
}
onSelect={ () =>
dataView.setColumnFilters( [
...otherFilters,
{
[ filter.field +
':' +
OPERATOR_NOT_IN ]:
filterInView?.value,
},
] )

return (
<DropdownMenuItem
key={ element.value }
suffix={
isActive && (
<Icon icon={ check } />
)
}
onSelect={ () => {
dataView.setColumnFilters( [
...otherFilters,
{
[ filter.field +
':' +
filterInView?.operator ]:
isActive
? undefined
: element.value,
},
] );
} }
>
{ element.label }
</DropdownMenuItem>
);
} ) }
</DropdownMenuGroup>
{ filter.operators.length > 1 && (
<DropdownSubMenu
trigger={
<DropdownSubMenuTrigger>
{ __( 'Settings' ) }
</DropdownSubMenuTrigger>
}
>
{ __( 'Hide matches' ) }
</DropdownMenuCheckboxItem>
</DropdownSubMenu>
) }
<DropdownMenuCheckboxItem
key="in-filter"
value={ OPERATOR_IN }
checked={
filterInView?.operator ===
OPERATOR_IN
}
onSelect={ () =>
dataView.setColumnFilters( [
...otherFilters,
{
[ filter.field +
':' +
OPERATOR_IN ]:
filterInView?.value,
},
] )
}
>
{ __( 'Show matches' ) }
</DropdownMenuCheckboxItem>
<DropdownMenuCheckboxItem
key="not-in-filter"
value={ OPERATOR_NOT_IN }
checked={
filterInView?.operator ===
OPERATOR_NOT_IN
}
onSelect={ () =>
dataView.setColumnFilters( [
...otherFilters,
{
[ filter.field +
':' +
OPERATOR_NOT_IN ]:
filterInView?.value,
},
] )
}
>
{ __( 'Hide matches' ) }
</DropdownMenuCheckboxItem>
</DropdownSubMenu>
) }
</WithSeparators>
</DropdownSubMenu>
</DropdownMenuGroup>
) }
Expand Down

0 comments on commit bb6935b

Please sign in to comment.