Skip to content

Commit

Permalink
Merge branch '2.x' into backport-165
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Ho <[email protected]>
  • Loading branch information
derek-ho authored Apr 29, 2024
2 parents 395b23b + 51b55ea commit a8b5998
Show file tree
Hide file tree
Showing 40 changed files with 1,415 additions and 809 deletions.
3 changes: 2 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# This should match the owning team set up in https://github.com/orgs/opensearch-project/teams
* @opensearch-project/notifications
* @opensearch-project/notifications
* @xluo-aws @gaobinlong @Hailong-am @SuZhou-Joe @zhichao-aws @yuye-aws @getsaurabh02 @sbcd90 @praveensameneni @amsiglan @AWSHurneyt
3 changes: 2 additions & 1 deletion .github/workflows/verify-binary-installation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ jobs:
- name: Health check
run: |
timeout 300 bash -c 'while [[ "$(curl http://localhost:5601/api/status | jq -r '.status.overall.state')" != "green" ]]; do sleep 5; done'
shell: bash
shell: bash

20 changes: 20 additions & 0 deletions MAINTAINERS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## Overview

This document contains a list of maintainers in this repo. See [opensearch-project/.github/RESPONSIBILITIES.md](https://github.com/opensearch-project/.github/blob/main/RESPONSIBILITIES.md#maintainer-responsibilities) that explains what the role of maintainer means, what maintainers do in this and other repos, and how they should be doing it. If you're interested in contributing, and becoming a maintainer, see [CONTRIBUTING](CONTRIBUTING.md).

## Current Maintainers
| Maintainer | GitHub ID | Affiliation |
|-----------------------|----------------------------------------------------------| ----------- |
| Saurabh Singh | [getsaurabh02](https://github.com/getsaurabh02) | Amazon |
| Subhobrata Dey | [sbcd90](https://github.com/sbcd90) | Amazon |
| Praveen Sameneni | [praveensameneni](https://github.com/praveensameneni) | Amazon |
| Amardeepsingh Siglani | [amsiglan](https://github.com/amsiglan) | Amazon |
| Xuesong Luo | [xluo-aws](https://github.com/xluo-aws) | Amazon |
| Hailong Cui | [Hailong-am](https://github.com/Hailong-am) | Amazon |
| Binlong Gao | [gaobinlong](https://github.com/gaobinlong) | Amazon |
| Zhou Su | [SuZhou-Joe](https://github.com/SuZhou-Joe) | Amazon |
| Yuye Zhu | [yuye-aws](https://github.com/yuye-aws) | Amazon |
| Zhichao Geng | [zhichao-aws](https://github.com/zhichao-aws) | Amazon |
| Thomas Hurney | [AWSHurneyt](https://github.com/AWSHurneyt) | Amazon |

[This document](https://github.com/opensearch-project/.github/blob/main/MAINTAINERS.md) explains what maintainers do in this repo, and how they should be doing it. If you're interested in contributing, see [CONTRIBUTING](CONTRIBUTING.md).
15 changes: 15 additions & 0 deletions common/MDSEnabledClientService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

export class MDSEnabledClientService {
static getClient(request, context, dataSourceEnabled) {
const { dataSourceId = "" } = (request.query || {}) as { dataSourceId?: string };
if (dataSourceEnabled && dataSourceId && dataSourceId.trim().length != 0) {
return context.dataSource.opensearch.legacy.getClient(dataSourceId.toString()).callAPI;
} else {
// fall back to default local cluster
return context.notificationsContext.notificationsClient.asScoped(
request,
).callAsCurrentUser;
}
}
}

23 changes: 23 additions & 0 deletions common/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export const BACKEND_CHANNEL_TYPE = Object.freeze({
SLACK: 'slack',
EMAIL: 'email',
CHIME: 'chime',
MICROSOFT_TEAMS: 'microsoft_teams',
CUSTOM_WEBHOOK: 'webhook',
SNS: 'sns',
});
export const CHANNEL_TYPE = Object.freeze({
[BACKEND_CHANNEL_TYPE.SLACK]: 'Slack',
[BACKEND_CHANNEL_TYPE.EMAIL]: 'Email',
[BACKEND_CHANNEL_TYPE.CHIME]: 'Chime',
[BACKEND_CHANNEL_TYPE.MICROSOFT_TEAMS]: 'Microsoft Teams',
[BACKEND_CHANNEL_TYPE.CUSTOM_WEBHOOK]: 'Custom webhook',
[BACKEND_CHANNEL_TYPE.SNS]: 'Amazon SNS',
}) as {
slack: string;
email: string;
chime: string;
microsoft_teams: string;
webhook: string;
sns: string;
};
4 changes: 3 additions & 1 deletion models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import { Direction } from '@elastic/eui';
import { WebhookMethodType } from '../public/pages/Channels/types';
import {
CHANNEL_TYPE,
ENCRYPTION_TYPE,
} from '../public/utils/constants';
import {
CHANNEL_TYPE,
} from '../common/constants';

export interface ChannelStatus {
config_id: string;
Expand Down
6 changes: 4 additions & 2 deletions opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
],
"optionalPlugins": [
"share",
"managementOverview"
"managementOverview",
"dataSource",
"dataSourceManagement"
],
"server": true,
"ui": true
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
"tough-cookie": "^4.1.3",
"@cypress/request": "^3.0.0"
}
}
}
21 changes: 14 additions & 7 deletions public/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,28 @@ import { CoreServicesContext } from './components/coreServices';
import Main from './pages/Main';
import { NotificationService } from './services';
import { ServicesContext } from './services/services';
import { DataSourceManagementPluginSetup } from '../../../src/plugins/data_source_management/public';
import { AppPluginStartDependencies } from "./types";

export const renderApp = (coreStart: CoreStart, params: AppMountParameters) => {
const http = coreStart.http;
const notificationService = new NotificationService(http);
const services = { notificationService };
export const renderApp = (
coreStart: CoreStart,
params: AppMountParameters,
dataSourceManagement: DataSourceManagementPluginSetup,
pluginStartDependencies: AppPluginStartDependencies,
) => {

ReactDOM.render(
<Router>
<Route
render={(props) => (
<ServicesContext.Provider value={services}>
<CoreServicesContext.Provider value={coreStart}>
<Main {...props} />
<Main {...props}
setActionMenu={params.setHeaderActionMenu}
multiDataSourceEnabled={!!pluginStartDependencies.dataSource}
dataSourceManagement={dataSourceManagement}
http={coreStart.http} // Pass http as a prop
/>
</CoreServicesContext.Provider>
</ServicesContext.Provider>
)}
/>
</Router>,
Expand Down
38 changes: 38 additions & 0 deletions public/components/MDSEnabledComponent/MDSEnabledComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React, { useContext, useEffect } from "react";
import { DataSourceMenuContext, DataSourceMenuProperties } from "../../services/DataSourceMenuContext";
import { useHistory } from "react-router";
import queryString from "query-string";
import { MainContext } from '../../pages/Main/Main';

export default class MDSEnabledComponent<
Props extends DataSourceMenuProperties,
State extends DataSourceMenuProperties
> extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
dataSourceId: props.dataSourceId,
multiDataSourceEnabled: props.multiDataSourceEnabled,
} as State;
}
}

export function isDataSourceChanged(prevProps, currentProps) {
if (
prevProps.notificationService?.multiDataSourceEnabled &&
currentProps.notificationService?.multiDataSourceEnabled
) {
const prevDataSourceId = prevProps.notificationService.dataSourceId;
const currDataSourceId = currentProps.notificationService.dataSourceId;
if (!_.isEqual(prevDataSourceId, currDataSourceId)) {
return true;
}
}
return false;
}

export function isDataSourceError(error) {
return (error.body && error.body.message && error.body.message.includes("Data Source Error"));
}


37 changes: 26 additions & 11 deletions public/pages/Channels/Channels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { Criteria } from '@elastic/eui/src/components/basic_table/basic_table';
import { Pagination } from '@elastic/eui/src/components/basic_table/pagination_bar';
import _ from 'lodash';
import React, { Component } from 'react';
import React, { Component, useContext } from 'react';
import { RouteComponentProps } from 'react-router-dom';
import { ChannelItemType, TableState } from '../../../models/interfaces';
import {
Expand All @@ -28,31 +28,37 @@ import { CoreServicesContext } from '../../components/coreServices';
import { NotificationService } from '../../services';
import {
BREADCRUMBS,
CHANNEL_TYPE,
ROUTES,
} from '../../utils/constants';
import {
CHANNEL_TYPE,
} from '../../../common/constants';
import { getErrorMessage } from '../../utils/helpers';
import { DEFAULT_PAGE_SIZE_OPTIONS } from '../Notifications/utils/constants';
import { ChannelActions } from './components/ChannelActions';
import { ChannelControls } from './components/ChannelControls';
import { ChannelFiltersType } from './types';
import { DataSourceMenuProperties } from '../../services/DataSourceMenuContext';
import MDSEnabledComponent, {
isDataSourceChanged,
isDataSourceError,
} from '../../components/MDSEnabledComponent/MDSEnabledComponent';

interface ChannelsProps extends RouteComponentProps {
interface ChannelsProps extends RouteComponentProps, DataSourceMenuProperties {
notificationService: NotificationService;
}

interface ChannelsState extends TableState<ChannelItemType> {
interface ChannelsState extends TableState<ChannelItemType>, DataSourceMenuProperties {
filters: ChannelFiltersType;
}

export class Channels extends Component<ChannelsProps, ChannelsState> {
export class Channels extends MDSEnabledComponent<ChannelsProps, ChannelsState> {
static contextType = CoreServicesContext;
columns: EuiTableFieldDataColumnType<ChannelItemType>[];

constructor(props: ChannelsProps) {
super(props);

this.state = {
const state: ChannelsState = {
total: 0,
from: 0,
size: 10,
Expand All @@ -65,6 +71,8 @@ export class Channels extends Component<ChannelsProps, ChannelsState> {
loading: true,
};

this.state = state;

this.columns = [
{
field: 'name',
Expand Down Expand Up @@ -116,14 +124,18 @@ export class Channels extends Component<ChannelsProps, ChannelsState> {
}

async componentDidUpdate(prevProps: ChannelsProps, prevState: ChannelsState) {
const prevQuery = Channels.getQueryObjectFromState(prevState);
const currQuery = Channels.getQueryObjectFromState(this.state);
const prevQuery = this.getQueryObjectFromState(prevState);
const currQuery = this.getQueryObjectFromState(this.state);

if (!_.isEqual(prevQuery, currQuery)) {
await this.refresh();
}
if (isDataSourceChanged(this.props, prevProps)) {
await this.refresh();
}
}

static getQueryObjectFromState(state: ChannelsState) {
getQueryObjectFromState(state: ChannelsState) {
const config_type = _.isEmpty(state.filters.type)
? Object.keys(CHANNEL_TYPE) // by default get all channels but not email senders/groups
: state.filters.type;
Expand All @@ -143,12 +155,15 @@ export class Channels extends Component<ChannelsProps, ChannelsState> {
async refresh() {
this.setState({ loading: true });
try {
const queryObject = Channels.getQueryObjectFromState(this.state);
const queryObject = this.getQueryObjectFromState(this.state);
const channels = await this.props.notificationService.getChannels(
queryObject
);
this.setState({ items: channels.items, total: channels.total });
} catch (error) {
if (isDataSourceError(error)) {
this.setState({ items: [], total: 0 });
}
this.context.notifications.toasts.addDanger(
getErrorMessage(error, 'There was a problem loading channels.')
);
Expand Down
2 changes: 0 additions & 2 deletions public/pages/Channels/__tests__/DetailsListModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { render } from '@testing-library/react';
import { configure, mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import React from 'react';
import { notificationServiceMock } from '../../../../test/mocks/serviceMock';
import { DetailsListModal } from '../components/modals/DetailsListModal';

describe('<DetailsListModal /> spec', () => {
Expand All @@ -31,7 +30,6 @@ describe('<DetailsListModal /> spec', () => {
title="Email addresses"
items={items}
onClose={onClose}
services={notificationServiceMock}
/>
);
expect(wrap).toMatchSnapshot();
Expand Down
3 changes: 0 additions & 3 deletions public/pages/Channels/__tests__/DetailsTableModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import { configure, mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import React from 'react';
import { notificationServiceMock } from '../../../../test/mocks/serviceMock';
import { DetailsTableModal } from '../components/modals/DetailsTableModal';

describe('<DetailsTableModal /> spec', () => {
Expand All @@ -24,7 +23,6 @@ describe('<DetailsTableModal /> spec', () => {
isParameters={true}
items={items}
onClose={onClose}
services={notificationServiceMock}
/>
);
expect(wrap).toMatchSnapshot();
Expand All @@ -42,7 +40,6 @@ describe('<DetailsTableModal /> spec', () => {
isParameters={false}
items={items}
onClose={onClose}
services={notificationServiceMock}
/>
);
expect(wrap).toMatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,6 @@ exports[`<DetailsListModal /> spec renders the component 1`] = `
]
}
onClose={[MockFunction]}
services={
Object {
"notificationService": NotificationService {
"createConfig": [Function],
"deleteConfigs": [Function],
"getChannel": [Function],
"getChannels": [Function],
"getConfig": [Function],
"getConfigs": [Function],
"getEmailConfigDetails": [Function],
"getNotification": [Function],
"getRecipientGroup": [Function],
"getRecipientGroups": [Function],
"getSESSender": [Function],
"getSESSenders": [Function],
"getSender": [Function],
"getSenders": [Function],
"getServerFeatures": [Function],
"httpClient": [MockFunction],
"sendTestMessage": [Function],
"updateConfig": [Function],
},
}
}
title="Email addresses"
>
<EuiOverlayMask>
Expand Down
Loading

0 comments on commit a8b5998

Please sign in to comment.