From 1d2c322082d45c158985c12ef324398314034bed Mon Sep 17 00:00:00 2001 From: Alex Windett Date: Wed, 25 Jan 2017 13:50:27 +0000 Subject: [PATCH] adding in functionality to determin current organisation when changing member role --- .../src/components/people-list/table/index.js | 5 ++++- .../people-list/table/person-role.js | 5 ++++- .../components/people-list/table/tooltip.js | 5 ++++- frontend/src/containers/org/people.js | 4 +++- frontend/src/state/reducers/orgs.js | 20 ++++++++++--------- frontend/src/state/selectors.js | 6 ++++++ package.json | 3 ++- yarn.lock | 9 ++++++--- 8 files changed, 40 insertions(+), 17 deletions(-) diff --git a/frontend/src/components/people-list/table/index.js b/frontend/src/components/people-list/table/index.js index ddc7fb5c..53fb9dbf 100644 --- a/frontend/src/components/people-list/table/index.js +++ b/frontend/src/components/people-list/table/index.js @@ -13,7 +13,8 @@ const PeopleTable = (props) => { handleRoleUpdate, handleStatusTooltip, people = [], - orgUI = {} + orgUI = {}, + orgIndex } = props; const columns = [{ @@ -49,6 +50,7 @@ const PeopleTable = (props) => { handleRoleTooltip={handleRoleTooltip} handleRoleUpdate={handleRoleUpdate} membersRolesOptions={orgUI.members_roles} + orgIndex={orgIndex} person={person} personIndex={index} toggledID={orgUI.member_role_tooltip} @@ -76,6 +78,7 @@ PeopleTable.propTypes = { handleRoleTooltip: React.PropTypes.func, handleRoleUpdate: React.PropTypes.func, handleStatusTooltip: React.PropTypes.func, + orgIndex: React.PropTypes.number, orgUI: React.PropTypes.object, people: React.PropTypes.array, }; diff --git a/frontend/src/components/people-list/table/person-role.js b/frontend/src/components/people-list/table/person-role.js index da48ed25..856026c2 100644 --- a/frontend/src/components/people-list/table/person-role.js +++ b/frontend/src/components/people-list/table/person-role.js @@ -54,7 +54,8 @@ const PersonRole = (props) => { person, personIndex, handleRoleTooltip, - handleRoleUpdate + handleRoleUpdate, + orgIndex } = props; const toggled = toggledID; @@ -78,6 +79,7 @@ const PersonRole = (props) => { ? @@ -90,6 +92,7 @@ PersonRole.propTypes = { handleRoleTooltip: React.PropTypes.func, handleRoleUpdate: React.PropTypes.func, membersRolesOptions: React.PropTypes.array, + orgIndex: React.PropTypes.number, person: React.PropTypes.object, personIndex: React.PropTypes.number, toggledID: React.PropTypes.oneOfType([ diff --git a/frontend/src/components/people-list/table/tooltip.js b/frontend/src/components/people-list/table/tooltip.js index 80cc6294..a24fd3a5 100644 --- a/frontend/src/components/people-list/table/tooltip.js +++ b/frontend/src/components/people-list/table/tooltip.js @@ -18,6 +18,7 @@ module.exports = ({ person = {}, personIndex, options = [], + orgIndex, }) => { const _options = options.map( (option, i) => { @@ -28,7 +29,8 @@ module.exports = ({ status: person.status, role: option }, - personIndex + personIndex, + orgIndex, }; const _onClick = () => handleSelect(payload); @@ -59,6 +61,7 @@ module.exports = ({ module.exports.propTypes = { handleSelect: React.PropTypes.func, options: React.PropTypes.array, + orgIndex: React.PropTypes.number, person: React.PropTypes.object, personIndex: React.PropTypes.number, }; \ No newline at end of file diff --git a/frontend/src/containers/org/people.js b/frontend/src/containers/org/people.js index 3e56bac1..c7707fb6 100644 --- a/frontend/src/containers/org/people.js +++ b/frontend/src/containers/org/people.js @@ -12,7 +12,8 @@ const { const { peopleByOrgIdSelector, orgUISelector, - membersSelector + orgIndexSelector, + membersSelector, } = selectors; const { @@ -36,6 +37,7 @@ const mapStateToProps = (state, { }) => ({ people: peopleByOrgIdSelector(params.org)(state), orgUI: orgUISelector(state), + orgIndex: orgIndexSelector(params.org)(state), platformMembers: membersSelector(state) }); diff --git a/frontend/src/state/reducers/orgs.js b/frontend/src/state/reducers/orgs.js index 896ff027..dce5f5bb 100644 --- a/frontend/src/state/reducers/orgs.js +++ b/frontend/src/state/reducers/orgs.js @@ -48,9 +48,11 @@ module.exports = handleActions({ }; }, [handleRoleUpdate.toString()]: (state, action) => { - // TODO: - // Change "1" to org index. At the moment only updates - // "biz-tech" + const { + orgIndex, + person, + personIndex, + } = action.payload; return { ...state, @@ -59,18 +61,18 @@ module.exports = handleActions({ member_role_tooltip: false }, data: [ - ...state.data.slice(0, 1), + ...state.data.slice(0, orgIndex), { - ...state.data[1], + ...state.data[orgIndex], members: [ - ...state.data[1].members.slice(0, action.payload.personIndex), + ...state.data[orgIndex].members.slice(0, personIndex), { - ...action.payload.person + ...person, }, - ...state.data[1].members.slice(action.payload.personIndex + 1) + ...state.data[orgIndex].members.slice(personIndex + 1) ] }, - ...state.data.slice(1+1), + ...state.data.slice(orgIndex + 1), ] }; } diff --git a/frontend/src/state/selectors.js b/frontend/src/state/selectors.js index 9e6700c9..b9f83dfb 100644 --- a/frontend/src/state/selectors.js +++ b/frontend/src/state/selectors.js @@ -35,6 +35,11 @@ const orgById = (orgId) => createSelector( (orgs) => find(orgs, ['id', orgId]) ); +const orgIndexById = (orgId) => createSelector( + orgs, + (orgs) => orgs.map((o) => o.id).indexOf(orgId) +); + const serviceById = (serviceId) => createSelector( [services], (services) => find(services, ['id', serviceId]) @@ -140,6 +145,7 @@ module.exports = { orgByIdSelector: orgById, orgsSelector: orgs, orgUISelector: orgUI, + orgIndexSelector: orgIndexById, servicesSelector: services, serviceByIdSelector: serviceById, orgSectionsSelector: orgSections, diff --git a/package.json b/package.json index 538e8eaf..025e1df5 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ }, "dependencies": { "husky": "^0.11.9", - "license-to-fail": "^2.2.0" + "license-to-fail": "^2.2.0", + "lodash.findindex": "^4.6.0" }, "devDependencies": { "tap-xunit": "^1.4.0" diff --git a/yarn.lock b/yarn.lock index 4e0ab1a9..89ef85a5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1,7 +1,5 @@ # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. # yarn lockfile v1 - - abbrev@1: version "1.0.9" resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.0.9.tgz#91b4792588a7738c25f35dd6f63752a2f8776135" @@ -136,7 +134,7 @@ inflight@^1.0.4: once "^1.3.0" wrappy "1" -inherits@2, inherits@~2.0.1: +inherits@~2.0.1, inherits@2: version "2.0.3" resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" @@ -190,6 +188,10 @@ license-to-fail@^2.2.0: dependencies: license-checker "^7.1.0" +lodash.findindex: + version "4.6.0" + resolved "https://registry.yarnpkg.com/lodash.findindex/-/lodash.findindex-4.6.0.tgz#a3245dee61fb9b6e0624b535125624bb69c11106" + lodash@^3.5.0: version "3.10.1" resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6" @@ -389,3 +391,4 @@ xmlbuilder@~4.1.0: xtend@~4.0.0, xtend@~4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af" +