Skip to content

Commit 6312c3d

Browse files
committed
Address review comments and update tests
Signed-off-by: Siddhant Deshmukh <[email protected]>
1 parent e9431b0 commit 6312c3d

File tree

12 files changed

+631
-65
lines changed

12 files changed

+631
-65
lines changed

public/pages/Configuration/Configuration.test.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,18 @@ const defaultMemorySettings = {
3535
currTimeUnit: 'HOURS',
3636
};
3737

38+
const groupBySettings = {
39+
groupBy: 'SIMILARITY',
40+
};
41+
3842
const renderConfiguration = (overrides = {}) =>
3943
render(
4044
<MemoryRouter>
4145
<Configuration
4246
latencySettings={{ ...defaultLatencySettings, ...overrides }}
4347
cpuSettings={defaultCpuSettings}
4448
memorySettings={defaultMemorySettings}
49+
groupBySettings={groupBySettings}
4550
configInfo={mockConfigInfo}
4651
core={mockCoreStart}
4752
/>
@@ -96,7 +101,15 @@ describe('Configuration Component', () => {
96101
fireEvent.change(getTopNSizeConfiguration(), { target: { value: '7' } });
97102
fireEvent.click(screen.getByText('Save'));
98103
await waitFor(() => {
99-
expect(mockConfigInfo).toHaveBeenCalledWith(false, true, 'latency', '7', '10', 'MINUTES');
104+
expect(mockConfigInfo).toHaveBeenCalledWith(
105+
false,
106+
true,
107+
'latency',
108+
'7',
109+
'10',
110+
'MINUTES',
111+
'SIMILARITY'
112+
);
100113
});
101114
});
102115

public/pages/Configuration/Configuration.tsx

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
import { useHistory, useLocation } from 'react-router-dom';
2626
import { CoreStart } from 'opensearch-dashboards/public';
2727
import { QUERY_INSIGHTS, MetricSettings, GroupBySettings } from '../TopNQueries/TopNQueries';
28+
import { METRIC_TYPES, TIME_UNITS, MINUTES_OPTIONS, GROUP_BY_OPTIONS } from '../Utils/Constants';
2829

2930
const Configuration = ({
3031
latencySettings,
@@ -41,29 +42,6 @@ const Configuration = ({
4142
configInfo: any;
4243
core: CoreStart;
4344
}) => {
44-
const metricTypes = [
45-
{ value: 'latency', text: 'Latency' },
46-
{ value: 'cpu', text: 'CPU' },
47-
{ value: 'memory', text: 'Memory' },
48-
];
49-
50-
const timeUnits = [
51-
{ value: 'MINUTES', text: 'Minute(s)' },
52-
{ value: 'HOURS', text: 'Hour(s)' },
53-
];
54-
55-
const minutesOptions = [
56-
{ value: '1', text: '1' },
57-
{ value: '5', text: '5' },
58-
{ value: '10', text: '10' },
59-
{ value: '30', text: '30' },
60-
];
61-
62-
const groupByOptions = [
63-
{ value: 'none', text: 'None' },
64-
{ value: 'similarity', text: 'Similarity' },
65-
];
66-
6745
const history = useHistory();
6846
const location = useLocation();
6947

@@ -147,7 +125,7 @@ const Configuration = ({
147125
<EuiSelect
148126
id="minutes"
149127
required={true}
150-
options={minutesOptions}
128+
options={MINUTES_OPTIONS}
151129
value={windowSize}
152130
onChange={onWindowSizeChange}
153131
/>
@@ -163,7 +141,7 @@ const Configuration = ({
163141
/>
164142
);
165143

166-
const WindowChoice = time === timeUnits[0].value ? MinutesBox : HoursBox;
144+
const WindowChoice = time === TIME_UNITS[0].value ? MinutesBox : HoursBox;
167145

168146
const isChanged =
169147
isEnabled !== metricSettingsMap[metric].isEnabled ||
@@ -175,7 +153,7 @@ const Configuration = ({
175153
const isValid = (() => {
176154
const nVal = parseInt(topNSize, 10);
177155
if (nVal < 1 || nVal > 100) return false;
178-
if (time === timeUnits[0].value) return true;
156+
if (time === TIME_UNITS[0].value) return true;
179157
const windowVal = parseInt(windowSize, 10);
180158
return windowVal >= 1 && windowVal <= 24;
181159
})();
@@ -213,7 +191,7 @@ const Configuration = ({
213191
<EuiSelect
214192
id="metricType"
215193
required={true}
216-
options={metricTypes}
194+
options={METRIC_TYPES}
217195
value={metric}
218196
onChange={onMetricChange}
219197
/>
@@ -283,7 +261,7 @@ const Configuration = ({
283261
<EuiSelect
284262
id="timeUnit"
285263
required={isEnabled}
286-
options={timeUnits}
264+
options={TIME_UNITS}
287265
value={time}
288266
onChange={onTimeChange}
289267
/>
@@ -365,7 +343,7 @@ const Configuration = ({
365343
<EuiSelect
366344
id="groupBy"
367345
required={true}
368-
options={groupByOptions}
346+
options={GROUP_BY_OPTIONS}
369347
value={groupBy}
370348
onChange={onGroupByChange}
371349
/>

0 commit comments

Comments
 (0)