Repository: mozilla-services/react-jsonschema-form
Pull request #1323 (2019-06-18 03:11:03)

Show netlify badge on deploy previews
This is needed because we're using Netlify to serve deploy previews and using their open-source plan.

We're not yet using Netlify to serve our playground, so the badge won't show up there.


Patch:
diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md
index 212fe4cd9..c9a3a7359 100644
--- a/PULL_REQUEST_TEMPLATE.md
+++ b/PULL_REQUEST_TEMPLATE.md
@@ -11,6 +11,5 @@ If this is related to existing tickets, include links to them as well.
 * [ ] **I'm adding or updating code**
   - [ ] I've added and/or updated tests
   - [ ] I've updated [docs](https://react-jsonschema-form.readthedocs.io/) if needed
-  - [ ] I've run `npm run cs-format` on my branch to conform my code to [prettier](https://github.com/prettier/prettier) coding style
 * [ ] **I'm adding a new feature**
   - [ ] I've updated the playground with an example use of the feature
diff --git a/netlify.toml b/netlify.toml
new file mode 100644
index 000000000..480331996
--- /dev/null
+++ b/netlify.toml
@@ -0,0 +1,2 @@
+[context.deploy-preview.environment]
+  SHOW_NETLIFY_BADGE = "true"
\ No newline at end of file
diff --git a/playground/app.js b/playground/app.js
index f8c972517..2d78b28d3 100644
--- a/playground/app.js
+++ b/playground/app.js
@@ -506,6 +506,27 @@ class App extends Component {
             </Form>
           )}
         </div>
+        <div className="col-sm-12">
+          <p style={{ textAlign: "center" }}>
+            Powered by
+            <a href="https://github.com/mozilla-services/react-jsonschema-form">
+              react-jsonschema-form
+            </a>
+            . Bootstrap themes courtesy of{" "}
+            <a href="http://bootswatch.com/">Bootswatch</a> and{" "}
+            <a href="https://github.com/aalpern/bootstrap-solarized/">
+              bootstrap-solarized
+            </a>
+            .
+            {process.env.SHOW_NETLIFY_BADGE === "true" && (
+              <div style={{ float: "right" }}>
+                <a href="https://www.netlify.com">
+                  <img src="https://www.netlify.com/img/global/badges/netlify-color-accent.svg" />
+                </a>
+              </div>
+            )}
+          </p>
+        </div>
       </div>
     );
   }
diff --git a/playground/index.html b/playground/index.html
index f17ae4859..68c028ee1 100644
--- a/playground/index.html
+++ b/playground/index.html
@@ -9,13 +9,6 @@
 </head>
 <body>
   <div id="app"></div>
-  <p style="text-align:center">
-    Powered by
-    <a href="https://github.com/mozilla-services/react-jsonschema-form">react-jsonschema-form</a>.
-    Bootstrap themes courtsesy of
-    <a href="http://bootswatch.com/">Bootswatch</a> and
-    <a href="https://github.com/aalpern/bootstrap-solarized/">bootstrap-solarized</a>.
-  </p>
   <script src="/static/bundle.js"></script>
 </body>
 </html>
diff --git a/playground/index.prod.html b/playground/index.prod.html
index 8cfb66c39..f2d838adc 100644
--- a/playground/index.prod.html
+++ b/playground/index.prod.html
@@ -10,13 +10,6 @@
 </head>
 <body>
   <div id="app"></div>
-  <p style="text-align:center">
-    Powered by
-    <a href="https://github.com/mozilla-services/react-jsonschema-form">react-jsonschema-form</a>.
-    Bootstrap themes courtsesy of
-    <a href="http://bootswatch.com/">Bootswatch</a> and
-    <a href="https://github.com/aalpern/bootstrap-solarized/">bootstrap-solarized</a>.
-  </p>
   <script src="./bundle.js"></script>
 </body>
 </html>
diff --git a/src/components/fields/ArrayField.js b/src/components/fields/ArrayField.js
index a232ef2ab..078857363 100644
--- a/src/components/fields/ArrayField.js
+++ b/src/components/fields/ArrayField.js
@@ -406,6 +406,7 @@ class ArrayField extends Component {
       formContext,
       formData,
       rawErrors,
+      registry,
     };
 
     // Check if a custom render function was passed in
diff --git a/webpack.config.prod.js b/webpack.config.prod.js
index 7f6e1d6f4..4911eb392 100644
--- a/webpack.config.prod.js
+++ b/webpack.config.prod.js
@@ -14,7 +14,8 @@ module.exports = {
     new MiniCssExtractPlugin({filename: "styles.css", allChunks: true}),
     new webpack.DefinePlugin({
       "process.env": {
-        NODE_ENV: JSON.stringify("production")
+        NODE_ENV: JSON.stringify("production"),
+        SHOW_NETLIFY_BADGE: JSON.stringify(process.env.SHOW_NETLIFY_BADGE)
       }
     })
   ],


Test patch:
diff --git a/test/ArrayFieldTemplate_test.js b/test/ArrayFieldTemplate_test.js
index c1a4c3999..be0f05257 100644
--- a/test/ArrayFieldTemplate_test.js
+++ b/test/ArrayFieldTemplate_test.js
@@ -1,5 +1,4 @@
 import React, { PureComponent } from "react";
-
 import { expect } from "chai";
 import { createFormComponent, createSandbox } from "./test_utils";
 
@@ -39,31 +38,6 @@ describe("ArrayFieldTemplate", () => {
       );
     }
 
-    describe("Stateful ArrayFieldTemplate", () => {
-      class ArrayFieldTemplate extends PureComponent {
-        render() {
-          return (
-            <div className="field-content">
-              {this.props.items.map((item, i) => (
-                <div key={i}>item.children</div>
-              ))}
-            </div>
-          );
-        }
-      }
-
-      it("should render a stateful custom component", () => {
-        const { node } = createFormComponent({
-          schema: { type: "array", items: { type: "string" } },
-          formData,
-          ArrayFieldTemplate,
-        });
-        expect(
-          node.querySelectorAll(".field-array .field-content div")
-        ).to.have.length.of(3);
-      });
-    });
-
     describe("not fixed items", () => {
       const schema = {
         type: "array",
@@ -176,4 +150,45 @@ describe("ArrayFieldTemplate", () => {
       });
     });
   });
+
+  describe("Stateful ArrayFieldTemplate", () => {
+    class ArrayFieldTemplate extends PureComponent {
+      render() {
+        return (
+          <div className="field-content">
+            {this.props.items.map((item, i) => (
+              <div key={i}>item.children</div>
+            ))}
+          </div>
+        );
+      }
+    }
+
+    it("should render a stateful custom component", () => {
+      const { node } = createFormComponent({
+        schema: { type: "array", items: { type: "string" } },
+        formData,
+        ArrayFieldTemplate,
+      });
+      expect(
+        node.querySelectorAll(".field-array .field-content div")
+      ).to.have.length.of(3);
+    });
+  });
+
+  describe("pass right props to ArrayFieldTemplate", () => {
+    it("should pass registry prop", () => {
+      const ArrayFieldTemplate = ({ registry }) => {
+        if (!registry) {
+          throw "Error";
+        }
+        return null;
+      };
+      createFormComponent({
+        schema: { type: "array", items: { type: "string" } },
+        formData,
+        ArrayFieldTemplate,
+      });
+    });
+  });
 });