mirror of
https://github.com/ascribe/onion.git
synced 2024-11-15 01:25:17 +01:00
Rename intersectAcls to intersectList and do some clean up
This commit is contained in:
parent
8417c2781e
commit
ddc2e7b919
@ -4,8 +4,7 @@ import React from 'react';
|
||||
import classnames from 'classnames';
|
||||
|
||||
import { InformationTexts } from '../../constants/information_text';
|
||||
import { replaceSubstringAtIndex, sanitize } from '../../utils/general_utils';
|
||||
import { intersectAcls } from '../../utils/acl_utils';
|
||||
import { replaceSubstringAtIndex, sanitize, intersectLists } from '../../utils/general_utils';
|
||||
import { getLangText } from '../../utils/lang_utils';
|
||||
|
||||
|
||||
@ -70,7 +69,7 @@ let AclInformation = React.createClass({
|
||||
const { titles, informationSentences, exampleSentences } = InformationTexts;
|
||||
const { verbs, aim } = this.props;
|
||||
|
||||
const availableInformations = intersectAcls(verbs, Object.keys(titles));
|
||||
const availableInformations = intersectLists(verbs, Object.keys(titles));
|
||||
|
||||
// sorting is not needed, as `this.props.verbs` takes care of sorting already
|
||||
// So we assume a user of `AclInformationButton` puts an ordered version of
|
||||
@ -83,10 +82,7 @@ let AclInformation = React.createClass({
|
||||
} else if(aim === 'button' && this.props.aclObject) {
|
||||
const { aclObject } = this.props;
|
||||
const sanitizedAclObject = sanitize(aclObject, (val) => !val);
|
||||
verbsToDisplay = verbsToDisplay.concat(intersectAcls(verbs, Object.keys(sanitizedAclObject)));
|
||||
} else {
|
||||
console.warn('AclInformation can only be used with aim === "button" or aim === "form".' +
|
||||
'For aim === "button", aclObject needs to be defined.');
|
||||
verbsToDisplay = verbsToDisplay.concat(intersectLists(verbs, Object.keys(sanitizedAclObject)));
|
||||
}
|
||||
|
||||
return verbsToDisplay.map((verb) => {
|
||||
|
@ -4,6 +4,8 @@ import React from 'react';
|
||||
|
||||
import Form from '../ascribe_forms/form';
|
||||
|
||||
import AclInformation from '../ascribe_buttons/acl_information';
|
||||
|
||||
import ApiUrls from '../../constants/api_urls';
|
||||
import AppConstants from '../../constants/application_constants';
|
||||
|
||||
@ -49,6 +51,7 @@ let PieceDeleteForm = React.createClass({
|
||||
<img src={AppConstants.baseUrl + 'static/img/ascribe_animated_small.gif'} />
|
||||
</div>
|
||||
}>
|
||||
<AclInformation aim={'form'} verbs={['acl_delete']}/>
|
||||
<p>{getLangText('Are you sure you would like to permanently delete this piece')}?</p>
|
||||
<p>{getLangText('This is an irrevocable action%s', '.')}</p>
|
||||
</Form>
|
||||
|
@ -1,10 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
import { sanitize } from './general_utils';
|
||||
|
||||
export function intersectAcls(a, b) {
|
||||
return a.filter((val) => b.indexOf(val) > -1);
|
||||
}
|
||||
import { sanitize, intersectLists } from './general_utils';
|
||||
|
||||
export function getAvailableAcls(editions, filterFn) {
|
||||
let availableAcls = [];
|
||||
@ -44,7 +40,7 @@ export function getAvailableAcls(editions, filterFn) {
|
||||
}
|
||||
if(editionsCopy.length >= 2) {
|
||||
for(let i = 1; i < editionsCopy.length; i++) {
|
||||
availableAcls = intersectAcls(availableAcls, editionsCopy[i].acl);
|
||||
availableAcls = intersectLists(availableAcls, editionsCopy[i].acl);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -242,4 +242,14 @@ export function getSubdomain() {
|
||||
let { host } = window.location;
|
||||
let tokens = host.split('.');
|
||||
return tokens.length > 2 ? tokens[0] : 'www';
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes two lists and returns their intersection as a list
|
||||
* @param {Array} a
|
||||
* @param {Array} b
|
||||
* @return {[Array]} Intersected list of a and b
|
||||
*/
|
||||
export function intersectLists(a, b) {
|
||||
return a.filter((val) => b.indexOf(val) > -1);
|
||||
}
|
Loading…
Reference in New Issue
Block a user