Skip to content

Commit

Permalink
Merge pull request #1783 from dhis2/DHIS2-9860/fix-hierarchy-operatio…
Browse files Browse the repository at this point in the history
…ns-paging

fix: hierarchy operations paging
  • Loading branch information
Birkbjo authored Jan 12, 2021
2 parents 39f6f44 + 4fcede0 commit 2fbff0e
Showing 1 changed file with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,31 @@ function onClickLeft(event, model) {
.take(1) // Only grab the current state
.subscribe(
(hierarchy) => {
const selectAllChildren = event.shiftKey

let selectedLeft = [];
const indexOfModelInSelected = hierarchy.selectedLeft
.map(model => model.id)
.indexOf(model.id);

if (indexOfModelInSelected >= 0) {
selectedLeft = hierarchy.selectedLeft
.slice(0, indexOfModelInSelected)
.concat(hierarchy.selectedLeft.slice(indexOfModelInSelected + 1));

let modelIdsToRemove = hierarchy.selectedLeft
.filter(m => m.id === model.id).map(m => m.id)

const children = model.children.toArray()
let childrenToAdd = []

// add all children that is not already selected if shift-clicked
if(selectAllChildren) {
childrenToAdd = children.filter(
(child) => hierarchy.selectedLeft.findIndex((m) => m.id === child.id) < 0
);
}

// remove selection if already present
if (modelIdsToRemove.length > 0) {
if(selectAllChildren) {
modelIdsToRemove.push(...children.map(child => child.id))
}
selectedLeft = hierarchy.selectedLeft.filter(m => modelIdsToRemove.indexOf(m.id) < 0)
} else {
selectedLeft = hierarchy.selectedLeft.concat([model]);
selectedLeft = hierarchy.selectedLeft.concat(model, ...childrenToAdd);
}

setAppState({
Expand All @@ -133,7 +147,7 @@ async function getOrganisationUnitByIds(ids) {
const d2 = await getInstance();

const organisationUnits = await d2.models.organisationUnit
.list({ filter: [`id:in:[${ids.join(',')}]`], fields: ':owner,href,id,parent,displayName,path,children[id,displayName,path]' });
.list({ filter: [`id:in:[${ids.join(',')}]`], fields: ':owner,href,id,parent,displayName,path,children[id,displayName,path]', paging: false });

return organisationUnits.toArray();
}
Expand Down

0 comments on commit 2fbff0e

Please sign in to comment.