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

Remove overview AngularJS controllers #6594

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8c9b043
Change overview view
yenienserrano Apr 17, 2024
5d68875
Change dashboards views
yenienserrano Apr 18, 2024
deb2bd0
Merge branch '4.9.0' into feat/6593-remove-discover-refactor-angularj…
yenienserrano Apr 25, 2024
7ae9780
Add filter _g url
yenienserrano Apr 26, 2024
a9b1b56
Merge branch '4.9.0' into feat/6593-remove-discover-refactor-angularj…
yenienserrano Apr 26, 2024
f3e7971
Merge branch '4.9.0' into feat/6593-remove-discover-refactor-angularj…
yenienserrano Apr 26, 2024
d0715b0
Add _a filter in url
yenienserrano Apr 30, 2024
c29f25f
Merge branch '4.9.0' into feat/6593-remove-discover-refactor-angularj…
yenienserrano Apr 30, 2024
1c18d24
Merge branch '4.9.0' into feat/6593-remove-discover-refactor-angularj…
yenienserrano Apr 30, 2024
a8329e3
Merge branch '4.9.0' into feat/6593-remove-discover-refactor-angularj…
yenienserrano May 2, 2024
d0b47d4
Fix stats margin
yenienserrano May 2, 2024
4a495b7
Fix cards styles
yenienserrano May 2, 2024
4a74d14
Fix unpin agent url
yenienserrano May 2, 2024
f15c25c
Merge branch '4.9.0' into feat/6593-remove-discover-refactor-angularj…
yenienserrano May 2, 2024
05c1bf6
Remove code unnecessary
yenienserrano May 3, 2024
6a689fc
Remove kibana-discover.js
yenienserrano May 3, 2024
379cadc
Merge branch '4.9.0' into feat/6593-remove-discover-refactor-angularj…
yenienserrano May 3, 2024
565fa6f
Remove overview controller
yenienserrano May 3, 2024
f22e354
Apply comments
yenienserrano May 6, 2024
167cfba
Fix snapshot
yenienserrano May 6, 2024
b41d219
Sync pinned agent with URL in Overview component without reload
yenienserrano May 6, 2024
bdf67eb
Add changelog
yenienserrano May 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Move AngularJS controllers and views of Tools and Dev Tools to ReactJS [#6544](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6544)
- Move the AngularJS controller and template of blank screen to ReactJS component [#6538](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6538)
- Move AngularJS controller for management to ReactJS component [#6555](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6555)
- Move AngularJS controller for overview to ReactJS component [#6594](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6594)
- Moved the registry data to in-memory cache [#6481](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6481)
- Enhance the validation for `enrollment.dns` on App Settings application [#6573](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6573)
- Remove some branding references across the application. [#6155](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6155)
Expand Down
1 change: 0 additions & 1 deletion plugins/main/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import 'angular-material/angular-material';
import './setup';

//App imports
import './kibana-integrations';
import './services';
import './controllers';
import './factories';
Expand Down
4 changes: 2 additions & 2 deletions plugins/main/public/components/common/welcome/welcome.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ span.statWithLink:hover {
text-decoration: underline;
}

[name="OverviewWelcome"] .flex-redirect-app-links {
yenienserrano marked this conversation as resolved.
Show resolved Hide resolved
.wz-welcome-page .flex-redirect-app-links {
display: flex;
flex-grow: 1;
}
}
215 changes: 215 additions & 0 deletions plugins/main/public/components/overview/overview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
import React, { useEffect, useState } from 'react';
import {
getAngularModule,
getDataPlugin,
getUiSettings,
} from '../../kibana-services';
import { Stats } from '../../controllers/overview/components/stats';
import { AppState, WzRequest } from '../../react-services';
import { OverviewWelcome } from '../common/welcome/overview-welcome';
import { MainModule } from '../common/modules/main';
import { UI_LOGGER_LEVELS } from '../../../common/constants';
import { UI_ERROR_SEVERITIES } from '../../react-services/error-orchestrator/types';
import { getErrorOrchestrator } from '../../react-services/common-services';
import { WzCurrentOverviewSectionWrapper } from '../common/modules/overview-current-section-wrapper';
import { createHashHistory } from 'history';
import {
connectToQueryState,
opensearchFilters,
syncQueryStateWithUrl,
} from '../../../../../src/plugins/data/public';
import { once } from 'lodash';
import {
createOsdUrlStateStorage,
createStateContainer,
syncState,
} from '../../../../../src/plugins/opensearch_dashboards_utils/public';

export const Overview: React.FC = () => {
const [agentsCounts, setAgentsCounts] = useState<object>({});
const [tabActive, setTabActive] = useState<string>('welcome');
const [tabViewActive, setTabViewActive] = useState<string>('panels');
const $location = getAngularModule().$injector.get('$location');
const $rootScope = getAngularModule().$injector.get('$rootScope');

useEffect(() => {
const tab = $location.search().tab;
const tabView = $location.search().tabView;
setTabActive(tab || 'welcome');
setTabViewActive(tabView || 'panels');
if (tab === 'welcome' || tab === undefined) {
getSummary();
}

// This is the code to sync the state of the URL with the state of the app
const data = getDataPlugin();
const config = getUiSettings();
const getHistory = once(() => createHashHistory());
const osdUrlStateStorage = createOsdUrlStateStorage({
useHash: config.get('state:storeInSessionStorage'),
history: getHistory(),
});

const appStateFromUrl = osdUrlStateStorage.get('_a') as AppState;
let initialAppState = {
...data.query.queryString.getDefaultQuery(),
...appStateFromUrl,
};
let previousAppState: AppState;
const appStateContainer = createStateContainer<AppState>(initialAppState);
const appStateContainerModified = {
...appStateContainer,
set: (value: AppState | null) => {
if (value) {
previousAppState = appStateContainer.getState();
appStateContainer.set(value);
}
},
};

const replaceUrlAppState = async (newPartial: AppState = {}) => {
const state = { ...appStateContainer.getState(), ...newPartial };
await osdUrlStateStorage.set('_a', state, { replace: true });
};

const { start, stop } = syncState({
storageKey: '_a',
stateContainer: appStateContainerModified,
stateStorage: osdUrlStateStorage,
});

const stopSyncingQueryAppStateWithStateContainer = connectToQueryState(
data.query,
appStateContainer,
{
filters: opensearchFilters.FilterStateStore.APP_STATE,
query: true,
},
);

const { stop: stopSyncingGlobalStateWithUrl } = syncQueryStateWithUrl(
data.query,
osdUrlStateStorage,
);

replaceUrlAppState().then(() => start());

return () => {
stop();
stopSyncingGlobalStateWithUrl();
stopSyncingQueryAppStateWithStateContainer();
};
}, []);

/**
* This fetch de agents summary
*/
const getSummary = async () => {
try {
const {
data: {
data: { connection: data },
},
} = await WzRequest.apiReq('GET', '/agents/summary/status', {});
setAgentsCounts(data);
} catch (error) {
return Promise.reject(error);
}
};

function switchTab(newTab: any, force: any) {
try {
if (tabActive === newTab && !force) {
return;
}
setTabActive(newTab);
setTabViewActive($location.search().tabView || 'panels');
} catch (error) {
const options = {
context: `${Overview.name}.switchTab`,
level: UI_LOGGER_LEVELS.ERROR,
severity: UI_ERROR_SEVERITIES.BUSINESS,
error: {
error: error,
message: error.message || error,
title: error.name || error,
},
};

getErrorOrchestrator().handleError(options);
}
}

const switchSubTab = (subTab: string) => {
try {
if (tabViewActive !== subTab) {
setTabViewActive(subTab);
}
} catch (error) {
const options = {
context: `${Overview.name}.switchSubtab`,
level: UI_LOGGER_LEVELS.ERROR,
severity: UI_ERROR_SEVERITIES.BUSINESS,
error: {
error: error,
message: error.message || error,
title: error.name || error,
},
};

getErrorOrchestrator().handleError(options);
}
};
// TODO: Create a service or add it in the dataSource the management of the pinned agent
const updateSelectedAgents = (agentList: Array<any>) => {
try {
// This is a workaround to sync the pinned agent with the URL
setTimeout(() => {
$location.search('agentId', agentList?.[0] || null);
$rootScope.$applyAsync();
}, 1);
} catch (error) {
const options = {
context: `${Overview.name}.updateSelectedAgents`,
level: UI_LOGGER_LEVELS.ERROR,
severity: UI_ERROR_SEVERITIES.BUSINESS,
error: {
error: error,
message: error.message || error,
title: error.name || error,
},
};

getErrorOrchestrator().handleError(options);
}
};

return (
<>
{tabActive && tabActive !== 'welcome' && (
<>
<MainModule
section={tabActive}
agentsSelectionProps={{
tab: tabActive,
subtab: tabViewActive,
setAgent: (agentList: Array<any>) =>
updateSelectedAgents(agentList),
}}
switchSubTab={subTab => switchSubTab(subTab)}
/>
<WzCurrentOverviewSectionWrapper
switchTab={(tab, force) => switchTab(tab, force)}
currentTab={tabActive}
/>
</>
)}
{tabActive === 'welcome' && (
<>
<Stats {...agentsCounts} />
<OverviewWelcome {...agentsCounts} />
</>
)}
</>
);
};
4 changes: 3 additions & 1 deletion plugins/main/public/controllers/agent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { RegisterAgent } from '../../components/endpoints-summary/register-agent
import { MainModule } from '../../components/common/modules/main';
import { getAngularModule } from '../../kibana-services';
import { MainEndpointsSummary } from '../../components/endpoints-summary';
import { Overview } from '../../components/overview/overview';
import { AgentView } from '../../components/endpoints-summary/agent';

const app = getAngularModule();
Expand All @@ -21,4 +22,5 @@ app
.value('RegisterAgent', RegisterAgent)
.value('AgentView', AgentView)
.value('MainModule', MainModule)
.value('MainEndpointsSummary', MainEndpointsSummary);
.value('MainEndpointsSummary', MainEndpointsSummary)
.value('Overview', Overview);
1 change: 0 additions & 1 deletion plugins/main/public/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* Find more information about this on the LICENSE file.
*/

import './overview';
import './management';
import './agent';
import './security';
Expand Down
Loading
Loading