Skip to content

Commit

Permalink
Merge pull request #736 from contember/fix/board-static
Browse files Browse the repository at this point in the history
board: fix static render
  • Loading branch information
matej21 authored Jul 1, 2024
2 parents 2a9bc8e + 5c5ffa5 commit 0bd0ac4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
18 changes: 11 additions & 7 deletions packages/react-board/src/components/Board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -95,8 +95,9 @@ const BoardQualifiedDynamic = Component<BoardQualifiedDynamicProps>(({ 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 (<>
<EntityListSubTree entities={entities} orderBy={orderBy} limit={limit} offset={offset}>
Expand Down Expand Up @@ -138,8 +139,9 @@ const RelativeDynamicBoard = Component<BoardRelativeDynamicProps>(({ field, orde
</BoardMethodsContext.Provider>
)
}, ({ 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 (<>
<HasMany field={field} orderBy={orderBy} limit={limit} offset={offset}>
<HasOne {...typeof discriminationField === 'string' ? { field: discriminationField } : discriminationField} />
Expand Down Expand Up @@ -175,7 +177,8 @@ const BoardQualifiedStatic = Component<BoardQualifiedStaticProps>(({ entities, o
</BoardMethodsContext.Provider>
)
}, ({ 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 (<>
<EntityListSubTree entities={entities} orderBy={orderBy} limit={limit} offset={offset}>
<Field {...typeof discriminationField === 'string' ? { field: discriminationField } : discriminationField} />
Expand Down Expand Up @@ -208,7 +211,8 @@ const RelativeStaticBoard = Component<BoardRelativeStaticProps>(({ field, orderB
</BoardMethodsContext.Provider>
)
}, ({ 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 (<>
<HasMany field={field} orderBy={orderBy} limit={limit} offset={offset}>
<Field {...typeof discriminationField === 'string' ? { field: discriminationField } : discriminationField} />
Expand Down
20 changes: 5 additions & 15 deletions packages/react-board/src/internal/boardAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
})

0 comments on commit 0bd0ac4

Please sign in to comment.