Skip to content

Commit

Permalink
Remove src/plugins/vis_default_editor -> src/plugins/visualizations c…
Browse files Browse the repository at this point in the history
…yclic dependencies

Part of elastic#86758
  • Loading branch information
alexwizp committed Dec 29, 2020
1 parent d843450 commit e001422
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 59 deletions.
1 change: 0 additions & 1 deletion src/dev/run_find_plugins_with_circular_deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ interface Options {
type CircularDepList = Set<string>;

const allowedList: CircularDepList = new Set([
'src/plugins/vis_default_editor -> src/plugins/visualizations',
'src/plugins/visualizations -> src/plugins/visualize',
'x-pack/plugins/actions -> x-pack/plugins/case',
'x-pack/plugins/case -> x-pack/plugins/security_solution',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import { mount, shallow } from 'enzyme';
import { act } from 'react-dom/test-utils';

import { IndexPattern, IAggType, AggGroupNames } from 'src/plugins/data/public';
import type { Schema } from 'src/plugins/visualizations/public';

import { DefaultEditorAgg, DefaultEditorAggProps } from './agg';
import { DefaultEditorAggParams } from './agg_params';
import { AGGS_ACTION_KEYS } from './agg_group_state';
import { Schema } from '../schemas';
import { EditorVisState } from './sidebar/state/reducers';

jest.mock('./agg_params', () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { IAggConfig, AggGroupNames } from '../../../data/public';
import { Schema } from '../schemas';
import type { Schema } from '../../../visualizations/public';

interface DefaultEditorAggAddProps {
group?: IAggConfig[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
* under the License.
*/

import { VisParams } from 'src/plugins/visualizations/public';
import { IAggType, IAggConfig, AggGroupName } from 'src/plugins/data/public';
import { Schema } from '../schemas';
import { EditorVisState } from './sidebar/state/reducers';
import type { VisParams } from 'src/plugins/visualizations/public';
import type { IAggType, IAggConfig, AggGroupName } from 'src/plugins/data/public';
import type { Schema } from 'src/plugins/visualizations/public';

import type { EditorVisState } from './sidebar/state/reducers';

type AggId = IAggConfig['id'];
type AggParams = IAggConfig['params'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import React from 'react';
import { mount, shallow } from 'enzyme';
import { act } from 'react-dom/test-utils';
import { IAggConfigs, IAggConfig } from 'src/plugins/data/public';
import type { IAggConfigs, IAggConfig } from 'src/plugins/data/public';
import type { ISchemas } from 'src/plugins/visualizations/public';

import { DefaultEditorAggGroup, DefaultEditorAggGroupProps } from './agg_group';
import { DefaultEditorAgg } from './agg';
import { DefaultEditorAggAdd } from './agg_add';
import { ISchemas, Schemas } from '../schemas';
import { EditorVisState } from './sidebar/state/reducers';
import { Schemas } from '../schemas';
import type { EditorVisState } from './sidebar/state/reducers';

jest.mock('@elastic/eui', () => ({
EuiTitle: 'eui-title',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
import { i18n } from '@kbn/i18n';

import { AggGroupNames, AggGroupLabels, IAggConfig, TimeRange } from '../../../data/public';
import type { Schema } from '../../../visualizations/public';
import { DefaultEditorAgg } from './agg';
import { DefaultEditorAggAdd } from './agg_add';
import { AddSchema, ReorderAggs, DefaultEditorAggCommonProps } from './agg_common_props';
Expand All @@ -41,7 +42,6 @@ import {
getEnabledMetricAggsCount,
} from './agg_group_helper';
import { aggGroupReducer, initAggsState, AGGS_ACTION_KEYS } from './agg_group_state';
import { Schema } from '../schemas';

export interface DefaultEditorAggGroupProps extends DefaultEditorAggCommonProps {
schemas: Schema[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
* under the License.
*/

import { IAggConfig } from 'src/plugins/data/public';
import type { IAggConfig } from 'src/plugins/data/public';
import type { Schema } from 'src/plugins/visualizations/public';

import {
isAggRemovable,
calcAggIsTooLow,
isInvalidAggsTouched,
getEnabledMetricAggsCount,
} from './agg_group_helper';
import { AggsState } from './agg_group_state';
import { Schema } from '../schemas';

describe('DefaultEditorGroup helpers', () => {
let group: IAggConfig[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
*/

import { findIndex, isEmpty } from 'lodash';
import { IAggConfig } from 'src/plugins/data/public';
import { AggsState } from './agg_group_state';
import { Schema, getSchemaByName } from '../schemas';
import type { IAggConfig } from 'src/plugins/data/public';
import type { Schema } from 'src/plugins/visualizations/public';

import { getSchemaByName } from '../schemas';
import type { AggsState } from './agg_group_state';

const isAggRemovable = (agg: IAggConfig, group: IAggConfig[], schemas: Schema[]) => {
const schema = getSchemaByName(schemas, agg.schema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import {
IndexPatternField,
OptionedValueProp,
} from 'src/plugins/data/public';
import type { Schema } from 'src/plugins/visualizations/public';
import { ComboBoxGroupedOptions } from '../utils';
import { EditorConfig } from './utils';
import { Schema } from '../schemas';
import { EditorVisState } from './sidebar/state/reducers';

// NOTE: we cannot export the interface with export { InterfaceName }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { i18n } from '@kbn/i18n';
import useUnmount from 'react-use/lib/useUnmount';

import { IAggConfig, IndexPattern, AggGroupNames } from '../../../data/public';
import type { Schema } from '../../../visualizations/public';

import { DefaultEditorAggSelect } from './agg_select';
import { DefaultEditorAggParam } from './agg_param';
Expand All @@ -39,7 +40,7 @@ import {
} from './agg_params_state';
import { DefaultEditorCommonProps } from './agg_common_props';
import { EditorParamConfig, TimeIntervalParam, FixedParam, getEditorConfig } from './utils';
import { Schema, getSchemaByName } from '../schemas';
import { getSchemaByName } from '../schemas';
import { useKibana } from '../../../kibana_react/public';
import { VisDefaultEditorKibanaServices } from '../types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ import {
IAggType,
IndexPattern,
} from 'src/plugins/data/public';
import type { Schema } from 'src/plugins/visualizations/public';

import {
getAggParamsToRender,
getAggTypeOptions,
isInvalidParamsTouched,
} from './agg_params_helper';
import { FieldParamEditor, OrderByParamEditor } from './controls';
import { EditorConfig } from './utils';
import { Schema } from '../schemas';
import { EditorVisState } from './sidebar/state/reducers';
import { groupAndSortBy } from '../utils';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ import {
IndexPattern,
IndexPatternField,
} from '../../../data/public';
import type { Schema } from '../../../visualizations/public';

import { filterAggTypes, filterAggTypeFields } from '../agg_filters';
import { groupAndSortBy, ComboBoxGroupedOptions } from '../utils';
import { AggTypeState, AggParamsState } from './agg_params_state';
import { AggParamEditorProps } from './agg_param_props';
import { aggParamsMap } from './agg_params_map';
import { EditorConfig } from './utils';
import { Schema, getSchemaByName } from '../schemas';
import { getSchemaByName } from '../schemas';
import { EditorVisState } from './sidebar/state/reducers';

interface ParamInstanceBase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
search,
TimeRange,
} from '../../../../data/public';
import type { ISchemas } from '../../../../visualizations/public';
import { DefaultEditorAggGroup } from '../agg_group';
import {
EditorAction,
Expand All @@ -38,9 +39,8 @@ import {
changeAggType,
toggleEnabledAgg,
} from './state';
import { AddSchema, ReorderAggs, DefaultEditorAggCommonProps } from '../agg_common_props';
import { ISchemas } from '../../schemas';
import { EditorVisState } from './state/reducers';
import type { AddSchema, ReorderAggs, DefaultEditorAggCommonProps } from '../agg_common_props';
import type { EditorVisState } from './state/reducers';

export interface DefaultEditorDataTabProps {
dispatch: React.Dispatch<EditorAction>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ import {
PersistedState,
VisualizeEmbeddableContract,
} from 'src/plugins/visualizations/public';
import type { Schema } from 'src/plugins/visualizations/public';
import { TimeRange } from 'src/plugins/data/public';
import { SavedObject } from 'src/plugins/saved_objects/public';
import { DefaultEditorNavBar } from './navbar';
import { DefaultEditorControls } from './controls';
import { setStateParamValue, useEditorReducer, useEditorFormState, discardChanges } from './state';
import { DefaultEditorAggCommonProps } from '../agg_common_props';
import { SidebarTitle } from './sidebar_title';
import { Schema } from '../../schemas';
import { useOptionTabs } from './use_option_tabs';

interface DefaultEditorSideBarProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
*/

import { Vis, VisParams } from 'src/plugins/visualizations/public';
import { IAggConfig } from 'src/plugins/data/public';
import type { IAggConfig } from 'src/plugins/data/public';
import type { Schema } from 'src/plugins/visualizations/public';

import { EditorStateActionTypes } from './constants';
import { Schema } from '../../../schemas';

export interface ActionType<T, P> {
type: T;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/vis_default_editor/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export { RangesParamEditor, RangeValues } from './components/controls/ranges';
export * from './editor_size';
export * from './vis_options_props';
export * from './utils';
export { ISchemas, Schemas, Schema } from './schemas';
export { Schemas } from './schemas';

export const plugin = (context: PluginInitializerContext) => {
return new VisDefaultEditorPlugin();
Expand Down
27 changes: 2 additions & 25 deletions src/plugins/vis_default_editor/public/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,12 @@
* under the License.
*/

import { ReactNode } from 'react';
import _, { defaults } from 'lodash';

import { Optional } from '@kbn/utility-types';

import { AggGroupNames, AggParam, AggGroupName } from '../../data/public';

export interface ISchemas {
[AggGroupNames.Buckets]: Schema[];
[AggGroupNames.Metrics]: Schema[];
all: Schema[];
}

export interface Schema {
aggFilter: string[];
editor: boolean | string;
group: AggGroupName;
max: number;
min: number;
name: string;
params: AggParam[];
title: string;
defaults: unknown;
hideCustomLabel?: boolean;
mustBeFirst?: boolean;
aggSettings?: any;
disabled?: boolean;
tooltip?: ReactNode;
}
import { AggGroupNames, AggParam } from '../../data/public';
import type { ISchemas, Schema } from '../../visualizations/public';

export class Schemas implements ISchemas {
all: Schema[] = [];
Expand Down
9 changes: 8 additions & 1 deletion src/plugins/visualizations/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ export { getSchemas as getVisSchemas } from './legacy/build_pipeline';
/** @public types */
export { VisualizationsSetup, VisualizationsStart };
export { VisGroups } from './vis_types';
export type { VisTypeAlias, VisType, BaseVisTypeOptions, ReactVisTypeOptions } from './vis_types';
export type {
VisTypeAlias,
VisType,
BaseVisTypeOptions,
ReactVisTypeOptions,
Schema,
ISchemas,
} from './vis_types';
export { VisParams, SerializedVis, SerializedVisData, VisData } from './vis';
export type VisualizeEmbeddableFactoryContract = PublicContract<VisualizeEmbeddableFactory>;
export type VisualizeEmbeddableContract = PublicContract<VisualizeEmbeddable>;
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/visualizations/public/vis_types/base_vis_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/

import { defaultsDeep } from 'lodash';
import { ISchemas } from 'src/plugins/vis_default_editor/public';

import { VisParams } from '../types';
import { VisType, VisTypeOptions, VisGroups } from './types';
import { VisType, VisTypeOptions, VisGroups, ISchemas } from './types';

interface CommonBaseVisTypeOptions<TVisParams>
extends Pick<
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/visualizations/public/vis_types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@

export * from './types_service';
export { VisGroups } from './types';
export type { VisType } from './types';
export type { VisType, ISchemas, Schema } from './types';
export type { BaseVisTypeOptions } from './base_vis_type';
export type { ReactVisTypeOptions } from './react_vis_type';
28 changes: 25 additions & 3 deletions src/plugins/visualizations/public/vis_types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
*/

import { IconType } from '@elastic/eui';
import React from 'react';
import React, { ReactNode } from 'react';
import { Adapters } from 'src/plugins/inspector';
import { IndexPattern } from 'src/plugins/data/public';
import { VisEditorConstructor } from 'src/plugins/visualize/public';
import { ISchemas } from 'src/plugins/vis_default_editor/public';
import { IndexPattern, AggGroupNames, AggParam, AggGroupName } from '../../../data/public';
import { TriggerContextMapping } from '../../../ui_actions/public';
import { Vis, VisParams, VisToExpressionAst, VisualizationControllerConstructor } from '../types';

Expand All @@ -40,6 +39,29 @@ export enum VisGroups {
AGGBASED = 'aggbased',
}

export interface ISchemas {
[AggGroupNames.Buckets]: Schema[];
[AggGroupNames.Metrics]: Schema[];
all: Schema[];
}

export interface Schema {
aggFilter: string[];
editor: boolean | string;
group: AggGroupName;
max: number;
min: number;
name: string;
params: AggParam[];
title: string;
defaults: unknown;
hideCustomLabel?: boolean;
mustBeFirst?: boolean;
aggSettings?: any;
disabled?: boolean;
tooltip?: ReactNode;
}

/**
* A visualization type representing one specific type of "classical"
* visualizations (i.e. not Lens visualizations).
Expand Down

0 comments on commit e001422

Please sign in to comment.