Skip to content

Commit

Permalink
Fix errors in conditions for activating vizAugmenter (opensearch-pr…
Browse files Browse the repository at this point in the history
…oject#5213)

Signed-off-by: Miki <[email protected]>
  • Loading branch information
AMoo-Miki authored and SuZhou-Joe committed Oct 7, 2023
1 parent d771c26 commit 2d8453a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [Discover] Fix misc navigation issues ([#5168](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5168))
- [Discover] Fix mobile view ([#5168](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5168))
- Fix `visAugmenter` forming empty key-value pairs in its calls to the `SavedObject` API ([#5190](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5190))
- Fix errors in conditions for activating `vizAugmenter` ([#5213](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5213))
- [Data Explorer][Discover] Automatically load solo added default index pattern ([#5171](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5171))
- [Data Explorer][Discover] Allow data grid to auto adjust size based on fetched data count ([#5191](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5191))
- [BUG][Data Explorer][Discover] Allow filter and query persist when refresh page or paste url to a new tab ([#5206](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5206))
Expand Down
52 changes: 29 additions & 23 deletions src/plugins/vis_augmenter/public/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,38 @@ import { getUISettings } from '../services';
import { IUiSettingsClient } from '../../../../core/public';

export const isEligibleForVisLayers = (vis: Vis, uiSettingsClient?: IUiSettingsClient): boolean => {
// Only support date histogram and ensure there is only 1 x-axis and it has to be on the bottom.
// Additionally to have a valid x-axis, there needs to be a segment aggregation
const hasValidXaxis =
vis.data?.aggs !== undefined &&
vis.data.aggs?.byTypeName('date_histogram').length === 1 &&
vis.params.categoryAxes.length === 1 &&
vis.params.categoryAxes[0].position === 'bottom' &&
vis.data.aggs?.bySchemaName('segment').length > 0;
// Support 1 segment for x axis bucket (that is date_histogram) and support metrics for
// multiple supported yaxis only. If there are other aggregation types, this is not
// valid for augmentation
const hasCorrectAggregationCount =
vis.data?.aggs !== undefined &&
vis.data.aggs?.bySchemaName('metric').length > 0 &&
vis.data.aggs?.bySchemaName('metric').length === vis.data.aggs?.aggs.length - 1;
const hasOnlyLineSeries =
vis.params?.seriesParams !== undefined &&
vis.params?.seriesParams?.every(
(seriesParam: { type: string }) => seriesParam.type === 'line'
) &&
vis.params?.type === 'line';
// Only support a date histogram
const dateHistograms = vis.data?.aggs?.byTypeName?.('date_histogram');
if (!Array.isArray(dateHistograms) || dateHistograms.length !== 1) return false;

// Ensure there is only 1 x-axis and it has to be on the bottom
const xAxis = vis.params?.categoryAxes;
if (!Array.isArray(xAxis) || xAxis.length !== 1 || xAxis[0]?.position !== 'bottom') return false;

// Additionally, to have a valid x-axis, there needs to be a segment aggregation
const segmentAggs = vis.data.aggs!.bySchemaName('segment');
if (!Array.isArray(segmentAggs) || segmentAggs.length === 0) return false;

// Require metrics for multiple supported y-axis only and no other aggregation types
const metricAggs = vis.data.aggs!.bySchemaName('metric');
if (
!Array.isArray(metricAggs) ||
metricAggs.length === 0 ||
metricAggs.length !== vis.data.aggs!.aggs?.length - 1
)
return false;

// Must have only line series
if (
!Array.isArray(vis.params.seriesParams) ||
vis.params.type !== 'line' ||
vis.params.seriesParams.some((seriesParam: { type: string }) => seriesParam.type !== 'line')
)
return false;

// Checks if the augmentation setting is enabled
const config = uiSettingsClient ?? getUISettings();
const isAugmentationEnabled = config.get(PLUGIN_AUGMENTATION_ENABLE_SETTING);
return isAugmentationEnabled && hasValidXaxis && hasCorrectAggregationCount && hasOnlyLineSeries;
return config.get(PLUGIN_AUGMENTATION_ENABLE_SETTING);
};

/**
Expand Down

0 comments on commit 2d8453a

Please sign in to comment.