Skip to content

Commit

Permalink
Backport/backport 186 to 2.x (#197)
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 MDS support

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

* fixed email tests due to a merge conflict in backport

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

* fixed email tests due to a merge conflict in backport

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

---------

Signed-off-by: Riya Saxena <[email protected]>
Signed-off-by: Riya <[email protected]>
  • Loading branch information
riysaxen-amzn authored Apr 27, 2024
1 parent dada2bf commit 0954519
Show file tree
Hide file tree
Showing 32 changed files with 1,304 additions and 756 deletions.
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;
}
}
}

4 changes: 3 additions & 1 deletion opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
],
"optionalPlugins": [
"share",
"managementOverview"
"managementOverview",
"dataSource",
"dataSourceManagement"
],
"server": true,
"ui": true
Expand Down
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
34 changes: 34 additions & 0 deletions public/components/MDSEnabledComponent/MDSEnabledComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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;
}


27 changes: 17 additions & 10 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 @@ -38,23 +38,24 @@ 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 } 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 @@ -67,6 +68,8 @@ export class Channels extends Component<ChannelsProps, ChannelsState> {
loading: true,
};

this.state = state;

this.columns = [
{
field: 'name',
Expand Down Expand Up @@ -118,14 +121,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 @@ -145,7 +152,7 @@ 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
);
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,6 @@ exports[`<DetailsTableModal /> spec renders headers 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],
},
}
}
>
<EuiOverlayMask>
<Portal
Expand Down Expand Up @@ -1886,30 +1862,6 @@ exports[`<DetailsTableModal /> spec renders parameters 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],
},
}
}
>
<EuiOverlayMask>
<Portal
Expand Down
1 change: 1 addition & 0 deletions public/pages/CreateChannel/CreateChannel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -530,3 +530,4 @@ export function CreateChannel(props: CreateChannelsProps) {
</>
);
}

8 changes: 6 additions & 2 deletions public/pages/Emails/EmailGroups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ import { RouteComponentProps } from 'react-router-dom';
import { CoreServicesContext } from '../../components/coreServices';
import { BREADCRUMBS } from '../../utils/constants';
import { RecipientGroupsTable } from './components/tables/RecipientGroupsTable';
import { MainContext } from '../Main/Main';
import { NotificationService } from '../../services';

interface EmailGroupsProps extends RouteComponentProps {}
interface EmailGroupsProps extends RouteComponentProps {
notificationService: NotificationService;
}

export function EmailGroups(props: EmailGroupsProps) {
const coreContext = useContext(CoreServicesContext)!;
Expand All @@ -29,7 +33,7 @@ export function EmailGroups(props: EmailGroupsProps) {
</EuiTitle>

<EuiSpacer />
<RecipientGroupsTable coreContext={coreContext} />
<RecipientGroupsTable coreContext={coreContext} notificationService={props.notificationService} />
</>
);
}
11 changes: 7 additions & 4 deletions public/pages/Emails/EmailSenders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ import { BREADCRUMBS } from '../../utils/constants';
import { MainContext } from '../Main/Main';
import { SendersTable } from './components/tables/SendersTable';
import { SESSendersTable } from './components/tables/SESSendersTable';
import { NotificationService } from '../../services';

interface EmailSendersProps extends RouteComponentProps {}
interface EmailSendersProps extends RouteComponentProps {
notificationService: NotificationService;
}

export function EmailSenders(props: EmailSendersProps) {
const coreContext = useContext(CoreServicesContext)!;
const mainStateContext = useContext(MainContext)!;


useEffect(() => {
coreContext.chrome.setBreadcrumbs([
BREADCRUMBS.NOTIFICATIONS,
Expand All @@ -31,19 +35,18 @@ export function EmailSenders(props: EmailSendersProps) {
<EuiTitle size="l">
<h1>Email senders</h1>
</EuiTitle>

{mainStateContext.availableConfigTypes.includes('smtp_account') && (
<>
<EuiSpacer />
<SendersTable coreContext={coreContext} />
<SendersTable coreContext={coreContext} notificationService={props.notificationService} />
</>
)}

{/* UI currently does not fully handle this condition, adding it just to avoid flashing */}
{mainStateContext.availableConfigTypes.includes('ses_account') && (
<>
<EuiSpacer />
<SESSendersTable coreContext={coreContext} />
<SESSendersTable coreContext={coreContext} notificationService={props.notificationService} />
</>
)}
</>
Expand Down
Loading

0 comments on commit 0954519

Please sign in to comment.