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

Bug fixes PageHeader and SideNav #1123

Merged
merged 7 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"server": true,
"ui": true,
"supportedOSDataSourceVersions": ">=2.16.0",
"requiredOSDataSourcePlugins": ["opensearch_security_analytics"]
"requiredOSDataSourcePlugins": ["opensearch-security-analytics"]
}
39 changes: 30 additions & 9 deletions public/pages/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import { Toast } from '@opensearch-project/oui/src/eui_components/toast/global_toast_list';
import { AppMountParameters, CoreStart, SavedObject } from 'opensearch-dashboards/public';
import { SaContextConsumer } from '../../services';
import { DEFAULT_DATE_RANGE, DATE_TIME_FILTER_KEY, ROUTES } from '../../utils/constants';
import { DEFAULT_DATE_RANGE, DATE_TIME_FILTER_KEY, ROUTES, dataSourceObservable } from '../../utils/constants';
import { CoreServicesConsumer } from '../../components/core_services';
import Findings from '../Findings';
import Detectors from '../Detectors';
Expand Down Expand Up @@ -64,6 +64,7 @@ import { ThreatIntelSource } from '../ThreatIntel/containers/ThreatIntelSource/T
import * as pluginManifest from "../../../opensearch_dashboards.json";
import { DataSourceAttributes } from "../../../../../src/plugins/data_source/common/data_sources";
import semver from "semver";
import queryString from "query-string";

enum Navigation {
SecurityAnalytics = 'Security Analytics',
Expand Down Expand Up @@ -136,19 +137,40 @@ export default class Main extends Component<MainProps, MainState> {
const defaultDateTimeFilter = cachedDateTimeFilter
? JSON.parse(cachedDateTimeFilter)
: {
startTime: DEFAULT_DATE_RANGE.start,
endTime: DEFAULT_DATE_RANGE.end,
};
startTime: DEFAULT_DATE_RANGE.start,
endTime: DEFAULT_DATE_RANGE.end,
};
let dataSourceId = "";
let dataSourceLabel = "";
if (props.multiDataSourceEnabled) {
const { dataSourceId: parsedDataSourceId, dataSourceLabel: parsedDataSourceLabel } = queryString.parse(
amsiglan marked this conversation as resolved.
Show resolved Hide resolved
this.props.location.search
) as {
dataSourceId: string;
dataSourceLabel: string;
};
dataSourceId = parsedDataSourceId;
dataSourceLabel = parsedDataSourceLabel || "";

if (dataSourceId) {
dataSourceObservable.next({ id: dataSourceId, label: dataSourceLabel });
}
}

this.state = {
getStartedDismissedOnce: false,
selectedNavItemId: Navigation.Overview,
dateTimeFilter: defaultDateTimeFilter,
showFlyoutData: null,
dataSourceLoading: props.multiDataSourceEnabled,
selectedDataSource: { id: '' },
/**
* undefined: need data source picker to help to determine which data source to use.
* empty string: using the local cluster.
* string: using the selected data source.
*/
dataSourceLoading: dataSourceId === undefined ? props.multiDataSourceEnabled : false,
selectedDataSource: { id: dataSourceId },
dataSourceMenuReadOnly: false,
};

DataStore.detectors.setHandlers(this.showCallout, this.showToast);
DataStore.findings.setFlyoutCallback(this.showFlyout);
}
Expand Down Expand Up @@ -237,7 +259,7 @@ export default class Main extends Component<MainProps, MainState> {
selectedDataSource: { ...sources[0] },
});
}

dataSourceObservable.next({ id: this.state.selectedDataSource.id, label: this.state.selectedDataSource.label });
if (dataSourceLoading) {
this.setState({ dataSourceLoading: false });
}
Expand Down Expand Up @@ -403,7 +425,6 @@ export default class Main extends Component<MainProps, MainState> {
dataSourceMenuReadOnly,
} = this.state;
const sideNav: EuiSideNavItemType<{ style: any }>[] = this.getSideNavItems();

const dataSourceContextValue: DataSourceContextType = {
dataSource: selectedDataSource,
setDataSource: this.onDataSourceSelected,
Expand Down
27 changes: 27 additions & 0 deletions public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import {
AppMountParameters,
AppUpdater,
CoreSetup,
CoreStart,
DEFAULT_APP_CATEGORIES,
Expand All @@ -24,6 +25,7 @@ import {
ROUTES,
THREAT_ALERTS_NAV_ID,
THREAT_INTEL_NAV_ID,
dataSourceObservable,
setDarkMode,
} from './utils/constants';
import { SecurityAnalyticsPluginSetup, SecurityAnalyticsPluginStart } from './index';
Expand All @@ -39,6 +41,7 @@ import {
setApplication,
setBreadCrumbsSetter,
} from './services/utils/constants';
import { BehaviorSubject } from 'rxjs';

export interface SecurityAnalyticsPluginSetupDeps {
data: DataPublicPluginSetup;
Expand All @@ -62,6 +65,15 @@ export class SecurityAnalyticsPlugin
private initializerContext: PluginInitializerContext<SecurityAnalyticsPluginConfigType>
) {}

private updateDefaultRouteOfManagementApplications: AppUpdater = () => {
const hash = `#/?dataSourceId=${dataSourceObservable.value?.id || ""}`;
return {
defaultPath: hash,
};
};

private appStateUpdater = new BehaviorSubject<AppUpdater>(this.updateDefaultRouteOfManagementApplications);

public setup(
core: CoreSetup<SecurityAnalyticsPluginStartDeps>,
{ dataSourceManagement }: SecurityAnalyticsPluginSetupDeps
Expand Down Expand Up @@ -93,6 +105,7 @@ export class SecurityAnalyticsPlugin
id: OVERVIEW_NAV_ID,
title: 'Overview',
order: 0,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.LANDING_PAGE);
},
Expand All @@ -103,6 +116,7 @@ export class SecurityAnalyticsPlugin
title: 'Threat alerts',
order: 9070,
category: DEFAULT_APP_CATEGORIES.investigate,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.ALERTS);
},
Expand All @@ -113,6 +127,7 @@ export class SecurityAnalyticsPlugin
title: 'Findings',
order: 9080,
category: DEFAULT_APP_CATEGORIES.investigate,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.FINDINGS);
},
Expand All @@ -123,6 +138,7 @@ export class SecurityAnalyticsPlugin
title: 'Correlations',
order: 9080,
category: DEFAULT_APP_CATEGORIES.investigate,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.CORRELATIONS);
},
Expand All @@ -133,6 +149,7 @@ export class SecurityAnalyticsPlugin
title: 'Threat detectors',
order: 9080,
category: DEFAULT_APP_CATEGORIES.configure,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.DETECTORS);
},
Expand All @@ -143,6 +160,7 @@ export class SecurityAnalyticsPlugin
title: 'Detection rules',
order: 9080,
category: DEFAULT_APP_CATEGORIES.configure,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.RULES);
},
Expand All @@ -153,6 +171,7 @@ export class SecurityAnalyticsPlugin
title: 'Correlation rules',
order: 9080,
category: DEFAULT_APP_CATEGORIES.configure,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.CORRELATION_RULES);
},
Expand All @@ -163,6 +182,7 @@ export class SecurityAnalyticsPlugin
title: 'Threat intelligence',
order: 9080,
category: DEFAULT_APP_CATEGORIES.configure,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.THREAT_INTEL_OVERVIEW);
},
Expand All @@ -173,11 +193,18 @@ export class SecurityAnalyticsPlugin
title: 'Log types',
order: 9080,
category: DEFAULT_APP_CATEGORIES.configure,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.LOG_TYPES);
},
});

dataSourceObservable.subscribe((dataSourceOption) => {
if (dataSourceOption) {
this.appStateUpdater.next(this.updateDefaultRouteOfManagementApplications);
}
});

const navlinks = [
{ id: OVERVIEW_NAV_ID, showInAllNavGroup: true },
{ id: THREAT_ALERTS_NAV_ID, showInAllNavGroup: true },
Expand Down
16 changes: 14 additions & 2 deletions public/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { DetectorInput, PeriodSchedule } from '../../models/interfaces';
import { DetectorHit } from '../../server/models/interfaces';
import _ from 'lodash';
import { euiPaletteColorBlind } from '@elastic/eui';
import { DataSourceOption } from 'src/plugins/data_source_management/public';
import { BehaviorSubject } from 'rxjs';
import { i18n } from "@osd/i18n";

export const DATE_MATH_FORMAT = 'YYYY-MM-DDTHH:mm:ss.SSSZ';
export const MAX_RECENTLY_USED_TIME_RANGES = 5;
Expand Down Expand Up @@ -77,7 +80,7 @@ export const BREADCRUMBS = Object.freeze({
SECURITY_ANALYTICS: { text: 'Security Analytics', href: '#/' },
OVERVIEW: { text: 'Overview', href: `#${ROUTES.OVERVIEW}` },
FINDINGS: { text: 'Findings', href: `#${ROUTES.FINDINGS}` },
DETECTORS: { text: 'Detectors', href: `#${ROUTES.DETECTORS}` },
DETECTORS: { text: 'Threat detectors', href: `#${ROUTES.DETECTORS}` },
DETECTORS_CREATE: { text: 'Create detector', href: `#${ROUTES.DETECTORS_CREATE}` },
EDIT_DETECTOR_DETAILS: { text: 'Edit detector details' },
DETECTORS_DETAILS: (name: string, detectorId: string) => ({
Expand All @@ -89,7 +92,7 @@ export const BREADCRUMBS = Object.freeze({
href: `#${ROUTES.EDIT_DETECTOR_DETAILS}/${detectorId}`,
}),
RULES: { text: 'Detection rules', href: `#${ROUTES.RULES}` },
ALERTS: { text: 'Alerts', href: `#${ROUTES.ALERTS}` },
ALERTS: { text: 'Threat alerts', href: `#${ROUTES.ALERTS}` },
RULES_CREATE: { text: 'Create detection rule', href: `#${ROUTES.RULES_CREATE}` },
RULES_EDIT: { text: 'Edit rule', href: `#${ROUTES.RULES_EDIT}` },
RULES_DUPLICATE: { text: 'Duplicate rule', href: `#${ROUTES.RULES_DUPLICATE}` },
Expand Down Expand Up @@ -241,3 +244,12 @@ export enum AlertTabId {
ThreatIntel = 'threat-intel',
Correlations = 'correlations',
}

const LocalCluster: DataSourceOption = {
label: i18n.translate("dataSource.localCluster", {
defaultMessage: "Local cluster",
}),
id: "",
};

export const dataSourceObservable = new BehaviorSubject<DataSourceOption>(LocalCluster);
Loading