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

[MDS] Do not decode datasource id from url; update global state on datasource change #1216

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 25 additions & 7 deletions public/pages/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
DATE_TIME_FILTER_KEY,
ROUTES,
dataSourceObservable,
OS_NOTIFICATION_PLUGIN,
} from '../../utils/constants';
import { CoreServicesConsumer } from '../../components/core_services';
import Findings from '../Findings';
Expand Down Expand Up @@ -66,9 +67,15 @@ import { ThreatIntelOverview } from '../ThreatIntel/containers/Overview/ThreatIn
import { AddThreatIntelSource } from '../ThreatIntel/containers/AddThreatIntelSource/AddThreatIntelSource';
import { ThreatIntelScanConfigForm } from '../ThreatIntel/containers/ScanConfiguration/ThreatIntelScanConfigForm';
import { ThreatIntelSource } from '../ThreatIntel/containers/ThreatIntelSource/ThreatIntelSource';
import queryString from 'query-string';
import { dataSourceFilterFn } from '../../utils/helpers';
import { parse } from 'query-string';
import {
dataSourceFilterFn,
getPlugins,
setIsNotificationPluginInstalled,
} from '../../utils/helpers';
import { GettingStartedContent } from '../Overview/components/GettingStarted/GettingStartedContent';
import { BrowserServices } from '../../models/interfaces';
import { CHANNEL_TYPES } from '../CreateDetector/components/ConfigureAlerts/utils/constants';

enum Navigation {
SecurityAnalytics = 'Security Analytics',
Expand Down Expand Up @@ -108,6 +115,7 @@ interface MainProps extends RouteComponentProps {
setActionMenu: AppMountParameters['setHeaderActionMenu'];
multiDataSourceEnabled: boolean;
dataSourceManagement?: DataSourceManagementPluginSetup;
services: BrowserServices;
}

interface MainState {
Expand Down Expand Up @@ -150,7 +158,7 @@ export default class Main extends Component<MainProps, MainState> {
const {
dataSourceId: parsedDataSourceId,
dataSourceLabel: parsedDataSourceLabel,
} = queryString.parse(this.props.location.search) as {
} = parse(this.props.location.search, { decode: false }) as {
dataSourceId: string;
dataSourceLabel: string;
};
Expand Down Expand Up @@ -263,6 +271,7 @@ export default class Main extends Component<MainProps, MainState> {

onDataSourceSelected = (sources: DataSourceOption[]) => {
const { selectedDataSource: dataSource, dataSourceLoading } = this.state;
const { services } = this.props;
if (
sources[0] &&
(dataSource?.id !== sources[0].id || dataSource?.label !== sources[0].label)
Expand All @@ -271,17 +280,26 @@ export default class Main extends Component<MainProps, MainState> {
this.setState({
selectedDataSource: { ...sources[0] },
});
dataSourceObservable.next(
dataSourceInfo.activeDataSource
);
dataSourceObservable.next(dataSourceInfo.activeDataSource);

services.notificationsService.getServerFeatures().then((response) => {
if (response.ok) {
CHANNEL_TYPES.splice(0, CHANNEL_TYPES.length, ...response.response);
}
});

getPlugins(services.opensearchService).then((plugins): void => {
setIsNotificationPluginInstalled(plugins.includes(OS_NOTIFICATION_PLUGIN));
});

DataStore.logTypes.getLogTypes();
}

if (dataSourceLoading) {
this.setState({ dataSourceLoading: false });
}
};


setDataSourceMenuReadOnly = (readOnly: boolean) => {
this.setState({ dataSourceMenuReadOnly: readOnly });
};
Expand Down
1 change: 1 addition & 0 deletions public/security_analytics_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export function renderApp(
<CoreServicesContext.Provider value={coreStart}>
<Main
{...props}
services={services}
landingPage={landingPage}
multiDataSourceEnabled={!!depsStart.dataSource}
dataSourceManagement={dataSourceManagement}
Expand Down
Loading