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

React Component-based Plugins - Introduce CmsContentFormRendererPlugin #4456

Merged
merged 2 commits into from
Dec 19, 2024

Conversation

adrians5j
Copy link
Member

@adrians5j adrians5j commented Dec 19, 2024

Changes

This PR introduces the CmsContentFormRendererPlugin plugin. In other words, it's a React component with the same feature set as the previous the CmsContentFormRendererPlugin (POJO) plugin, which also plays well with extensions.

import React from "react";
import { CmsContentFormRendererPlugin } from "@webiny/app-headless-cms";
import { Grid, Cell } from "@webiny/ui/Grid";
import { Tabs, Tab } from "@webiny/ui/Tabs";
import { useSecurity } from "@webiny/app-security";

interface LayoutProps {
    fields: Record<string, JSX.Element>;
}

const PizzaLayout = ({ fields }: LayoutProps) => {
    // Access security identity.
    const { getPermission } = useSecurity();

    // Get the necessary permission.
    const bakeryPermission = getPermission("bakery");

    // Check if the user has the permission to edit a recipe.
    const canEditRecipe = bakeryPermission && bakeryPermission["canEditRecipe"] === true;

    console.log('nice')
    return (
        <Tabs>
            <Tab label="General">
                <Grid>
                    <Cell span={12}>{fields["name"]}</Cell>
                </Grid>
                <Grid>
                    <Cell span={6}>{fields["price"]}</Cell>
                    <Cell span={6}>{fields["numberOfIngredients"]}</Cell>
                </Grid>
            </Tab>
            {/* Hide the Recipe tab if the user doesn't have the required permission. */}
            {canEditRecipe && (
                <Tab label="Recipe">
                    <Grid>
                        <Cell span={12}>{fields["recipe"]}</Cell>
                    </Grid>
                </Tab>
            )}
            <Tab label="History">
                <Grid>
                    <Cell span={12}>{fields["history"]}</Cell>
                </Grid>
            </Tab>
        </Tabs>
    );
};

export const Extension = () => {
    return <CmsContentFormRendererPlugin modelId="article" render={PizzaLayout} />;
};

How Has This Been Tested?

Manually.

Documentation

Changelog / update existing doc.

@adrians5j adrians5j changed the base branch from next to dev December 19, 2024 10:47
@webiny-bot webiny-bot added this to the 5.41.4 milestone Dec 19, 2024
@adrians5j adrians5j changed the title Adrian/cms content form renderer plugin React Component-based Plugins - Introduce CmsContentFormRendererPlugin Dec 19, 2024
@adrians5j adrians5j merged commit f0224a2 into dev Dec 19, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants