Skip to content

Commit

Permalink
UI prop types fix; install eslint and a typescript (required due to a…
Browse files Browse the repository at this point in the history
  • Loading branch information
ozydingo committed May 23, 2021
1 parent 98e4246 commit 863281c
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 20 deletions.
1 change: 1 addition & 0 deletions factory_burgers-ui/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EXTEND_ESLINT=true
5 changes: 5 additions & 0 deletions factory_burgers-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion factory_burgers-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
"react-bootstrap": "^1.6.0",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"typescript": "^4.2.4",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build && cp -r build/* ../lib/assets",
"test": "react-scripts test",
"eject": "react-scripts eject"
"eject": "react-scripts eject",
"lint": "eslint ./src"
},
"eslintConfig": {
"extends": [
Expand Down
7 changes: 2 additions & 5 deletions factory_burgers-ui/src/components/Factories.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function Factories(props) {
item => findAssociationFactory(factories, item)
);
return matchingFactories;
}, [selectedObject]);
}, [factories, selectedObject]);

const blueprints = selectedObject ? associationFactories : factoryList;
const inquiry = selectedObject ? `Would you like fries with that ${selectedObject.type}?` : null;
Expand Down Expand Up @@ -122,9 +122,7 @@ function Factories(props) {
}

function formData(form) {
const data = new FormData(form);
data.append("authenticity_token", props.csrfToken);
return data;
return new FormData(form);
}

return (
Expand Down Expand Up @@ -169,7 +167,6 @@ function Factories(props) {
}

Factories.propTypes = {
csrfToken: PropTypes.string,
factories: PropTypes.arrayOf(factoryShape),
submitPath: PropTypes.string,
};
Expand Down
12 changes: 6 additions & 6 deletions factory_burgers-ui/src/components/FactoryForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { factoryShape } from "lib/shapes";
import { indexBy, usePrevious } from "./framework";

function FactoryForm(props) {
const blueprints = props.blueprints || [];
const owner = props.owner;
const inquiry = props.inquiry || "What'll it be?";

Expand All @@ -26,10 +25,11 @@ function FactoryForm(props) {
setFactoryInput(value);
}

const blueprints = useMemo(() => props.blueprints || [], [props.blueprints]);
const indexedBluePrints = useMemo(() => indexBy(blueprints, blueprint => blueprint.factory.name), [blueprints]);
const selectedBlueprint = useMemo(() => indexedBluePrints[factoryInput], [factoryInput]);
const attributes = useMemo(() => selectedBlueprint && selectedBlueprint.factory.attributes || [], [selectedBlueprint]);
const traits = useMemo(() => selectedBlueprint && selectedBlueprint.factory.traits || [], [selectedBlueprint]);
const selectedBlueprint = useMemo(() => indexedBluePrints[factoryInput], [factoryInput, indexedBluePrints]);
const attributes = useMemo(() => (selectedBlueprint && selectedBlueprint.factory.attributes) || [], [selectedBlueprint]);
const traits = useMemo(() => (selectedBlueprint && selectedBlueprint.factory.traits) || [], [selectedBlueprint]);
const validSelection = !!selectedBlueprint;

const prevOwner = usePrevious(props.owner);
Expand All @@ -39,12 +39,12 @@ function FactoryForm(props) {
const ownerId = owner && owner.id;
const otherOwnerType = other && other.type;
const otherOwnerId = other && other.id;
return ownerType === otherOwnerType && ownerId == otherOwnerId;
return ownerType === otherOwnerType && ownerId === otherOwnerId;
}

useEffect(() => {
if (!sameOwner(props.owner, prevOwner)) { setFactoryInput(""); }
}, [props.owner]);
}, [props.owner, prevOwner]);

const form = useRef(null);

Expand Down
2 changes: 1 addition & 1 deletion factory_burgers-ui/src/components/partials/Attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function Traits(props) {
const { attributes } = props;

const [inputAttributes, setInputAttributes] = useState([]);
const remainingAttributes = useMemo(() => attrDiff(attributes, inputAttributes));
const remainingAttributes = useMemo(() => attrDiff(attributes, inputAttributes), [attributes, inputAttributes]);

const remainingAttributeOptions = remainingAttributes.map(attr => (
<option key={attr.name} value={attr.name}>{attr.name}</option>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ function FormFieldsForOwner(props) {
<Form.Group controlId="factories.OwnerType">
<Form.Control
type="hidden"
value={owner && owner.type || ""}
value={(owner && owner.type) || ""}
name="owner_type"
/>
</Form.Group>
<Form.Group controlId="factories.OwnerId">
<Form.Control
type="hidden"
value={owner && owner.id || ""}
value={(owner && owner.id) || ""}
name="owner_id"
/>
</Form.Group>
Expand Down
2 changes: 1 addition & 1 deletion factory_burgers-ui/src/lib/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function useRemoteData(loadFn, dependencies = []) {
useEffect(() => {
setFetching(true);
asyncFetch().then(setResponse).catch(setError).then(done);
}, dependencies);
}, dependencies); // eslint-disable-line react-hooks/exhaustive-deps

async function asyncFetch() {
return loadFn();
Expand Down
6 changes: 3 additions & 3 deletions lib/assets/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"files": {
"main.css": "./static/css/main.510d0fb6.chunk.css",
"main.js": "./static/js/main.06049a6c.chunk.js",
"main.js.map": "./static/js/main.06049a6c.chunk.js.map",
"main.js": "./static/js/main.317bde1c.chunk.js",
"main.js.map": "./static/js/main.317bde1c.chunk.js.map",
"runtime-main.js": "./static/js/runtime-main.38f920d2.js",
"runtime-main.js.map": "./static/js/runtime-main.38f920d2.js.map",
"static/js/2.3ff1dc5f.chunk.js": "./static/js/2.3ff1dc5f.chunk.js",
Expand All @@ -18,6 +18,6 @@
"static/js/runtime-main.38f920d2.js",
"static/js/2.3ff1dc5f.chunk.js",
"static/css/main.510d0fb6.chunk.css",
"static/js/main.06049a6c.chunk.js"
"static/js/main.317bde1c.chunk.js"
]
}
2 changes: 1 addition & 1 deletion lib/assets/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="./favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="stylesheet" href="./bootstrap.4.0.0.min.css"/><link rel="apple-touch-icon" href="./logo192.png"/><link rel="manifest" href="./manifest.json"/><title>React App</title><link href="./static/css/main.510d0fb6.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function r(r){for(var n,i,a=r[0],c=r[1],l=r[2],s=0,p=[];s<a.length;s++)i=a[s],Object.prototype.hasOwnProperty.call(o,i)&&o[i]&&p.push(o[i][0]),o[i]=0;for(n in c)Object.prototype.hasOwnProperty.call(c,n)&&(e[n]=c[n]);for(f&&f(r);p.length;)p.shift()();return u.push.apply(u,l||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,a=1;a<t.length;a++){var c=t[a];0!==o[c]&&(n=!1)}n&&(u.splice(r--,1),e=i(i.s=t[0]))}return e}var n={},o={1:0},u=[];function i(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,i),t.l=!0,t.exports}i.e=function(e){var r=[],t=o[e];if(0!==t)if(t)r.push(t[2]);else{var n=new Promise((function(r,n){t=o[e]=[r,n]}));r.push(t[2]=n);var u,a=document.createElement("script");a.charset="utf-8",a.timeout=120,i.nc&&a.setAttribute("nonce",i.nc),a.src=function(e){return i.p+"static/js/"+({}[e]||e)+"."+{3:"996d9368"}[e]+".chunk.js"}(e);var c=new Error;u=function(r){a.onerror=a.onload=null,clearTimeout(l);var t=o[e];if(0!==t){if(t){var n=r&&("load"===r.type?"missing":r.type),u=r&&r.target&&r.target.src;c.message="Loading chunk "+e+" failed.\n("+n+": "+u+")",c.name="ChunkLoadError",c.type=n,c.request=u,t[1](c)}o[e]=void 0}};var l=setTimeout((function(){u({type:"timeout",target:a})}),12e4);a.onerror=a.onload=u,document.head.appendChild(a)}return Promise.all(r)},i.m=e,i.c=n,i.d=function(e,r,t){i.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,r){if(1&r&&(e=i(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(i.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)i.d(t,n,function(r){return e[r]}.bind(null,n));return t},i.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(r,"a",r),r},i.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},i.p="./",i.oe=function(e){throw console.error(e),e};var a=this["webpackJsonpfactory_burgers-ui"]=this["webpackJsonpfactory_burgers-ui"]||[],c=a.push.bind(a);a.push=r,a=a.slice();for(var l=0;l<a.length;l++)r(a[l]);var f=c;t()}([])</script><script src="./static/js/2.3ff1dc5f.chunk.js"></script><script src="./static/js/main.06049a6c.chunk.js"></script></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="./favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="stylesheet" href="./bootstrap.4.0.0.min.css"/><link rel="apple-touch-icon" href="./logo192.png"/><link rel="manifest" href="./manifest.json"/><title>React App</title><link href="./static/css/main.510d0fb6.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function r(r){for(var n,i,a=r[0],c=r[1],l=r[2],s=0,p=[];s<a.length;s++)i=a[s],Object.prototype.hasOwnProperty.call(o,i)&&o[i]&&p.push(o[i][0]),o[i]=0;for(n in c)Object.prototype.hasOwnProperty.call(c,n)&&(e[n]=c[n]);for(f&&f(r);p.length;)p.shift()();return u.push.apply(u,l||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,a=1;a<t.length;a++){var c=t[a];0!==o[c]&&(n=!1)}n&&(u.splice(r--,1),e=i(i.s=t[0]))}return e}var n={},o={1:0},u=[];function i(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,i),t.l=!0,t.exports}i.e=function(e){var r=[],t=o[e];if(0!==t)if(t)r.push(t[2]);else{var n=new Promise((function(r,n){t=o[e]=[r,n]}));r.push(t[2]=n);var u,a=document.createElement("script");a.charset="utf-8",a.timeout=120,i.nc&&a.setAttribute("nonce",i.nc),a.src=function(e){return i.p+"static/js/"+({}[e]||e)+"."+{3:"996d9368"}[e]+".chunk.js"}(e);var c=new Error;u=function(r){a.onerror=a.onload=null,clearTimeout(l);var t=o[e];if(0!==t){if(t){var n=r&&("load"===r.type?"missing":r.type),u=r&&r.target&&r.target.src;c.message="Loading chunk "+e+" failed.\n("+n+": "+u+")",c.name="ChunkLoadError",c.type=n,c.request=u,t[1](c)}o[e]=void 0}};var l=setTimeout((function(){u({type:"timeout",target:a})}),12e4);a.onerror=a.onload=u,document.head.appendChild(a)}return Promise.all(r)},i.m=e,i.c=n,i.d=function(e,r,t){i.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,r){if(1&r&&(e=i(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(i.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)i.d(t,n,function(r){return e[r]}.bind(null,n));return t},i.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(r,"a",r),r},i.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},i.p="./",i.oe=function(e){throw console.error(e),e};var a=this["webpackJsonpfactory_burgers-ui"]=this["webpackJsonpfactory_burgers-ui"]||[],c=a.push.bind(a);a.push=r,a=a.slice();for(var l=0;l<a.length;l++)r(a[l]);var f=c;t()}([])</script><script src="./static/js/2.3ff1dc5f.chunk.js"></script><script src="./static/js/main.317bde1c.chunk.js"></script></body></html>
Loading

0 comments on commit 863281c

Please sign in to comment.