From 7c35fc09ec5881f39335caa718ab39602f827c2d Mon Sep 17 00:00:00 2001 From: zvictor Date: Fri, 9 Dec 2022 15:02:43 +0100 Subject: [PATCH] split CmsQueryRepeater into CmsQuery and CmsQueryRepeater --- plasmicpkgs/plasmic-cms/src/components.tsx | 35 ++++++++++++++++------ 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/plasmicpkgs/plasmic-cms/src/components.tsx b/plasmicpkgs/plasmic-cms/src/components.tsx index 766713896a3..25a1b2978e3 100644 --- a/plasmicpkgs/plasmic-cms/src/components.tsx +++ b/plasmicpkgs/plasmic-cms/src/components.tsx @@ -165,10 +165,10 @@ function isDatabaseConfigured(config?: DatabaseConfig) { return config?.databaseId && config?.databaseToken; } -interface CmsQueryRepeaterProps +interface CmsQueryProps extends QueryParams, CanvasComponentProps { - children?: React.ReactNode; + children: (rows: ApiCmsRow[]) => React.ReactNode; table?: string; emptyMessage?: React.ReactNode; forceEmptyState?: boolean; @@ -180,6 +180,10 @@ interface CmsQueryRepeaterProps filterValue?: string; } +interface CmsQueryRepeaterProps extends Omit { + children?: React.ReactNode; +} + export const cmsQueryRepeaterMeta: ComponentMeta = { name: `${componentPrefix}-query-repeater`, displayName: "CMS Data Loader", @@ -307,7 +311,7 @@ export const cmsQueryRepeaterMeta: ComponentMeta = { }, }; -export function CmsQueryRepeater({ +export function CmsQuery({ table, children, setControlContextData, @@ -324,7 +328,7 @@ export function CmsQueryRepeater({ className, filterField, filterValue, -}: CmsQueryRepeaterProps) { +}: CmsQueryProps) { const databaseConfig = useDatabase(); const tables = useTables(); @@ -377,11 +381,7 @@ export function CmsQueryRepeater({ } return ( - {rows.map((row, index) => ( - - {repeatedElement(index, children)} - - ))} + {children(rows)} ); }, @@ -393,6 +393,23 @@ export function CmsQueryRepeater({ return noLayout ? <> {node} :
{node}
; } +export function CmsQueryRepeater({ + children, + ...query +}: CmsQueryRepeaterProps) { + return ( + + {(rows) => + rows.map((row, index) => ( + + {repeatedElement(index, children)} + + )) + } + + ); +} + interface CmsRowFieldProps extends CanvasComponentProps { table?: string; field?: string;