Skip to content
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

Nav block: enable creation from existing WP Menus #18869

Merged
merged 67 commits into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
53dd4d7
Create Navigation block from existing WP Menus (interactive rebase m…
getdave Feb 18, 2020
63396f3
Update to use CustomSelect control to match Design
getdave May 29, 2020
87f9fae
Update labels and add Create from Pages to dropdown
getdave May 29, 2020
ca833da
Update all options to be under the select dropdown
getdave May 29, 2020
d032323
DRY up dropdown menu options
getdave May 29, 2020
69ab3f1
Rename UI vars to be agnostic to Pages or Menus specifically.
getdave May 29, 2020
9c54663
Improve code readability via naming changes
getdave May 29, 2020
8670dd9
Updates dropown UI styles to match visual Design
getdave May 29, 2020
cf1ae42
Removes divider option and replace with CSS created divider
getdave May 29, 2020
590fe14
Fix size jump depending on dropdown selection
getdave May 29, 2020
65e70c8
Fix to not allow selection of PLACEHOLDER option as valid dropdown se…
getdave May 29, 2020
e7f0709
Simplify conditionals
getdave May 29, 2020
ab2b115
Move constants outside of Component
getdave May 29, 2020
aaad738
Update create from Pages e2e spec to match new Design
getdave Jun 1, 2020
136e667
Remove unneeded wait command
getdave Jun 1, 2020
7b1ca48
Fix avoid Menu Items requests for invalid Menus
getdave Jun 1, 2020
9b4ee04
Fix disable Create button if Menu Items not yet resolved from API
getdave Jun 1, 2020
7121e1e
Fixes e2e tests for Menus specs
getdave Jun 1, 2020
8466538
Refactor out process of clicking on Create button
getdave Jun 1, 2020
c53f54a
Fix test checking for empty block creation if menu is empty
getdave Jun 1, 2020
8855014
Fix test don’t show dropdown options for Menus if there aren’t any
getdave Jun 1, 2020
cf0173d
Fix create button enable if create from empty is selected
getdave Jun 1, 2020
342a7bf
Fix empty nav populatoin test
getdave Jun 1, 2020
53b5c93
Fix test create pages from Block using new util to create empty nav b…
getdave Jun 1, 2020
4d49b21
Update nomenclature for mock matching to “routes” not URLs
getdave Jun 1, 2020
be282bd
Fix dropdown to use pointer cursor style instead of text
getdave Jun 1, 2020
9b21e0d
Fix button not disabled if Pages are available.
getdave Jun 2, 2020
36c3f4b
Make placeholder instruction text contextually aware
getdave Jun 2, 2020
9e5aa1d
Updates e2e test snapshot
getdave Jun 2, 2020
cd64d50
Disable e2e failures due to unrelated state update issue
getdave Jun 2, 2020
cc8dc86
Update snapshot
getdave Jun 2, 2020
ad81036
Revert "Disable e2e failures due to unrelated state update issue"
getdave Jun 3, 2020
0d80deb
Update to modern syntax for looping
getdave Jun 4, 2020
2d6e60a
Update packages/block-library/src/navigation/edit.js
getdave Jun 4, 2020
294e552
Update packages/e2e-tests/specs/experiments/navigation.test.js
getdave Jun 4, 2020
4c7d005
Update packages/block-library/src/navigation/style.scss
getdave Jun 4, 2020
6f0be7f
Update packages/block-library/src/navigation/edit.js
getdave Jun 4, 2020
5e332f1
Update packages/block-library/src/navigation/edit.js
getdave Jun 4, 2020
3b8a91e
Update packages/block-library/src/navigation/edit.js
getdave Jun 4, 2020
27e5187
Fix duplicate entities
getdave Jun 5, 2020
ddb3f7c
Fix if conditional to conform to coding standards
getdave Jun 5, 2020
edfd84a
Refactor menu selects to use core shorthand
getdave Jun 5, 2020
97cd484
Revert unintended style mod to CustomSelectControl component
getdave Jun 5, 2020
b216fd0
Fix selectors to use core shorthand
getdave Jun 5, 2020
e194861
Remove CustomSelectControl fixes now in upstream
getdave Jun 5, 2020
9f20385
Consistently name selector props with get prefix when function
getdave Jun 5, 2020
83be08f
Rename var to better reflect purpose and avoid ambiguity
getdave Jun 5, 2020
e8aeaf2
Update function name to prefix with verb for clarity
getdave Jun 5, 2020
2329e79
Update case so that placeholder is a single word
getdave Jun 5, 2020
56c8e78
Update packages/block-library/src/navigation/create-data-tree.js
getdave Jun 5, 2020
d65d7e8
Update packages/block-library/src/navigation/create-data-tree.js
getdave Jun 5, 2020
bdde794
Memozie dropdown options to avoid re-renders
getdave Jun 5, 2020
a14245a
Rename to disambiguate dropdown term
getdave Jun 5, 2020
6e5a561
Adds @return to docblock
getdave Jun 8, 2020
3aa695d
Normalise selector format
getdave Jun 8, 2020
8dc5189
Avoid setState re-render for same option selection
getdave Jun 8, 2020
d460016
Update to show placeholder loading state when requesting pages or menus.
getdave Jun 9, 2020
8cd6467
Fixes loading spinner alignment
getdave Jun 9, 2020
468f3e7
Update to use var to store ref to common state property
getdave Jun 9, 2020
ca2cbb2
Apply useCallback to utility function
getdave Jun 9, 2020
b0eb65d
Apply useCallback to improve perf
getdave Jun 9, 2020
e97cbe7
FIx e2e test to wait for dropdown to be present before interaction
getdave Jun 10, 2020
fc85695
Janitorial - fix to single quotes
getdave Jun 10, 2020
47a450b
Updates dropdown divider to rely on classname over placement
getdave Jun 10, 2020
87305bc
Fix double with single quotes
getdave Jun 10, 2020
2b95d56
Update packages/block-library/src/navigation/edit.js
getdave Jun 10, 2020
792937d
Move fixture to subfolder
getdave Jun 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions packages/block-library/src/navigation/create-data-tree.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Creates a nested, hierarchical tree representation from unstructured data that
* has an inherent relationship defined between individual items.
*
* For example, by default, each element in the dataset should have an `id` and
* `parent` property where the `parent` property indicates a relationship between
* the current item and another item with a matching `id` properties.
*
* This is useful for building linked lists of data from flat data structures.
*
* @param {Array} dataset linked data to be rearranged into a hierarchical tree based on relational fields.
* @param {string} id the property which uniquely identifies each entry within the array.
* @param {*} relation the property which identifies how the current item is related to other items in the data (if at all).
* @return {Array} a nested array of parent/child relationships
*/
getdave marked this conversation as resolved.
Show resolved Hide resolved
function createDataTree( dataset, id = 'id', relation = 'parent' ) {
getdave marked this conversation as resolved.
Show resolved Hide resolved
const hashTable = Object.create( null );
getdave marked this conversation as resolved.
Show resolved Hide resolved
const dataTree = [];

for ( const data of dataset ) {
hashTable[ data[ id ] ] = {
...data,
children: [],
};
}
for ( const data of dataset ) {
if ( data[ relation ] ) {
hashTable[ data[ relation ] ].children.push(
hashTable[ data[ id ] ]
);
} else {
dataTree.push( hashTable[ data[ id ] ] );
}
}

return dataTree;
}

export default createDataTree;
Loading