Skip to content

Commit 250c498

Browse files
committed
Reuse DataSource and fix bug when isMinimal is true
Signed-off-by: Heng Qian <qianheng@amazon.com>
1 parent 7453960 commit 250c498

File tree

2 files changed

+8
-69
lines changed

2 files changed

+8
-69
lines changed

public/pages/CreateMonitor/containers/DataSource/DataSource.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class DataSource extends Component {
5858
);
5959

6060
if (isMinimal) {
61-
return { monitorIndexDisplay };
61+
return monitorIndexDisplay;
6262
}
6363
return (
6464
<ContentPanel

public/pages/CreateMonitor/containers/DataSource/DataSourceFlyout.tsx

+7-68
Original file line numberDiff line numberDiff line change
@@ -4,97 +4,36 @@
44
*/
55

66
import React, { Component } from 'react';
7-
import PropTypes from 'prop-types';
87
import { EuiSpacer } from '@elastic/eui';
9-
import MonitorIndex from '../MonitorIndex';
10-
import MonitorTimeField from '../../components/MonitorTimeField';
11-
import { MONITOR_TYPE, SEARCH_TYPE } from '../../../../utils/constants';
8+
import { connect } from 'formik';
129
import MinimalAccordion from '../../../../components/FeatureAnywhereContextMenu/MinimalAccordion';
10+
import DataSource from '../DataSource'
1311

14-
interface DataSourceProps {
15-
values: Object;
16-
dataTypes: Object;
17-
httpClient: Object;
18-
notifications: Object;
19-
isMinimal: boolean;
20-
canCallGetRemoteIndexes: boolean;
21-
remoteMonitoringEnabled: boolean;
22-
}
23-
interface DataSourceState {
24-
performanceResponse: null | any;
25-
response: null | any;
26-
formikSnapshot: Object;
27-
accordionOpen: boolean;
28-
}
29-
30-
const propTypes = {
31-
values: PropTypes.object.isRequired,
32-
dataTypes: PropTypes.object.isRequired,
33-
httpClient: PropTypes.object.isRequired,
34-
notifications: PropTypes.object.isRequired,
35-
isMinimal: PropTypes.bool,
36-
canCallGetRemoteIndexes: PropTypes.bool,
37-
remoteMonitoringEnabled: PropTypes.bool,
38-
};
39-
const defaultProps = {
40-
isMinimal: false,
41-
};
42-
class DataSourceFlyout extends Component<DataSourceProps, DataSourceState> {
43-
constructor(props: DataSourceProps) {
12+
class DataSourceFlyout extends Component<any, any> {
13+
constructor(props: any) {
4414
super(props);
4515

4616
this.state = {
47-
performanceResponse: null,
48-
response: null,
49-
formikSnapshot: this.props.values,
5017
accordionOpen: false,
5118
};
5219
}
5320

5421
render() {
55-
const { canCallGetRemoteIndexes, remoteMonitoringEnabled } = this.props;
56-
// @ts-ignore
57-
const { monitor_type, searchType } = this.props.values;
58-
const displayTimeField =
59-
searchType === SEARCH_TYPE.GRAPH &&
60-
monitor_type !== MONITOR_TYPE.DOC_LEVEL &&
61-
monitor_type !== MONITOR_TYPE.CLUSTER_METRICS;
62-
const monitorIndexDisplay = (
63-
<>
64-
<MonitorIndex
65-
httpClient={this.props.httpClient}
66-
monitorType={monitor_type}
67-
canCallGetRemoteIndexes={canCallGetRemoteIndexes}
68-
remoteMonitoringEnabled={remoteMonitoringEnabled}
69-
/>
70-
71-
{displayTimeField && (
72-
<>
73-
<EuiSpacer />
74-
<MonitorTimeField dataTypes={this.props.dataTypes} />
75-
</>
76-
)}
77-
</>
78-
);
79-
8022
return (
8123
<><MinimalAccordion
8224
{...{
8325
id: 'dataSource',
8426
isOpen: this.state.accordionOpen,
8527
onToggle: () => {this.setState({accordionOpen: !this.state.accordionOpen})},
8628
title: 'Data Source',
87-
subTitle: `Index: [${this.state.formikSnapshot.index.map((index: {label: string} )=> index.label).join(",")}], timeField: ${this.state.formikSnapshot.timeField}`
29+
subTitle: `Index: [${this.props.formik.values.index.map((index: {label: string} )=> index.label).join(",")}], timeField: ${this.props.formik.values.timeField}`
8830
,
8931
}}
9032
>
91-
{monitorIndexDisplay}
33+
<DataSource {...this.props} isMinimal={true}/>
9234
</MinimalAccordion><EuiSpacer size="xs" /></>
9335
);
9436
}
9537
}
9638

97-
DataSourceFlyout.propTypes = propTypes;
98-
DataSourceFlyout.defaultProps = defaultProps;
99-
100-
export default DataSourceFlyout;
39+
export default connect(DataSourceFlyout);

0 commit comments

Comments
 (0)