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

Open
wants to merge 32 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
@yenienserrano yenienserrano self-requested a review November 21, 2024 21:17
Co-authored-by: Guido Modarelli <38738725+guidomodarelli@users.noreply.github.com>
@Desvelao Desvelao marked this pull request as ready for review November 28, 2024 13:17
…e interfaces in state and services types files
…wz-api-check.js to improve code readability and flow
…s for better clarity and type safety in creator.tsx
…type safety in state management functionalities
… robustness in state management functionality
…rror for better clarity in data source alerts handling
…r clearer messages in server host cluster info handling
…larity with explicit Error casting in server host state management
guidomodarelli
guidomodarelli previously approved these changes Dec 12, 2024
Copy link
Contributor

@guidomodarelli guidomodarelli left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@guidomodarelli guidomodarelli left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

Wazuh Engine plugin code coverage (Jest) test % values
Statements 8.63% ( 64 / 741 )
Branches 7.94% ( 22 / 277 )
Functions 1.87% ( 7 / 373 )
Lines 9.1% ( 64 / 703 )

Copy link
Contributor

Wazuh Fleet plugin code coverage (Jest) test % values
Statements 4.68% ( 9 / 192 )
Branches 16.66% ( 7 / 42 )
Functions 1.11% ( 1 / 90 )
Lines 4.76% ( 9 / 189 )

Copy link
Contributor

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

Wazuh Core plugin code coverage (Jest) test % values
Statements 36.33% ( 803 / 2210 )
Branches 39.83% ( 439 / 1102 )
Functions 39.93% ( 256 / 641 )
Lines 36.6% ( 799 / 2183 )

Copy link
Contributor

Main plugin code coverage (Jest) test % values
Statements 13.42% ( 4021 / 29957 )
Branches 8.98% ( 1746 / 19439 )
Functions 12.96% ( 941 / 7259 )
Lines 13.59% ( 3920 / 28838 )

Copy link
Member

@yenienserrano yenienserrano left a comment

Choose a reason for hiding this comment

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

Test: 🔴

The application is not working for me

image

image

image

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
3 participants