Skip to content

Commit

Permalink
fix(app-headless-cms): ref fields component key (#3571)
Browse files Browse the repository at this point in the history
  • Loading branch information
brunozoric committed Oct 3, 2023
1 parent 8ac4546 commit 8743fd6
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import React from "react";
import { CmsContentEntry, CmsModelField, CmsModelFieldRendererPlugin } from "~/types";
import { CmsModelField, CmsModelFieldRendererPlugin } from "~/types";
import ContentEntriesMultiAutocomplete from "./components/ContentEntriesMultiAutoComplete";

import { i18n } from "@webiny/app/i18n";
import { BindComponentRenderProp } from "@webiny/form";

const t = i18n.ns("app-headless-cms/admin/fields/ref");

const getKey = (
field: CmsModelField,
bind: BindComponentRenderProp<string, CmsContentEntry>
data?: {
id?: string;
}
): string => {
return bind.form.data.id + "." + field.fieldId;
return (data?.id || "unknown") + "." + field.fieldId;
};

const plugin: CmsModelFieldRendererPlugin = {
Expand All @@ -30,7 +31,7 @@ const plugin: CmsModelFieldRendererPlugin = {
<Bind>
{bind => (
<ContentEntriesMultiAutocomplete
key={getKey(props.field, bind as any)}
key={getKey(props.field, bind.form?.data)}
{...props}
bind={bind}
/>
Expand Down

0 comments on commit 8743fd6

Please sign in to comment.