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 ability to edit the wazuh.updates.disabled setting from UI #7156

2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Added new field columns and ability to select the visible fields in the File Integrity Monitoring Files and Registry tables [#7119](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7119)
- Added filter by value to document details fields [#7081](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7081)
- Added pinned agent mechanic to inventory data, stats, and configuration for consistent functionality [#7135](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7135)
- Added ability to edit the `wazuh.updates.disabled` configuration setting from UI [#7156](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7156)

### Changed

Expand Down Expand Up @@ -43,6 +44,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Fixed the Mitre ATT&CK exception in the agent view, the redirections of ID, Tactics, Dashboard Icon and Event Icon in the drop-down menu and the card not displaying information when the flyout was opened [#7116](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7116)
- Fixed the filter are displayed cropped on screens of 575px to 767px in vulnerability detection module [#7047](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7047)
- Fixed ability to filter from files inventory details flyout of File Integrity Monitoring [#7119](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7119)
- Fixed the check updates UI was displayed despite it could be configured as disabled [#7156](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7156)

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,28 @@
* Find more information about this on the LICENSE file.
*/
import { getHttp } from '../../../kibana-services';
import React, { useEffect, useState, useRef } from 'react';
import React, { useEffect, useRef } from 'react';
import { BehaviorSubject } from 'rxjs';
import useObservable from 'react-use/lib/useObservable';

export const useKbnLoadingIndicator = (): [
boolean,
React.Dispatch<React.SetStateAction<boolean>>,
boolean
(value: boolean) => void,
] => {
const [loading, setLoading] = useState(false);
const [flag, setFlag] = useState(false);
const [visible, setVisible] = useState(0);
const loadingCount$ = useRef(new BehaviorSubject(0))

const loadingCount$ = useRef(new BehaviorSubject(0));
const loading = Boolean(useObservable(loadingCount$.current, 0));

useEffect(() => {
getHttp().addLoadingCountSource(loadingCount$.current);
const subscriber = getHttp()
.getLoadingCount$()
.subscribe((count) => {
setVisible(count);
!count && setFlag(false);
});
return () => subscriber.unsubscribe();
}, []);

useEffect(() => {
if (loading && visible <= 0) {
const setLoading = (value: boolean) => {
if (value) {
loadingCount$.current.next(loadingCount$.current.value + 1);
setFlag(true);
}

if (!loading && flag && visible > 0) {
} else {
loadingCount$.current.next(loadingCount$.current.value - 1);
}
}, [visible, loading]);
return [loading, setLoading, visible > 0];
};
};

return [loading, setLoading];
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`WzUpdatesNotification tests should render a WzUpdatesNotification 1`] = `
exports[`WzUpdatesNotification tests should not render a WzUpdatesNotification because is disabled 1`] = `<div />`;

exports[`WzUpdatesNotification tests should not render a WzUpdatesNotification is not defined 1`] = `<div />`;

exports[`WzUpdatesNotification tests should render a WzUpdatesNotification is enabled 1`] = `
<div>
<div>
Updates notification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,35 @@ jest.mock('../../kibana-services', () => ({
}));

describe('WzUpdatesNotification tests', () => {
test('should render a WzUpdatesNotification', () => {
test('should render a WzUpdatesNotification is enabled', () => {
const { container } = renderWithProviders(<WzUpdatesNotification />, {
preloadedState: {
appConfig: {
data: {
'wazuh.updates.disabled': false,
},
},
},
});

expect(container).toMatchSnapshot();
});

test('should not render a WzUpdatesNotification because is disabled', () => {
const { container } = renderWithProviders(<WzUpdatesNotification />, {
preloadedState: {
appConfig: {
data: {
'wazuh.updates.disabled': true,
},
},
},
});

expect(container).toMatchSnapshot();
});

test('should not render a WzUpdatesNotification is not defined', () => {
const { container } = renderWithProviders(<WzUpdatesNotification />);

expect(container).toMatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const mapStateToProps = state => {
export const WzUpdatesNotification = connect(mapStateToProps)(
({ appConfig }) => {
const isUpdatesEnabled =
!appConfig?.isLoading && !appConfig?.data?.['wazuh.updates.disabled'];
!appConfig?.isLoading &&
appConfig?.data?.['wazuh.updates.disabled'] === false;
const { UpdatesNotification } = getWazuhCheckUpdatesPlugin();

return isUpdatesEnabled ? <UpdatesNotification /> : <></>;
Expand Down
14 changes: 8 additions & 6 deletions plugins/main/public/redux/render-with-redux-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { PropsWithChildren } from 'react';
import { render } from '@testing-library/react';
import storeRedux from './store';
import storeRedux, { setupStore } from './store';
import { Provider } from 'react-redux';
import type { RenderOptions } from '@testing-library/react';

Expand All @@ -13,13 +13,15 @@ interface ExtendedRenderOptions extends Omit<RenderOptions, 'queries'> {

export function renderWithProviders(
ui: React.ReactElement,
{
options: ExtendedRenderOptions = {},
) {
const {
preloadedState = {},
// Automatically create a store instance if no store was passed in
store = storeRedux,
// Automatically create a store instance with the preloadedState
store = setupStore(preloadedState),
...renderOptions
}: ExtendedRenderOptions = {},
) {
} = options;

function Wrapper({ children }: PropsWithChildren<{}>): JSX.Element {
return <Provider store={store}>{children}</Provider>;
}
Expand Down
5 changes: 5 additions & 0 deletions plugins/main/public/redux/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ import rootReducer from './reducers/rootReducers';
const store = createStore(rootReducer, applyMiddleware(thunk));

export default store;

// This is used by some tests to preload a state
export function setupStore(preloadedState) {
return createStore(rootReducer, preloadedState, applyMiddleware(thunk));
}
6 changes: 3 additions & 3 deletions plugins/wazuh-core/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1747,16 +1747,16 @@ hosts:
},
'wazuh.updates.disabled': {
title: 'Check updates',
description: 'Define if the check updates service is active.',
description: 'Define if the check updates service is disabled.',
category: SettingCategory.GENERAL,
type: EpluginSettingType.switch,
defaultValue: false,
store: {
file: {
configurableManaged: false,
configurableManaged: true,
},
},
isConfigurableFromSettings: false,
isConfigurableFromSettings: true,
options: {
switch: {
values: {
Expand Down
Loading