Skip to content

Commit

Permalink
added check for multi dat (#1132)
Browse files Browse the repository at this point in the history
a source support

Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>
  • Loading branch information
amsiglan committed Sep 5, 2024
1 parent 930b74a commit ac24194
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 19 deletions.
15 changes: 15 additions & 0 deletions common/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import _ from 'lodash';
import { DEFAULT_METRICS_COUNTER } from '../server/utils/constants';
import { MetricsCounter, PartialMetricsCounter } from '../types';
import { SecurityAnalyticsPluginConfigType } from '../config';
import { Get, Set } from '../../../src/plugins/opensearch_dashboards_utils/common';

export function aggregateMetrics(
metrics: PartialMetricsCounter,
Expand Down Expand Up @@ -61,3 +62,17 @@ export function extractFieldsFromMappings(
}
});
}

export function createNullableGetterSetter<T>(): [Get<T | undefined>, Set<T>] {
let value: T;

const get = () => {
return value;
};

const set = (newValue: T) => {
value = newValue;
};

return [get, set];
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ import { OverviewAlertItem } from '../../../types';
import { Time } from '@opensearch-project/opensearch/api/types';

export interface DataSourceAlertsCardProps {
getDataSourceMenu: DataSourceManagementPluginSetup['ui']['getDataSourceMenu'];
getDataSourceMenu?: DataSourceManagementPluginSetup['ui']['getDataSourceMenu'];
detectorService: DetectorsService;
}

export const DataSourceThreatAlertsCard: React.FC<DataSourceAlertsCardProps> = ({
getDataSourceMenu,
detectorService,
}) => {
const DataSourceSelector = getDataSourceMenu();
const DataSourceSelector = getDataSourceMenu?.();
const notifications = getNotifications();
const [loading, setLoading] = useState(false);
const [dataSource, setDataSource] = useState<DataSourceOption>({
Expand Down Expand Up @@ -157,19 +157,21 @@ export const DataSourceThreatAlertsCard: React.FC<DataSourceAlertsCardProps> = (
<h3>Recent threat alerts</h3>
</EuiTitle>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<DataSourceSelector
componentType={'DataSourceSelectable'}
componentConfig={{
savedObjects: getSavedObjectsClient(),
notifications: getNotifications(),
onSelectedDataSources: onDataSourceSelected,
fullWidth: false,
dataSourceFilter: dataSourceFilterFn,
activeOption: dataSource ? [{ id: dataSource.id }] : undefined,
}}
/>
</EuiFlexItem>
{DataSourceSelector && (
<EuiFlexItem grow={false}>
<DataSourceSelector
componentType={'DataSourceSelectable'}
componentConfig={{
savedObjects: getSavedObjectsClient(),
notifications: getNotifications(),
onSelectedDataSources: onDataSourceSelected,
fullWidth: false,
dataSourceFilter: dataSourceFilterFn,
activeOption: dataSource ? [{ id: dataSource.id }] : undefined,
}}
/>
</EuiFlexItem>
)}
</EuiFlexGroup>
</EuiFlexItem>
<EuiFlexItem style={{ overflow: 'scroll' }}>
Expand Down
8 changes: 5 additions & 3 deletions public/services/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { NavigationPublicPluginStart } from '../../../../../src/plugins/navigati
import { ContentManagementPluginStart } from '../../../../../src/plugins/content_management/public';
import { BrowserServices } from '../../models/interfaces';
import { DataSourceManagementPluginSetup } from '../../../../../src/plugins/data_source_management/public';
import { createNullableGetterSetter } from '../../../common/helpers';

export const dataSourceInfo: { activeDataSource: DataSourceOption } = {
activeDataSource: {
Expand Down Expand Up @@ -51,6 +52,7 @@ export const [getSavedObjectsClient, setSavedObjectsClient] = createGetterSetter
CoreStart['savedObjects']['client']
>('SavedObjectsClient');

export const [getDataSourceManagementPlugin, setDataSourceManagementPlugin] = createGetterSetter<
DataSourceManagementPluginSetup
>('DataSourceManagement');
export const [
getDataSourceManagementPlugin,
setDataSourceManagementPlugin,
] = createNullableGetterSetter<DataSourceManagementPluginSetup>();
2 changes: 1 addition & 1 deletion public/utils/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ export function registerThreatAlertsCard() {
order: 20,
render: () => (
<DataSourceThreatAlertsCard
getDataSourceMenu={getDataSourceManagementPlugin().ui.getDataSourceMenu}
getDataSourceMenu={getDataSourceManagementPlugin()?.ui.getDataSourceMenu}
detectorService={getBrowserServices().detectorsService}
/>
),
Expand Down

0 comments on commit ac24194

Please sign in to comment.