mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 09:23:13 +01:00
Use sanitize from js-utility-belt
This commit is contained in:
parent
5172b4da1f
commit
9e03ef2b90
@ -90,7 +90,7 @@ let AclInformation = React.createClass({
|
||||
verbsToDisplay = verbsToDisplay.concat(verbs);
|
||||
} else if(aim === 'button' && this.props.aclObject) {
|
||||
const { aclObject } = this.props;
|
||||
const sanitizedAclObject = sanitize(aclObject, (val) => !val);
|
||||
const sanitizedAclObject = sanitize(aclObject);
|
||||
verbsToDisplay = verbsToDisplay.concat(intersectLists(verbs, Object.keys(sanitizedAclObject)));
|
||||
}
|
||||
|
||||
|
@ -370,7 +370,7 @@ let Form = React.createClass({
|
||||
const validatedRef = this._hasRefErrors(refToValidate);
|
||||
validatedFormInputs[refName] = validatedRef;
|
||||
});
|
||||
const errorMessagesForRefs = sanitize(validatedFormInputs, (val) => !val);
|
||||
const errorMessagesForRefs = sanitize(validatedFormInputs);
|
||||
this.handleError({ json: { errors: errorMessagesForRefs } });
|
||||
return !Object.keys(errorMessagesForRefs).length;
|
||||
},
|
||||
|
@ -20,7 +20,7 @@ export function getAvailableAcls(editions, filterFn) {
|
||||
edition.acl.edition = false;
|
||||
edition.acl.piece = false;
|
||||
|
||||
edition.acl = sanitize(edition.acl, (val) => !val);
|
||||
edition.acl = sanitize(edition.acl);
|
||||
edition.acl = Object.keys(edition.acl);
|
||||
|
||||
// additionally, the user can specify a filter function for
|
||||
|
@ -6,23 +6,10 @@
|
||||
*/
|
||||
export { default as isShallowEqual } from 'shallow-equals';
|
||||
|
||||
/**
|
||||
* Takes an object and returns a shallow copy without any keys
|
||||
* that fail the passed in filter function.
|
||||
* Does not modify the passed in object.
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
// Re-export general utilities from js-utility-belt for easier access
|
||||
export {
|
||||
sanitize
|
||||
} from 'js-utility-belt/es6';
|
||||
|
||||
/**
|
||||
* Removes all falsy values (undefined, null, false, ...) from a list/array
|
||||
|
Loading…
Reference in New Issue
Block a user