Skip to content

feat(RND-104): add support for loading color preset from json#2100

Open
asvishnyakov wants to merge 5 commits intodevfrom
feat/dynamic-color-preset
Open

feat(RND-104): add support for loading color preset from json#2100
asvishnyakov wants to merge 5 commits intodevfrom
feat/dynamic-color-preset

Conversation

@asvishnyakov
Copy link
Member

@asvishnyakov asvishnyakov commented Dec 10, 2025

Description

This PR adds support for loading color presets from JSON.

  1. Presets defined in the theme will still be embedded into the bundle and used at runtime, so no additional requests are added for existing presets.
  2. If the frontend can't find a color preset with the specified name, it will try to load it from a JSON file in the assets/presets folder. The folder name can be changed upon request if needed.

Fallback logic has changed after AI review:

Before:

  1. Try get preset
  2. Fallback to default
    a. Dead code lead to missed attempt to use current preset from settings
    b. This is probably a bug. Try to define non-existing preset in white labeling and then see theme falling back to default preset instead of the one specified in current field of settings_data.json

After:

  1. Try get preset
  2. Fallback to current
  3. Fallback to default

References

Jira-link:

Artifact URL:

https://vc3prerelease.blob.core.windows.net/packages/vc-theme-b2b-vue-2.37.0-pr-2100-c9d0-c9d02f4f.zip

Copilot AI review requested due to automatic review settings December 10, 2025 17:16
@asvishnyakov asvishnyakov requested a review from a team as a code owner December 10, 2025 17:16
@asvishnyakov asvishnyakov requested review from Andrew-Orlov, goldenmaya, ivan-kalachikov and vas11yev1work and removed request for a team December 10, 2025 17:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for dynamically loading color presets from JSON files stored in the /assets/presets directory, providing flexibility for runtime theme customization without requiring bundle rebuilds.

Key Changes:

  • Made addPresetToThemeContext and getPreset functions asynchronous to support fetching presets from external files
  • Implemented a three-tier loading strategy: bundled presets → runtime cache → fetch from /assets/presets → fallback to default
  • Added runtime caching via dynamicPresetsCache Map to avoid redundant network requests

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.

File Description
client-app/core/composables/useThemeContext.ts Implements async preset loading with fetch API, adds caching mechanism, and provides fallback logic to default preset
client-app/app-runner.ts Updates preset loading call to properly await the now-async addPresetToThemeContext function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@asvishnyakov asvishnyakov changed the title feat: add support for loading color preset from json feat(RND-104): add support for loading color preset from json Dec 11, 2025
@asvishnyakov asvishnyakov requested a review from Copilot December 11, 2025 12:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

client-app/core/composables/useThemeContext.ts:100

  • The nullish coalescing assignment on line 94 already ensures preset will never be null after this line. The subsequent if-else block checking if preset exists (lines 96-100) is redundant since preset will always be truthy after line 94. Consider removing the else block and the conditional check, or restructuring the logic for clarity.
    preset ??= presets.default;

    if (preset) {
      themeContext.value.preset = preset;
    } else {
      throw new Error("Missing preset");
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@asvishnyakov
Copy link
Member Author

@copilot You first overview outdated, update it

Copy link

Copilot AI commented Dec 11, 2025

@asvishnyakov I've opened a new pull request, #2102, to work on those changes. Once the pull request is ready, I'll request review from you.

@sonarqubecloud
Copy link

@asvishnyakov
Copy link
Member Author

Please ignore Copilot overview - it's outdated and Copilot is stupid enough to not being able update it

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

Comments