Skip to content

Commit

Permalink
do not decode ds id from url; update global state on ds change (#1216) (
Browse files Browse the repository at this point in the history
#1219)

Signed-off-by: Amardeepsingh Siglani <[email protected]>
(cherry picked from commit ad76b7b)

Co-authored-by: Amardeepsingh Siglani <[email protected]>
  • Loading branch information
AWSHurneyt and amsiglan authored Dec 2, 2024
1 parent c6dca67 commit 8ec2772
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
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

0 comments on commit 8ec2772

Please sign in to comment.