Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontend: PluginSettings: Rework plugin settings local storage usage #2596

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vyncent-t
Copy link
Contributor

@vyncent-t vyncent-t commented Nov 21, 2024

Description

resolves issue #2595

This PR refactors the way Headlamp handles plugin settings stored in local storage, focusing on simplifying and improving the management of plugin states. Previously, the project stored the entire JSON data of plugin information in headlampPluginSettings, which included unnecessary details. This refactor reduces complexity by saving only the essential state information, improving performance and maintainability.

Key Changes

  1. Simplified Storage:

    • Replaced the old headlampPluginSettings structure with enabledPluginsList in local storage.
    • The new structure saves only the plugin name and its on/off state, eliminating the need to store complete JSON data.
  2. State Management Updates:

    • Introduced the pluginData slice in the plugin state to store plugin information.
    • Added enabledPlugins to maintain a list of plugins currently in use.
  3. Backward Compatibility:

    • The project now detects the existence of the old headlampPluginSettings in local storage.
    • If detected, it converts and migrates the old settings into the new enabledPluginsList format automatically upon visiting the plugin settings page.

Steps to Test

To verify the changes and ensure backward compatibility:

  1. Setup:

    • Start on the main branch with multiple plugins installed.
    • Disable one plugin while keeping others enabled, and save the settings.
    • Open the browser’s local storage and confirm that the disabled plugin’s state is saved in the headlampPluginSettings JSON.
  2. Switch to this Branch:

    • Checkout this branch and navigate to the plugin settings page.
  3. Observe Migration:

    • Confirm that the page detects the headlampPluginSettings in local storage, migrates the settings into a new enabledPluginsList object, deletes the old headlampPluginSettings, and reloads the page.
    • Verify that the plugin states from the previous settings are preserved in the new format.
  4. Post-Migration:

    • Ensure that plugin settings updates are correctly saved in the new enabledPluginsList structure.
    • Confirm that enabling/disabling plugins reflects accurately on subsequent reloads.

Notes

  • It improves the performance and clarity of plugin state management by reducing storage overhead.
  • The migration process ensures a seamless transition for users upgrading from previous versions.

@vyncent-t vyncent-t added the frontend Issues related to the frontend label Nov 21, 2024
@vyncent-t vyncent-t self-assigned this Nov 21, 2024
@vyncent-t vyncent-t force-pushed the plugin-settings-storage-refactor branch 7 times, most recently from 825bbe1 to 5ba4e15 Compare November 25, 2024 18:10
@vyncent-t
Copy link
Contributor Author

last push

  • allows old storage settings to be migrated to the new settings

@vyncent-t vyncent-t force-pushed the plugin-settings-storage-refactor branch from 5ba4e15 to 6b0ad82 Compare November 25, 2024 18:17
@vyncent-t
Copy link
Contributor Author

last push fixes merge conflicts

@vyncent-t vyncent-t force-pushed the plugin-settings-storage-refactor branch from 6b0ad82 to fb4cd59 Compare November 27, 2024 17:30
@vyncent-t
Copy link
Contributor Author

last push rebases and fixes storybook

@vyncent-t vyncent-t force-pushed the plugin-settings-storage-refactor branch 2 times, most recently from e257f80 to 0e02bf1 Compare November 27, 2024 18:21
@vyncent-t vyncent-t changed the title WIP: frontend: PluginSettings: Rework plugin settings local storage usage frontend: PluginSettings: Rework plugin settings local storage usage Nov 27, 2024
@vyncent-t vyncent-t marked this pull request as ready for review November 27, 2024 18:32
@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Nov 27, 2024
Copy link
Collaborator

@joaquimrocha joaquimrocha left a comment

Choose a reason for hiding this comment

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

I am a bit surprised this needs so many changes. Wasn't the idea just to remove the saving of the whole package.json from the settings and use just the plugin name instead? Even if we change the name of the key in local storage, or move it to index db, why are we touching the plugin settings this much?

I would also like to understand: are plugins now supposed to be disabled by default? I understood that shipped plugins need to be enabled by default, and that the other ones were also like that for keeping a consistent behavior with the previous versions.

@vyncent-t vyncent-t marked this pull request as draft December 2, 2024 15:40
@vyncent-t
Copy link
Contributor Author

noticed some weird behavior when not using any of the old headlampPluginSettings or enabledPluginsList in local storage, working on a fix again

@vyncent-t vyncent-t force-pushed the plugin-settings-storage-refactor branch from 0e02bf1 to 5c99964 Compare December 2, 2024 16:38
@vyncent-t vyncent-t marked this pull request as ready for review December 2, 2024 16:38
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Dec 2, 2024
@vyncent-t
Copy link
Contributor Author

some meeting notes

  • can keep the enabledPluginsList to handle toggles
  • may need to handle default loading state of a plugin if they come disabled or enabled but most come enabled as of current
  • handled the backwards compatibility for users on pervious vers that allow migration of old settings to new settings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend Issues related to the frontend size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants