Skip to content

Commit

Permalink
Release 3.23.0
Browse files Browse the repository at this point in the history
Merge remote-tracking branch 'upstream/master'
  • Loading branch information
ifoche committed Nov 15, 2023
2 parents fde88c4 + a1f4c5d commit 4b40b77
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 19 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": ".",
Expand All @@ -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.3",
"@eyeseetea/xlsx-populate": "4.1.0",
"@material-ui/core": "4.12.3",
"@material-ui/icons": "4.11.2",
Expand Down
27 changes: 20 additions & 7 deletions src/domain/usecases/DownloadTemplateUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface DownloadTemplateProps {
templateType?: TemplateType;
splitDataEntryTabsBySection: boolean;
useCodesForMetadata: boolean;
orgUnitShortName?: boolean;
}

export class DownloadTemplateUseCase implements UseCase {
Expand Down Expand Up @@ -69,9 +70,11 @@ export class DownloadTemplateUseCase implements UseCase {
templateType,
splitDataEntryTabsBySection,
useCodesForMetadata,
orgUnitShortName,
}: DownloadTemplateProps
): Promise<void> {
i18n.setDefaultNamespace("bulk-load");
const useShortNameInOrgUnit = orgUnitShortName || false;
const templateId =
templateType === "custom" && customTemplateId ? customTemplateId : getGeneratedTemplateId(type);
const template = await this.templateRepository.getTemplate(templateId);
Expand All @@ -98,6 +101,7 @@ export class DownloadTemplateUseCase implements UseCase {
populateStartDate: populateStartDate?.toDate(),
populateEndDate: populateEndDate?.toDate(),
relationshipsOuFilter,
orgUnitShortName: useShortNameInOrgUnit,
});

// FIXME: Legacy code, sheet generator
Expand All @@ -112,6 +116,7 @@ export class DownloadTemplateUseCase implements UseCase {
downloadRelationships,
splitDataEntryTabsBySection,
useCodesForMetadata,
orgUnitShortName: useShortNameInOrgUnit,
});
const workbook = await sheetBuilder.generate();

Expand Down Expand Up @@ -206,6 +211,7 @@ async function getElementMetadata({
populateEndDate,
downloadRelationships,
relationshipsOuFilter,
orgUnitShortName,
}: {
element: any;
api: D2Api;
Expand All @@ -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";
Expand All @@ -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()
);

Expand Down
3 changes: 3 additions & 0 deletions src/webapp/components/template-selector/TemplateSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ({
Expand All @@ -49,6 +50,7 @@ export const TemplateSelector = ({
onChange,
onChangeModel,
customTemplates,
onUseShortNamesChange,
}: TemplateSelectorProps) => {
const classes = useStyles();
const { api, compositionRoot } = useAppContext();
Expand Down Expand Up @@ -370,6 +372,7 @@ export const TemplateSelector = ({
typeInput={isMultipleSelection ? undefined : "radio"}
listParams={orgUnitListParams}
showNameSetting
onUseShortNamesChange={onUseShortNamesChange}
/>
</div>
) : (
Expand Down
11 changes: 6 additions & 5 deletions src/webapp/logic/sheetBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export interface SheetBuilderParams {
downloadRelationships: boolean;
splitDataEntryTabsBySection: boolean;
useCodesForMetadata: boolean;
orgUnitShortName: boolean;
}

export class SheetBuilder {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 ?? "");
Expand Down Expand Up @@ -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) ?? [];

Expand Down Expand Up @@ -1047,7 +1048,7 @@ export class SheetBuilder {
) {
return { name: item.code, description };
} else {
return { name, description };
return { name: selectedName ? item.displayShortName : name, description };
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/webapp/pages/download-template/DownloadTemplatePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default function DownloadTemplatePage({ settings, themes, customTemplates

const [template, setTemplate] = useState<TemplateSelectorState | null>(null);
const [_availableModels, setAvailableModels] = useState<DataModelProps[]>([]);
const [orgUnitShortName, setOrgUnitShortName] = useState(false);

const handleTemplateDownloadClick = async () => {
if (!template) {
Expand Down Expand Up @@ -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"));
Expand All @@ -79,6 +80,7 @@ export default function DownloadTemplatePage({ settings, themes, customTemplates
themes={themes}
onChange={setTemplate}
customTemplates={customTemplates}
onUseShortNamesChange={setOrgUnitShortName}
/>

<div className={classes.downloadTemplateRow}>
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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.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"
Expand Down

0 comments on commit 4b40b77

Please sign in to comment.