From cc000f51738f998a71581593e28083529074cc79 Mon Sep 17 00:00:00 2001 From: Ashwin Pc Date: Fri, 9 Sep 2022 16:15:24 +0000 Subject: [PATCH 1/2] fixes time series for new chart types Signed-off-by: Ashwin Pc --- .../visualizations/vislib/area/to_expression.ts | 10 +++------- .../vislib/common/get_pipeline_params.ts | 15 +++++++++++++++ .../public/visualizations/vislib/common/index.ts | 9 +++++++++ .../vislib/histogram/to_expression.ts | 10 +++------- .../visualizations/vislib/line/to_expression.ts | 10 +++------- 5 files changed, 33 insertions(+), 21 deletions(-) create mode 100644 src/plugins/wizard/public/visualizations/vislib/common/get_pipeline_params.ts create mode 100644 src/plugins/wizard/public/visualizations/vislib/common/index.ts diff --git a/src/plugins/wizard/public/visualizations/vislib/area/to_expression.ts b/src/plugins/wizard/public/visualizations/vislib/area/to_expression.ts index 012c6589f57b..9d40d64c1cfc 100644 --- a/src/plugins/wizard/public/visualizations/vislib/area/to_expression.ts +++ b/src/plugins/wizard/public/visualizations/vislib/area/to_expression.ts @@ -7,8 +7,7 @@ import { Vis, buildVislibDimensions } from '../../../../../visualizations/public import { buildExpression, buildExpressionFunction } from '../../../../../expressions/public'; import { AreaOptionsDefaults } from './area_vis_type'; import { getAggExpressionFunctions } from '../../common/expression_helpers'; -import { VislibRootState } from '../common/types'; -import { getValueAxes } from '../common/get_value_axes'; +import { VislibRootState, getValueAxes, getPipelineParams } from '../common'; export const toExpression = async ({ style: styleState, @@ -16,15 +15,12 @@ export const toExpression = async ({ }: VislibRootState) => { const { aggConfigs, expressionFns } = await getAggExpressionFunctions(visualization); const { addLegend, addTooltip, legendPosition, type } = styleState; - const pipelineConfigs = { - // todo: this will blow up for time x dimensions - timefilter: null, // todo: get the time filter from elsewhere - }; + const params = getPipelineParams(); const vis = new Vis(type); vis.data.aggs = aggConfigs; - const dimensions = await buildVislibDimensions(vis, pipelineConfigs as any); + const dimensions = await buildVislibDimensions(vis, params); const valueAxes = getValueAxes(dimensions.y); // TODO: what do we want to put in this "vis config"? diff --git a/src/plugins/wizard/public/visualizations/vislib/common/get_pipeline_params.ts b/src/plugins/wizard/public/visualizations/vislib/common/get_pipeline_params.ts new file mode 100644 index 000000000000..12288c138b2e --- /dev/null +++ b/src/plugins/wizard/public/visualizations/vislib/common/get_pipeline_params.ts @@ -0,0 +1,15 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { BuildPipelineParams } from '../../../../../visualizations/public'; +import { getTimeFilter } from '../../../plugin_services'; + +export const getPipelineParams = (): BuildPipelineParams => { + const timeFilter = getTimeFilter(); + return { + timefilter: timeFilter, + timeRange: timeFilter.getTime(), + }; +}; diff --git a/src/plugins/wizard/public/visualizations/vislib/common/index.ts b/src/plugins/wizard/public/visualizations/vislib/common/index.ts new file mode 100644 index 000000000000..70614ce555eb --- /dev/null +++ b/src/plugins/wizard/public/visualizations/vislib/common/index.ts @@ -0,0 +1,9 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +export * from './basic_vis_options'; +export * from './get_pipeline_params'; +export * from './get_value_axes'; +export * from './types'; diff --git a/src/plugins/wizard/public/visualizations/vislib/histogram/to_expression.ts b/src/plugins/wizard/public/visualizations/vislib/histogram/to_expression.ts index 6b6f0fe30baf..6357b6acee22 100644 --- a/src/plugins/wizard/public/visualizations/vislib/histogram/to_expression.ts +++ b/src/plugins/wizard/public/visualizations/vislib/histogram/to_expression.ts @@ -7,8 +7,7 @@ import { Vis, buildVislibDimensions } from '../../../../../visualizations/public import { buildExpression, buildExpressionFunction } from '../../../../../expressions/public'; import { HistogramOptionsDefaults } from './histogram_vis_type'; import { getAggExpressionFunctions } from '../../common/expression_helpers'; -import { VislibRootState } from '../common/types'; -import { getValueAxes } from '../common/get_value_axes'; +import { VislibRootState, getValueAxes, getPipelineParams } from '../common'; export const toExpression = async ({ style: styleState, @@ -16,15 +15,12 @@ export const toExpression = async ({ }: VislibRootState) => { const { aggConfigs, expressionFns } = await getAggExpressionFunctions(visualization); const { addLegend, addTooltip, legendPosition, type } = styleState; - const pipelineConfigs = { - // todo: this will blow up for time x dimensions - timefilter: null, // todo: get the time filter from elsewhere - }; + const params = getPipelineParams(); const vis = new Vis(type); vis.data.aggs = aggConfigs; - const dimensions = await buildVislibDimensions(vis, pipelineConfigs as any); + const dimensions = await buildVislibDimensions(vis, params); const valueAxes = getValueAxes(dimensions.y); // TODO: what do we want to put in this "vis config"? diff --git a/src/plugins/wizard/public/visualizations/vislib/line/to_expression.ts b/src/plugins/wizard/public/visualizations/vislib/line/to_expression.ts index d7c7a13d2be7..32d40726bedf 100644 --- a/src/plugins/wizard/public/visualizations/vislib/line/to_expression.ts +++ b/src/plugins/wizard/public/visualizations/vislib/line/to_expression.ts @@ -7,8 +7,7 @@ import { Vis, buildVislibDimensions } from '../../../../../visualizations/public import { buildExpression, buildExpressionFunction } from '../../../../../expressions/public'; import { LineOptionsDefaults } from './line_vis_type'; import { getAggExpressionFunctions } from '../../common/expression_helpers'; -import { VislibRootState } from '../common/types'; -import { getValueAxes } from '../common/get_value_axes'; +import { VislibRootState, getValueAxes, getPipelineParams } from '../common'; export const toExpression = async ({ style: styleState, @@ -16,15 +15,12 @@ export const toExpression = async ({ }: VislibRootState) => { const { aggConfigs, expressionFns } = await getAggExpressionFunctions(visualization); const { addLegend, addTooltip, legendPosition, type } = styleState; - const pipelineConfigs = { - // todo: this will blow up for time x dimensions - timefilter: null, // todo: get the time filter from elsewhere - }; + const params = getPipelineParams(); const vis = new Vis(type); vis.data.aggs = aggConfigs; - const dimensions = await buildVislibDimensions(vis, pipelineConfigs as any); + const dimensions = await buildVislibDimensions(vis, params); const valueAxes = getValueAxes(dimensions.y); // TODO: what do we want to put in this "vis config"? From aa946df853ecf486aef4c9d7bf3bbcdece18e1e9 Mon Sep 17 00:00:00 2001 From: Ashwin Pc Date: Fri, 9 Sep 2022 17:31:54 +0000 Subject: [PATCH 2/2] moves translate to source string Signed-off-by: Ashwin Pc --- .../application/utils/get_top_nav_config.tsx | 8 +------- .../public/application/utils/use/use_can_save.ts | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/plugins/wizard/public/application/utils/get_top_nav_config.tsx b/src/plugins/wizard/public/application/utils/get_top_nav_config.tsx index 8d83807c058f..75ebd87fbd7c 100644 --- a/src/plugins/wizard/public/application/utils/get_top_nav_config.tsx +++ b/src/plugins/wizard/public/application/utils/get_top_nav_config.tsx @@ -80,13 +80,7 @@ export const getTopNavConfig = ( }), testId: 'wizardSaveButton', disableButton: !!saveDisabledReason, - tooltip() { - if (saveDisabledReason) { - return i18n.translate('wizard.topNavMenu.saveVisualizationDisabledButtonTooltip', { - defaultMessage: saveDisabledReason, - }); - } - }, + tooltip: saveDisabledReason, run: (_anchorElement) => { const onSave = async ({ newTitle, diff --git a/src/plugins/wizard/public/application/utils/use/use_can_save.ts b/src/plugins/wizard/public/application/utils/use/use_can_save.ts index 6cb19018a7bd..adfb15c03e48 100644 --- a/src/plugins/wizard/public/application/utils/use/use_can_save.ts +++ b/src/plugins/wizard/public/application/utils/use/use_can_save.ts @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { i18n } from '@osd/i18n'; import { useTypedSelector } from '../state_management'; export const useCanSave = () => { @@ -20,12 +21,20 @@ export const useCanSave = () => { // TODO: Need to finalize the error messages const getErrorMsg = (isEmpty, hasNoChange, hasDraftAgg) => { + const i18nTranslate = (key: string, defaultMessage: string) => + i18n.translate(`wizard.saveVisualizationTooltip.${key}`, { + defaultMessage, + }); + if (isEmpty) { - return 'The canvas is empty. Add some aggregations before saving.'; + return i18nTranslate('empty', 'The canvas is empty. Add some aggregations before saving.'); } else if (hasNoChange) { - return 'Add some changes before saving.'; + return i18nTranslate('noChange', 'Add some changes before saving.'); } else if (hasDraftAgg) { - return 'Has unapplied aggregations changes, update them before saving.'; + return i18nTranslate( + 'hasDraftAgg', + 'Has unapplied aggregations changes, update them before saving.' + ); } else { return undefined; }