Skip to content

Commit

Permalink
Merge pull request #486 from EyeSeeTea/development
Browse files Browse the repository at this point in the history
Release 1.4.1
  • Loading branch information
adrianq authored Mar 7, 2023
2 parents a9e80af + 44a1b65 commit 35ee609
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "data-management-app",
"description": "DHIS2 Data Management App",
"version": "1.4.0",
"version": "1.4.1",
"license": "GPL-3.0",
"author": "EyeSeeTea team",
"homepage": ".",
Expand Down
82 changes: 74 additions & 8 deletions src/models/ProjectsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type BaseProject = Omit<
"organisationUnitGroups"
>;

type D2OrgUnit = SelectedPick<D2OrganisationUnitSchema, typeof orgUnitFields>;

export interface ProjectForList extends BaseProject {
sectors: Sector[];
sharing: Sharing;
Expand All @@ -68,9 +70,8 @@ export default class ProjectsList {
const order = `${sorting.field}:i${sorting.order}`;
const orgUnitIds = await this.getBaseOrgUnitIds(api, config, filters, order);

const d2OrgUnitsNested = await promiseMap(
_.chunk(orgUnitIds, 300),
async orgUnitIdsGroup => {
const d2OrgUnitsUnsorted = _.flatten(
await promiseMap(_.chunk(orgUnitIds, 300), async orgUnitIdsGroup => {
const { objects } = await api.models.organisationUnits
.get({
paging: false,
Expand All @@ -80,12 +81,10 @@ export default class ProjectsList {
})
.getData();
return objects;
}
})
);
const d2OrgUnits = _(d2OrgUnitsNested)
.flatten()
.orderBy([sorting.field], [sorting.order])
.value();

const d2OrgUnits = await this.sortOrgUnits(d2OrgUnitsUnsorted, sorting);

const projects = d2OrgUnits.map(getProjectFromOrgUnit);
const dataSetCodes = new Set(projects.map(ou => `${ou.id}_ACTUAL`));
Expand Down Expand Up @@ -157,6 +156,73 @@ export default class ProjectsList {
return paginate(_.compact(projectsWithSectors), pagination);
}

private async getDataSetsWithLastUpdatedData() {
const { objects: dataSets } = await this.api.models.dataSets
.get({
paging: false,
fields: { attributeValues: { attribute: { id: true }, value: true } },
filter: {
"attributeValues.attribute.id": {
eq: this.config.attributes.lastUpdatedData.id,
},
},
})
.getData();
return dataSets;
}

private async sortOrgUnits(
orgUnits: D2OrgUnit[],
sorting: TableSorting<ProjectForList>
): Promise<D2OrgUnit[]> {
switch (sorting.field) {
case "lastUpdatedData": {
const dataSets = await this.getDataSetsWithLastUpdatedData();
const orgUnitsInfo = this.getOrgUnitsWithLastUpdatedData(dataSets, orgUnits);
const [orgUnitsWithUpdate, orgUnitsWithoutUpdate] = _.partition(
orgUnitsInfo,
info => Boolean(info.lastUpdatedData)
);

return _(orgUnitsWithUpdate)
.orderBy([info => info.lastUpdatedData], [sorting.order])
.concat(orgUnitsWithoutUpdate)
.map(info => info.orgUnit)
.value();
}
default:
return _(orgUnits).orderBy([sorting.field], [sorting.order]).value();
}
}

private getOrgUnitsWithLastUpdatedData(
dataSets: {
attributeValues: Array<{ attribute: { id: string }; value: string }>;
}[],
orgUnits: D2OrgUnit[]
) {
const lastUpdatedDataByOrgUnitId = _(dataSets)
.map((dataSet): [Id, string] | null => {
const orgUnitId = dataSet.attributeValues.find(
dv => dv.attribute.id === this.config.attributes.orgUnitProject.id
)?.value;

const lastUpdatedData = dataSet.attributeValues.find(
dv => dv.attribute.id === this.config.attributes.lastUpdatedData.id
)?.value;

return orgUnitId && lastUpdatedData ? [orgUnitId, lastUpdatedData] : null;
})
.compact()
.fromPairs()
.value();

return orgUnits.map(orgUnit => ({
orgUnit: orgUnit,
lastUpdatedData: lastUpdatedDataByOrgUnitId[orgUnit.id],
}));
}

private getOrgUnitsCountByAwardNumber(
organisationUnitGroups: Array<{ id: string; organisationUnits: Ref[] }>
) {
Expand Down
8 changes: 4 additions & 4 deletions src/pages/projects-list/ProjectsListConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,23 @@ export function getComponentConfig(
{
...columnDate("lastUpdatedData", "datetime"),
text: i18n.t("Last Updated (data)"),
getValue: project => formatDateLong(project.lastUpdatedData) || "-",
sortable: true,
},
];

const details = [
const details: TableColumn<ProjectForList>[] = [
...columns,
{ name: "displayDescription" as const, text: i18n.t("Description") },
{
name: "user" as const,
text: i18n.t("Created By"),
getValue: (project: ProjectForList) => `${project.user.displayName}`,
getValue: project => `${project.user.displayName}`,
},
{
name: "lastUpdatedBy" as const,
text: i18n.t("Last Updated By"),
getValue: (project: ProjectForList) =>
`${project.lastUpdatedBy ? project.lastUpdatedBy.name : "-"}`,
getValue: project => `${project.lastUpdatedBy ? project.lastUpdatedBy.name : "-"}`,
},
{
name: "sharing" as const,
Expand Down

0 comments on commit 35ee609

Please sign in to comment.