From 3e70a995cbbc07bf505b509dedea057b4baef3ca Mon Sep 17 00:00:00 2001 From: Eduardo Peredo Rivero Date: Thu, 2 Nov 2023 11:14:37 -0500 Subject: [PATCH 1/5] update d2-ui-components to 2.7.0_beta.2 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 58bb802..c49bd5c 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@dhis2/ui-core": "6.24.0", "@dhis2/ui-widgets": "6.24.0", "@eyeseetea/d2-api": "1.11.0", - "@eyeseetea/d2-ui-components": "2.7.0", + "@eyeseetea/d2-ui-components": "2.7.0_beta.2", "@eyeseetea/xlsx-populate": "4.1.0", "@material-ui/core": "4.12.3", "@material-ui/icons": "4.11.2", diff --git a/yarn.lock b/yarn.lock index e4d973f..9c81b68 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3985,10 +3985,10 @@ react "^16.12.0" yargs "^14.0.0" -"@eyeseetea/d2-ui-components@2.7.0": - version "2.7.0" - resolved "https://registry.yarnpkg.com/@eyeseetea/d2-ui-components/-/d2-ui-components-2.7.0.tgz#5a09f5212d4da6ce4fa510978d2535a0f6a4de57" - integrity sha512-g/nl0PFQCFjcn9V/YSIwbCrQJOtTa5ngkKGBvY85Cba17PzFAwqjD5D2JQY5cBAc0NxSkIyH4QucqaSnX5/11g== +"@eyeseetea/d2-ui-components@2.7.0_beta.2": + version "2.7.0-beta.2" + resolved "https://registry.yarnpkg.com/@eyeseetea/d2-ui-components/-/d2-ui-components-2.7.0-beta.2.tgz#52fb074cf09d4f818f1df1f4a777b6e6b3dc6a2f" + integrity sha512-q3YGTvlN/pNN20VAwlA1WQba3O/Z9RqHL0bE0NRNU1t9xTJJKRUdhksL/HLjSt1U1HlCrwDTpsJ5Z6Q4lvOxuA== dependencies: "@date-io/core" "1.3.6" "@date-io/moment" "1.0.2" From b661df38bd70df336f9f55269d5b22f9e62aebb8 Mon Sep 17 00:00:00 2001 From: Eduardo Peredo Rivero Date: Thu, 2 Nov 2023 19:01:59 -0500 Subject: [PATCH 2/5] fix version --- package.json | 2 +- yarn.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c49bd5c..de60807 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@dhis2/ui-core": "6.24.0", "@dhis2/ui-widgets": "6.24.0", "@eyeseetea/d2-api": "1.11.0", - "@eyeseetea/d2-ui-components": "2.7.0_beta.2", + "@eyeseetea/d2-ui-components": "2.7.0-beta.2", "@eyeseetea/xlsx-populate": "4.1.0", "@material-ui/core": "4.12.3", "@material-ui/icons": "4.11.2", diff --git a/yarn.lock b/yarn.lock index 9c81b68..d83991e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3985,7 +3985,7 @@ react "^16.12.0" yargs "^14.0.0" -"@eyeseetea/d2-ui-components@2.7.0_beta.2": +"@eyeseetea/d2-ui-components@2.7.0-beta.2": version "2.7.0-beta.2" resolved "https://registry.yarnpkg.com/@eyeseetea/d2-ui-components/-/d2-ui-components-2.7.0-beta.2.tgz#52fb074cf09d4f818f1df1f4a777b6e6b3dc6a2f" integrity sha512-q3YGTvlN/pNN20VAwlA1WQba3O/Z9RqHL0bE0NRNU1t9xTJJKRUdhksL/HLjSt1U1HlCrwDTpsJ5Z6Q4lvOxuA== From d14a7fb04a5be3c717a0db64ea681c66a7d317a1 Mon Sep 17 00:00:00 2001 From: Eduardo Peredo Rivero Date: Fri, 3 Nov 2023 20:40:11 -0500 Subject: [PATCH 3/5] use short names in templates --- .../usecases/DownloadTemplateUseCase.ts | 27 ++++++++++++++----- .../template-selector/TemplateSelector.tsx | 3 +++ src/webapp/logic/sheetBuilder.ts | 11 ++++---- .../DownloadTemplatePage.tsx | 4 ++- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/domain/usecases/DownloadTemplateUseCase.ts b/src/domain/usecases/DownloadTemplateUseCase.ts index 7715538..6c8d3c8 100644 --- a/src/domain/usecases/DownloadTemplateUseCase.ts +++ b/src/domain/usecases/DownloadTemplateUseCase.ts @@ -38,6 +38,7 @@ export interface DownloadTemplateProps { templateType?: TemplateType; splitDataEntryTabsBySection: boolean; useCodesForMetadata: boolean; + orgUnitShortName?: boolean; } export class DownloadTemplateUseCase implements UseCase { @@ -69,9 +70,11 @@ export class DownloadTemplateUseCase implements UseCase { templateType, splitDataEntryTabsBySection, useCodesForMetadata, + orgUnitShortName, }: DownloadTemplateProps ): Promise { i18n.setDefaultNamespace("bulk-load"); + const useShortNameInOrgUnit = orgUnitShortName || false; const templateId = templateType === "custom" && customTemplateId ? customTemplateId : getGeneratedTemplateId(type); const template = await this.templateRepository.getTemplate(templateId); @@ -98,6 +101,7 @@ export class DownloadTemplateUseCase implements UseCase { populateStartDate: populateStartDate?.toDate(), populateEndDate: populateEndDate?.toDate(), relationshipsOuFilter, + orgUnitShortName: useShortNameInOrgUnit, }); // FIXME: Legacy code, sheet generator @@ -112,6 +116,7 @@ export class DownloadTemplateUseCase implements UseCase { downloadRelationships, splitDataEntryTabsBySection, useCodesForMetadata, + orgUnitShortName: useShortNameInOrgUnit, }); const workbook = await sheetBuilder.generate(); @@ -206,6 +211,7 @@ async function getElementMetadata({ populateEndDate, downloadRelationships, relationshipsOuFilter, + orgUnitShortName, }: { element: any; api: D2Api; @@ -216,6 +222,7 @@ async function getElementMetadata({ populateEndDate?: Date; downloadRelationships: boolean; relationshipsOuFilter?: RelationshipOrgUnitFilter; + orgUnitShortName: boolean; }) { const elementMetadataMap = new Map(); const endpoint = element.type === "dataSets" ? "dataSets" : "programs"; @@ -239,13 +246,19 @@ async function getElementMetadata({ const responses = await promiseMap(_.chunk(_.uniq(requestOrgUnits), 400), orgUnits => api - .get<{ organisationUnits: { id: string; displayName: string; code?: string; translations: unknown }[] }>( - "/metadata", - { - fields: "id,displayName,code,translations", - filter: `id:in:[${orgUnits}]`, - } - ) + .get<{ + organisationUnits: { + id: string; + displayShortName: string; + displayName: string; + code?: string; + translations: unknown; + }[]; + }>("/metadata", { + fields: "id,displayName,code,translations,displayShortName", + filter: `id:in:[${orgUnits}]`, + order: orgUnitShortName ? "displayShortName:asc" : "displayName:asc", + }) .getData() ); diff --git a/src/webapp/components/template-selector/TemplateSelector.tsx b/src/webapp/components/template-selector/TemplateSelector.tsx index a51f6d5..feff238 100644 --- a/src/webapp/components/template-selector/TemplateSelector.tsx +++ b/src/webapp/components/template-selector/TemplateSelector.tsx @@ -41,6 +41,7 @@ export interface TemplateSelectorProps { onChange(state: TemplateSelectorState | null): void; onChangeModel(state: DataModelProps[]): void; customTemplates: CustomTemplate[]; + onUseShortNamesChange(value: boolean): void; } export const TemplateSelector = ({ @@ -49,6 +50,7 @@ export const TemplateSelector = ({ onChange, onChangeModel, customTemplates, + onUseShortNamesChange, }: TemplateSelectorProps) => { const classes = useStyles(); const { api, compositionRoot } = useAppContext(); @@ -370,6 +372,7 @@ export const TemplateSelector = ({ typeInput={isMultipleSelection ? undefined : "radio"} listParams={orgUnitListParams} showNameSetting + onUseShortNamesChange={onUseShortNamesChange} /> ) : ( diff --git a/src/webapp/logic/sheetBuilder.ts b/src/webapp/logic/sheetBuilder.ts index bde25a9..3032420 100644 --- a/src/webapp/logic/sheetBuilder.ts +++ b/src/webapp/logic/sheetBuilder.ts @@ -51,6 +51,7 @@ export interface SheetBuilderParams { downloadRelationships: boolean; splitDataEntryTabsBySection: boolean; useCodesForMetadata: boolean; + orgUnitShortName: boolean; } export class SheetBuilder { @@ -125,7 +126,7 @@ export class SheetBuilder { this.metadataSheet = this.workbook.addWorksheet("Metadata", protectedSheet); this.fillValidationSheet(); - this.fillMetadataSheet(); + this.fillMetadataSheet(this.builder.orgUnitShortName || false); this.fillLegendSheet(); if (isTrackerProgram(element)) { @@ -638,7 +639,7 @@ export class SheetBuilder { validationSheet.cell(1, 1, 1, columnId, true).formula(`_${element.id}`).style(baseStyle); } - private fillMetadataSheet() { + private fillMetadataSheet(orgUnitShortName: boolean) { const { elementMetadata: metadata, organisationUnits } = this.builder; const metadataSheet = this.metadataSheet; @@ -713,7 +714,7 @@ export class SheetBuilder { }); organisationUnits.forEach(orgUnit => { - const { name } = this.translate(orgUnit); + const { name } = this.translate(orgUnit, orgUnitShortName); metadataSheet.cell(rowId, 1).string(orgUnit.id !== undefined ? orgUnit.id : ""); metadataSheet.cell(rowId, 2).string("organisationUnit"); metadataSheet.cell(rowId, 3).string(name ?? ""); @@ -1018,7 +1019,7 @@ export class SheetBuilder { .value(); } - private translate(item: any) { + private translate(item: any, selectedName?: boolean) { const { elementMetadata, language } = this.builder; const translations = item?.translations?.filter(({ locale }: any) => locale === language) ?? []; @@ -1047,7 +1048,7 @@ export class SheetBuilder { ) { return { name: item.code, description }; } else { - return { name, description }; + return { name: selectedName ? item.displayShortName : name, description }; } } diff --git a/src/webapp/pages/download-template/DownloadTemplatePage.tsx b/src/webapp/pages/download-template/DownloadTemplatePage.tsx index ae2da18..e187a83 100644 --- a/src/webapp/pages/download-template/DownloadTemplatePage.tsx +++ b/src/webapp/pages/download-template/DownloadTemplatePage.tsx @@ -18,6 +18,7 @@ export default function DownloadTemplatePage({ settings, themes, customTemplates const [template, setTemplate] = useState(null); const [_availableModels, setAvailableModels] = useState([]); + const [orgUnitShortName, setOrgUnitShortName] = useState(false); const handleTemplateDownloadClick = async () => { if (!template) { @@ -62,7 +63,7 @@ export default function DownloadTemplatePage({ settings, themes, customTemplates loading.show(true, i18n.t("Downloading template...")); try { - await compositionRoot.templates.download(api, templateToDownload); + await compositionRoot.templates.download(api, { ...templateToDownload, orgUnitShortName }); } catch (error: any) { console.error(error); snackbar.error(error.message ?? i18n.t("Couldn't generate template")); @@ -79,6 +80,7 @@ export default function DownloadTemplatePage({ settings, themes, customTemplates themes={themes} onChange={setTemplate} customTemplates={customTemplates} + onUseShortNamesChange={setOrgUnitShortName} />
From 21e414eaebf6341480e0c1fc61b316695aeb5e6a Mon Sep 17 00:00:00 2001 From: Eduardo Peredo Rivero Date: Wed, 15 Nov 2023 11:43:34 -0500 Subject: [PATCH 4/5] update d2-ui-components version --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index de60807..4d90d82 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@dhis2/ui-core": "6.24.0", "@dhis2/ui-widgets": "6.24.0", "@eyeseetea/d2-api": "1.11.0", - "@eyeseetea/d2-ui-components": "2.7.0-beta.2", + "@eyeseetea/d2-ui-components": "2.7.0-beta.3", "@eyeseetea/xlsx-populate": "4.1.0", "@material-ui/core": "4.12.3", "@material-ui/icons": "4.11.2", diff --git a/yarn.lock b/yarn.lock index d83991e..136ef14 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3985,10 +3985,10 @@ react "^16.12.0" yargs "^14.0.0" -"@eyeseetea/d2-ui-components@2.7.0-beta.2": - version "2.7.0-beta.2" - resolved "https://registry.yarnpkg.com/@eyeseetea/d2-ui-components/-/d2-ui-components-2.7.0-beta.2.tgz#52fb074cf09d4f818f1df1f4a777b6e6b3dc6a2f" - integrity sha512-q3YGTvlN/pNN20VAwlA1WQba3O/Z9RqHL0bE0NRNU1t9xTJJKRUdhksL/HLjSt1U1HlCrwDTpsJ5Z6Q4lvOxuA== +"@eyeseetea/d2-ui-components@2.7.0-beta.3": + version "2.7.0-beta.3" + resolved "https://registry.yarnpkg.com/@eyeseetea/d2-ui-components/-/d2-ui-components-2.7.0-beta.3.tgz#22d3ac990621ef440c33db9a389c4014fc343f37" + integrity sha512-bxdlZujwxxMuCwE/d7vvqx0x/uuQYI9K1x4RbAvFZWrytzGCtH+XTi3OsaFOKBt1RqeG2mxwSep04/DSF6AcTA== dependencies: "@date-io/core" "1.3.6" "@date-io/moment" "1.0.2" From c7734563a011986b647737ab6941cb4d5ca6ed14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ignacio=20Foche=20P=C3=A9rez?= Date: Wed, 15 Nov 2023 21:22:39 +0100 Subject: [PATCH 5/5] version bumped --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4d90d82..d136709 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "bulk-load", "description": "Bulk importing made easy", - "version": "3.22.0", + "version": "3.23.0", "license": "GPL-3.0", "author": "EyeSeeTea team", "homepage": ".",