From 2e115b7b7b7880ecd9b4747a679dec15f4b44b38 Mon Sep 17 00:00:00 2001 From: Greg Wilson Date: Wed, 24 Mar 2021 02:58:23 -0400 Subject: [PATCH] DAT-103: show dedupe mechs and OUs on info tab. secondary sort by ou --- package.json | 2 +- public/manifest.webapp | 2 +- .../action/components/action.component.tsx | 36 ++++++++++++++----- .../mechanism/mechanismTabs.component.tsx | 2 +- src/modules/action/services/ou.service.tsx | 14 ++++++++ 5 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 src/modules/action/services/ou.service.tsx diff --git a/package.json b/package.json index 1f9978d..4d8ccc9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "datim-approvals", - "version": "2.0.9", + "version": "2.0.10", "private": true, "dependencies": { "@dhis2/app-runtime": "^2.0.4", diff --git a/public/manifest.webapp b/public/manifest.webapp index 4e62666..012e14b 100644 --- a/public/manifest.webapp +++ b/public/manifest.webapp @@ -3,7 +3,7 @@ "default_locale": "en", "appType": "APP", "name": "Data Approval", - "version": "2.0.9", + "version": "2.0.10", "description": "DATIM Mechanisms Approval App", "developer": { "name": "Jakub Flaska", diff --git a/src/modules/action/components/action.component.tsx b/src/modules/action/components/action.component.tsx index badabba..34cf716 100644 --- a/src/modules/action/components/action.component.tsx +++ b/src/modules/action/components/action.component.tsx @@ -6,6 +6,7 @@ import {getMechanismsInfo, getMechanismStates, performAction} from "../services/ import Step from "./step/step.component"; import MechanismTabs from "./mechanism/mechanismTabs.component"; import {fetchUserOu, fetchUserType} from "../services/user.service"; +import {getLevel3OUs} from "../services/ou.service"; import WorkflowOverview from "./workflowOverview.component"; import {idName} from "../models/idName"; import WorkflowPeriodService from "../../shared/services/workflowsPeriods.service"; @@ -22,7 +23,8 @@ export default class Action extends React.Component< userType: string, mechanisms: MechanismModel[], mechanismState: MechanismState, - processing: boolean + processing: boolean, + ous: [] } > { constructor(props){ @@ -42,12 +44,10 @@ export default class Action extends React.Component< userOu: null, mechanismState: null, mechanisms: mechanisms, - processing: false + processing: false, + ous: [] }; this.getMechanismStatuses(this.state.workflow.id, this.state.period.id, this.state.mechanisms); - this.getMechanismsInfo(this.state.mechanisms); - this.getUserType(); - this.getUserOu(); let wfService = new WorkflowPeriodService(); wfService.init().then(()=>{ @@ -55,18 +55,33 @@ export default class Action extends React.Component< }); } + async componentDidMount() { + await this.getL3Ous(); + this.getMechanismsInfo(this.state.mechanisms, this.state.ous); + this.getUserType(); + this.getUserOu(); + } + getMechanismStatuses(workflow: string, period: string, mechanisms: MechanismModel[]){ return getMechanismStates(workflow, period, mechanisms).then(state=>{ this.setState({mechanismState: state}); }); } - getMechanismsInfo(mechanisms: MechanismModel[]){ + getMechanismsInfo(mechanisms: MechanismModel[], ous: []){ getMechanismsInfo(mechanisms.map(m=>m.meta.cocId)).then(mechanismsInfo=>{ mechanismsInfo.forEach((info,i)=>{ - mechanisms[i].info = mechanismsInfo[i]; + //assign is necessary because of dedupe sharing mechanismInfo + mechanisms[i].info = Object.assign({},mechanismsInfo[i]); + // Dedupe fix to get the correct OU displayed + if (!mechanisms[i].info['ou'] && mechanisms[i].meta['ou']) { + let lookup = ous.filter(f=>f['id']===mechanisms[i].meta['ou']); + if (lookup[0] && lookup[0]['displayName']) { + mechanisms[i].info['ou'] = lookup[0]['displayName']; + } + } }); - mechanisms = mechanisms.sort((a,b)=>a.info.name>b.info.name?1:-1) + mechanisms = mechanisms.sort((a,b)=>a.info.name>b.info.name?1:a.info.ou>b.info.ou?1:-1) this.setState({mechanisms}); }); }; @@ -81,6 +96,11 @@ export default class Action extends React.Component< fetchUserOu().then(ou=>this.setState({userOu: ou})); } + async getL3Ous(){ + let ous = await getLevel3OUs(); + this.setState({ous: ous}); + } + performAction = (action:string)=>{ this.setState({processing: true}); performAction(action, this.state.workflow.id, this.state.period.id, this.state.mechanisms.map(m=>m.meta), this.state.mechanismState.status).then((response)=>{ diff --git a/src/modules/action/components/mechanism/mechanismTabs.component.tsx b/src/modules/action/components/mechanism/mechanismTabs.component.tsx index e2d54f2..8083207 100644 --- a/src/modules/action/components/mechanism/mechanismTabs.component.tsx +++ b/src/modules/action/components/mechanism/mechanismTabs.component.tsx @@ -69,7 +69,7 @@ export default function MechanismTabs({workflow, period, userOu, mechanisms, mec return setOpenTab(tabIndex)} variant="scrollable" onClick={()=>userClicked(clicks+1)}> {renderOverviewTab(mechanisms.length)} - {mechanisms.slice(0, 29).map(mechanism=>)} + {mechanisms.slice(0, 29).map(mechanism=>)} {lengthWarning(mechanisms.length, clicks)} {renderMechanismInfo(openTab, workflow, period, userOu, mechanismState, mechanisms)} diff --git a/src/modules/action/services/ou.service.tsx b/src/modules/action/services/ou.service.tsx new file mode 100644 index 0000000..8c42295 --- /dev/null +++ b/src/modules/action/services/ou.service.tsx @@ -0,0 +1,14 @@ +import api from "../../shared/services/api.service"; + +/** + * get all the level 3 OUs which + * @param workflow string + * @param period string + */ + function getLevelThreeOusUrl(){ + return `/organisationUnits/?level=3&paging=false`; +} + +export function getLevel3OUs():Promise<[]>{ + return api.get(getLevelThreeOusUrl()).then(response=>response.organisationUnits); +}