-
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.
Navigation: Use the ListView in the Navigation block inspector contro…
…ls (#49417) * avigtion: Use the ListView in the Navigation block inspector controls * use the hook from list view * remove prop drilling * remove prop drilling * Allow list view to scroll * add custom scrollbars on hover * update navigation block tests to account for using the list view * fix test
- Loading branch information
Showing
6 changed files
with
159 additions
and
31 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
43 changes: 43 additions & 0 deletions
43
packages/block-library/src/navigation-link/use-inserted-block.js
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,43 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { store as blockEditorStore } from '@wordpress/block-editor'; | ||
|
||
export const useInsertedBlock = ( insertedBlockClientId ) => { | ||
const { insertedBlockAttributes, insertedBlockName } = useSelect( | ||
( select ) => { | ||
const { getBlockName, getBlockAttributes } = | ||
select( blockEditorStore ); | ||
|
||
return { | ||
insertedBlockAttributes: getBlockAttributes( | ||
insertedBlockClientId | ||
), | ||
insertedBlockName: getBlockName( insertedBlockClientId ), | ||
}; | ||
}, | ||
[ insertedBlockClientId ] | ||
); | ||
|
||
const { updateBlockAttributes } = useDispatch( blockEditorStore ); | ||
|
||
const setInsertedBlockAttributes = ( _updatedAttributes ) => { | ||
if ( ! insertedBlockClientId ) return; | ||
updateBlockAttributes( insertedBlockClientId, _updatedAttributes ); | ||
}; | ||
|
||
if ( ! insertedBlockClientId ) { | ||
return { | ||
insertedBlockAttributes: undefined, | ||
insertedBlockName: undefined, | ||
setInsertedBlockAttributes, | ||
}; | ||
} | ||
|
||
return { | ||
insertedBlockAttributes, | ||
insertedBlockName, | ||
setInsertedBlockAttributes, | ||
}; | ||
}; |
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