Skip to content

Commit

Permalink
Backport/backport 205 to 2.x (#209)
Browse files Browse the repository at this point in the history
* bumping up the opensearch dashboards versions

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

* manual backport of #205

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

* Update opensearch_dashboards.json

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

---------

Signed-off-by: Riya Saxena <[email protected]>
Signed-off-by: Riya <[email protected]>
  • Loading branch information
riysaxen-amzn authored Jun 10, 2024
1 parent 22e2fdc commit d176ffb
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 49 deletions.
2 changes: 1 addition & 1 deletion opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
],
"server": true,
"ui": true
}
}
8 changes: 2 additions & 6 deletions public/components/MDSEnabledComponent/MDSEnabledComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React, { useContext, useEffect } from "react";
import React from "react";
import { DataSourceMenuContext, DataSourceMenuProperties } from "../../services/DataSourceMenuContext";
import { useHistory } from "react-router";
import queryString from "query-string";
import { MainContext } from '../../pages/Main/Main';
import _ from 'lodash'

export default class MDSEnabledComponent<
Props extends DataSourceMenuProperties,
Expand Down Expand Up @@ -34,5 +32,3 @@ export function isDataSourceChanged(prevProps, currentProps) {
export function isDataSourceError(error) {
return (error.body && error.body.message && error.body.message.includes("Data Source Error"));
}


77 changes: 39 additions & 38 deletions public/pages/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,51 +94,52 @@ export default class Main extends Component<MainProps, MainState> {
}

async componentDidMount() {
this.setServerFeatures();
}

const services = this.getServices(this.props.http) // Assuming this.context holds the value provided by ServicesContext
componentDidUpdate(prevProps, prevState) {
if (this.props.multiDataSourceEnabled && (prevState.dataSourceId !== this.state.dataSourceId)) {
// Call setServerFeatures when dataSourceId is updated or dataSourceComponent is loaded
this.setServerFeatures();
}
}

async setServerFeatures() : Promise<void> {
const services = this.getServices(this.props.http);
const serverFeatures = await services.notificationService.getServerFeatures();
const defaultConfigTypes = [
'slack',
'chime',
'microsoft_teams',
'webhook',
'email',
'sns',
'smtp_account',
'ses_account',
'email_group',
];

if (serverFeatures != null) {
const { availableChannels, availableConfigTypes, tooltipSupport } = serverFeatures;
const { dataSourceId = "", dataSourceLabel = "" } = this.state;
const dataSourceReadOnly = false;
const dataSourceLoading = this.props.multiDataSourceEnabled;
let newState = {
dataSourceId: this.state.dataSourceId || '',
dataSourceLabel: this.state.dataSourceLabel || '',
dataSourceReadOnly: false,
dataSourceLoading: this.state.dataSourceLoading,
availableChannels: this.props.multiDataSourceEnabled ? CHANNEL_TYPE : defaultConfigTypes,
availableConfigTypes: defaultConfigTypes,
tooltipSupport: false,
};

this.setState({
dataSourceId,
dataSourceLabel,
dataSourceReadOnly,
dataSourceLoading,
if (serverFeatures) {
const { availableChannels, availableConfigTypes, tooltipSupport } = serverFeatures;
newState = {
...newState,
availableChannels,
availableConfigTypes,
tooltipSupport
});
} else {
const { dataSourceId = "", dataSourceLabel = "" } = this.state;
const dataSourceReadOnly = false;
const dataSourceLoading = this.props.multiDataSourceEnabled;
const defaultConfigTypes = [
'slack',
'chime',
'microsoft_teams',
'webhook',
'email',
'sns',
'smtp_account',
'ses_account',
'email_group',
];

this.setState({
dataSourceId,
dataSourceLabel,
dataSourceReadOnly,
dataSourceLoading,
availableChannels: this.props.multiDataSourceEnabled ? CHANNEL_TYPE : defaultConfigTypes,
availableConfigTypes: defaultConfigTypes,
tooltipSupport: false
});
tooltipSupport,
};
}

this.setState(newState);
}

onSelectedDataSources = (dataSources: DataSourceOption[]) => {
Expand Down
6 changes: 2 additions & 4 deletions public/services/NotificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
SenderType,
SESSenderItemType,
} from '../../models/interfaces';
import { CHANNEL_TYPE } from '../../common/constants';
import {
configListToChannels,
configListToRecipientGroups,
Expand Down Expand Up @@ -248,9 +247,8 @@ export default class NotificationService {

getServerFeatures = async () => {
try {
const response = await this.httpClient.get(
NODE_API.GET_AVAILABLE_FEATURES
);
const query = this.multiDataSourceEnabled ? { dataSourceId: this.dataSourceId } : undefined;
const response = await this.httpClient.get(NODE_API.GET_AVAILABLE_FEATURES, { query });
return response;
} catch (error) {
console.error('error fetching available features', error);
Expand Down

0 comments on commit d176ffb

Please sign in to comment.