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 13 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
import React from 'react';
export const createHOCs = ({ useStateContainer }) => {
return {
withStateContainer: (name: string) => WrappedComponent => props => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
withStateContainer: (name: string) => WrappedComponent => props => {
withStateContainer:
(name: string) =>
(WrappedComponent: React.ElementType) =>
(props: any) => {

Copy link
Contributor

Wazuh Core plugin code coverage (Jest) test % values
Statements 40.79% ( 419 / 1027 )
Branches 40.45% ( 159 / 393 )
Functions 41.86% ( 144 / 344 )
Lines 40.96% ( 417 / 1018 )

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

Main plugin code coverage (Jest) test % values
Statements 13.42% ( 4022 / 29962 )
Branches 8.96% ( 1748 / 19502 )
Functions 12.98% ( 943 / 7265 )
Lines 13.59% ( 3920 / 28839 )

@Desvelao Desvelao marked this pull request as ready for review November 28, 2024 13:17
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
2 participants