-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add author and status filters to the page list (#55270)
- Loading branch information
Showing
7 changed files
with
165 additions
and
17 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import TextFilter from './text-filter'; | ||
import InFilter from './in-filter'; | ||
|
||
export default function Filters( { fields, view, onChangeView } ) { | ||
const filters = {}; | ||
fields.forEach( ( field ) => { | ||
if ( ! field.filters ) { | ||
return; | ||
} | ||
|
||
field.filters.forEach( ( f ) => { | ||
filters[ f.id ] = { type: f.type }; | ||
} ); | ||
} ); | ||
|
||
return ( | ||
view.visibleFilters?.map( ( filterName ) => { | ||
const filter = filters[ filterName ]; | ||
|
||
if ( ! filter ) { | ||
return null; | ||
} | ||
|
||
if ( filter.type === 'search' ) { | ||
return ( | ||
<TextFilter | ||
key={ filterName } | ||
id={ filterName } | ||
view={ view } | ||
onChangeView={ onChangeView } | ||
/> | ||
); | ||
} | ||
if ( filter.type === 'enumeration' ) { | ||
return ( | ||
<InFilter | ||
key={ filterName } | ||
id={ filterName } | ||
fields={ fields } | ||
view={ view } | ||
onChangeView={ onChangeView } | ||
/> | ||
); | ||
} | ||
|
||
return null; | ||
} ) || __( 'No filters available' ) | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
__experimentalInputControlPrefixWrapper as InputControlPrefixWrapper, | ||
SelectControl, | ||
} from '@wordpress/components'; | ||
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { unlock } from '../../lock-unlock'; | ||
|
||
const { cleanEmptyObject } = unlock( blockEditorPrivateApis ); | ||
|
||
export default ( { id, fields, view, onChangeView } ) => { | ||
const field = fields.find( ( f ) => f.id === id ); | ||
|
||
return ( | ||
<SelectControl | ||
value={ view.filters[ id ] } | ||
prefix={ | ||
<InputControlPrefixWrapper | ||
as="span" | ||
className="dataviews__select-control-prefix" | ||
> | ||
{ field.header + ':' } | ||
</InputControlPrefixWrapper> | ||
} | ||
options={ field?.elements || [] } | ||
onChange={ ( value ) => { | ||
if ( value === '' ) { | ||
value = undefined; | ||
} | ||
|
||
onChangeView( ( currentView ) => ( { | ||
...currentView, | ||
filters: cleanEmptyObject( { | ||
...currentView.filters, | ||
[ id ]: value, | ||
} ), | ||
} ) ); | ||
} } | ||
/> | ||
); | ||
}; |
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