Repository: mozilla-services/react-jsonschema-form
Pull request #1331 (2019-06-23 21:11:10)

Minor changes that I forgot to push to my last PR #1283
Very minor changes that I forgot to push to my last PR, #1283. One of the code review comments was to rename `toNameSchema` to `toPathSchema`, which I thought was a good idea. The other change was to add `lodash.get` to the `package.json`.

### Reasons for making this change

I realized I forgot to push these review changes before last PR was merged.

### Checklist

* [x] **I'm adding or updating code**
  - [x] I've added and/or updated tests


epicfaace: Yeah, good point, sorry I forgot about those -- thanks for catching.

Patch:
diff --git a/package-lock.json b/package-lock.json
index e15bddad0..f6a474b48 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -7663,6 +7663,11 @@
         "lodash._root": "^3.0.0"
       }
     },
+    "lodash.get": {
+      "version": "4.4.2",
+      "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz",
+      "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk="
+    },
     "lodash.isarguments": {
       "version": "3.1.0",
       "resolved": "https://registry.npmjs.org/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz",
diff --git a/package.json b/package.json
index 0f64c688f..a44c246b4 100644
--- a/package.json
+++ b/package.json
@@ -46,6 +46,7 @@
     "@babel/runtime-corejs2": "^7.4.5",
     "ajv": "^6.7.0",
     "core-js": "^2.5.7",
+    "lodash.get": "^4.4.2",
     "lodash.pick": "^4.4.0",
     "lodash.topath": "^4.5.2",
     "prop-types": "^15.5.8",
diff --git a/src/components/Form.js b/src/components/Form.js
index 7a461619d..7d5d7d6d7 100644
--- a/src/components/Form.js
+++ b/src/components/Form.js
@@ -12,7 +12,7 @@ import {
   setState,
   getDefaultRegistry,
   deepEquals,
-  toNameSchema,
+  toPathSchema,
 } from "../utils";
 import validateFormData, { toErrorList } from "../validate";
 
@@ -77,7 +77,7 @@ export default class Form extends Component {
       formData,
       props.idPrefix
     );
-    const nameSchema = toNameSchema(retrievedSchema, "", definitions, formData);
+    const pathSchema = toPathSchema(retrievedSchema, "", definitions, formData);
     return {
       schema,
       uiSchema,
@@ -87,7 +87,7 @@ export default class Form extends Component {
       errors,
       errorSchema,
       additionalMetaSchemas,
-      nameSchema,
+      pathSchema,
     };
   }
 
@@ -141,7 +141,7 @@ export default class Form extends Component {
     return _pick(formData, fields);
   };
 
-  getFieldNames = (nameSchema, formData) => {
+  getFieldNames = (pathSchema, formData) => {
     const getAllPaths = (_obj, acc = [], paths = []) => {
       Object.keys(_obj).forEach(key => {
         if (typeof _obj[key] === "object") {
@@ -167,7 +167,7 @@ export default class Form extends Component {
       return acc;
     };
 
-    return getAllPaths(nameSchema);
+    return getAllPaths(pathSchema);
   };
 
   onChange = (formData, newErrorSchema) => {
@@ -179,7 +179,7 @@ export default class Form extends Component {
       const newState = this.getStateFromProps(this.props, formData);
 
       const fieldNames = this.getFieldNames(
-        newState.nameSchema,
+        newState.pathSchema,
         newState.formData
       );
 
@@ -220,10 +220,10 @@ export default class Form extends Component {
     event.persist();
     let newFormData = this.state.formData;
 
-    const { nameSchema } = this.state;
+    const { pathSchema } = this.state;
 
     if (this.props.omitExtraData === true) {
-      const fieldNames = this.getFieldNames(nameSchema, this.state.formData);
+      const fieldNames = this.getFieldNames(pathSchema, this.state.formData);
       newFormData = this.getUsedFormData(this.state.formData, fieldNames);
     }
 
diff --git a/src/utils.js b/src/utils.js
index 33d5f4532..0b943949b 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -839,19 +839,19 @@ export function toIdSchema(
   return idSchema;
 }
 
-export function toNameSchema(schema, name = "", definitions, formData = {}) {
-  const nameSchema = {
+export function toPathSchema(schema, name = "", definitions, formData = {}) {
+  const pathSchema = {
     $name: name,
   };
   if ("$ref" in schema || "dependencies" in schema) {
     const _schema = retrieveSchema(schema, definitions, formData);
-    return toNameSchema(_schema, name, definitions, formData);
+    return toPathSchema(_schema, name, definitions, formData);
   }
   if ("items" in schema) {
     const retVal = {};
     if (Array.isArray(formData) && formData.length > 0) {
       formData.forEach((element, index) => {
-        retVal[`${index}`] = toNameSchema(
+        retVal[`${index}`] = toPathSchema(
           schema.items,
           `${name}.${index}`,
           definitions,
@@ -862,15 +862,15 @@ export function toNameSchema(schema, name = "", definitions, formData = {}) {
     return retVal;
   }
   if (schema.type !== "object") {
-    return nameSchema;
+    return pathSchema;
   }
   for (const property in schema.properties || {}) {
     const field = schema.properties[property];
-    const fieldId = nameSchema.$name
-      ? nameSchema.$name + "." + property
+    const fieldId = pathSchema.$name
+      ? pathSchema.$name + "." + property
       : property;
 
-    nameSchema[property] = toNameSchema(
+    pathSchema[property] = toPathSchema(
       field,
       fieldId,
       definitions,
@@ -879,7 +879,7 @@ export function toNameSchema(schema, name = "", definitions, formData = {}) {
       (formData || {})[property]
     );
   }
-  return nameSchema;
+  return pathSchema;
 }
 
 export function parseDateString(dateString, includeTime = true) {


Test patch:
diff --git a/test/Form_test.js b/test/Form_test.js
index 566a6da66..6cf309c2b 100644
--- a/test/Form_test.js
+++ b/test/Form_test.js
@@ -946,15 +946,15 @@ describe("Form", () => {
         onSubmit,
       });
 
-      const nameSchema = {
+      const pathSchema = {
         $name: "",
       };
 
-      const fieldNames = comp.getFieldNames(nameSchema, formData);
+      const fieldNames = comp.getFieldNames(pathSchema, formData);
       expect(fieldNames).eql([]);
     });
 
-    it("should get field names from nameSchema", () => {
+    it("should get field names from pathSchema", () => {
       const schema = {};
 
       const formData = {
@@ -979,7 +979,7 @@ describe("Form", () => {
         onSubmit,
       });
 
-      const nameSchema = {
+      const pathSchema = {
         $name: "",
         level1: {
           $name: "level1",
@@ -999,7 +999,7 @@ describe("Form", () => {
         },
       };
 
-      const fieldNames = comp.getFieldNames(nameSchema, formData);
+      const fieldNames = comp.getFieldNames(pathSchema, formData);
       expect(fieldNames.sort()).eql(
         [
           "level1a",
@@ -1010,7 +1010,7 @@ describe("Form", () => {
       );
     });
 
-    it("should get field names from nameSchema with array", () => {
+    it("should get field names from pathSchema with array", () => {
       const schema = {};
 
       const formData = {
@@ -1035,7 +1035,7 @@ describe("Form", () => {
         onSubmit,
       });
 
-      const nameSchema = {
+      const pathSchema = {
         $name: "",
         address_list: {
           "0": {
@@ -1065,7 +1065,7 @@ describe("Form", () => {
         },
       };
 
-      const fieldNames = comp.getFieldNames(nameSchema, formData);
+      const fieldNames = comp.getFieldNames(pathSchema, formData);
       expect(fieldNames.sort()).eql(
         [
           "address_list.0.city",
diff --git a/test/utils_test.js b/test/utils_test.js
index b365053be..0da762e49 100644
--- a/test/utils_test.js
+++ b/test/utils_test.js
@@ -20,7 +20,7 @@ import {
   shouldRender,
   toDateString,
   toIdSchema,
-  toNameSchema,
+  toPathSchema,
   guessType,
 } from "../src/utils";
 
@@ -1868,14 +1868,14 @@ describe("utils", () => {
     });
   });
 
-  describe("toNameSchema", () => {
-    it("should return a nameSchema for root field", () => {
+  describe("toPathSchema", () => {
+    it("should return a pathSchema for root field", () => {
       const schema = { type: "string" };
 
-      expect(toNameSchema(schema)).eql({ $name: "" });
+      expect(toPathSchema(schema)).eql({ $name: "" });
     });
 
-    it("should return a nameSchema for nested objects", () => {
+    it("should return a pathSchema for nested objects", () => {
       const schema = {
         type: "object",
         properties: {
@@ -1888,7 +1888,7 @@ describe("utils", () => {
         },
       };
 
-      expect(toNameSchema(schema)).eql({
+      expect(toPathSchema(schema)).eql({
         $name: "",
         level1: {
           $name: "level1",
@@ -1897,7 +1897,7 @@ describe("utils", () => {
       });
     });
 
-    it("should return a nameSchema for a schema with dependencies", () => {
+    it("should return a pathSchema for a schema with dependencies", () => {
       const schema = {
         type: "object",
         properties: {
@@ -1941,7 +1941,7 @@ describe("utils", () => {
         ],
       };
 
-      expect(toNameSchema(schema, "", schema.definitions, formData)).eql({
+      expect(toPathSchema(schema, "", schema.definitions, formData)).eql({
         $name: "",
         list: {
           "0": {
@@ -1978,7 +1978,7 @@ describe("utils", () => {
       });
     });
 
-    it("should return a nameSchema for a schema with references", () => {
+    it("should return a pathSchema for a schema with references", () => {
       const schema = {
         definitions: {
           address: {
@@ -2014,7 +2014,7 @@ describe("utils", () => {
         },
       };
 
-      expect(toNameSchema(schema, "", schema.definitions, formData)).eql({
+      expect(toPathSchema(schema, "", schema.definitions, formData)).eql({
         $name: "",
         billing_address: {
           $name: "billing_address",
@@ -2031,7 +2031,7 @@ describe("utils", () => {
       });
     });
 
-    it("should return a nameSchema for a schema with references in an array item", () => {
+    it("should return a pathSchema for a schema with references in an array item", () => {
       const schema = {
         definitions: {
           address: {
@@ -2077,7 +2077,7 @@ describe("utils", () => {
         ],
       };
 
-      expect(toNameSchema(schema, "", schema.definitions, formData)).eql({
+      expect(toPathSchema(schema, "", schema.definitions, formData)).eql({
         $name: "",
         address_list: {
           "0": {
@@ -2108,7 +2108,7 @@ describe("utils", () => {
       });
     });
 
-    it("should return an nameSchema with different types of arrays", () => {
+    it("should return an pathSchema with different types of arrays", () => {
       const schema = {
         definitions: {
           Thing: {
@@ -2294,7 +2294,7 @@ describe("utils", () => {
         ],
       };
 
-      expect(toNameSchema(schema, "", schema.definitions, formData)).eql({
+      expect(toPathSchema(schema, "", schema.definitions, formData)).eql({
         $name: "",
         defaultsAndMinItems: {
           "0": {