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

[draft] Split CmsQueryRepeater into CmsQuery and CmsQueryRepeater #62

Closed
wants to merge 1 commit into from
Closed
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
35 changes: 26 additions & 9 deletions plasmicpkgs/plasmic-cms/src/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ function isDatabaseConfigured(config?: DatabaseConfig) {
return config?.databaseId && config?.databaseToken;
}

interface CmsQueryRepeaterProps
interface CmsQueryProps
extends QueryParams,
CanvasComponentProps<TableContextData> {
children?: React.ReactNode;
children: (rows: ApiCmsRow[]) => React.ReactNode;
table?: string;
emptyMessage?: React.ReactNode;
forceEmptyState?: boolean;
Expand All @@ -180,6 +180,10 @@ interface CmsQueryRepeaterProps
filterValue?: string;
}

interface CmsQueryRepeaterProps extends Omit<CmsQueryProps, "children"> {
children?: React.ReactNode;
}

export const cmsQueryRepeaterMeta: ComponentMeta<CmsQueryRepeaterProps> = {
name: `${componentPrefix}-query-repeater`,
displayName: "CMS Data Loader",
Expand Down Expand Up @@ -307,7 +311,7 @@ export const cmsQueryRepeaterMeta: ComponentMeta<CmsQueryRepeaterProps> = {
},
};

export function CmsQueryRepeater({
export function CmsQuery({
table,
children,
setControlContextData,
Expand All @@ -324,7 +328,7 @@ export function CmsQueryRepeater({
className,
filterField,
filterValue,
}: CmsQueryRepeaterProps) {
}: CmsQueryProps) {
const databaseConfig = useDatabase();
const tables = useTables();

Expand Down Expand Up @@ -377,11 +381,7 @@ export function CmsQueryRepeater({
}
return (
<QueryResultProvider table={table!} rows={rows}>
{rows.map((row, index) => (
<RowProvider key={index} table={table!} row={row}>
{repeatedElement(index, children)}
</RowProvider>
))}
{children(rows)}
</QueryResultProvider>
);
},
Expand All @@ -393,6 +393,23 @@ export function CmsQueryRepeater({
return noLayout ? <> {node} </> : <div className={className}> {node} </div>;
}

export function CmsQueryRepeater({
children,
...query
}: CmsQueryRepeaterProps) {
return (
<CmsQuery {...query}>
{(rows) =>
rows.map((row, index) => (
<RowProvider key={index} table={query.table!} row={row}>
{repeatedElement(index, children)}
</RowProvider>
))
}
</CmsQuery>
);
}

interface CmsRowFieldProps extends CanvasComponentProps<RowContextData> {
table?: string;
field?: string;
Expand Down