Skip to content

Commit

Permalink
fix UI issue
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwizp committed Mar 25, 2021
1 parent d600f39 commit 9715acc
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ export async function fetchFields(
{}
);

if (defaultIndexPattern?.title && patterns.includes(defaultIndexPattern.title)) {
fields[''] = fields[defaultIndexPattern.title];
if (defaultIndexPattern) {
fields[''] = toSanitizedFieldType(await defaultIndexPattern.getNonScriptedFields());
}

return fields;
} catch (error) {
if (error.name !== 'AbortError') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
*/

import { SavedObjectReference } from '../../../../../core/types';
import { VisParams } from '../../../common';

export const extractControlsReferences = (
visState: Record<string, any>,
visParams: VisParams,
references: SavedObjectReference[] = []
) => {
const controls = visState.params?.controls ?? [];
const controls = visParams?.controls ?? [];

controls.forEach((control: Record<string, string>, i: number) => {
if (!control.indexPattern) {
Expand All @@ -29,10 +30,10 @@ export const extractControlsReferences = (
};

export const injectControlsReferences = (
visState: Record<string, any>,
visParams: VisParams,
references: SavedObjectReference[]
) => {
const controls = visState.params?.controls ?? [];
const controls = visParams.controls ?? [];

controls.forEach((control: Record<string, string>) => {
if (!control.indexPatternRefName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
* Side Public License, v 1.
*/

export { extractControlsReferences, injectControlsReferences } from './controls_references';
export { extractTimeSeriesReferences, injectTimeSeriesReferences } from './timeseries_references';

export { extractReferences, injectReferences } from './saved_visualization_references';
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
SavedObjectAttributes,
SavedObjectReference,
} from '../../../../../core/public';
import { VisSavedObject } from '../../types';
import { SavedVisState, VisSavedObject } from '../../types';
import {
extractSearchSourceReferences,
injectSearchSourceReferences,
Expand Down Expand Up @@ -52,10 +52,13 @@ export function extractReferences({

// Extract index patterns from controls
if (updatedAttributes.visState) {
const visState = JSON.parse(String(updatedAttributes.visState));
const visState = JSON.parse(String(updatedAttributes.visState)) as SavedVisState;

extractControlsReferences(visState, updatedReferences);
extractTimeSeriesReferences(visState, updatedReferences);
extractControlsReferences(visState.params, updatedReferences);

if (visState.type === 'metrics') {
extractTimeSeriesReferences(visState.params, updatedReferences);
}

updatedAttributes.visState = JSON.stringify(visState);
}
Expand Down Expand Up @@ -85,7 +88,10 @@ export function injectReferences(savedObject: VisSavedObject, references: SavedO
}

if (savedObject.visState?.params) {
injectControlsReferences(savedObject.visState, references);
injectTimeSeriesReferences(savedObject.visState, references);
injectControlsReferences(savedObject.visState.params, references);

if (savedObject.visState.type === 'metrics') {
injectTimeSeriesReferences(savedObject.visState.params, references);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { SavedObjectReference } from '../../../../../core/types';
import { VisParams } from '../../../common';

/** @internal **/
const REF_NAME_POSTFIX = '_ref_name';
Expand All @@ -17,28 +18,24 @@ const INDEX_PATTERN_REF_TYPE = 'index_pattern';
/** @internal **/
type Action = (object: Record<string, any>, key: string) => void;

const doForExtractedIndices = (action: Action, visState: Record<string, any>) => {
if (visState.type !== 'metrics') {
return;
}

action(visState.params, 'index_pattern');
const doForExtractedIndices = (action: Action, visParams: VisParams) => {
action(visParams, 'index_pattern');

visState.params.series.forEach((series: any) => {
visParams.series.forEach((series: any) => {
if (series.override_index_pattern) {
action(series, 'series_index_pattern');
}
});

if (visState.params.annotations) {
visState.params.annotations.forEach((annotation: any) => {
if (visParams.annotations) {
visParams.annotations.forEach((annotation: any) => {
action(annotation, 'index_pattern');
});
}
};

export const extractTimeSeriesReferences = (
visState: Record<string, any>,
visParams: VisParams,
references: SavedObjectReference[] = []
) => {
let i = 0;
Expand All @@ -55,11 +52,11 @@ export const extractTimeSeriesReferences = (
});
delete object[key];
}
}, visState);
}, visParams);
};

export const injectTimeSeriesReferences = (
visState: Record<string, any>,
visParams: VisParams,
references: SavedObjectReference[]
) => {
doForExtractedIndices((object, key) => {
Expand All @@ -74,5 +71,5 @@ export const injectTimeSeriesReferences = (

delete object[refKey];
}
}, visState);
}, visParams);
};

0 comments on commit 9715acc

Please sign in to comment.