Skip to content

Commit

Permalink
chore(NA): update visualizations and visualize to lodash4
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic committed Jun 24, 2020
1 parent 09b8b69 commit 92ec97e
Show file tree
Hide file tree
Showing 18 changed files with 61 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { get } from 'lodash';
import { get } from 'lodash4';
import React from 'react';
import { PersistedState } from '../../../../plugins/visualizations/public';
import { memoizeLast } from '../legacy/memoize';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import _, { get } from 'lodash';
import _, { get } from 'lodash4';
import { Subscription } from 'rxjs';
import * as Rx from 'rxjs';
import { VISUALIZE_EMBEDDABLE_TYPE } from './constants';
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/visualizations/public/expressions/vis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/

import { EventEmitter } from 'events';
import _ from 'lodash';
import _ from 'lodash4';
import { VisParams, PersistedState } from '../../../../plugins/visualizations/public';

import { getTypes } from '../services';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { get } from 'lodash';
import { get } from 'lodash4';
import { i18n } from '@kbn/i18n';
import { VisResponseValue, PersistedState } from '../../../../plugins/visualizations/public';
import { ExpressionFunctionDefinition, Render } from '../../../../plugins/expressions/public';
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/visualizations/public/legacy/build_pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { get } from 'lodash';
import { get } from 'lodash4';
import moment from 'moment';
import { SerializedFieldFormat } from '../../../../plugins/expressions/public';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import _ from 'lodash';
import _ from 'lodash4';

/**
* Will figure out if an heatmap state was saved before the auto coloring
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import _ from 'lodash';
import _ from 'lodash4';
import { updateOldState } from './vis_update_state';

// eslint-disable-next-line camelcase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,17 @@

import { EventEmitter } from 'events';

import { isPlainObject, cloneDeep, get, set, isEqual, isString, merge } from 'lodash';
import toPath from 'lodash/internal/toPath';
import {
isPlainObject,
cloneDeep,
get,
set,
isEqual,
isString,
merge,
mergeWith,
toPath,
} from 'lodash4';

function prepSetParams(key: PersistedStateKey, value: any, path: PersistedStatePath) {
// key must be the value, set the entire state using it
Expand Down Expand Up @@ -150,7 +159,7 @@ export class PersistedState extends EventEmitter {
while (partialPath.length > 0) {
const lastKey = partialPath.splice(partialPath.length - 1, 1)[0];
const statePath = [...this._path, partialPath];
const stateVal = statePath.length > 0 ? get(stateTree, statePath) : stateTree;
const stateVal = statePath.length > 0 ? get(stateTree, statePath as string[]) : stateTree;

// if stateVal isn't an object, do nothing
if (!isPlainObject(stateVal)) return;
Expand Down Expand Up @@ -240,7 +249,7 @@ export class PersistedState extends EventEmitter {
// If `mergeMethod` is provided it is invoked to produce the merged values of the
// destination and source properties.
// If `mergeMethod` returns `undefined` the default merging method is used
this._mergedState = merge(targetObj, sourceObj, mergeMethod);
this._mergedState = mergeWith(targetObj, sourceObj, mergeMethod);

// sanity check; verify that there are actually changes
if (isEqual(this._mergedState, this._defaultState)) this._changedState = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import _ from 'lodash';
import _ from 'lodash4';
import { SavedObjectAttributes, SavedObjectsClientContract } from '../../../../core/public';
import { SavedObjectLoader } from '../../../../plugins/saved_objects/public';
import { VisTypeAlias } from '../vis_types';
Expand Down Expand Up @@ -49,7 +49,7 @@ export async function findListItems({
}, acc);
}, {} as { [visType: string]: VisualizationsAppExtension });
const searchOption = (field: string, ...defaults: string[]) =>
_(extensions).pluck(field).concat(defaults).compact().flatten().uniq().value() as string[];
_(extensions).map(field).concat(defaults).compact().flatten().uniq().value() as string[];
const searchOptions = {
type: searchOption('docTypes', 'visualization'),
searchFields: searchOption('searchFields', 'title^3', 'description'),
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/visualizations/public/vis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* Not to be confused with vislib/vis.js.
*/

import { isFunction, defaults, cloneDeep } from 'lodash';
import { isFunction, defaults, cloneDeep } from 'lodash4';
import { Assign } from '@kbn/utility-types';
import { PersistedState } from './persisted_state';
import { getTypes, getAggs, getSearch, getSavedSearchLoader } from './services';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import _ from 'lodash';
import _ from 'lodash4';
import { VisualizationControllerConstructor } from '../types';

export interface BaseVisTypeOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { cloneDeep } from 'lodash';
import { cloneDeep } from 'lodash4';
import { ReactVisType } from './react_vis_type';

describe('React Vis Type', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { sortByOrder } from 'lodash';
import { orderBy } from 'lodash4';
import React, { ChangeEvent } from 'react';

import {
Expand Down Expand Up @@ -201,7 +201,7 @@ class TypeSelection extends React.Component<TypeSelectionProps, TypeSelectionSta
});
}

return sortByOrder(entries, ['highlighted', 'promotion', 'title'], ['desc', 'asc', 'asc']);
return orderBy(entries, ['highlighted', 'promotion', 'title'], ['desc', 'asc', 'asc']);
}

private renderVisType = (visType: VisTypeListEntry | VisTypeAliasListEntry) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { SavedObjectMigrationFn } from 'kibana/server';
import { cloneDeep, get, omit, has, flow } from 'lodash';
import { cloneDeep, get, omit, has, flow } from 'lodash4';
import { DEFAULT_QUERY_LANGUAGE } from '../../../data/common';

const migrateIndexPattern: SavedObjectMigrationFn<any, any> = (doc) => {
Expand Down Expand Up @@ -65,7 +65,7 @@ const migrateIndexPattern: SavedObjectMigrationFn<any, any> = (doc) => {

// [TSVB] Migrate percentile-rank aggregation (value -> values)
const migratePercentileRankAggregation: SavedObjectMigrationFn<any, any> = (doc) => {
const visStateJSON = get<string>(doc, 'attributes.visState');
const visStateJSON = get(doc, 'attributes.visState');
let visState;

if (visStateJSON) {
Expand Down Expand Up @@ -101,7 +101,7 @@ const migratePercentileRankAggregation: SavedObjectMigrationFn<any, any> = (doc)

// [TSVB] Remove stale opperator key
const migrateOperatorKeyTypo: SavedObjectMigrationFn<any, any> = (doc) => {
const visStateJSON = get<string>(doc, 'attributes.visState');
const visStateJSON = get(doc, 'attributes.visState');
let visState;

if (visStateJSON) {
Expand Down Expand Up @@ -137,7 +137,7 @@ const migrateOperatorKeyTypo: SavedObjectMigrationFn<any, any> = (doc) => {
* @see https://github.com/elastic/kibana/pull/58462/files#diff-ae69fe15b20a5099d038e9bbe2ed3849
**/
const migrateSplitByChartRow: SavedObjectMigrationFn<any, any> = (doc) => {
const visStateJSON = get<string>(doc, 'attributes.visState');
const visStateJSON = get(doc, 'attributes.visState');
let visState: any;

if (visStateJSON) {
Expand Down Expand Up @@ -177,7 +177,7 @@ const migrateSplitByChartRow: SavedObjectMigrationFn<any, any> = (doc) => {

// Migrate date histogram aggregation (remove customInterval)
const migrateDateHistogramAggregation: SavedObjectMigrationFn<any, any> = (doc) => {
const visStateJSON = get<string>(doc, 'attributes.visState');
const visStateJSON = get(doc, 'attributes.visState');
let visState;

if (visStateJSON) {
Expand Down Expand Up @@ -219,7 +219,7 @@ const migrateDateHistogramAggregation: SavedObjectMigrationFn<any, any> = (doc)
};

const removeDateHistogramTimeZones: SavedObjectMigrationFn<any, any> = (doc) => {
const visStateJSON = get<string>(doc, 'attributes.visState');
const visStateJSON = get(doc, 'attributes.visState');
if (visStateJSON) {
let visState;
try {
Expand Down Expand Up @@ -251,7 +251,7 @@ const removeDateHistogramTimeZones: SavedObjectMigrationFn<any, any> = (doc) =>
// migrate gauge verticalSplit to alignment
// https://github.com/elastic/kibana/issues/34636
const migrateGaugeVerticalSplitToAlignment: SavedObjectMigrationFn<any, any> = (doc, logger) => {
const visStateJSON = get<string>(doc, 'attributes.visState');
const visStateJSON = get(doc, 'attributes.visState');

if (visStateJSON) {
try {
Expand Down Expand Up @@ -289,7 +289,7 @@ const transformFilterStringToQueryObject: SavedObjectMigrationFn<any, any> = (do
// Migrate filters
// If any filters exist and they are a string, we assume it to be lucene and transform the filter into an object accordingly
const newDoc = cloneDeep(doc);
const visStateJSON = get<string>(doc, 'attributes.visState');
const visStateJSON = get(doc, 'attributes.visState');
if (visStateJSON) {
let visState;
try {
Expand All @@ -298,7 +298,7 @@ const transformFilterStringToQueryObject: SavedObjectMigrationFn<any, any> = (do
// let it go, the data is invalid and we'll leave it as is
}
if (visState) {
const visType = get<string>(visState, 'params.type');
const visType = get(visState, 'params.type');
const tsvbTypes = ['metric', 'markdown', 'top_n', 'gauge', 'table', 'timeseries'];
if (tsvbTypes.indexOf(visType) === -1) {
// skip
Expand Down Expand Up @@ -373,7 +373,7 @@ const transformSplitFiltersStringToQueryObject: SavedObjectMigrationFn<any, any>
// Migrate split_filters in TSVB objects that weren't migrated in 7.3
// If any filters exist and they are a string, we assume them to be lucene syntax and transform the filter into an object accordingly
const newDoc = cloneDeep(doc);
const visStateJSON = get<string>(doc, 'attributes.visState');
const visStateJSON = get(doc, 'attributes.visState');
if (visStateJSON) {
let visState;
try {
Expand All @@ -382,7 +382,7 @@ const transformSplitFiltersStringToQueryObject: SavedObjectMigrationFn<any, any>
// let it go, the data is invalid and we'll leave it as is
}
if (visState) {
const visType = get<string>(visState, 'params.type');
const visType = get(visState, 'params.type');
const tsvbTypes = ['metric', 'markdown', 'top_n', 'gauge', 'table', 'timeseries'];
if (tsvbTypes.indexOf(visType) === -1) {
// skip
Expand Down Expand Up @@ -415,7 +415,7 @@ const transformSplitFiltersStringToQueryObject: SavedObjectMigrationFn<any, any>
};

const migrateFiltersAggQuery: SavedObjectMigrationFn<any, any> = (doc) => {
const visStateJSON = get<string>(doc, 'attributes.visState');
const visStateJSON = get(doc, 'attributes.visState');

if (visStateJSON) {
try {
Expand Down Expand Up @@ -447,7 +447,7 @@ const migrateFiltersAggQuery: SavedObjectMigrationFn<any, any> = (doc) => {
};

const replaceMovAvgToMovFn: SavedObjectMigrationFn<any, any> = (doc, logger) => {
const visStateJSON = get<string>(doc, 'attributes.visState');
const visStateJSON = get(doc, 'attributes.visState');
let visState;

if (visStateJSON) {
Expand Down Expand Up @@ -495,7 +495,7 @@ const replaceMovAvgToMovFn: SavedObjectMigrationFn<any, any> = (doc, logger) =>
};

const migrateFiltersAggQueryStringQueries: SavedObjectMigrationFn<any, any> = (doc, logger) => {
const visStateJSON = get<string>(doc, 'attributes.visState');
const visStateJSON = get(doc, 'attributes.visState');

if (visStateJSON) {
try {
Expand Down Expand Up @@ -533,7 +533,7 @@ const addDocReferences: SavedObjectMigrationFn<any, any> = (doc) => ({
});

const migrateSavedSearch: SavedObjectMigrationFn<any, any> = (doc) => {
const savedSearchId = get<string>(doc, 'attributes.savedSearchId');
const savedSearchId = get(doc, 'attributes.savedSearchId');

if (savedSearchId && doc.references) {
doc.references.push({
Expand All @@ -550,7 +550,7 @@ const migrateSavedSearch: SavedObjectMigrationFn<any, any> = (doc) => {
};

const migrateControls: SavedObjectMigrationFn<any, any> = (doc) => {
const visStateJSON = get<string>(doc, 'attributes.visState');
const visStateJSON = get(doc, 'attributes.visState');

if (visStateJSON) {
let visState;
Expand Down Expand Up @@ -617,7 +617,7 @@ const migrateTableSplits: SavedObjectMigrationFn<any, any> = (doc) => {
};

const migrateMatchAllQuery: SavedObjectMigrationFn<any, any> = (doc) => {
const searchSourceJSON = get<string>(doc, 'attributes.kibanaSavedObjectMeta.searchSourceJSON');
const searchSourceJSON = get(doc, 'attributes.kibanaSavedObjectMeta.searchSourceJSON');

if (searchSourceJSON) {
let searchSource: any;
Expand Down Expand Up @@ -651,7 +651,7 @@ const migrateMatchAllQuery: SavedObjectMigrationFn<any, any> = (doc) => {

// [TSVB] Default color palette is changing, keep the default for older viz
const migrateTsvbDefaultColorPalettes: SavedObjectMigrationFn<any, any> = (doc) => {
const visStateJSON = get<string>(doc, 'attributes.visState');
const visStateJSON = get(doc, 'attributes.visState');
let visState;

if (visStateJSON) {
Expand Down Expand Up @@ -693,30 +693,24 @@ export const visualizationSavedObjectTypeMigrations = {
* in that version. So we apply this twice, once with 6.7.2 and once with 7.0.1 while the backport to 6.7
* only contained the 6.7.2 migration and not the 7.0.1 migration.
*/
'6.7.2': flow<SavedObjectMigrationFn<any, any>>(
migrateMatchAllQuery,
removeDateHistogramTimeZones
),
'7.0.0': flow<SavedObjectMigrationFn<any, any>>(
'6.7.2': flow(migrateMatchAllQuery, removeDateHistogramTimeZones),
'7.0.0': flow(
addDocReferences,
migrateIndexPattern,
migrateSavedSearch,
migrateControls,
migrateTableSplits
),
'7.0.1': flow<SavedObjectMigrationFn<any, any>>(removeDateHistogramTimeZones),
'7.2.0': flow<SavedObjectMigrationFn<any, any>>(
migratePercentileRankAggregation,
migrateDateHistogramAggregation
),
'7.3.0': flow<SavedObjectMigrationFn<any, any>>(
'7.0.1': flow(removeDateHistogramTimeZones),
'7.2.0': flow(migratePercentileRankAggregation, migrateDateHistogramAggregation),
'7.3.0': flow(
migrateGaugeVerticalSplitToAlignment,
transformFilterStringToQueryObject,
migrateFiltersAggQuery,
replaceMovAvgToMovFn
),
'7.3.1': flow<SavedObjectMigrationFn<any, any>>(migrateFiltersAggQueryStringQueries),
'7.4.2': flow<SavedObjectMigrationFn<any, any>>(transformSplitFiltersStringToQueryObject),
'7.7.0': flow<SavedObjectMigrationFn<any, any>>(migrateOperatorKeyTypo, migrateSplitByChartRow),
'7.8.0': flow<SavedObjectMigrationFn<any, any>>(migrateTsvbDefaultColorPalettes),
'7.3.1': flow(migrateFiltersAggQueryStringQueries),
'7.4.2': flow(transformSplitFiltersStringToQueryObject),
'7.7.0': flow(migrateOperatorKeyTypo, migrateSplitByChartRow),
'7.8.0': flow(migrateTsvbDefaultColorPalettes),
};
2 changes: 1 addition & 1 deletion src/plugins/visualize/public/application/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import angular from 'angular';
import _ from 'lodash';
import _ from 'lodash4';
import { Subscription } from 'rxjs';
import { map } from 'rxjs/operators';
import { i18n } from '@kbn/i18n';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { get, omit } from 'lodash';
import { get, omit } from 'lodash4';
import { VisualizeAppState } from '../../types';

/**
Expand All @@ -36,7 +36,7 @@ export function migrateAppState(appState: VisualizeAppState) {
return appState;
}

const visAggs: any = get<VisualizeAppState>(appState, 'vis.aggs');
const visAggs: any = get(appState, 'vis.aggs');

if (visAggs) {
let splitCount = 0;
Expand Down
Loading

0 comments on commit 92ec97e

Please sign in to comment.