Skip to content

Commit

Permalink
some refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: Riya Saxena <[email protected]>
  • Loading branch information
riysaxen-amzn committed Jul 19, 2024
1 parent f31710b commit 0507e1b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
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"]
}
16 changes: 4 additions & 12 deletions public/components/MDS/DataSourceMenuWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,24 @@ import {
import { AppMountParameters, CoreStart, SavedObject } from 'opensearch-dashboards/public';
import { ROUTES } from '../../utils/constants';
import { DataSourceContext } from '../../services/DataSourceContext';
import * as pluginManifest from "../../../opensearch_dashboards.json";
import { DataSourceAttributes } from "../../../../../src/plugins/data_source/common/data_sources";
import semver from "semver";
import { DataSourceAttributes } from 'src/plugins/data_source/common/data_sources';

export interface DataSourceMenuWrapperProps {
core: CoreStart;
dataSourceManagement?: DataSourceManagementPluginSetup;
dataSourceMenuReadOnly: boolean;
dataSourceLoading: boolean;
setHeaderActionMenu: AppMountParameters['setHeaderActionMenu'];
dataSourceFilterFn?: (dataSource: SavedObject<DataSourceAttributes>) => boolean;
}

const dataSourceFilterFn = (dataSource: SavedObject<DataSourceAttributes>) => {
const dataSourceVersion = dataSource?.attributes?.dataSourceVersion || "";
const installedPlugins = dataSource?.attributes?.installedPlugins || [];
return (
semver.satisfies(dataSourceVersion, pluginManifest.supportedOSDataSourceVersions) &&
pluginManifest.requiredOSDataSourcePlugins.every((plugin) => installedPlugins.includes(plugin))
);
};

export const DataSourceMenuWrapper: React.FC<DataSourceMenuWrapperProps> = ({
core,
dataSourceManagement,
dataSourceMenuReadOnly,
dataSourceLoading,
setHeaderActionMenu,
dataSourceFilterFn,
}) => {
if (!dataSourceManagement) {
return null;
Expand Down Expand Up @@ -141,6 +132,7 @@ export const DataSourceMenuWrapper: React.FC<DataSourceMenuWrapperProps> = ({
notifications: core.notifications,
onSelectedDataSources: setDataSource,
savedObjects: core.savedObjects.client,
dataSourceFilter: dataSourceFilterFn,
}}
/>
);
Expand Down
15 changes: 14 additions & 1 deletion public/pages/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
EuiFlexItem,
} from '@elastic/eui';
import { Toast } from '@opensearch-project/oui/src/eui_components/toast/global_toast_list';
import { AppMountParameters, CoreStart } from 'opensearch-dashboards/public';
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 { CoreServicesConsumer } from '../../components/core_services';
Expand Down Expand Up @@ -61,6 +61,9 @@ 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 * as pluginManifest from "../../../opensearch_dashboards.json";
import { DataSourceAttributes } from "../../../../../src/plugins/data_source/common/data_sources";
import semver from "semver";

enum Navigation {
SecurityAnalytics = 'Security Analytics',
Expand Down Expand Up @@ -373,6 +376,15 @@ export default class Main extends Component<MainProps, MainState> {
];
};

dataSourceFilterFn = (dataSource: SavedObject<DataSourceAttributes>) => {
const dataSourceVersion = dataSource?.attributes?.dataSourceVersion || "";
const installedPlugins = dataSource?.attributes?.installedPlugins || [];
return (
semver.satisfies(dataSourceVersion, pluginManifest.supportedOSDataSourceVersions) &&
pluginManifest.requiredOSDataSourcePlugins.every((plugin) => installedPlugins.includes(plugin))
);
};

render() {
const {
landingPage,
Expand Down Expand Up @@ -419,6 +431,7 @@ export default class Main extends Component<MainProps, MainState> {
dataSourceLoading={this.state.dataSourceLoading}
dataSourceMenuReadOnly={dataSourceMenuReadOnly}
setHeaderActionMenu={setActionMenu}
dataSourceFilterFn={this.dataSourceFilterFn}
/>
)}
{!dataSourceLoading && services && (
Expand Down

0 comments on commit 0507e1b

Please sign in to comment.