From ddc2e7b919f5643b7d910384e204c82f6669d1e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Tue, 20 Oct 2015 18:10:48 +0200 Subject: [PATCH] Rename intersectAcls to intersectList and do some clean up --- js/components/ascribe_buttons/acl_information.js | 10 +++------- js/components/ascribe_forms/form_delete_piece.js | 3 +++ js/utils/acl_utils.js | 8 ++------ js/utils/general_utils.js | 10 ++++++++++ 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/js/components/ascribe_buttons/acl_information.js b/js/components/ascribe_buttons/acl_information.js index af510d71..2d7533ec 100644 --- a/js/components/ascribe_buttons/acl_information.js +++ b/js/components/ascribe_buttons/acl_information.js @@ -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) => { diff --git a/js/components/ascribe_forms/form_delete_piece.js b/js/components/ascribe_forms/form_delete_piece.js index 552c38c0..80b08f37 100644 --- a/js/components/ascribe_forms/form_delete_piece.js +++ b/js/components/ascribe_forms/form_delete_piece.js @@ -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({ }> +

{getLangText('Are you sure you would like to permanently delete this piece')}?

{getLangText('This is an irrevocable action%s', '.')}

diff --git a/js/utils/acl_utils.js b/js/utils/acl_utils.js index a3998576..fc3987c1 100644 --- a/js/utils/acl_utils.js +++ b/js/utils/acl_utils.js @@ -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); } } diff --git a/js/utils/general_utils.js b/js/utils/general_utils.js index af4cb752..fb1a71fa 100644 --- a/js/utils/general_utils.js +++ b/js/utils/general_utils.js @@ -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); } \ No newline at end of file