diff --git a/packages/react-board/src/components/Board.tsx b/packages/react-board/src/components/Board.tsx index c0964a9ab..cf20f6229 100644 --- a/packages/react-board/src/components/Board.tsx +++ b/packages/react-board/src/components/Board.tsx @@ -11,7 +11,7 @@ import { useEntityList, useEntityListSubTree, } from '@contember/react-binding' -import { boardColumnsAnalyzer, boardItemsAnalyzer } from '../internal/boardAnalyzer' +import { boardAnalyzer } from '../internal/boardAnalyzer' import { Fragment, ReactNode } from 'react' import { useDynamicBoard } from '../internal/useDynamicBoard' import { useStaticBoard } from '../internal/useStaticBoard' @@ -95,8 +95,9 @@ const BoardQualifiedDynamic = Component(({ entities, ) }, ({ entities, orderBy, limit, offset, columns, discriminationField, sortableBy, columnsSortableBy, children }, env) => { - const columnChildren = boardColumnsAnalyzer.processChildren(children, env) - const itemChildren = boardItemsAnalyzer.processChildren(children, env) + const childrenByType = boardAnalyzer.processChildren(children, env) + const columnChildren = childrenByType.filter(it => it.type === 'column').map(it => it.children) + const itemChildren = childrenByType.filter(it => it.type === 'item').map(it => it.children) return (<> @@ -138,8 +139,9 @@ const RelativeDynamicBoard = Component(({ field, orde ) }, ({ field, orderBy, limit, offset, columns, discriminationField, sortableBy, columnsSortableBy, children }, env) => { - const columnChildren = boardColumnsAnalyzer.processChildren(children, env) - const itemChildren = boardItemsAnalyzer.processChildren(children, env) + const childrenByType = boardAnalyzer.processChildren(children, env) + const columnChildren = childrenByType.filter(it => it.type === 'column').map(it => it.children) + const itemChildren = childrenByType.filter(it => it.type === 'item').map(it => it.children) return (<> @@ -175,7 +177,8 @@ const BoardQualifiedStatic = Component(({ entities, o ) }, ({ entities, orderBy, limit, offset, columns, discriminationField, sortableBy, children }, env) => { - const itemChildren = boardItemsAnalyzer.processChildren(children, env) + const childrenByType = boardAnalyzer.processChildren(children, env) + const itemChildren = childrenByType.filter(it => it.type === 'item').map(it => it.children) return (<> @@ -208,7 +211,8 @@ const RelativeStaticBoard = Component(({ field, orderB ) }, ({ field, orderBy, limit, offset, columns, discriminationField, sortableBy, children }, env) => { - const itemChildren = boardItemsAnalyzer.processChildren(children, env) + const childrenByType = boardAnalyzer.processChildren(children, env) + const itemChildren = childrenByType.filter(it => it.type === 'item').map(it => it.children) return (<> diff --git a/packages/react-board/src/internal/boardAnalyzer.ts b/packages/react-board/src/internal/boardAnalyzer.ts index af653e5d6..1b5dd20f4 100644 --- a/packages/react-board/src/internal/boardAnalyzer.ts +++ b/packages/react-board/src/internal/boardAnalyzer.ts @@ -4,24 +4,14 @@ import { BoardItem } from '../components/BoardItem' import { ReactNode } from 'react' import { BoardColumn } from '../components/BoardColumn' -const itemLeaf = new Leaf(node => node.props.children, BoardItem) -const columnLeaf = new Leaf(node => node.props.children, BoardColumn) +const itemLeaf = new Leaf(node => ({ type: 'item' as const, children: node.props.children }), BoardItem) +const columnLeaf = new Leaf(node => ({ type: 'column' as const, children: node.props.children }), BoardColumn) - -export const boardColumnsAnalyzer = new ChildrenAnalyzer< - ReactNode, - never, - Environment ->([columnLeaf], { - staticRenderFactoryName: 'staticRender', - staticContextFactoryName: 'generateEnvironment', -}) - -export const boardItemsAnalyzer = new ChildrenAnalyzer< - ReactNode, +export const boardAnalyzer = new ChildrenAnalyzer< + { type: 'column' | 'item', children: ReactNode }, never, Environment ->([itemLeaf], { +>([itemLeaf, columnLeaf], { staticRenderFactoryName: 'staticRender', staticContextFactoryName: 'generateEnvironment', })