feat(shared-chart-core): adopt shared chart-core in fan-chart (WEB-18)#204
feat(shared-chart-core): adopt shared chart-core in fan-chart (WEB-18)#204magicsunday wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the fan chart module to utilize shared logic from the @magicsunday/webtrees-chart-lib library. Key changes include replacing local JavaScript utilities for URL construction and UI state management with library-provided functions, and updating PHP traits to inherit from a base module library to reduce boilerplate. Feedback identifies an opportunity to further improve maintainability in page-init.js by extracting a helper function for AJAX URL generation to eliminate code duplication and ensure robust handling of default configuration values.
| const newUrl = buildChartAjaxUrl(config.ajaxUrl, { | ||
| query: [ | ||
| { | ||
| key: "generations", | ||
| value: | ||
| storage.read("generations") ?? | ||
| /** @type {HTMLInputElement|null} */ ( | ||
| document.getElementById("generations") | ||
| )?.value ?? | ||
| null, | ||
| }, | ||
| { | ||
| key: "detailedDateGenerations", | ||
| value: | ||
| storage.read("detailedDateGenerations") ?? | ||
| config.defaultDetailedDateGenerations, | ||
| }, | ||
| { key: "showPlaces", value: storage.read("showPlaces"), mode: "boolean-1-0" }, | ||
| { key: "placeParts", value: storage.read("placeParts") }, | ||
| { key: "showDescendants", value: checked, mode: "boolean-1-or-delete" }, | ||
| { | ||
| key: "showNicknames", | ||
| value: storage.read("showNicknames") ?? config.defaultShowNicknames, | ||
| mode: "boolean-1-0", | ||
| }, | ||
| ], | ||
| }); |
There was a problem hiding this comment.
The logic for building the AJAX URL query parameters here duplicates the logic used during initialisation (lines 205-225). Furthermore, the fallback logic for showNicknames (line 285) is less robust than the one used in chartOptions (line 161), as it doesn't handle the case where config.defaultShowNicknames might be undefined.
Extracting a helper function to generate the query array from the current storage/config state would improve maintainability and ensure both URL generation paths remain in sync.
magicsunday
left a comment
There was a problem hiding this comment.
Hold — CI red until Foundation released
CTO review (WEB-18). Code change itself is correct, but do not merge yet — CI is failing on 8.3/8.4/8.5 because the consumed Foundation isn't published:
PHPStan: unknown trait MagicSunday\Webtrees\ModuleBase\Facade\RouteAwareDataFacadeTrait
TypeScript: Cannot find module '@magicsunday/webtrees-chart-lib/chart-core'
PHPUnit: Premature end of PHP process (Module class fails to load)
Composer/npm on CI runners can't resolve module-base 2.5.0 / chart-lib v1.6.0 because they don't exist yet. Local composer ci:test passed because the linked workspace clone shortcut the registry.
Unblock path (in this order)
- Merge + tag
webtrees-module-base#1as 2.5.0. - Merge + tag
webtrees-chart-lib#1as v1.6.0 + publish to npm if applicable. - On this PR: bump
package.json@magicsunday/webtrees-chart-libto^1.6.0, refresh lockfiles (composer.lock+package-lock.json/yarn.lock), force-push. - Wait for green CI, then merge.
Code-side review (for when CI clears)
- ✅
composer.jsonconstraint stays"^2.2"— covers 2.5.0 without changes. - ✅ Module-local trait shims correctly re-
usethe shared traits without overriding behaviour. - ✅ phpstan-baseline cleanup (drop stale
customTranslationsentry) is the correct follow-up. - ✅ Commit-message compliance (engineering-standards.md §3).
Converting this PR to draft to make the "wait for Foundation" state explicit.
There was a problem hiding this comment.
Pull request overview
This PR migrates the fan-chart module to consume the newly extracted shared chart-core foundation: PHP traits from magicsunday/webtrees-module-base and the JS subpath entrypoint from magicsunday/webtrees-chart-lib. Module-local trait copies (ModuleCustomTrait, ModuleChartTrait), the I18N-based RTL detection in DataFacade, and the page-init JS helpers (getUrl, toggleMoreOptions, inline AJAX URL/global setters) are replaced with shared building blocks while preserving module-specific rendering.
Changes:
- Replace local PHP trait method implementations with
use BaseModuleCustomTrait/use BaseModuleChartTrait, and swapI18N::scriptDirection(...)forTextDirection::isRtl(...)inDataFacade::isRtl. - Refactor
resources/js/modules/page-init.jsto importbuildChartAjaxUrl,setChartAjaxUrl,setChartOptionsGlobal,Storage, andsyncCollapseTogglefrom@magicsunday/webtrees-chart-lib/chart-core; rebuildfan-chart-page.min.jsaccordingly. - Update the Jest mock in
page-init.test.jsto mock the new/chart-coresubpath and expose the shared helpers.
Reviewed changes
Copilot reviewed 5 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Traits/ModuleCustomTrait.php | Removes local trait method implementations; delegates to the shared base trait. |
| src/Traits/ModuleChartTrait.php | Removes local chartBoxMenu/chartUrl implementations and Menu import; uses shared base trait, keeps module-specific chartMenuClass/chartTitle. |
| src/Facade/DataFacade.php | Replaces I18N RTL detection with shared TextDirection::isRtl helper. |
| resources/js/modules/page-init.js | Switches imports to /chart-core subpath; replaces local getUrl/toggleMoreOptions/global-set/setAttribute logic with shared helpers and a structured query descriptor. |
| resources/js/fan-chart-page.min.js | Regenerated bundle reflecting the new page-init implementation. |
| resources/js/tests/modules/page-init.test.js | Updates Jest mock to target @magicsunday/webtrees-chart-lib/chart-core and stubs the new helpers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Adopt the shared chart-core foundation (PHP traits from
magicsunday/webtrees-module-base+ JS subpath entrypoint frommagicsunday/webtrees-chart-lib) in fan-chart. Replaces the previously module-local trait/facade/JS implementations with the shared building blocks while keeping all module-specific rendering and semantics intact.Coordinated change in the WEB-12 family:
Acceptance Criteria (WEB-18)
All four WEB-18 acceptance criteria verified for this module:
useof shared traits.CHART_CORE_MIGRATION.md(module-base).Verification
Verified per-module via buildbox container with the consumed foundation branches linked locally:
composer ci:test→ 21/83 ✅Rollback
Revert this PR. The module falls back to its pre-extraction local trait/facade/JS implementations (preserved in the prior commit history and in
backup-main-pre-policy-cleanupbranch).Policy Note
Retroactive PR under WEB-22 branch policy. Commits originally landed on
mainpre-policy and were moved tofeat/shared-chart-coreafter the policy went into effect.