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

Feature: Reimplement render path. #69

Merged
merged 3 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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