Skip to content

Commit 3769a3a

Browse files
committed
Misc fixes
Signed-off-by: Ashwin Pc <ashwinpc@amazon.com>
1 parent 3b6c3d3 commit 3769a3a

File tree

6 files changed

+88
-13
lines changed

6 files changed

+88
-13
lines changed

src/plugins/wizard/public/application/components/right_nav.tsx

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,24 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import React from 'react';
7-
import { EuiSuperSelect, EuiSuperSelectOption, EuiIcon, IconType } from '@elastic/eui';
6+
import React, { useState } from 'react';
7+
import {
8+
EuiSuperSelect,
9+
EuiSuperSelectOption,
10+
EuiIcon,
11+
IconType,
12+
EuiConfirmModal,
13+
} from '@elastic/eui';
14+
import { i18n } from '@osd/i18n';
15+
import { FormattedMessage } from '@osd/i18n/react';
816
import { useVisualizationType } from '../utils/use';
917
import './side_nav.scss';
1018
import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public';
1119
import { WizardServices } from '../../types';
1220
import { setActiveVisualization, useTypedDispatch } from '../utils/state_management';
1321

1422
export const RightNav = () => {
23+
const [newVisType, setNewVisType] = useState<string>();
1524
const {
1625
services: { types },
1726
} = useOpenSearchDashboards<WizardServices>();
@@ -32,19 +41,46 @@ export const RightNav = () => {
3241
options={options}
3342
valueOfSelected={activeVisName}
3443
onChange={(name) => {
35-
dispatch(
36-
setActiveVisualization({
37-
name,
38-
style: types.get(name)?.ui.containerConfig.style.defaults,
39-
})
40-
);
44+
setNewVisType(name);
4145
}}
4246
fullWidth
4347
/>
4448
</div>
4549
<div className="wizSidenav__style">
4650
<StyleSection />
4751
</div>
52+
{newVisType && (
53+
<EuiConfirmModal
54+
title={i18n.translate('wizard.rightNav.changeVisType.modalTitle', {
55+
defaultMessage: 'Change Visualization type',
56+
})}
57+
confirmButtonText={i18n.translate('wizard.rightNav.changeVisType.confirmText', {
58+
defaultMessage: 'Ok',
59+
})}
60+
cancelButtonText={i18n.translate('wizard.rightNav.changeVisType.cancelText', {
61+
defaultMessage: 'Cancel',
62+
})}
63+
onCancel={() => setNewVisType(undefined)}
64+
onConfirm={() => {
65+
dispatch(
66+
setActiveVisualization({
67+
name: newVisType,
68+
style: types.get(newVisType)?.ui.containerConfig.style.defaults,
69+
})
70+
);
71+
72+
setNewVisType(undefined);
73+
}}
74+
maxWidth="300px"
75+
>
76+
<p>
77+
<FormattedMessage
78+
id="wizard.rightNav.changeVisType.modalDescription"
79+
defaultMessage="Currently, changing the visualization type clears the existing selection of fields. Are you sure you want to change the visualization type?"
80+
/>
81+
</p>
82+
</EuiConfirmModal>
83+
)}
4884
</section>
4985
);
5086
};

src/plugins/wizard/public/visualizations/vislib/area/to_expression.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { buildExpression, buildExpressionFunction } from '../../../../../express
88
import { AreaOptionsDefaults } from './area_vis_type';
99
import { getAggExpressionFunctions } from '../../common/expression_helpers';
1010
import { VislibRootState } from '../common/types';
11+
import { getValueAxes } from '../common/get_value_axes';
1112

1213
export const toExpression = async ({
1314
style: styleState,
@@ -24,6 +25,7 @@ export const toExpression = async ({
2425
vis.data.aggs = aggConfigs;
2526

2627
const dimensions = await buildVislibDimensions(vis, pipelineConfigs as any);
28+
const valueAxes = getValueAxes(dimensions.y);
2729

2830
// TODO: what do we want to put in this "vis config"?
2931
const visConfig = {
@@ -32,6 +34,7 @@ export const toExpression = async ({
3234
addTimeMarker: false,
3335
addTooltip,
3436
dimensions,
37+
valueAxes,
3538
};
3639

3740
const vislib = buildExpressionFunction<any>('vislib', {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { SchemaConfig } from '../../../../../visualizations/public';
7+
import { ValueAxis } from '../../../../../vis_type_vislib/public';
8+
9+
interface ValueAxisConfig extends ValueAxis {
10+
style: any;
11+
}
12+
13+
export const getValueAxes = (yAxes: SchemaConfig[]): ValueAxisConfig[] =>
14+
yAxes.map((y, index) => ({
15+
id: `ValueAxis-${index + 1}`,
16+
labels: {
17+
show: true,
18+
},
19+
name: `ValueAxis-${index + 1}`,
20+
position: 'left',
21+
scale: {
22+
type: 'linear',
23+
mode: 'normal',
24+
},
25+
show: true,
26+
style: {},
27+
title: {
28+
text: y.label,
29+
},
30+
type: 'value',
31+
}));

src/plugins/wizard/public/visualizations/vislib/histogram/to_expression.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { buildExpression, buildExpressionFunction } from '../../../../../express
88
import { HistogramOptionsDefaults } from './histogram_vis_type';
99
import { getAggExpressionFunctions } from '../../common/expression_helpers';
1010
import { VislibRootState } from '../common/types';
11+
import { getValueAxes } from '../common/get_value_axes';
1112

1213
export const toExpression = async ({
1314
style: styleState,
@@ -24,6 +25,7 @@ export const toExpression = async ({
2425
vis.data.aggs = aggConfigs;
2526

2627
const dimensions = await buildVislibDimensions(vis, pipelineConfigs as any);
28+
const valueAxes = getValueAxes(dimensions.y);
2729

2830
// TODO: what do we want to put in this "vis config"?
2931
const visConfig = {
@@ -32,6 +34,7 @@ export const toExpression = async ({
3234
addTimeMarker: false,
3335
addTooltip,
3436
dimensions,
37+
valueAxes,
3538
};
3639

3740
const vislib = buildExpressionFunction<any>('vislib', {

src/plugins/wizard/public/visualizations/vislib/line/to_expression.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { buildExpression, buildExpressionFunction } from '../../../../../express
88
import { LineOptionsDefaults } from './line_vis_type';
99
import { getAggExpressionFunctions } from '../../common/expression_helpers';
1010
import { VislibRootState } from '../common/types';
11+
import { getValueAxes } from '../common/get_value_axes';
1112

1213
export const toExpression = async ({
1314
style: styleState,
@@ -24,6 +25,7 @@ export const toExpression = async ({
2425
vis.data.aggs = aggConfigs;
2526

2627
const dimensions = await buildVislibDimensions(vis, pipelineConfigs as any);
28+
const valueAxes = getValueAxes(dimensions.y);
2729

2830
// TODO: what do we want to put in this "vis config"?
2931
const visConfig = {
@@ -32,6 +34,7 @@ export const toExpression = async ({
3234
addTimeMarker: false,
3335
addTooltip,
3436
dimensions,
37+
valueAxes,
3538
};
3639

3740
const vislib = buildExpressionFunction<any>('vislib', {

test/functional/apps/wizard/_base.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import expect from '@osd/expect';
77
import { FtrProviderContext } from '../../ftr_provider_context';
88

99
export default function ({ getService, getPageObjects }: FtrProviderContext) {
10-
const PageObjects = getPageObjects(['visualize', 'wizard']);
10+
const PageObjects = getPageObjects(['visualize', 'wizard', 'visChart']);
1111
const log = getService('log');
1212
const retry = getService('retry');
1313

@@ -28,11 +28,10 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
2828

2929
it('should show visualization when a field is added', async () => {
3030
await PageObjects.wizard.addField('metric', 'Average', 'machine.ram');
31-
const avgMachineRam = ['13,104,036,080.615', 'Average machine.ram'];
3231

33-
await retry.try(async function tryingForTime() {
34-
const metricValue = await PageObjects.wizard.getMetric();
35-
expect(avgMachineRam).to.eql(metricValue);
32+
await retry.try(async () => {
33+
const data = await PageObjects.visChart.getBarChartData('Average machine.ram');
34+
expect(data).to.eql([13104038093]);
3635
});
3736
});
3837

0 commit comments

Comments
 (0)