-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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: implement multiple selection for filters #59610
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
9e792ad
Implement multiple selection in filters
oandregal 0de9f37
Make Sync filter in pattern single selection and remove test from Pages
oandregal 44f3052
Document singleSelection
oandregal e6cc4b0
Implement multiple selection for combobox
oandregal eff89cf
Fix Combobox multiselection
oandregal 7ced562
Add OPERATOR_EQUAL and OPERATOR_NOT_EQUAL
oandregal e9ae362
Sanitize operators: do not allow mixing single&multi selection
oandregal 5608a77
Update docs
oandregal 46da75d
Update docs
oandregal b9237bd
Fix translations
oandregal c432000
Add changelog note
oandregal 91b285a
Truncate text
oandregal d5a4d86
Fix templates & template parts custom filters
oandregal c273bea
Update changelog
oandregal 54ef165
Update terms
oandregal 532d4ee
Fix summary tag
oandregal 2ad3269
Sanitize operators: remove multiselection ops if any single op is pre…
oandregal 8f36ce3
Remove truncation
oandregal 5f3450c
Fix template & parts custom filtering
oandregal 374ad5a
Tag the changes as Enhancements
oandregal bee646a
DataViews: use is/isNot/isAny/isNone operators
oandregal aa6aec0
Site editor: use is/isNot/isAny/isNone operators
oandregal 7e109e1
fixup
oandregal 70e40ed
Update changelog and docs
oandregal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,43 +24,67 @@ import { ENTER, SPACE } from '@wordpress/keycodes'; | |
* Internal dependencies | ||
*/ | ||
import SearchWidget from './search-widget'; | ||
import { OPERATOR_IN, OPERATOR_NOT_IN, OPERATORS } from './constants'; | ||
import { | ||
OPERATORS, | ||
OPERATOR_IS, | ||
OPERATOR_IS_NOT, | ||
OPERATOR_IS_ANY, | ||
OPERATOR_IS_NONE, | ||
} from './constants'; | ||
|
||
const FilterText = ( { activeElement, filterInView, filter } ) => { | ||
if ( activeElement === undefined ) { | ||
const FilterText = ( { activeElements, filterInView, filter } ) => { | ||
if ( activeElements === undefined || activeElements.length === 0 ) { | ||
return filter.name; | ||
} | ||
|
||
const filterTextWrappers = { | ||
Span1: <span className="dataviews-filter-summary__filter-text-name" />, | ||
Span2: <span className="dataviews-filter-summary__filter-text-value" />, | ||
Name: <span className="dataviews-filter-summary__filter-text-name" />, | ||
Value: <span className="dataviews-filter-summary__filter-text-value" />, | ||
}; | ||
|
||
if ( | ||
activeElement !== undefined && | ||
filterInView?.operator === OPERATOR_IN | ||
) { | ||
if ( filterInView?.operator === OPERATOR_IS_ANY ) { | ||
return createInterpolateElement( | ||
sprintf( | ||
/* translators: 1: Filter name. 3: Filter value. e.g.: "Author is any: Admin, Editor". */ | ||
__( '<Name>%1$s is any: </Name><Value>%2$s</Value>' ), | ||
filter.name, | ||
activeElements.map( ( element ) => element.label ).join( ', ' ) | ||
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. I suspect that some (few) locales will want to have a say in the punctuation used to enumerate filters: activeElements.map( ... ).join(
/* translators: string used to join together active filters, e.g. "Author is any: Admin, Editor" */
__( ', ')
) @swissspidy: do you know if this is done elsewhere in WP? |
||
), | ||
filterTextWrappers | ||
); | ||
} | ||
|
||
if ( filterInView?.operator === OPERATOR_IS_NONE ) { | ||
return createInterpolateElement( | ||
sprintf( | ||
/* translators: 1: Filter name. 2: Filter value. e.g.: "Author is Admin". */ | ||
__( '<Span1>%1$s </Span1><Span2>is %2$s</Span2>' ), | ||
/* translators: 1: Filter name. 3: Filter value. e.g.: "Author is none: Admin, Editor". */ | ||
__( '<Name>%1$s is none: </Name><Value>%2$s</Value>' ), | ||
filter.name, | ||
activeElement.label | ||
activeElements.map( ( element ) => element.label ).join( ', ' ) | ||
), | ||
filterTextWrappers | ||
); | ||
} | ||
|
||
if ( | ||
activeElement !== undefined && | ||
filterInView?.operator === OPERATOR_NOT_IN | ||
) { | ||
if ( filterInView?.operator === OPERATOR_IS ) { | ||
return createInterpolateElement( | ||
sprintf( | ||
/* translators: 1: Filter name. 2: Filter value. e.g.: "Author is not Admin". */ | ||
__( '<Span1>%1$s </Span1><Span2>is not %2$s</Span2>' ), | ||
/* translators: 1: Filter name. 3: Filter value. e.g.: "Author is: Admin". */ | ||
__( '<Name>%1$s is: </Name><Value>%2$s</Value>' ), | ||
filter.name, | ||
activeElement.label | ||
activeElements[ 0 ].label | ||
), | ||
filterTextWrappers | ||
); | ||
} | ||
|
||
if ( filterInView?.operator === OPERATOR_IS_NOT ) { | ||
return createInterpolateElement( | ||
sprintf( | ||
/* translators: 1: Filter name. 3: Filter value. e.g.: "Author is not: Admin". */ | ||
__( '<Name>%1$s is not: </Name><Value>%2$s</Value>' ), | ||
filter.name, | ||
activeElements[ 0 ].label | ||
), | ||
filterTextWrappers | ||
); | ||
|
@@ -140,9 +164,12 @@ export default function FilterSummary( { | |
const toggleRef = useRef(); | ||
const { filter, view, onChangeView } = commonProps; | ||
const filterInView = view.filters.find( ( f ) => f.field === filter.field ); | ||
const activeElement = filter.elements.find( | ||
( element ) => element.value === filterInView?.value | ||
); | ||
const activeElements = filter.elements.filter( ( element ) => { | ||
if ( filter.singleSelection ) { | ||
return element.value === filterInView?.value; | ||
} | ||
return filterInView?.value?.includes( element.value ); | ||
} ); | ||
const isPrimary = filter.isPrimary; | ||
const hasValues = filterInView?.value !== undefined; | ||
const canResetOrRemove = ! isPrimary || hasValues; | ||
|
@@ -188,7 +215,7 @@ export default function FilterSummary( { | |
ref={ toggleRef } | ||
> | ||
<FilterText | ||
activeElement={ activeElement } | ||
activeElements={ activeElements } | ||
filterInView={ filterInView } | ||
filter={ filter } | ||
/> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a UX perspective, I wonder if we shouldn't switch the string based on the number of active filters:
… or if that would make things more confusing because "Is:" overlaps with
OPERATOR_IS
. 🤔(I also wonder whether "Is any of" would sound more natural.)