Skip to content

Commit

Permalink
fix(app-headless-cms): select the first plugin renderer (#4121)
Browse files Browse the repository at this point in the history
  • Loading branch information
leopuleo authored May 10, 2024
1 parent 7cd60c5 commit 918aeb0
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useEffect } from "react";
import { Grid, Cell } from "@webiny/ui/Grid";
import { i18n } from "@webiny/app/i18n";
import { Radio, RadioGroup } from "@webiny/ui/Radio";
Expand All @@ -10,6 +10,7 @@ import { Typography } from "@webiny/ui/Typography";
import { RendererOptions } from "./AppearanceTab/RendererOptions";
import { LegacyRichTextInput } from "./AppearanceTab/LegacyRichTextInput";
import { useRendererPlugins } from "./useRendererPlugins";
import { useModelField } from "~/admin/components/ModelFieldProvider";

const t = i18n.ns("app-headless-cms/admin/content-model-editor/tabs/appearance-tab");

Expand All @@ -26,6 +27,7 @@ const style = {

const AppearanceTab = () => {
const renderers = useRendererPlugins();
const { field } = useModelField();

const rendererName = useBind({
name: "renderer.name",
Expand All @@ -47,6 +49,20 @@ const AppearanceTab = () => {
);
}

useEffect(() => {
// If the currently selected render plugin is no longer available, select the first available one.
if (selectedPlugin) {
return;
}

if (renderers[0]) {
rendererName.onChange(renderers[0].renderer.rendererName);
return;
}

console.info(`No renderers for field ${field.fieldId} found.`, field);
}, [field.id, field.multipleValues, field.predefinedValues?.enabled, selectedPlugin]);

return (
<>
<Grid>
Expand Down

0 comments on commit 918aeb0

Please sign in to comment.