-
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
6 changed files
with
76 additions
and
5 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
55 changes: 55 additions & 0 deletions
55
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,55 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
__experimentalToggleGroupControl as ToggleGroupControl, | ||
__experimentalToggleGroupControlOption as ToggleGroupControlOption, | ||
} 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 ( | ||
<ToggleGroupControl | ||
__nextHasNoMarginBottom | ||
__next40pxDefaultSize | ||
isBlock | ||
label={ __( 'Hierarchy' ) } | ||
value={ | ||
view.layout?.hierarchicalSort === true ? 'enabled' : 'disabled' | ||
} | ||
onChange={ ( value ) => { | ||
onChangeView( { | ||
...view, | ||
layout: { | ||
...view.layout, | ||
hierarchicalSort: value === 'enabled', | ||
}, | ||
} ); | ||
} } | ||
> | ||
<ToggleGroupControlOption | ||
key="enabled" | ||
value="enabled" | ||
label={ __( 'Enabled' ) } | ||
/> | ||
<ToggleGroupControlOption | ||
key="disabled" | ||
value="disabled" | ||
label={ __( 'Disabled' ) } | ||
/> | ||
</ToggleGroupControl> | ||
); | ||
} | ||
|
||
export default SortHierarchicalControl; |
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