Skip to content

Conversation

@greinard
Copy link
Collaborator

Overview

This branch adds multi-state capability to the CalendarDay component.

Previously, a fixed state configuration was supplied to the component. The component would dynamically acquire the single state key to use for each day, pull that state from the fixed state configuration, and apply it. This mechanism has been deprecated.

The new state acquisition mechanism does not require a fixed state configuration up front. Instead, the component dynamically asks for a collection of states to apply to each day. The states for a given day can also have a note and/or custom display value attached. The Storybook has been updated to demonstrate these new rendering options.

This change is intended to be fully backward compatible, so existing usage of the CalendarDay component should not need to be updated until we decide to remove the deprecated functionality in a future major release.

Single-State | Multi-State

  

Other Notable Items

  • Fixed an issue with loss of precision when using the crypto-based predictableRandomNumber helper function.
  • Added a new FNV (Fowler-Noll-Vo) predictable random number generating helper function that can be executed synchronously.
  • Fixed a minor styling issue on the Asthma Control Calendar.

Security

  • I have ensured no secure credentials or sensitive information remain in code, metadata, comments, etc.
    • Please verify that you double checked that .storybook/preview.js does not contain your participant access key details.
    • There are no temporary testing changes committed such as API base URLs, access tokens, print/log statements, etc.
  • These changes do not introduce any security risks, or any such risks have been properly mitigated.

No new security risks. This is just an adjustment to how a bit of rendering configuration is managed and applied.

Testing

  • This change can be adequately tested using the MDH Storybook.
  • This change requires additional testing in the MDH iOS/Android/Web apps. (Create a pre-release tag/build and test in a ViewBuilder PR.)

Some basic regression should be performed on the AsthmaControlCalendar and the SeverityCalendar to ensure they still function as expected.

Documentation

  • I have added relevant Storybook updates to this PR.
  • If this feature requires a developer doc update, I have tagged @CareEvolution/api-docs.
  • This change does not impact documentation or Storybook.

const backgroundColor = createConicGradient(backgroundColors);
const borderColor = createConicGradient(states.map((state, index) => state.borderColor ?? backgroundColors[index]));
const textBackgroundColor = resolveColor(layoutContext.colorScheme, { lightMode: '#eee', darkMode: '#444' })?.replace('#', '%23');
const textBorderColor = resolveColor(layoutContext.colorScheme, { lightMode: '#aaa', darkMode: '#333' })?.replace('#', '%23');

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding High

This replaces only the first occurrence of '#'.

Copilot Autofix

AI 4 days ago

To fix the problem, all occurrences of # in the color strings used inside the data:image/svg+xml URLs must be escaped, not just the first one. The general approach is to replace the string-literal argument to .replace with a regular expression that has the global (g) flag, so every # is transformed to %23.

Concretely, in src/components/presentational/CalendarDay/CalendarDay.tsx, within the createCombinedStateIfNecessary function, update both lines where .replace('#', '%23') is called on the result of resolveColor. Change them to .replace(/#/g, '%23'). This change preserves existing behavior for single-# colors and makes the code robust if resolveColor ever returns a more complex color string containing multiple # characters (e.g., gradients). No additional imports or helper methods are needed; it uses built-in JavaScript regex support.

Suggested changeset 1
src/components/presentational/CalendarDay/CalendarDay.tsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/components/presentational/CalendarDay/CalendarDay.tsx b/src/components/presentational/CalendarDay/CalendarDay.tsx
--- a/src/components/presentational/CalendarDay/CalendarDay.tsx
+++ b/src/components/presentational/CalendarDay/CalendarDay.tsx
@@ -186,8 +186,8 @@
 
         const backgroundColor = createConicGradient(backgroundColors);
         const borderColor = createConicGradient(states.map((state, index) => state.borderColor ?? backgroundColors[index]));
-        const textBackgroundColor = resolveColor(layoutContext.colorScheme, { lightMode: '#eee', darkMode: '#444' })?.replace('#', '%23');
-        const textBorderColor = resolveColor(layoutContext.colorScheme, { lightMode: '#aaa', darkMode: '#333' })?.replace('#', '%23');
+        const textBackgroundColor = resolveColor(layoutContext.colorScheme, { lightMode: '#eee', darkMode: '#444' })?.replace(/#/g, '%23');
+        const textBorderColor = resolveColor(layoutContext.colorScheme, { lightMode: '#aaa', darkMode: '#333' })?.replace(/#/g, '%23');
 
         return {
             ...states[0],
EOF
@@ -186,8 +186,8 @@

const backgroundColor = createConicGradient(backgroundColors);
const borderColor = createConicGradient(states.map((state, index) => state.borderColor ?? backgroundColors[index]));
const textBackgroundColor = resolveColor(layoutContext.colorScheme, { lightMode: '#eee', darkMode: '#444' })?.replace('#', '%23');
const textBorderColor = resolveColor(layoutContext.colorScheme, { lightMode: '#aaa', darkMode: '#333' })?.replace('#', '%23');
const textBackgroundColor = resolveColor(layoutContext.colorScheme, { lightMode: '#eee', darkMode: '#444' })?.replace(/#/g, '%23');
const textBorderColor = resolveColor(layoutContext.colorScheme, { lightMode: '#aaa', darkMode: '#333' })?.replace(/#/g, '%23');

return {
...states[0],
Copilot is powered by AI and may make mistakes. Always verify output.
@aws-amplify-us-east-1
Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-553.d1xp2kmk6zrv44.amplifyapp.com

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.

1 participant