Skip to content

Commit

Permalink
plugin decoupling changes (opensearch-project#1079)
Browse files Browse the repository at this point in the history
* plugin decoupling changes

Signed-off-by: Riya Saxena <[email protected]>

* some refactoring

Signed-off-by: Riya Saxena <[email protected]>

* removed optional

Signed-off-by: Riya Saxena <[email protected]>

---------

Signed-off-by: Riya Saxena <[email protected]>
  • Loading branch information
riysaxen-amzn authored Jul 19, 2024
1 parent bcb2303 commit b1d93c6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
4 changes: 3 additions & 1 deletion opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
"requiredPlugins": ["data"],
"optionalPlugins": ["dataSource", "dataSourceManagement"],
"server": true,
"ui": true
"ui": true,
"supportedOSDataSourceVersions": ">=2.16.0",
"requiredOSDataSourcePlugins": ["opensearch_security_analytics"]
}
9 changes: 8 additions & 1 deletion public/components/MDS/DataSourceMenuWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ import {
DataSourceSelectableConfig,
DataSourceViewConfig,
} from '../../../../../src/plugins/data_source_management/public';
import { AppMountParameters, CoreStart } from 'opensearch-dashboards/public';
import { AppMountParameters, CoreStart, SavedObject } from 'opensearch-dashboards/public';
import { ROUTES } from '../../utils/constants';
import { DataSourceContext } from '../../services/DataSourceContext';
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;
}

export const DataSourceMenuWrapper: React.FC<DataSourceMenuWrapperProps> = ({
Expand All @@ -28,6 +30,7 @@ export const DataSourceMenuWrapper: React.FC<DataSourceMenuWrapperProps> = ({
dataSourceMenuReadOnly,
dataSourceLoading,
setHeaderActionMenu,
dataSourceFilterFn,
}) => {
if (!dataSourceManagement) {
return null;
Expand Down Expand Up @@ -64,6 +67,7 @@ export const DataSourceMenuWrapper: React.FC<DataSourceMenuWrapperProps> = ({
componentConfig={{
fullWidth: false,
activeOption: [dataSource],
dataSourceFilter: dataSourceFilterFn,
}}
componentType="DataSourceView"
setMenuMountPoint={setHeaderActionMenu}
Expand All @@ -79,6 +83,7 @@ export const DataSourceMenuWrapper: React.FC<DataSourceMenuWrapperProps> = ({
componentConfig={{
fullWidth: false,
activeOption: [dataSource],
dataSourceFilter: dataSourceFilterFn,
}}
componentType="DataSourceView"
setMenuMountPoint={setHeaderActionMenu}
Expand All @@ -93,6 +98,7 @@ export const DataSourceMenuWrapper: React.FC<DataSourceMenuWrapperProps> = ({
notifications: core.notifications,
onSelectedDataSources: setDataSource,
savedObjects: core.savedObjects.client,
dataSourceFilter: dataSourceFilterFn,
}}
/>
);
Expand Down Expand Up @@ -126,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 b1d93c6

Please sign in to comment.