Skip to content

Commit

Permalink
Merge pull request #424 from EyeSeeTea/development
Browse files Browse the repository at this point in the history
Release 1.0.1
  • Loading branch information
adrianq authored Feb 11, 2022
2 parents 5e6b4d1 + 915d0cb commit 2652ffa
Show file tree
Hide file tree
Showing 42 changed files with 898 additions and 236 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ module.exports = {
},
plugins: ["cypress"],
env: { "cypress/globals": true },
parserOptions: {
warnOnUnsupportedTypeScriptVersion: false,
},
settings: {
react: {
pragma: "React",
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Application testing
on:
push:
workflow_dispatch:
jobs:
unit-tests:
name: Unit tests
runs-on: self-hosted
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: "12.x"

- name: Install yarn
run: npm install -g yarn

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Cache yarn dependencies
uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Installing Dependencies
run: yarn install --frozen-lockfile --silent

- name: Install translations
run: yarn localize

- name: Run jest tests
run: yarn test

- name: Run typescript tests
run: npx tsc
44 changes: 0 additions & 44 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions cypress/integration/00.project-create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ describe("Projects - Create", () => {
const startDate = moment();
const endDate = moment().add(3, "months");

cy.contains("Start Date").click({ force: true });
cy.contains("Start Date (*)").click({ force: true });
selectDatePicker(startDate.year(), startDate.format("MMM"));

cy.contains("End Date").click({ force: true });
cy.contains("End Date (*)").click({ force: true });
selectDatePicker(endDate.year(), endDate.format("MMM"));

// Funders
Expand Down
6 changes: 3 additions & 3 deletions cypress/integration/08.project-indicators.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ describe("Projects - Indicators", () => {
selectInMultiSelector("sectors", "Nutrition");
cy.contains("Next").click();

// Set pageSize = 50
cy.contains("20").click();
cy.contains("50").click();
// Change pageSize so all indicators are shown in a single page
cy.get(".MuiTablePagination-root").contains("20").click();
cy.get(".MuiMenu-list").contains("100").click();

new IndicatorsPage(cy)
.selectSector("Agriculture")
Expand Down
1 change: 1 addition & 0 deletions cypress/support/pages/indicators-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default class IndicatorsPage {
}

select(code) {
cy.log(`Select indicator ${code}`);
this.clickSelected(code);
return this;
}
Expand Down
10 changes: 5 additions & 5 deletions 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.0.0",
"version": "1.0.1",
"license": "GPL-3.0",
"author": "EyeSeeTea team",
"homepage": ".",
Expand All @@ -18,8 +18,8 @@
"@dhis2/d2-ui-forms": "^6.5.3",
"@dhis2/ui-core": "^4.8.0",
"@dhis2/ui-widgets": "^2.0.8",
"@eyeseetea/d2-api": "1.10.0",
"@eyeseetea/d2-ui-components": "2.6.6",
"@eyeseetea/d2-api": "1.11.0",
"@eyeseetea/d2-ui-components": "2.6.11",
"@material-ui/core": "4.11.3",
"@material-ui/icons": "4.11.2",
"@material-ui/styles": "4.11.3",
Expand Down Expand Up @@ -125,9 +125,9 @@
"husky": "4.3.8",
"jest": "26.6.3",
"parse-typed-args": "^0.2.0",
"prettier": "2.2.1",
"prettier": "2.5.1",
"ts-node": "9.1.1",
"typescript": "4.1.3",
"typescript": "4.5.5",
"wait-on": "5.2.1"
},
"manifest.webapp": {
Expand Down
2 changes: 1 addition & 1 deletion src/components/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function initFeedbackTool(d2: D2, appConfig: AppConfig): void {
...appConfig.feedback,
i18nPath: "feedback-tool/i18n",
};
((window as unknown) as AppWindow).$.feedbackDhis2(d2, appKey, feedbackOptions);
(window as unknown as AppWindow).$.feedbackDhis2(d2, appKey, feedbackOptions);
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/components/data-entry/DataEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,8 @@ function setSelectPeriod(
if (!iframe || !iframe.contentWindow) return false;

const iframeWindow = iframe.contentWindow as Window & DataEntryWindow;
const periodSelector = iframeWindow.document.querySelector<HTMLSelectElement>(
"#selectedPeriodId"
);
const periodSelector =
iframeWindow.document.querySelector<HTMLSelectElement>("#selectedPeriodId");

if (periodSelector && periodKey) {
const now = moment();
Expand Down
2 changes: 1 addition & 1 deletion src/components/data-entry/data-entry-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export interface Options {

/* Function to eval within the iframe to send/receive events to/from the parent page */
function setupDataEntryInterceptors(options: Options = {}) {
const iframeWindow = (window as unknown) as DataEntryWindow;
const iframeWindow = window as unknown as DataEntryWindow;
console.debug("|data-entry|:setup-interceptors", iframeWindow.dataEntryHooksInit, options);
if (iframeWindow.dataEntryHooksInit) return;

Expand Down
4 changes: 2 additions & 2 deletions src/components/steps/data-elements/DataElementsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export interface DataElementsTableProps {
}

const paginationOptions = {
pageSizeOptions: [10, 20, 50],
pageSizeOptions: [10, 20, 50, 100],
};

const initialPagination: Partial<TablePagination> = {
Expand All @@ -49,7 +49,7 @@ const initialPagination: Partial<TablePagination> = {
};

const initialSorting: TableSorting<DataElement> = {
field: "series",
field: "crossInfo",
order: "asc" as const,
};

Expand Down
7 changes: 4 additions & 3 deletions src/components/steps/org-units/OrgUnitsStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ const OrgUnitsStep: React.FC<StepProps> = ({ project, onChange }) => {
.map(location => ({ value: location.id, text: location.displayName }));
}, [project]);

const selectedLocations = React.useMemo(() => project.locations.map(location => location.id), [
project,
]);
const selectedLocations = React.useMemo(
() => project.locations.map(location => location.id),
[project]
);

return (
<React.Fragment>
Expand Down
2 changes: 1 addition & 1 deletion src/components/steps/save/SaveStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function useSave(project: Project, action: StepProps["action"], projectInfo: Rea
} else {
setErrorMessage(JSON.stringify({ response, payload }, null, 2));
}
} catch (err) {
} catch (err: any) {
setSaving(false);
console.error(err);
snackbar.error(err.message || err.toString());
Expand Down
8 changes: 4 additions & 4 deletions src/components/steps/sharing/SharingStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ const SharingStep: React.FC<StepProps> = props => {
},
[project, projectSharing, onChange]
);
const search = React.useCallback((query: string) => searchUsers(api, query, project), [
api,
project,
]);
const search = React.useCallback(
(query: string) => searchUsers(api, query, project),
[api, project]
);

const classes = useStyles();

Expand Down
2 changes: 1 addition & 1 deletion src/components/utils/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export async function withSnackbarOnError<T>(
const { onCatch, onFinally } = options || {};
try {
return await fn();
} catch (err) {
} catch (err: any) {
const bodyMessage = err.response?.data?.message;
console.error(err);
if (onCatch) onCatch();
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function configI18n(userSettings: UserSettings) {
async function main() {
const baseUrl = await getBaseUrl();
const d2 = await init({ baseUrl: baseUrl + "/api", schemas: [] });
const api = new D2Api({ baseUrl, backend: "xhr", timeout: 60 * 1000 });
const api = new D2Api({ baseUrl, backend: "fetch", timeout: 60 * 1000 });
const userSettings = (await api.get("/userSettings").getData()) as UserSettings;
configI18n(userSettings);
const config = { baseUrl, apiVersion: 30 };
Expand All @@ -55,7 +55,7 @@ async function main() {
),
document.getElementById("root")
);
} catch (err) {
} catch (err: any) {
console.error(err);
ReactDOM.render(
React.createElement("div", {}, err.toString()),
Expand Down
2 changes: 1 addition & 1 deletion src/migrations/dataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function deleteDataStore(
): Promise<void> {
try {
await api.delete(`/dataStore/${dataStoreNamespace}/${dataStoreKey}`).getData();
} catch (error) {
} catch (error: any) {
if (!error.response || error.response.status !== 404) {
throw error;
}
Expand Down
2 changes: 1 addition & 1 deletion src/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class MigrationsRunner {
debug(`Apply migration ${zeroPad(migration.version, 2)} - ${migration.name}`);
try {
await migration.migrate(api, debug);
} catch (error) {
} catch (error: any) {
const errorMsg = `${migration.name}: ${error.message}`;
await this.saveConfig({ errorMsg });
throw error;
Expand Down
2 changes: 1 addition & 1 deletion src/migrations/tasks/05.extend-covid-disaggregation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ExtendCovidDisaggregation {
console.debug(res);

this.debug("Update category option combos");
await this.api.maintenance.categoryOptionComboUpdate().getData();
await this.api.maintenance.runTasks(["categoryOptionComboUpdate"]).getData();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/migrations/tasks/06.add-benefits-disaggregation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class AddBenefitsDisaggregationMigration {
await post(this.api, this.debug, payload);

this.debug("Update category option combos");
await this.api.maintenance.categoryOptionComboUpdate().getData();
await this.api.maintenance.runTasks(["categoryOptionComboUpdate"]).getData();
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/models/Disaggregation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,10 @@ export class Disaggregation {
return !!this.data.mapping[dataElementId];
}

setCovid19WithRelations(
options: SetCovid19WithRelationsOptions
): { selectionInfo: SelectionInfo; disaggregation: Disaggregation } {
setCovid19WithRelations(options: SetCovid19WithRelationsOptions): {
selectionInfo: SelectionInfo;
disaggregation: Disaggregation;
} {
const { dataElementsSet, sectorId, isSet } = options;
const isCovid = this.isCovid19.bind(this);

Expand Down
11 changes: 6 additions & 5 deletions src/models/MerReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,11 +521,12 @@ async function getProjectInfoByOrgUnitId(api: D2Api, orgUnits: Ref[]) {
return _.fromPairs(
_.compact(
await runPromises(
orgUnits.map(orgUnit => () =>
dataStore
.get<ProjectInfo | undefined>(getProjectStorageKey(orgUnit))
.getData()
.then(value => [orgUnit.id, value] as [string, ProjectInfo])
orgUnits.map(
orgUnit => () =>
dataStore
.get<ProjectInfo | undefined>(getProjectStorageKey(orgUnit))
.getData()
.then(value => [orgUnit.id, value] as [string, ProjectInfo])
),
{ concurrency: 3 }
)
Expand Down
8 changes: 2 additions & 6 deletions src/models/MerReportSpreadsheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,8 @@ class MerReportSpreadsheet {
addNarrativeSheet(workbook: Workbook) {
const { config } = this.merReport;
const { merReport } = this;
const {
date,
organisationUnit,
countryDirector,
projectedActivitiesNextMonth,
} = merReport.data;
const { date, organisationUnit, countryDirector, projectedActivitiesNextMonth } =
merReport.data;
const countryName = organisationUnit.displayName;
const title = i18n.t("Monthly Executive Report") + " - " + countryName;
const now = moment();
Expand Down
7 changes: 4 additions & 3 deletions src/models/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,10 @@ class Project {
return new ProjectDelete(config, api).delete(ids);
}

setCovid19(
options: SetCovid19WithRelationsOptions
): { selectionInfo: SelectionInfo; project: Project } {
setCovid19(options: SetCovid19WithRelationsOptions): {
selectionInfo: SelectionInfo;
project: Project;
} {
const res = this.disaggregation.setCovid19WithRelations(options);
const { selectionInfo, disaggregation: newDisaggregation } = res;
const newProject = this.setObj({ disaggregation: newDisaggregation });
Expand Down
9 changes: 5 additions & 4 deletions src/models/ProjectAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ export default class ProjectAnalytics {
return new ProjectAnalytics(project, orgUnit, valuesByKey);
}

get(dataElement: DataElement, periodId: string, categoryOptions: Ref[]): number {
get(dataElement: DataElement, periodId: string, categoryOptions: Ref[]): number | undefined {
const key = ProjectAnalytics.getKey([periodId, this.orgUnit.id, dataElement.id]);
const data = this.valuesByKey[key] || [];
const getCategoryOptionIds = new Set(getIds(categoryOptions));
return _(data)
const values = data
.filter(({ categoryOptionIds }) => isSuperset(categoryOptionIds, getCategoryOptionIds))
.map(({ value }) => value)
.sum();
.map(({ value }) => value);

return values.length > 0 ? _.sum(values) : undefined;
}

static getKey(ss: string[]): string {
Expand Down
Loading

0 comments on commit 2652ffa

Please sign in to comment.