refactor(statmodel): Set up a constants file for all namespace IDs#130
refactor(statmodel): Set up a constants file for all namespace IDs#130tonywu1999 merged 11 commits intodevelfrom
Conversation
|
Failed to generate code suggestions for PR |
WalkthroughAdds two centralized constant maps ( Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant UI as StatModel UI (ns)
participant Server as StatModel Server
participant Builder as Contrast Builder
User->>UI: select comparison mode (radio)
UI->>Server: input[[NAMESPACE_STATMODEL$comparison_mode]]
Server->>Server: map mode via CONSTANTS_STATMODEL
Server->>UI: render panel (uiOutput id from NAMESPACE_STATMODEL)
User->>UI: fill choices & click submit (namespaced submit)
UI->>Server: input[[NAMESPACE_STATMODEL$..._submit]]
Server->>Builder: call build_*_contrast() based on CONSTANTS_STATMODEL
Builder-->>Server: contrast matrix
Server->>UI: enable calculate / show matrix (namespaced outputs)
note right of Server: Observers and validators use namespaced inputs\n(submit, clear, mode) for flow control
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested labels
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
R/constants.R (1)
2-25: Centralizing statmodel IDs/modes via constants looks solid
NAMESPACE_STATMODELandCONSTANTS_STATMODELare internally consistent with their later usages (UI, server, tests) and provide a clear single source of truth for IDs and mode keys. You might consider, in a follow-up, documenting these in package-level docs if they’re intended as part of the public API, but nothing here blocks this PR.R/statmodel-ui-headers.R (1)
9-48: Namespaced CSS selectors correctly aligned with new constantsUsing
'#statmodel-'plusNAMESPACE_STATMODEL$…for the contrast buttons keeps styling tied to the same IDs used in the UI builders, reducing drift risk. If you ever want to trim duplication, these eighttags$style()calls could be generated in a small helper over a vector of the relevant constants, but the current form is perfectly acceptable.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
R/constants.R(1 hunks)R/module-statmodel-server.R(3 hunks)R/statmodel-ui-headers.R(1 hunks)R/statmodel-ui-options-contrasts.R(5 hunks)tests/testthat/test-module-statmodel-server.R(9 hunks)tests/testthat/test-module-statmodel-ui.R(4 hunks)tests/testthat/test-statmodel-ui-options-contrasts.R(4 hunks)tests/testthat/test-utils-statmodel-server.R(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (4)
tests/testthat/test-statmodel-ui-options-contrasts.R (1)
5-9: UI option-panel tests now correctly keyed off shared namespace constantsThe tests for all four contrast option panels now assert against
NAMESPACE_STATMODEL$comparisons_*IDs, which is consistent with the refactored UI code using the same constants vians(). This centralization should make future ID changes far less brittle across the suite.Also applies to: 21-23, 34-35, 47-50
R/statmodel-ui-options-contrasts.R (1)
8-15: Contrast UI successfully migrated to constants-based IDs and mode keys
create_contrast_section(),create_contrast_radio_buttons(), and all four panel builders now consistently useNAMESPACE_STATMODELandCONSTANTS_STATMODELfor IDs and mode values. This matches the server’s use of the same constants and the updated tests, so the contrast UI is now cleanly centralized around a single set of identifiers.Also applies to: 20-33, 40-47, 52-58, 63-67, 72-79
tests/testthat/test-utils-statmodel-server.R (1)
334-371:get_contrast_panel_uitests correctly track constant-based modes and namespace IDsThe updated tests for
get_contrast_panel_ui()now:
- Call the helper with
CONSTANTS_STATMODEL$comparison_mode_*rather than string literals, and- Assert on the presence of
NAMESPACE_STATMODEL$comparisons_*IDs in the returned HTML,plus they cover the new behavior of returning
NULLforNULL, empty, or invalid modes. This keeps the helper tightly coupled to the centralized constants and validates the new guard logic.R/module-statmodel-server.R (1)
22-38: Server-side refactor is correct; shinyjs calls properly target namespaced elementsVerification confirms:
get_contrast_panel_ui()cleanly dispatches onCONSTANTS_STATMODEL$comparison_mode_*and returnsNULLfor NULL/empty/invalid modes, matching updated tests.- All dynamic contrast inputs/outputs (
comparisons_*) are rendered and observed viaNAMESPACE_STATMODELkeys, in sync withR/statmodel-ui-options-contrasts.Rand the test suite.Rownames,check_cond, andmatrix_buildare consistently triggered off the four namespaced submit inputs, andvalidate_contrast_inputs()centralizes validation logic.- shinyjs
enable("calculate")anddisable("calculate")calls correctly target the namespaced button: shinyjs state functions automatically apply module namespacing by default, so plain names work as written without requiring explicitsession$ns().
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tests/testthat/test-module-statmodel-server.R (1)
192-193: Original review comment's concern is valid but overstated; production code is correct.The inputs ARE properly namespaced in production:
selectInput(ns("group1"), ...)andnumericInput(ns(paste0("weight", i)), ...)in the renderUI functions correctly apply namespacing via thens()wrapper. When accessed in module server context (e.g.,input$group1), they work correctly.The test pattern (
inputs$group1 <- "Group1") is acceptable when testing helper functions with mock data, not the Shiny module reactivity itself.Actual inconsistency: Output slots use
NAMESPACE_STATMODELconstants (e.g.,comparisons_custom_pairwise_choice1) but input IDs themselves ("group1","group2","comp_name","weight1"-"weightN") are hardcoded strings in renderUI calls. For consistency and maintainability, consider adding constants for input IDs similar to the existing output slot constants—this would allow referencing them throughout the codebase (server functions, tests) consistently.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
tests/testthat/test-module-statmodel-server.R(9 hunks)tests/testthat/test-module-statmodel-ui.R(4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- tests/testthat/test-module-statmodel-ui.R
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (2)
tests/testthat/test-module-statmodel-server.R (2)
189-196: Past issue resolved: Namespaced submit inputs now correctly configured.All test cases now properly use the namespaced submit constants (e.g.,
NAMESPACE_STATMODEL$comparisons_custom_pairwise_submit) instead of the baresubmitfield. This ensures tests correctly trigger the refactored server event handlers.Also applies to: 239-243, 281-285, 323-331, 375-380, 413-420, 453-458, 498-503, 506-507, 541-544
191-191: ****The constants
NAMESPACE_STATMODELandCONSTANTS_STATMODELare properly available in the test environment. These are internal objects defined inR/constants.Rand are automatically loaded as part of the package namespace during testing. R packages load all objects fromR/files when the package is initialized, making them available to test code even without explicit@exporttags or NAMESPACE entries. This is standard R package structure and requires no changes.Likely an incorrect or invalid review comment.
Summary by CodeRabbit
Refactor
Tests
✏️ Tip: You can customize this high-level summary in your review settings.