Skip to content

Commit

Permalink
Merge pull request #69 from sevenwestmedia-labs/feature/re-implement-…
Browse files Browse the repository at this point in the history
…render-path

Feature: Reimplement render path.
  • Loading branch information
NathanP-7West authored Apr 12, 2024
2 parents 42ceac5 + 72753da commit 3d247b5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-mugs-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'json-react-layouts': minor
---

Reintroduce render path for middlewares. Refine types.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

exports[`can load data for component 1`] = `
Object {
"componentRenderPath": "[0]test-composition/main/[0]",
"dataProps": Object {
"data": Object {
"dataDefinitionArgs": Object {
Expand All @@ -14,6 +13,7 @@ Object {
},
"layoutType": "test-with-data",
"length": 3,
"renderPath": "[0]test-composition/main/[0]",
}
`;

Expand Down Expand Up @@ -65,5 +65,6 @@ Object {
}
services={Object {}}
/>,
"renderPath": "[0]test-with-data",
}
`;
3 changes: 2 additions & 1 deletion packages/json-react-layouts/src/middlewares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export type MiddlwareHandler<TProps, TMiddlewareProps extends {}, LoadDataServic

interface ComponentOrCompositionProps {
layoutType: string
[props: string]: any
renderPath: string
[props: string]: unknown
}

export type RendererMiddleware<Services extends {}, MiddlewareProps extends {}> = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ export const ComponentRenderer: React.FC<ComponentRendererProps> = ({
return rendered
}

const { componentType, ...rest } = componentProps
const { componentType, componentRenderPath, ...rest } = componentProps

const middlewareRender =
componentMiddleware(
{ layoutType: componentType, ...rest },
{ layoutType: componentType, renderPath: componentRenderPath, ...rest },
middlewareProps,
componentServices,
render,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const CompositionRenderer: React.FunctionComponent<CompositionRendererPro
compositionMiddleware(
{
layoutType: composition.type,
renderPath: componentRenderPath,
...composition.props,
},
middlewareProps,
Expand Down

0 comments on commit 3d247b5

Please sign in to comment.