Skip to content

Commit

Permalink
fix(app-headless-cms): sort renderers before picking defaults [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed May 8, 2024
1 parent c7f9bbb commit 3cc545e
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,17 @@ import { Dialog, DialogContent, DialogTitle, DialogActions } from "~/admin/compo
import { Form, FormOnSubmit } from "@webiny/form";
import { Tabs, Tab } from "@webiny/ui/Tabs";
import { i18n } from "@webiny/app/i18n";
import {
CmsEditorContentModel,
CmsModelField,
CmsEditorFieldRendererPlugin,
CmsEditorFieldTypePlugin
} from "~/types";
import { plugins } from "@webiny/plugins";
import { CmsEditorContentModel, CmsModelField } from "~/types";
import GeneralTab from "./EditFieldDialog/GeneralTab";
import AppearanceTab from "./EditFieldDialog/AppearanceTab";
import PredefinedValues from "./EditFieldDialog/PredefinedValues";
import { ValidatorsList } from "./EditFieldDialog/ValidatorsList";
import { ButtonDefault, ButtonPrimary } from "@webiny/ui/Button";
import { useModelField, useModelEditor, useModel } from "~/admin/hooks";
import { useModelField, useModelEditor } from "~/admin/hooks";
import { ModelFieldProvider } from "~/admin/components/ModelFieldProvider";
import { ValidationsSection } from "~/admin/components/FieldEditor/EditFieldDialog/ValidationsSection";
import { getFieldValidators, getListValidators } from "./EditFieldDialog/getValidators";
import { useRendererPlugins } from "~/admin/components/FieldEditor/EditFieldDialog/useRendererPlugins";

const t = i18n.namespace("app-headless-cms/admin/components/editor");

Expand All @@ -41,18 +36,11 @@ const FullScreenDialog = styled(Dialog)`
}
`;

function setupState(
field: CmsModelField,
fieldPlugin: CmsEditorFieldTypePlugin,
contentModel: CmsEditorContentModel
): EditFieldState {
function setupState(field: CmsModelField, contentModel: CmsEditorContentModel): EditFieldState {
const clonedField = cloneDeep(field);
const { model } = useModel();

if (!clonedField.renderer || !clonedField.renderer.name) {
const [renderPlugin] = plugins
.byType<CmsEditorFieldRendererPlugin>("cms-editor-field-renderer")
.filter(item => item.renderer.canUse({ field, fieldPlugin, model }));
const [renderPlugin] = useRendererPlugins();

if (renderPlugin) {
clonedField.renderer = { name: renderPlugin.renderer.rendererName };
Expand All @@ -78,9 +66,7 @@ interface EditFieldDialogProps {
const EditFieldDialog = (props: EditFieldDialogProps) => {
const { field, fieldPlugin } = useModelField();
const { data: contentModel, setData: setContentModelData } = useModelEditor();
const [{ shadowField, isTitleField }] = useState<EditFieldState>(
setupState(field, fieldPlugin, contentModel)
);
const [{ shadowField, isTitleField }] = useState(setupState(field, contentModel));

const headerTitle = t`Field Settings - {fieldTypeLabel}`({
fieldTypeLabel: fieldPlugin.field.label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import { allowCmsLegacyRichTextInput } from "~/utils/allowCmsLegacyRichTextInput
import { Typography } from "@webiny/ui/Typography";
import { RendererOptions } from "./AppearanceTab/RendererOptions";
import { LegacyRichTextInput } from "./AppearanceTab/LegacyRichTextInput";
import { useRendererPlugins } from "./AppearanceTab/useRendererPlugins";
import { useSelectFirstAvailableRenderer } from "./AppearanceTab/useSelectFirstAvailableRenderer";
import { useRendererPlugins } from "./useRendererPlugins";

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

Expand All @@ -33,8 +32,6 @@ const AppearanceTab = () => {
validate: validation.create("required")
});

useSelectFirstAvailableRenderer(rendererName);

const selectedPlugin = rendererName.value
? renderers.find(pl => pl.renderer.rendererName === rendererName.value)
: undefined;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const GeneralTab = () => {
const { data: contentModel } = useModelEditor();
const { getField } = useModelFieldEditor();

// Had problems with auto-focusing the "label" field. A couple of comments on this.
// Had problems with autofocusing the "label" field. A couple of comments on this.
// 1. It's probably caused by the Tabs component which wraps this component.
// 2. It seems that the "autoFocus" prop on the Input doesn't work. I can't see it attached in the actual DOM.
// 3. This works, but it's not 100%. Visually, the cursor is frozen, and that's probably caused by a bug / design
Expand Down

0 comments on commit 3cc545e

Please sign in to comment.