faustjs icon indicating copy to clipboard operation
faustjs copied to clipboard

Should flatListToHierarchical default params correspond to current content block props

Open JEverhart383 opened this issue 11 months ago • 3 comments

When implementing a new project using Faust and WPGraphQL content blocks, I stumbled when converting my list of blocks into a tree because the default client and parent id keys for the function are different from what content blocks return.

We should consider changing the default params to correspond to what GraphQL will return so that no additional work is needed beyond passing in the array of blocks.

In addition, this doc should be updated to reflect the updated properties that WPGraphQL returns related to ids and show the need to pass an additional param to this utility function:

const blocks = flatListToHierarchical(editorBlocks, {idKey: 'clientId', parentKey: 'clientParentId'});

It looks like the docs also include an example where clientId is aliased as id, which is maybe another way to approach this in examples, but I'm not sure we can assume that everyone coming to Faust will know what that means and how to do it in GraphQL parlance. If we do go that route, we should call out why we're doing this and link to the GraphQL docs on aliasing.

JEverhart383 avatar Jul 20 '23 14:07 JEverhart383