Skip to content

Created new fields for phonebook contacts#179

Open
tonyco97 wants to merge 9 commits into
mainfrom
issue7124
Open

Created new fields for phonebook contacts#179
tonyco97 wants to merge 9 commits into
mainfrom
issue7124

Conversation

@tonyco97

@tonyco97 tonyco97 commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

@tonyco97 tonyco97 self-assigned this Jul 6, 2026
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

Automatic builds from https://github.com/NethServer/nethlink/actions/runs/28807043109.
Commit: 225cebd

Name Platform Link
win-app.exe Windows (x64) Link
macos-app-x64.dmg MacOS (x64) Link
macos-app-arm64.dmg MacOS (arm64) Link
linux-app.AppImage Linux (x64) Link

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Automatic builds from https://github.com/NethServer/nethlink/actions/runs/28847264196.
Commit: ae61b21

Name Platform Link
win-app.exe Windows (x64) Link
macos-app-x64.dmg MacOS (x64) Link
macos-app-arm64.dmg MacOS (arm64) Link
linux-app.AppImage Linux (x64) Link

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Automatic builds from https://github.com/NethServer/nethlink/actions/runs/28856025673.
Commit: a17467f

Name Platform Link
win-app.exe Windows (x64) Link
macos-app-x64.dmg MacOS (x64) Link
macos-app-arm64.dmg MacOS (arm64) Link
linux-app.AppImage Linux (x64) Link

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Automatic builds from https://github.com/NethServer/nethlink/actions/runs/28859923656.
Commit: 6b2a492

Name Platform Link
win-app.exe Windows (x64) Link
macos-app-x64.dmg MacOS (x64) Link
macos-app-arm64.dmg MacOS (arm64) Link
linux-app.AppImage Linux (x64) Link

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Automatic builds from https://github.com/NethServer/nethlink/actions/runs/28865604004.
Commit: 3742ad9

Name Platform Link
win-app.exe Windows (x64) Link
macos-app-x64.dmg MacOS (x64) Link
macos-app-arm64.dmg MacOS (arm64) Link
linux-app.AppImage Linux (x64) Link

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

Automatic builds from https://github.com/NethServer/nethlink/actions/runs/28943202979.
Commit: bf45315

Name Platform Link
win-app.exe Windows (x64) Link
macos-app-x64.dmg MacOS (x64) Link
macos-app-arm64.dmg MacOS (arm64) Link
linux-app.AppImage Linux (x64) Link

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

Automatic builds from https://github.com/NethServer/nethlink/actions/runs/28945604891.
Commit: 21caa4a

Name Platform Link
win-app.exe Windows (x64) Link
macos-app-x64.dmg MacOS (x64) Link
macos-app-arm64.dmg MacOS (arm64) Link
linux-app.AppImage Linux (x64) Link

@tonyco97 tonyco97 requested a review from tommaso-ascani July 8, 2026 13:26
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

Automatic builds from https://github.com/NethServer/nethlink/actions/runs/28949568810.
Commit: 6afd407

Name Platform Link
win-app.exe Windows (x64) Link
macos-app-x64.dmg MacOS (x64) Link
macos-app-arm64.dmg MacOS (arm64) Link
linux-app.AppImage Linux (x64) Link

@tommaso-ascani tommaso-ascani left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review

Same feature as the sibling PRs (nethesis/nethvoice-cti#515, nethesis/nethcti-middleware#63): split firstname/lastname + new social/phone/email fields. Good news first: this PR avoided the sibling CTI PR's crash pattern — the person/company toggle keeps first name/last name/job inputs permanently mounted and only CSS-hides them (className={contactType === 'company' ? 'hidden' : ''}), so there's no ref-after-unmount dereference and no data loss switching contact type back and forth.

Bugs

1. Missing translation keysrc/renderer/src/components/Modules/NethVoice/SearchResults/SearchNumberBox.tsx (~line 209).
The new "Add to phonebook" button calls t('Phonebook.Create contact'), but only Phonebook.Create new contact was added to any of the four locale files (public/locales/{en,it} and src/renderer/public/locales/{en,it}). This key is never defined, so i18next falls back to showing the raw key/fallback text instead of a translated label.

2. "+N other numbers" badge undercounts with the new phone fieldssrc/renderer/src/components/Modules/NethVoice/SearchResults/SearchNumber.tsx (~line 55, 73).
otherDevicesCount is still computed from the old hardcoded keys = ['extension','cellphone','homephone','workphone'], never extended for workphone2/cellphone2/otherphone added by this PR. A contact whose only extra numbers are in the new fields shows no "+N other numbers" indicator at all, even though it has multiple callable numbers.

3. ModuleTitle lost its truncation tooltip with no replacement, affecting untouched consumerssrc/renderer/src/components/ModuleTitle.tsx (~lines 26-33).
The react-tooltip <Tooltip>/data-tooltip-* wiring was removed (title still gets truncate), while ContactNameAndAction.tsx got a proper replacement via the new useIsTruncated hook + CustomThemedTooltip. ModuleTitle itself didn't. Consumers this PR never touched now truncate long titles with no way to see the full text: Parking/ParkingBox.tsx (Parking (N), grows with parked-call count), About/AboutModule.tsx, Speeddials/SpeedDials/SpeedDialFormBox.tsx (localized "Edit/Create speed dial" strings can run long, e.g. in Italian).

Cleanup

4. MultiSelectCombobox and the "Add field" flyout hand-roll what Dropdown/HeadlessUI already providesrc/renderer/src/components/Nethesis/MultiSelectCombobox.tsx, AddToPhonebookBox.tsx (~lines 140-166, 318-337, 838-925).
Own outside-click listener + manual keyboard handling instead of extending the existing Dropdown/DropdownItem (which gained a topLeft position in this very PR) or the HeadlessUI Combobox pattern already used elsewhere. The file's own comment says this was "ported from the NethVoice CTI component" — i.e. the same anti-pattern flagged in the sibling PR was intentionally carried over here too.

5. Zod validation schema rebuilt on every renderAddToPhonebookBox.tsx (~lines 60-116).
The discriminatedUnion/superRefine schema (now ~20+ fields, up from ~3) is constructed inline in the component body instead of useMemo'd or hoisted to module scope, so every re-render (typing, toggling person/company, opening a submenu) reconstructs the whole zod object graph for nothing.

6. i18n already drifted between the two locale trees this PR must keep in sync by handpublic/locales/en/translations.json vs src/renderer/public/locales/en/translations.json. A quick diff shows src/renderer/... already has a "Hold" key absent from the top-level copy — evidence the manual-sync convention is already leaking, on top of finding #1 above.

7. New app-wide DropdownItem text-color class, not visually re-verified on unrelated menussrc/renderer/src/components/Nethesis/dropdown/DropdownItem.tsx (~line 38).
!isRed && !active ? theme?.item?.light : '' applies unconditionally to every non-active, non-red item, added to support the new phonebook dropdowns but with blast radius over PresenceBadge's status menu and both SettingsDevicesDialog/SettingsIncomingCallsDialog device pickers.

8. Per-item truncation hook mounted with no payoff in list viewssrc/renderer/src/components/Modules/NethVoice/BaseModule/ContactNameAndAction.tsx (~lines 93-95).
useIsTruncated([contact.company]) runs unconditionally per row, but ContactNumber.tsx (used by FavouritesBox/SpeedDialsBox) never passes showCompany, so the ref this hook watches never attaches in those exact render-heavy list contexts — pure per-item hook overhead for zero benefit there.

@tonyco97 tonyco97 requested a review from tommaso-ascani July 9, 2026 14:16
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

Automatic builds from https://github.com/NethServer/nethlink/actions/runs/29024504085.
Commit: c30556d

Name Platform Link
win-app.exe Windows (x64) Link
macos-app-x64.dmg MacOS (x64) Link
macos-app-arm64.dmg MacOS (arm64) Link
linux-app.AppImage Linux (x64) Link

@tommaso-ascani tommaso-ascani left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up on latest fixes (c30556d1)

Fix status of the 8 prior findings:

  1. Missing translation key — Turns out not actually broken: Phonebook.Create contact exists in all four locale files (it's distinct from Create new contact, the page title). False alarm on my end, sorry for the noise.
  2. "+N other numbers" undercount — Fixed. SearchNumber.tsx's keys array now includes workphone2/cellphone2/otherphone, deduped via Set.
  3. ModuleTitle lost its tooltip — Fixed. Truncation-gated tooltip reintroduced internally (useIsTruncated + data-tooltip-id + CustomThemedTooltip), so Parking/About/SpeedDialFormBox inherit it automatically with no changes needed on their end.
  4. MultiSelectCombobox/"Add field" hand-rolled — Not fixed, left as-is intentionally. Both now have explicit comments justifying the divergence ("ported from the NethVoice CTI component", "the only one with a nested submenu, so hand-rolled like the CTI"). Noting as accepted, not re-flagging.
  5. Zod schema rebuilt every render — Fixed via useMemo, but see the new bug below — the fix has a side effect.
  6. i18n drift between locale trees — Not fixed, same class persists (e.g. Parks.Hold still present in src/renderer/public/locales/{en,it} but absent from the top-level public/locales/{en,it} copies).
  7. App-wide DropdownItem text-color class — Not fixed, unchanged since it was introduced. Still blast-radius over PresenceBadge/SettingsDevicesDialog/SettingsIncomingCallsDialog.
  8. Per-item useIsTruncated with no payoff in list views — Not fixed. ContactNumber.tsx (used by FavouritesBox/SpeedDialsBox) still never passes showCompany, so the hook mounted in ContactNameAndAction.tsx still has nothing to measure there.

New bug introduced by the zod memoization fix

AddToPhonebookBox.tsx's resultSchema is now useMemo(..., [t]), but t is imported directly from i18next at module scope (import { t } from 'i18next'), not the reactive function useTranslation() returns — its reference never changes. If the app's language is switched while this component stays mounted, the schema's baked-in validation messages (e.g. Common.This field is required) stay frozen in whichever language was active on first render, instead of picking up the new language like they did before this fix (when the schema was rebuilt every render).

@tonyco97

tonyco97 commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator Author

Follow-up fix (5dd48ea)

Thanks for the second pass — you're right about the regression the memoization introduced. Fixed it.

Fixed

New bug (zod memoization freezes validation messages on language switch)AddToPhonebookBox.tsx.
Confirmed and fixed. Root cause exactly as you described: t comes from import { t } from 'i18next' (module scope, stable reference), so useMemo(..., [t]) never recomputed and the baked-in messages (Common.This field is required) stayed frozen in whichever language was active on first render. Runtime language change is real here — src/renderer/src/lib/i18n.ts wires onLanguageChangei18next.changeLanguage.

Fix: memoize on the current language instead of the stable t:

- import { t } from 'i18next'
+ import i18next, { t } from 'i18next'
...
-   }, [t])
+   }, [t, i18next.language])

On the first re-render after a language change, i18next.language differs and the schema recomputes with the new-language messages — restoring the exact pre-memoization behavior (which also only refreshed on re-render) while keeping the win of not rebuilding the ~20-field zod graph on every keystroke. I deliberately did not switch to useTranslation(): no file in this repo uses it (the convention is the static import { t } everywhere), so introducing it here would diverge from the codebase for no additional benefit given the above already restores parity.

Typecheck + build green.

Not changed (intentional)

  • package.json update description #6 i18n drift between the two locale trees (Parks.Hold present in src/renderer/public/locales/* but absent from top-level public/locales/*) — pre-existing drift, not introduced by this PR, and out of scope for the phonebook-fields work. Happy to open a separate cleanup PR to reconcile the two trees rather than mixing it in here.
  • downloadPage. Created download page for nethlink #7 app-wide DropdownItem text-color class — left as-is. Changing it has blast radius over PresenceBadge/SettingsDevicesDialog/SettingsIncomingCallsDialog and can't be safely validated without a visual pass across those menus; not worth the regression risk in this PR.
  • fix quit logic #8 per-item useIsTruncated in ContactNameAndAction.tsx — left as-is. It's harmless micro-overhead (the ref simply never attaches when showCompany is unset); touching it risks the truncation-tooltip behavior for the contexts that do pass showCompany for no real gain.
  • package.json update description #4 MultiSelectCombobox / "Add field" flyout — kept, as previously agreed; the divergence is documented inline in the code.

Let me know if you'd prefer #6/#7/#8 handled here instead of separately.

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

Automatic builds from https://github.com/NethServer/nethlink/actions/runs/29026736873.
Commit: 5dd48ea

Name Platform Link
win-app.exe Windows (x64) Link
macos-app-x64.dmg MacOS (x64) Link
macos-app-arm64.dmg MacOS (arm64) Link
linux-app.AppImage Linux (x64) Link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants