Skip to content

Commit

Permalink
fix: add missing check for array syntax when resolving paths to plugi…
Browse files Browse the repository at this point in the history
…n IDs (microsoft#1359)
  • Loading branch information
janechu authored Feb 5, 2019
1 parent 54f46d3 commit d23ff00
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
41 changes: 41 additions & 0 deletions packages/fast-data-utilities-react/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
5 changes: 4 additions & 1 deletion packages/fast-data-utilities-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit d23ff00

Please sign in to comment.