Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors in conditions for activating vizAugmenter #5213

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [Discover] Fix misc navigation issues ([#5168](https:/opensearch-project/OpenSearch-Dashboards/pull/5168))
- [Discover] Fix mobile view ([#5168](https:/opensearch-project/OpenSearch-Dashboards/pull/5168))
- Fix `visAugmenter` forming empty key-value pairs in its calls to the `SavedObject` API ([#5190](https:/opensearch-project/OpenSearch-Dashboards/pull/5190))
- Fix errors in conditions for activating `vizAugmenter` ([#5213](https:/opensearch-project/OpenSearch-Dashboards/pull/5213))
- [Data Explorer][Discover] Automatically load solo added default index pattern ([#5171](https:/opensearch-project/OpenSearch-Dashboards/pull/5171))
- [Data Explorer][Discover] Allow data grid to auto adjust size based on fetched data count ([#5191](https:/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:/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 { 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;

Check warning on line 46 in src/plugins/vis_augmenter/public/utils/utils.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/vis_augmenter/public/utils/utils.ts#L46

Added line #L46 was not covered by tests

// 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
Loading