diff --git a/CHANGELOG.md b/CHANGELOG.md index 16f51e6038..9cc5747e67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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) - Fixed filter by value in document details in safari [#7151](https://github.com/wazuh/wazuh-dashboard-plugins/pull/7151) ### Removed diff --git a/plugins/main/public/components/common/hooks/use-kbn-loading-indicator.ts b/plugins/main/public/components/common/hooks/use-kbn-loading-indicator.ts index 6073f94d56..0a21d66082 100644 --- a/plugins/main/public/components/common/hooks/use-kbn-loading-indicator.ts +++ b/plugins/main/public/components/common/hooks/use-kbn-loading-indicator.ts @@ -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>, - 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]; -}; \ No newline at end of file + }; + + return [loading, setLoading]; +}; diff --git a/plugins/main/public/components/wz-updates-notification/__snapshots__/index.test.tsx.snap b/plugins/main/public/components/wz-updates-notification/__snapshots__/index.test.tsx.snap index 786686287e..0a1a2250ca 100644 --- a/plugins/main/public/components/wz-updates-notification/__snapshots__/index.test.tsx.snap +++ b/plugins/main/public/components/wz-updates-notification/__snapshots__/index.test.tsx.snap @@ -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`] = `
`; + +exports[`WzUpdatesNotification tests should not render a WzUpdatesNotification is not defined 1`] = `
`; + +exports[`WzUpdatesNotification tests should render a WzUpdatesNotification is enabled 1`] = `
Updates notification diff --git a/plugins/main/public/components/wz-updates-notification/index.test.tsx b/plugins/main/public/components/wz-updates-notification/index.test.tsx index 9e129ce9bf..8b8eaf1262 100644 --- a/plugins/main/public/components/wz-updates-notification/index.test.tsx +++ b/plugins/main/public/components/wz-updates-notification/index.test.tsx @@ -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(, { + preloadedState: { + appConfig: { + data: { + 'wazuh.updates.disabled': false, + }, + }, + }, + }); + + expect(container).toMatchSnapshot(); + }); + + test('should not render a WzUpdatesNotification because is disabled', () => { + const { container } = renderWithProviders(, { + preloadedState: { + appConfig: { + data: { + 'wazuh.updates.disabled': true, + }, + }, + }, + }); + + expect(container).toMatchSnapshot(); + }); + + test('should not render a WzUpdatesNotification is not defined', () => { const { container } = renderWithProviders(); expect(container).toMatchSnapshot(); diff --git a/plugins/main/public/components/wz-updates-notification/wz-updates-notification.tsx b/plugins/main/public/components/wz-updates-notification/wz-updates-notification.tsx index 0c8e39c59f..068a13a831 100644 --- a/plugins/main/public/components/wz-updates-notification/wz-updates-notification.tsx +++ b/plugins/main/public/components/wz-updates-notification/wz-updates-notification.tsx @@ -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 ? : <>; diff --git a/plugins/main/public/redux/render-with-redux-provider.tsx b/plugins/main/public/redux/render-with-redux-provider.tsx index 82aa9fb540..b72d2c66e7 100644 --- a/plugins/main/public/redux/render-with-redux-provider.tsx +++ b/plugins/main/public/redux/render-with-redux-provider.tsx @@ -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'; @@ -13,13 +13,15 @@ interface ExtendedRenderOptions extends Omit { 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 {children}; } diff --git a/plugins/main/public/redux/store.js b/plugins/main/public/redux/store.js index 4244931cc1..0b8597a8be 100644 --- a/plugins/main/public/redux/store.js +++ b/plugins/main/public/redux/store.js @@ -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)); +} diff --git a/plugins/wazuh-core/common/constants.ts b/plugins/wazuh-core/common/constants.ts index 3b51f2e9bf..ff299bcf02 100644 --- a/plugins/wazuh-core/common/constants.ts +++ b/plugins/wazuh-core/common/constants.ts @@ -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: {