-
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 view config control to switch on/off hierarchical vizualization
- Loading branch information
Showing
3 changed files
with
55 additions
and
2 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
37 changes: 37 additions & 0 deletions
37
packages/dataviews/src/dataviews-layouts/table/sort-hierarchical.tsx
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,37 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { ToggleControl } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useContext } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import DataViewsContext from '../../components/dataviews-context'; | ||
import type { ViewTable } from '../../types'; | ||
|
||
function SortHierarchicalControl() { | ||
const context = useContext( DataViewsContext ); | ||
const view = context.view as ViewTable; | ||
const onChangeView = context.onChangeView; | ||
|
||
return ( | ||
<ToggleControl | ||
__nextHasNoMarginBottom | ||
label={ __( 'Show hierarchy' ) } | ||
checked={ !! view.layout?.hierarchicalSort } | ||
onChange={ ( checked: boolean ) => { | ||
onChangeView( { | ||
...view, | ||
layout: { | ||
...view.layout, | ||
hierarchicalSort: checked, | ||
}, | ||
} ); | ||
} } | ||
/> | ||
); | ||
} | ||
|
||
export default SortHierarchicalControl; |
16 changes: 16 additions & 0 deletions
16
packages/dataviews/src/dataviews-layouts/table/view-config-options.tsx
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,16 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import DensityPicker from './density-picker'; | ||
import SortHierarchical from './sort-hierarchical'; | ||
|
||
function ViewConfigOptions() { | ||
return ( | ||
<> | ||
<SortHierarchical /> | ||
<DensityPicker /> | ||
</> | ||
); | ||
} | ||
|
||
export default ViewConfigOptions; |