diff --git a/packages/fast-data-utilities-react/src/__tests__/schemas/children-plugin.schema.json b/packages/fast-data-utilities-react/src/__tests__/schemas/children-plugin.schema.json index d1387912bbb..96a5fc19d31 100644 --- a/packages/fast-data-utilities-react/src/__tests__/schemas/children-plugin.schema.json +++ b/packages/fast-data-utilities-react/src/__tests__/schemas/children-plugin.schema.json @@ -18,6 +18,20 @@ "title": "String", "type": "string" } + }, + "arrayObject": { + "title": "Array of objects", + "type": "array", + "items": { + "title": "Object", + "type": "object", + "reactProperties": { + "content": { + "type": "children", + "pluginId": "children-plugin-resolver" + } + } + } } }, "reactProperties": { diff --git a/packages/fast-data-utilities-react/src/index.spec.ts b/packages/fast-data-utilities-react/src/index.spec.ts index 6aec30d250d..d33abab2bf3 100644 --- a/packages/fast-data-utilities-react/src/index.spec.ts +++ b/packages/fast-data-utilities-react/src/index.spec.ts @@ -363,6 +363,47 @@ describe("getDataLocationsOfPlugins", () => { expect(dataLocationsOfPlugins).toHaveLength(1); expect(dataLocationsOfPlugins[0].dataLocation).toBe("children.props.array"); }); + test("should return data locations of children nested in an array of items", () => { + const data: any = { + children: { + id: childrenWithPluginPropsSchema.id, + props: { + arrayObject: [ + { + content: { + id: childrenSchema.id, + props: { + children: "foo", + }, + }, + }, + { + content: { + id: childrenSchema.id, + props: { + children: "bat", + }, + }, + }, + ], + }, + }, + }; + + const dataLocationsOfPlugins: PluginLocation[] = getDataLocationsOfPlugins( + childrenSchema, + data, + childOptions + ); + + expect(dataLocationsOfPlugins).toHaveLength(2); + expect(dataLocationsOfPlugins[0].dataLocation).toBe( + "children.props.arrayObject[0].content" + ); + expect(dataLocationsOfPlugins[1].dataLocation).toBe( + "children.props.arrayObject[1].content" + ); + }); }); describe("getDataLocationsOfChildren", () => { diff --git a/packages/fast-data-utilities-react/src/index.ts b/packages/fast-data-utilities-react/src/index.ts index 9a627546b94..747fdc7e052 100644 --- a/packages/fast-data-utilities-react/src/index.ts +++ b/packages/fast-data-utilities-react/src/index.ts @@ -406,7 +406,10 @@ export function getDataLocationsOfPlugins( const dataLocationOfPlugin: string = dataLocationPrefix === "" ? dataLocation - : `${dataLocationPrefix}.${propsKeyword}.${dataLocation}`; + : `${dataLocationPrefix}.${propsKeyword}.${normalizeDataLocation( + dataLocation, + data + )}`; // check to see if the data location matches with the current schema and includes a plugin identifier if (