From 6a1f57fd9a7fa1c92f2ba59c5d85b1a50e8b31af Mon Sep 17 00:00:00 2001 From: Eduardo Peredo Rivero Date: Mon, 3 Jun 2024 16:49:36 -0500 Subject: [PATCH 1/5] update i18n imports on edit page --- .../components/form/fields/PreviewInputFF.tsx | 2 +- .../user-edit-wizard/UserEditWizard.tsx | 118 +++++++++--------- src/webapp/utils/list.ts | 2 +- 3 files changed, 62 insertions(+), 60 deletions(-) diff --git a/src/webapp/components/form/fields/PreviewInputFF.tsx b/src/webapp/components/form/fields/PreviewInputFF.tsx index f621bd5..5339612 100644 --- a/src/webapp/components/form/fields/PreviewInputFF.tsx +++ b/src/webapp/components/form/fields/PreviewInputFF.tsx @@ -1,6 +1,6 @@ import { InputField } from "@dhis2/ui"; import { ConfirmationDialog } from "@eyeseetea/d2-ui-components"; -import i18n from "@eyeseetea/d2-ui-components/locales"; +import i18n from "../../../../locales"; import _ from "lodash"; import React, { useState } from "react"; import { Field, FieldRenderProps } from "react-final-form"; diff --git a/src/webapp/components/user-edit-wizard/UserEditWizard.tsx b/src/webapp/components/user-edit-wizard/UserEditWizard.tsx index a0e3621..0c5a809 100644 --- a/src/webapp/components/user-edit-wizard/UserEditWizard.tsx +++ b/src/webapp/components/user-edit-wizard/UserEditWizard.tsx @@ -1,5 +1,5 @@ import { Button, ButtonStrip, NoticeBox } from "@dhis2/ui"; -import i18n from "@eyeseetea/d2-ui-components/locales"; +import i18n from "../../../locales"; import { Paper, Step, StepLabel, Stepper } from "@material-ui/core"; import { ArrowBack, ArrowForward } from "@material-ui/icons"; import { FORM_ERROR } from "final-form"; @@ -11,59 +11,6 @@ import { User } from "../../../domain/entities/User"; import { useGoBack } from "../../hooks/useGoBack"; import { UserEditWizardStep, UserEditWizardStepProps } from "./UserEditWizardStep"; -const steps: WizardStep[] = [ - { - key: `general-info`, - label: i18n.t("General info"), - component: UserEditWizardStep, - props: { - fields: [ - "username", - "firstName", - "surname", - "email", - "externalAuth", - "password", - "openId", - "ldapId", - "accountExpiry", - ], - }, - }, - - { - key: `assignment`, - label: i18n.t("Assignment"), - component: UserEditWizardStep, - props: { - fields: [ - "userRoles", - "organisationUnits", - "dataViewOrganisationUnits", - "searchOrganisationsUnits", - "userGroups", - ], - }, - }, - { - key: `other`, - label: i18n.t("Other information"), - component: UserEditWizardStep, - props: { - fields: [ - "uiLocale", - "dbLocale", - "phoneNumber", - "whatsApp", - "facebookMessenger", - "skype", - "telegram", - "twitter", - ], - }, - }, -]; - interface WizardStep { key: string; label: string; @@ -94,6 +41,61 @@ export const UserEditWizard: React.FC = ({ user, onSave, on [onSave, goBack] ); + const steps = React.useMemo((): WizardStep[] => { + return [ + { + key: `general-info`, + label: i18n.t("General info"), + component: UserEditWizardStep, + props: { + fields: [ + "username", + "firstName", + "surname", + "email", + "externalAuth", + "password", + "openId", + "ldapId", + "accountExpiry", + ], + }, + }, + + { + key: `assignment`, + label: i18n.t("Assignment"), + component: UserEditWizardStep, + props: { + fields: [ + "userRoles", + "organisationUnits", + "dataViewOrganisationUnits", + "searchOrganisationsUnits", + "userGroups", + ], + }, + }, + { + key: `other`, + label: i18n.t("Other information"), + component: UserEditWizardStep, + props: { + fields: [ + "uiLocale", + "dbLocale", + "phoneNumber", + "whatsApp", + "facebookMessenger", + "skype", + "telegram", + "twitter", + ], + }, + }, + ]; + }, []); + return ( autocomplete="off" @@ -107,7 +109,7 @@ export const UserEditWizard: React.FC = ({ user, onSave, on )} - + {steps.map(({ component: Component, props, key }) => ( ))} @@ -118,7 +120,7 @@ export const UserEditWizard: React.FC = ({ user, onSave, on ); }; -const Wizard: React.FC<{ onCancel: any }> = ({ children, onCancel }) => { +const Wizard: React.FC<{ steps: WizardStep[]; onCancel: any }> = ({ children, onCancel, steps }) => { const [step, setStep] = useState(steps[0]?.key ?? ""); const index = _.findIndex(steps, ({ key }) => key === step); const page = index > 0 ? index : 0; @@ -129,14 +131,14 @@ const Wizard: React.FC<{ onCancel: any }> = ({ children, onCancel }) => { const index = steps.findIndex(({ key }) => key === step); return steps[index + 1]?.key ?? step; }); - }, []); + }, [steps]); const onPrev = useCallback(() => { setStep(step => { const index = steps.findIndex(({ key }) => key === step); return steps[index - 1]?.key ?? step; }); - }, []); + }, [steps]); const jumpStep = useCallback((currentStep: string) => setStep(currentStep), []); diff --git a/src/webapp/utils/list.ts b/src/webapp/utils/list.ts index a8c4e8b..8f2167e 100644 --- a/src/webapp/utils/list.ts +++ b/src/webapp/utils/list.ts @@ -1,4 +1,4 @@ -import i18n from "@eyeseetea/d2-ui-components/locales"; +import i18n from "../../locales"; import _ from "lodash"; export function ellipsizedList(items: string[], limit = 3): string { From bbf1777a0d1c10b464301e8f8eba8b8c05cecf41 Mon Sep 17 00:00:00 2001 From: nshandra <34254522+nshandra@users.noreply.github.com> Date: Mon, 23 Sep 2024 13:06:31 +0200 Subject: [PATCH 2/5] fix: use usersToSave instead of users in the users metadata POST, make organisationUnits a mandatory CSV column --- src/legacy/models/userHelpers.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/legacy/models/userHelpers.js b/src/legacy/models/userHelpers.js index d205b36..a7d2120 100644 --- a/src/legacy/models/userHelpers.js +++ b/src/legacy/models/userHelpers.js @@ -12,7 +12,8 @@ const fieldSplitChar = "||"; export const fieldImportSuffix = "Import"; -const requiredPropertiesOnImport = ["username", "password", "firstName", "surname", "userRoles"]; +// NOTE: UEApp allows to create a user without organisationUnits, but DHIS2 User App does not. +const requiredPropertiesOnImport = ["username", "password", "firstName", "surname", "userRoles", "organisationUnits"]; const propertiesIgnoredOnImport = ["id", "created", "lastUpdated", "lastLogin"]; @@ -404,6 +405,7 @@ async function saveUsers(d2, users, d2Api, currentUser) { const d2Logger = await buildLogger(d2Api, currentUser); d2Logger?.log({ users: buildUserWithoutPassword(users) }); const response = await postMetadata(api, { users: users }, d2Logger); + // NOTE: this executes even when postMetadata fails await userRepository.updateUserGroups(usersToSave, existingUsersToUpdate, d2Logger).runAsync(); return response; } From 549c10b880add7a6b2737b2437dbb57395091ef5 Mon Sep 17 00:00:00 2001 From: nshandra <34254522+nshandra@users.noreply.github.com> Date: Mon, 23 Sep 2024 13:21:20 +0200 Subject: [PATCH 3/5] fix: use usersToSave (for real this time) --- src/legacy/models/userHelpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/legacy/models/userHelpers.js b/src/legacy/models/userHelpers.js index a7d2120..6d37b68 100644 --- a/src/legacy/models/userHelpers.js +++ b/src/legacy/models/userHelpers.js @@ -404,7 +404,7 @@ async function saveUsers(d2, users, d2Api, currentUser) { const usersToSave = getUsersToSave(users, existingUsersToUpdate); const d2Logger = await buildLogger(d2Api, currentUser); d2Logger?.log({ users: buildUserWithoutPassword(users) }); - const response = await postMetadata(api, { users: users }, d2Logger); + const response = await postMetadata(api, { users: usersToSave }, d2Logger); // NOTE: this executes even when postMetadata fails await userRepository.updateUserGroups(usersToSave, existingUsersToUpdate, d2Logger).runAsync(); return response; From 19b81d2b38ca3882aee3700c50502927f7fcf3da Mon Sep 17 00:00:00 2001 From: Adrian Quintana Date: Tue, 24 Sep 2024 11:51:37 +0100 Subject: [PATCH 4/5] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index deb7795..2321323 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "user-extended-app", "description": "DHIS2 Extended User app", - "version": "1.5.1", + "version": "1.5.2", "license": "GPL-3.0", "author": "EyeSeeTea team", "homepage": ".", From 0cb65277111392112bac20189f8942f9af67d4bf Mon Sep 17 00:00:00 2001 From: Adrian Quintana Date: Tue, 24 Sep 2024 11:53:17 +0100 Subject: [PATCH 5/5] translations --- i18n/en.pot | 10 +++++----- i18n/es.po | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/i18n/en.pot b/i18n/en.pot index 53b984b..ad55f5b 100644 --- a/i18n/en.pot +++ b/i18n/en.pot @@ -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-07-08T18:07:48.975Z\n" -"PO-Revision-Date: 2024-07-08T18:07:48.975Z\n" +"POT-Creation-Date: 2024-09-24T10:51:56.735Z\n" +"PO-Revision-Date: 2024-09-24T10:51:56.735Z\n" msgid "ID" msgstr "" @@ -224,6 +224,9 @@ msgstr "" msgid "Logger" msgstr "" +msgid "Error saving user" +msgstr "" + msgid "General info" msgstr "" @@ -233,9 +236,6 @@ msgstr "" msgid "Other information" msgstr "" -msgid "Error saving user" -msgstr "" - msgid "Cancel" msgstr "" diff --git a/i18n/es.po b/i18n/es.po index 1f0138f..acd3ae4 100644 --- a/i18n/es.po +++ b/i18n/es.po @@ -1,7 +1,7 @@ msgid "" msgstr "" "Project-Id-Version: i18next-conv\n" -"POT-Creation-Date: 2024-07-08T18:07:48.975Z\n" +"POT-Creation-Date: 2024-09-24T10:51:56.735Z\n" "PO-Revision-Date: 2018-10-25T09:02:35.143Z\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -228,6 +228,9 @@ msgstr "Configuración" msgid "Logger" msgstr "" +msgid "Error saving user" +msgstr "Error al guardar usuario" + msgid "General info" msgstr "Información General" @@ -237,9 +240,6 @@ msgstr "" msgid "Other information" msgstr "Otra información" -msgid "Error saving user" -msgstr "Error al guardar usuario" - msgid "Cancel" msgstr "Cancelar"