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

Add frontend state service #7037

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Desvelao
Copy link
Member

@Desvelao Desvelao commented Sep 30, 2024

Description

This pull request adds a state service to the wazuh-core plugin and expose it in the plugin lifecycle methods.

The state service manages the shared state of the Wazuh plugins and it is a HUB of state containers. Features:

  • Extensible
  • Register state containers
  • Ability to get, set, remove data and subscribe to changes of state containers

The state containers provides a mechanism to manage a specific state. For example, some data is stored in cookies, others could be managed in-memory, local storage, session storage.

Others plugins can register new state containers.

The service creates hooks and HOCs that are exposed through the plugin lifecycle.

The state services is based on AppState old service:

AppState state Description
getClusterInfo server_host_cluster_info > get
setClusterInfo server_host_cluster_info > set
getCurrentApi server_host > get
setCurrentApi server_host > set
removeCurrentAPI server_host > remove
getCurrentPattern data_source_alerts > get
setCurrentPattern data_source_alerts > set
removeCurrentPattern data_source_alerts > remove

Issues Resolved

#6959

Check List

  • All tests pass
    • yarn test:jest
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

- Create state service based on AppState from main plugin
- Create state containers
  - server_host
  - server_host_cluster_info
  - data_source_alerts
- Add documentation for state service
@Desvelao Desvelao self-assigned this Sep 30, 2024
@Desvelao Desvelao linked an issue Sep 30, 2024 that may be closed by this pull request
6 tasks
- Remove unused methods:
  - AppState.setCreatedAt
  - AppState.getCreatedAt
  - AppState.getAPISelector
  - AppState.getPatternSelector
  - AppState.setPatternSelector (no-effect)

- Remove usage of AppState.setPatternSelector because this has no
  effect in the current application
…bed when the plugin stops

- Remove console.log
- Dispatch new values when remove from the state containers
Copy link
Contributor

github-actions bot commented Oct 1, 2024

Wazuh Core plugin code coverage (Jest) test % values
Statements 40.31% ( 414 / 1027 )
Branches 40.45% ( 159 / 393 )
Functions 41.56% ( 143 / 344 )
Lines 40.47% ( 412 / 1018 )

Copy link
Contributor

github-actions bot commented Oct 1, 2024

Wazuh Check Updates plugin code coverage (Jest) test % values
Statements 76.44% ( 172 / 225 )
Branches 58.65% ( 61 / 104 )
Functions 61.7% ( 29 / 47 )
Lines 76.44% ( 172 / 225 )

Copy link
Contributor

github-actions bot commented Oct 1, 2024

Main plugin code coverage (Jest) test % values
Statements 13.43% ( 4019 / 29918 )
Branches 8.97% ( 1748 / 19482 )
Functions 12.99% ( 943 / 7255 )
Lines 13.6% ( 3917 / 28795 )

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.

Extract common services from main plugin
1 participant