1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +01:00

Use sanitize from js-utility-belt

This commit is contained in:
Brett Sun 2016-06-13 15:57:50 +02:00
parent 5172b4da1f
commit 9e03ef2b90
4 changed files with 7 additions and 20 deletions

View File

@ -90,7 +90,7 @@ let AclInformation = React.createClass({
verbsToDisplay = verbsToDisplay.concat(verbs); verbsToDisplay = verbsToDisplay.concat(verbs);
} else if(aim === 'button' && this.props.aclObject) { } else if(aim === 'button' && this.props.aclObject) {
const { aclObject } = this.props; const { aclObject } = this.props;
const sanitizedAclObject = sanitize(aclObject, (val) => !val); const sanitizedAclObject = sanitize(aclObject);
verbsToDisplay = verbsToDisplay.concat(intersectLists(verbs, Object.keys(sanitizedAclObject))); verbsToDisplay = verbsToDisplay.concat(intersectLists(verbs, Object.keys(sanitizedAclObject)));
} }

View File

@ -370,7 +370,7 @@ let Form = React.createClass({
const validatedRef = this._hasRefErrors(refToValidate); const validatedRef = this._hasRefErrors(refToValidate);
validatedFormInputs[refName] = validatedRef; validatedFormInputs[refName] = validatedRef;
}); });
const errorMessagesForRefs = sanitize(validatedFormInputs, (val) => !val); const errorMessagesForRefs = sanitize(validatedFormInputs);
this.handleError({ json: { errors: errorMessagesForRefs } }); this.handleError({ json: { errors: errorMessagesForRefs } });
return !Object.keys(errorMessagesForRefs).length; return !Object.keys(errorMessagesForRefs).length;
}, },

View File

@ -20,7 +20,7 @@ export function getAvailableAcls(editions, filterFn) {
edition.acl.edition = false; edition.acl.edition = false;
edition.acl.piece = false; edition.acl.piece = false;
edition.acl = sanitize(edition.acl, (val) => !val); edition.acl = sanitize(edition.acl);
edition.acl = Object.keys(edition.acl); edition.acl = Object.keys(edition.acl);
// additionally, the user can specify a filter function for // additionally, the user can specify a filter function for

View File

@ -6,23 +6,10 @@
*/ */
export { default as isShallowEqual } from 'shallow-equals'; export { default as isShallowEqual } from 'shallow-equals';
/** // Re-export general utilities from js-utility-belt for easier access
* Takes an object and returns a shallow copy without any keys export {
* that fail the passed in filter function. sanitize
* Does not modify the passed in object. } from 'js-utility-belt/es6';
*
* @param {object} obj regular javascript object
* @return {object} regular javascript object without null values or empty strings
*/
export function sanitize(obj, filterFn) {
if (!filterFn) {
// By matching null with a double equal, we can match undefined and null
// http://stackoverflow.com/a/15992131
filterFn = (val) => val == null || val === '';
}
return omitFromObject(obj, filterFn);
}
/** /**
* Removes all falsy values (undefined, null, false, ...) from a list/array * Removes all falsy values (undefined, null, false, ...) from a list/array