Skip to content

Commit

Permalink
Merge pull request #526 from EyeSeeTea/development
Browse files Browse the repository at this point in the history
Release 1.6.2
  • Loading branch information
adrianq authored Dec 13, 2023
2 parents d414246 + 0e1de0f commit 7ad7840
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 23 deletions.
12 changes: 9 additions & 3 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: 2023-11-30T21:50:54.611Z\n"
"PO-Revision-Date: 2023-11-30T21:50:54.611Z\n"
"POT-Creation-Date: 2023-12-05T11:01:02.938Z\n"
"PO-Revision-Date: 2023-12-05T11:01:02.938Z\n"

msgid "Validating Project"
msgstr ""
Expand All @@ -20,6 +20,9 @@ msgstr ""
msgid "Unknown error"
msgstr ""

msgid "Error uploading files: {{message}}"
msgstr ""

msgid "Files"
msgstr ""

Expand Down Expand Up @@ -514,7 +517,10 @@ msgstr ""
msgid "Documents"
msgstr ""

msgid "Is this DART applicable?"
msgid "DART"
msgstr ""

msgid "Partner"
msgstr ""

msgid "Award Number should be a number of 5 digits"
Expand Down
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.6.1",
"version": "1.6.2",
"license": "GPL-3.0",
"author": "EyeSeeTea team",
"homepage": ".",
Expand Down
4 changes: 3 additions & 1 deletion src/components/attach-files-dialog/AttachFilesDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ export const AttachFilesDialog: React.FC<AttachFilesDialogProps> = props => {
onClose();
} catch (err: any) {
const message = err?.response?.data?.message || i18n.t("Unknown error");
snackbar.error(i18n.t("Error uploading files: {{message}}", { message }));
snackbar.error(
i18n.t("Error uploading files: {{message}}", { message, nsSeparator: false })
);
} finally {
loading.hide();
}
Expand Down
8 changes: 7 additions & 1 deletion src/components/steps/general-info/GeneralInfoStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type StringField = "name" | "description" | "awardNumber" | "subsequentLettering

type DateField = "startDate" | "endDate";

type BooleanField = "isDartApplicable";
type BooleanField = "isDartApplicable" | "partner";

type ProjectData = Pick<Project, StringField | DateField | BooleanField>;

Expand Down Expand Up @@ -77,6 +77,12 @@ class GeneralInfoStep extends React.Component<StepProps> {
checked: project.isDartApplicable,
},
}),
getCheckBoxField("partner", project.partner, {
onUpdateField: this.onUpdateField,
props: {
checked: project.partner,
},
}),
];
return (
<Card>
Expand Down
8 changes: 6 additions & 2 deletions src/models/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ export const baseConfig = {
awardNumberPrefix: "AWARD_NUMBER_",
},
organisationUnitGroups: {
isDartApplicable: "IS_DART_APPLICABLE",
isDartApplicable: "DART",
partner: "PARTNER",
},
organisationUnitGroupSets: {
funder: "FUNDER",
Expand Down Expand Up @@ -251,7 +252,10 @@ const metadataParams = {
},
filter: {
code: {
in: [baseConfig.organisationUnitGroups.isDartApplicable],
in: [
baseConfig.organisationUnitGroups.isDartApplicable,
baseConfig.organisationUnitGroups.partner,
],
},
},
},
Expand Down
5 changes: 4 additions & 1 deletion src/models/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export interface ProjectData {
sharing: Sharing;
documents: ProjectDocument[];
isDartApplicable: boolean;
partner: boolean;
}

export interface Dashboard {
Expand Down Expand Up @@ -234,7 +235,8 @@ class Project {
initialData: i18n.t("Initial Data"),
sharing: i18n.t("Sharing"),
documents: i18n.t("Documents"),
isDartApplicable: i18n.t("Is this DART applicable?"),
isDartApplicable: i18n.t("DART"),
partner: i18n.t("Partner"),
};

static getFieldName(field: ProjectField): string {
Expand Down Expand Up @@ -468,6 +470,7 @@ class Project {
sharing: ProjectSharing.getInitialSharing(config),
initialData: undefined,
isDartApplicable: false,
partner: false,
};
return new Project(api, config, projectData);
}
Expand Down
37 changes: 29 additions & 8 deletions src/models/ProjectDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,10 @@ export default class ProjectDb {
group => group.id === config.organisationUnitGroups.isDartApplicable.id
);

const partnerGroup = orgUnit.organisationUnitGroups.some(
group => group.id === config.organisationUnitGroups.partner.id
);

const projectData = {
id: orgUnit.id,
name: displayName,
Expand All @@ -781,6 +785,7 @@ export default class ProjectDb {
return ProjectDocument.create(projectDocument);
}),
isDartApplicable: isInDartApplicableGroup,
partner: partnerGroup,
};
const project = new Project(api, config, { ...projectData, initialData: projectData });
return project;
Expand Down Expand Up @@ -933,6 +938,7 @@ async function getOrgUnitGroupsMetadata(
...project.locations,
awardNumberOrgUnitGroupBase,
{ id: config.organisationUnitGroups.isDartApplicable.id },
{ id: config.organisationUnitGroups.partner.id },
])
);

Expand Down Expand Up @@ -962,14 +968,15 @@ async function getOrgUnitGroupsMetadata(

const organisationUnitGroups = orgUnitGroupsToSave.map(orgUnitGroup => {
if (orgUnitGroup.id === config.organisationUnitGroups.isDartApplicable.id) {
const currentOrgUnits = orgUnitGroup.organisationUnits || [];
const orgUnitsDartApplicable = project.isDartApplicable
? _([...currentOrgUnits, { id: project.id }])
.uniqBy(ou => ou.id)
.value()
: currentOrgUnits.filter(ou => ou.id !== project.id);

return { ...orgUnitGroup, organisationUnits: orgUnitsDartApplicable };
return checkIfProjectIsInGroup(orgUnitGroup, {
projectId: project.id,
condition: project.isDartApplicable,
});
} else if (orgUnitGroup.id === config.organisationUnitGroups.partner.id) {
return checkIfProjectIsInGroup(orgUnitGroup, {
projectId: project.id,
condition: project.partner,
});
} else {
const organisationUnits = _(orgUnitGroup.organisationUnits || [])
.filter(ou => ou.id !== orgUnitId)
Expand All @@ -991,6 +998,20 @@ async function getOrgUnitGroupsMetadata(
return { organisationUnitGroups, organisationUnitGroupSets };
}

function checkIfProjectIsInGroup(
orgUnitGroup: OrgUnitGroup,
{ projectId, condition }: { projectId: string; condition: boolean }
) {
const currentOrgUnits = orgUnitGroup.organisationUnits || [];
const orgUnitsDartApplicable = condition
? _([...currentOrgUnits, { id: projectId }])
.uniqBy(ou => ou.id)
.value()
: currentOrgUnits.filter(ou => ou.id !== projectId);

return { ...orgUnitGroup, organisationUnits: orgUnitsDartApplicable };
}

function getOrgUnitId(orgUnit: { path: string }): string {
const id = _.last(orgUnit.path.split("/"));
if (id) return id;
Expand Down
1 change: 1 addition & 0 deletions src/models/ProjectInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class ProjectInfo {
field(fields.isDartApplicable, project =>
project.isDartApplicable ? i18n.t("Yes") : i18n.t("No")
),
field(fields.partner, project => (project.partner ? i18n.t("Yes") : i18n.t("No"))),
field(fields.funders, project => displayNames(project.funders)),
field(i18n.t("Selected country"), project =>
project.parentOrgUnit ? project.parentOrgUnit.displayName : "-"
Expand Down
5 changes: 5 additions & 0 deletions src/models/__tests__/Project.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ describe("Project", () => {
expect(project.dashboard).toEqual({});
expect(project.initialData).toEqual(undefined);
expect(project.isDartApplicable).toEqual(false);
expect(project.partner).toEqual(false);
});

it("has data element sets", () => {
Expand All @@ -99,6 +100,7 @@ describe("Project", () => {
moment("2020-03-31").format("L")
);
expect(project.isDartApplicable).toEqual(true);
expect(project.partner).toEqual(true);
expect(project.sectors.map(sector => sector.code)).toEqual(["SECTOR_LIVELIHOODS"]);
expect(project.funders.map(funder => funder.displayName)).toEqual([]);
expect(project.locations.map(location => location.displayName)).toEqual([
Expand Down Expand Up @@ -517,6 +519,9 @@ const metadataForGet = {
{
id: "q0u5u6Of0Wm",
},
{
id: "VnvEdFSucIW",
},
],
},
],
Expand Down
2 changes: 1 addition & 1 deletion src/models/__tests__/ProjectDb.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ describe("ProjectDb", () => {
params: {
"organisationUnitGroups:fields": ":owner",
"organisationUnitGroups:filter": [
"id:in:[aOYJkeWdv2t,yQKIZzBl22A,GsGG8967YDU,WIEp6vpQw6n,q0u5u6Of0Wm]",
"id:in:[aOYJkeWdv2t,yQKIZzBl22A,GsGG8967YDU,WIEp6vpQw6n,q0u5u6Of0Wm,VnvEdFSucIW]",
],
},
}).replyOnce(200, orgUnitsMetadata);
Expand Down
15 changes: 12 additions & 3 deletions src/models/__tests__/__snapshots__/ProjectInfo.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ exports[`getAsString 1`] = `
- Subsequent Lettering: en
- Additional Designation (Funder, Location, Sector, etc): -
- Period dates: October 2018 - March 2019
- Is this DART applicable?: No
- DART: No
- Partner: No
- Funders: funder-aOYJkeWdv2t, funder-yQKIZzBl22A
- Selected country: Bahamas
- Locations: loc-GsGG8967YDU
Expand All @@ -33,7 +34,8 @@ exports[`getAsString on new project 1`] = `
- Subsequent Lettering: en
- Additional Designation (Funder, Location, Sector, etc): -
- Period dates: October 2018 - March 2019
- Is this DART applicable?: No
- DART: No
- Partner: No
- Funders: funder-aOYJkeWdv2t, funder-yQKIZzBl22A
- Selected country: Bahamas
- Locations: loc-GsGG8967YDU
Expand Down Expand Up @@ -97,7 +99,14 @@ Array [
},
Object {
"action": "none",
"name": "Is this DART applicable?",
"name": "DART",
"prevValue": "No",
"type": "field",
"value": "No",
},
Object {
"action": "none",
"name": "Partner",
"prevValue": "No",
"type": "field",
"value": "No",
Expand Down
9 changes: 7 additions & 2 deletions src/models/__tests__/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
"awardNumberPrefix": "AWARD_NUMBER_"
},
"organisationUnitGroups": {
"isDartApplicable": "IS_DART_APPLICABLE"
"isDartApplicable": "DART",
"partner": "PARTNER"
},
"organisationUnitGroupSets": {
"funder": "FUNDER",
Expand Down Expand Up @@ -62945,7 +62946,11 @@
"organisationUnitGroups": {
"isDartApplicable": {
"id": "q0u5u6Of0Wm",
"code": "IS_DART_APPLICABLE"
"code": "DART"
},
"partner": {
"id": "VnvEdFSucIW",
"code": "PARTNER"
}
}
}

0 comments on commit 7ad7840

Please sign in to comment.