Skip to content

Commit

Permalink
feat: Add Org Units filter
Browse files Browse the repository at this point in the history
upgrade dependencies
  • Loading branch information
MatiasArriola committed Dec 30, 2024
1 parent eacd33f commit 5eb79f7
Show file tree
Hide file tree
Showing 25 changed files with 731 additions and 911 deletions.
20 changes: 19 additions & 1 deletion i18n/ar.po
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: i18next-conv\n"
"POT-Creation-Date: 2024-12-16T17:57:18.316Z\n"
"POT-Creation-Date: 2024-12-30T12:25:50.318Z\n"
"PO-Revision-Date: 2018-10-25T09:02:35.143Z\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down Expand Up @@ -41,6 +41,24 @@ msgstr ""
msgid "Close"
msgstr ""

msgid "Loading..."
msgstr ""

msgid "Error"
msgstr ""

msgid "Select Organization Units"
msgstr ""

msgid "Cancel"
msgstr ""

msgid "Select"
msgstr ""

msgid "Clear"
msgstr ""

msgid "Back"
msgstr ""

Expand Down
22 changes: 20 additions & 2 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2024-12-16T17:57:18.316Z\n"
"PO-Revision-Date: 2024-12-16T17:57:18.316Z\n"
"POT-Creation-Date: 2024-12-30T12:25:50.318Z\n"
"PO-Revision-Date: 2024-12-30T12:25:50.318Z\n"

msgid "Select Dashboard"
msgstr ""
Expand Down Expand Up @@ -41,6 +41,24 @@ msgstr ""
msgid "Close"
msgstr ""

msgid "Loading..."
msgstr ""

msgid "Error"
msgstr ""

msgid "Select Organization Units"
msgstr ""

msgid "Cancel"
msgstr ""

msgid "Select"
msgstr ""

msgid "Clear"
msgstr ""

msgid "Back"
msgstr ""

Expand Down
20 changes: 19 additions & 1 deletion i18n/es.po
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: i18next-conv\n"
"POT-Creation-Date: 2024-12-16T17:57:18.316Z\n"
"POT-Creation-Date: 2024-12-30T12:25:50.318Z\n"
"PO-Revision-Date: 2018-10-25T09:02:35.143Z\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down Expand Up @@ -41,6 +41,24 @@ msgstr ""
msgid "Close"
msgstr ""

msgid "Loading..."
msgstr ""

msgid "Error"
msgstr ""

msgid "Select Organization Units"
msgstr ""

msgid "Cancel"
msgstr ""

msgid "Select"
msgstr ""

msgid "Clear"
msgstr ""

msgid "Back"
msgstr "Volver"

Expand Down
20 changes: 19 additions & 1 deletion i18n/fr.po
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: i18next-conv\n"
"POT-Creation-Date: 2024-12-16T17:57:18.316Z\n"
"POT-Creation-Date: 2024-12-30T12:25:50.318Z\n"
"PO-Revision-Date: 2018-10-25T09:02:35.143Z\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down Expand Up @@ -41,6 +41,24 @@ msgstr ""
msgid "Close"
msgstr ""

msgid "Loading..."
msgstr ""

msgid "Error"
msgstr ""

msgid "Select Organization Units"
msgstr ""

msgid "Cancel"
msgstr ""

msgid "Select"
msgstr ""

msgid "Clear"
msgstr ""

msgid "Back"
msgstr ""

Expand Down
20 changes: 19 additions & 1 deletion i18n/pt.po
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: i18next-conv\n"
"POT-Creation-Date: 2024-12-16T17:57:18.316Z\n"
"POT-Creation-Date: 2024-12-30T12:25:50.318Z\n"
"PO-Revision-Date: 2018-10-25T09:02:35.143Z\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down Expand Up @@ -41,6 +41,24 @@ msgstr ""
msgid "Close"
msgstr ""

msgid "Loading..."
msgstr ""

msgid "Error"
msgstr ""

msgid "Select Organization Units"
msgstr ""

msgid "Cancel"
msgstr ""

msgid "Select"
msgstr ""

msgid "Clear"
msgstr ""

msgid "Back"
msgstr ""

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
"url": "git+https://github.com/eyeseetea/dashboard-reports.git"
},
"dependencies": {
"@dhis2/app-runtime": "2.8.0",
"@dhis2/app-runtime": "3.10.4",
"@dhis2/d2-i18n": "1.1.0",
"@dhis2/d2-i18n-extract": "1.0.8",
"@dhis2/d2-i18n-generate": "1.2.0",
"@dhis2/ui": "6.12.0",
"@eyeseetea/d2-api": "1.13.1",
"@eyeseetea/d2-ui-components": "2.6.11",
"@dhis2/ui": "6.15.2",
"@eyeseetea/d2-api": "1.16.1",
"@eyeseetea/d2-ui-components": "2.9.0",
"@eyeseetea/feedback-component": "0.0.3",
"@krakenjs/post-robot": "^11.0.0",
"@material-ui/core": "4.12.4",
Expand Down
8 changes: 8 additions & 0 deletions src/CompositionRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import { StorageName } from "./domain/entities/Settings";
import { DataStoreD2Repository } from "./data/repositories/DataStoreD2Repository";
import { PluginVisualizationD2Repository } from "./data/repositories/PluginVisualizationD2Repository";
import { GetPluginVisualizationUseCase } from "./domain/usecases/GetPluginVisualizationUseCase";
import { GetRootOrgUnitsUseCase } from "./domain/usecases/GetRootOrgUnitsUseCase";
import { OrgUnitD2Repository } from "./data/repositories/OrgUnitD2Repository";
import { GetOrgUnitsByIdsUseCase } from "./domain/usecases/GetOrgUnitsByIdsUseCase";

export function getCompositionRoot(api: D2Api, instance: Instance, storageName: StorageName) {
const instanceRepository = new InstanceDefaultRepository(instance);
Expand All @@ -24,6 +27,7 @@ export function getCompositionRoot(api: D2Api, instance: Instance, storageName:
storageName === "datastore" ? new DataStoreD2Repository(api) : new SettingsD2ConstantRepository(api);
const exportDocxRepository = new DashboardExportDocxRepository();
const pluginVisualizationsRepository = new PluginVisualizationD2Repository(api);
const orgUnitsRepository = new OrgUnitD2Repository(api);

return {
instance: {
Expand All @@ -45,6 +49,10 @@ export function getCompositionRoot(api: D2Api, instance: Instance, storageName:
export: {
save: new SaveRawReportUseCase(exportDocxRepository),
},
orgUnits: {
getRoots: new GetRootOrgUnitsUseCase(orgUnitsRepository),
getByIds: new GetOrgUnitsByIdsUseCase(orgUnitsRepository),
},
};
}

Expand Down
36 changes: 36 additions & 0 deletions src/data/repositories/OrgUnitD2Repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { FutureData } from "../../domain/entities/Future";
import { OrgUnit } from "../../domain/entities/OrgUnit";
import { Id } from "../../domain/entities/Ref";
import { OrgUnitRepository } from "../../domain/repositories/OrgUnitRepository";
import { D2Api } from "../../types/d2-api";
import { apiToFuture } from "../../utils/futures";

const orgUnitFields = { id: true, name: true, displayName: true, path: true, level: true };

export class OrgUnitD2Repository implements OrgUnitRepository {
constructor(private api: D2Api) {}

public getOrgUnitRoots(): FutureData<OrgUnit[]> {
return apiToFuture(
this.api.models.organisationUnits.get({
paging: false,
filter: { level: { eq: "1" } },
fields: orgUnitFields,
})
).map(orgUnits => {
return orgUnits.objects;
});
}

public getOrgUnitsByIds(ids: Id[]): FutureData<OrgUnit[]> {
return apiToFuture(
this.api.models.organisationUnits.get({
paging: false,
fields: orgUnitFields,
filter: { id: { in: ids } },
})
).map(orgUnits => {
return orgUnits.objects;
});
}
}
42 changes: 35 additions & 7 deletions src/data/repositories/PluginVisualizationD2Repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class PluginVisualizationD2Repository implements PluginVisualizationRepos

get(options: {
dashboardItem: DashboardItem;
orgUnitId: Maybe<Id>;
orgUnitIds: Maybe<Id[]>;
period: ReportPeriod;
}): FutureData<PluginVisualization> {
const params = processFieldsFilterParams({ fields: visualizationFields, filter: {} });
Expand All @@ -24,7 +24,7 @@ export class PluginVisualizationD2Repository implements PluginVisualizationRepos
);
return res$
.map(res => this.applyPeriodFilters(res, options.period))
.map(res => (options.orgUnitId ? this.applyOrgUnitFilters(res, options.orgUnitId) : res))
.map(res => (options.orgUnitIds ? this.applyOrgUnitFilters(res, options.orgUnitIds) : res))
.map(res => (isD2Map(res) ? { ...res, type: "MAP" } : res));
}

Expand Down Expand Up @@ -52,11 +52,6 @@ export class PluginVisualizationD2Repository implements PluginVisualizationRepos
}
}

private applyOrgUnitFilters(item: D2PluginVisualization, _orgUnit: string) {
// TODO: filter by org unit
return item;
}

private applyPeriodToDimensionAttrs(obj: WithDimensionAttributes, period: PeriodItem[]) {
return {
rows: this.applyPeriodToDimensions(obj.rows, period),
Expand All @@ -71,6 +66,39 @@ export class PluginVisualizationD2Repository implements PluginVisualizationRepos
items: dimension.dimension === "pe" ? period : dimension.items,
}));
}

private applyOrgUnitFilters(item: D2PluginVisualization, orgUnitIds: Id[]) {
if (isD2Map(item)) {
return {
...item,
mapViews: item.mapViews.map((mapView: MapView) => ({
...mapView,
...this.applyOrgUnitToDimensionAttrs(mapView as WithDimensionAttributes, orgUnitIds),
})),
} as D2MapVisualization;
} else {
return {
...item,
...this.applyOrgUnitToDimensionAttrs(item as WithDimensionAttributes, orgUnitIds),
};
}
}

private applyOrgUnitToDimensionAttrs(obj: WithDimensionAttributes, orgUnitIds: Id[]) {
return {
rows: this.applyOrgUnitToDimensions(obj.rows, orgUnitIds),
columns: this.applyOrgUnitToDimensions(obj.columns, orgUnitIds),
filters: this.applyOrgUnitToDimensions(obj.filters, orgUnitIds),
};
}

private applyOrgUnitToDimensions(dimensions: D2Dimension[], orgUnitIds: Id[]) {
const newItems = orgUnitIds.map(id => ({ id, dimensionItemType: "ORGANISATION_UNIT" }));
return dimensions.map(dimension => ({
...dimension,
items: dimension.dimension === "ou" ? newItems : dimension.items,
}));
}
}

function isD2Map(visualization: D2PluginVisualization): visualization is D2MapVisualization {
Expand Down
22 changes: 22 additions & 0 deletions src/domain/entities/OrgUnit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import _ from "lodash";
import { Id } from "./Ref";

export type OrgUnitPath = string;

export interface OrgUnit {
id: Id;
path: OrgUnitPath;
name: string;
displayName: string;
level: number;
}

const pathSeparator = "/";

export function getIdFromPath(path: OrgUnitPath): Id {
return _.last(path.split(pathSeparator)) as Id;
}

export function getOrgUnitParentPath(path: OrgUnitPath) {
return _(path).split(pathSeparator).initial().join(pathSeparator);
}
8 changes: 8 additions & 0 deletions src/domain/repositories/OrgUnitRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { FutureData } from "../entities/Future";
import { OrgUnit } from "../entities/OrgUnit";
import { Id } from "../entities/Ref";

export interface OrgUnitRepository {
getOrgUnitRoots(): FutureData<OrgUnit[]>;
getOrgUnitsByIds(ids: Id[]): FutureData<OrgUnit[]>;
}
2 changes: 1 addition & 1 deletion src/domain/repositories/PluginVisualizationRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Maybe } from "../../types/utils";
export interface PluginVisualizationRepository {
get(options: {
dashboardItem: DashboardItem;
orgUnitId: Maybe<Id>;
orgUnitIds: Maybe<Id[]>;
period: ReportPeriod;
}): FutureData<PluginVisualization>;
}
10 changes: 10 additions & 0 deletions src/domain/usecases/GetOrgUnitsByIdsUseCase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Id } from "../entities/Ref";
import { OrgUnitRepository } from "../repositories/OrgUnitRepository";

export class GetOrgUnitsByIdsUseCase {
constructor(private orgUnitRepository: OrgUnitRepository) {}

execute(ids: Id[]) {
return this.orgUnitRepository.getOrgUnitsByIds(ids);
}
}
2 changes: 1 addition & 1 deletion src/domain/usecases/GetPluginVisualizationUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class GetPluginVisualizationUseCase {

execute(options: {
dashboardItem: DashboardItem;
orgUnitId: Maybe<Id>;
orgUnitIds: Maybe<Id[]>;
period: ReportPeriod;
}): FutureData<PluginVisualization> {
return this.visualizationRepository.get(options);
Expand Down
9 changes: 9 additions & 0 deletions src/domain/usecases/GetRootOrgUnitsUseCase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { OrgUnitRepository } from "../repositories/OrgUnitRepository";

export class GetRootOrgUnitsUseCase {
constructor(private orgUnitRepository: OrgUnitRepository) {}

execute() {
return this.orgUnitRepository.getOrgUnitRoots();
}
}
Loading

0 comments on commit 5eb79f7

Please sign in to comment.