From 7eed77e3fc74090bbe0b54a1cd5c808fe70263cc Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Fri, 14 Feb 2020 16:06:08 +0100 Subject: [PATCH 1/4] fix agg type shims and move paginated table to kibana_legacy --- .../public/visualize/kibana_services.ts | 2 + .../kibana/public/visualize/legacy.ts | 2 + .../np_ready/editor/visualization_editor.js | 1 + .../public/visualize/np_ready/types.d.ts | 2 + .../kibana/public/visualize/plugin.ts | 15 +- .../public/components/agg_params.tsx | 30 ++- .../components/agg_params_helper.test.ts | 20 +- .../public/components/agg_params_helper.ts | 19 +- .../public/components/sidebar/state/index.ts | 5 +- .../components/sidebar/state/reducers.ts | 11 +- .../public/default_editor.tsx | 2 +- .../public/default_editor_controller.tsx | 3 +- .../public/legacy_imports.ts | 33 ++- .../vis_default_editor/public/types.ts | 26 ++ .../vis_type_metric/public/legacy_imports.ts | 2 +- .../public/get_inner_angular.ts | 8 +- .../vis_type_table/public/legacy_imports.ts | 6 +- .../public/legacy_imports.ts | 2 +- .../vis_type_vislib/public/legacy_imports.ts | 2 +- src/legacy/ui/public/directives/paginate.js | 217 +---------------- src/plugins/kibana_legacy/public/index.ts | 1 + .../public/paginate/paginate.d.ts | 21 ++ .../kibana_legacy/public/paginate/paginate.js | 230 ++++++++++++++++++ .../public/paginate}/paginate_controls.html | 0 24 files changed, 385 insertions(+), 275 deletions(-) create mode 100644 src/legacy/core_plugins/vis_default_editor/public/types.ts create mode 100644 src/plugins/kibana_legacy/public/paginate/paginate.d.ts create mode 100644 src/plugins/kibana_legacy/public/paginate/paginate.js rename src/{legacy/ui/public/directives/partials => plugins/kibana_legacy/public/paginate}/paginate_controls.html (100%) diff --git a/src/legacy/core_plugins/kibana/public/visualize/kibana_services.ts b/src/legacy/core_plugins/kibana/public/visualize/kibana_services.ts index 6082fb8428ac3..72369290a52a0 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/kibana_services.ts +++ b/src/legacy/core_plugins/kibana/public/visualize/kibana_services.ts @@ -37,6 +37,7 @@ import { SavedVisualizations } from './np_ready/types'; import { UsageCollectionSetup } from '../../../../../plugins/usage_collection/public'; import { Chrome } from './legacy_imports'; import { KibanaLegacyStart } from '../../../../../plugins/kibana_legacy/public'; +import { DataStart } from '../../../data/public'; export interface VisualizeKibanaServices { pluginInitializerContext: PluginInitializerContext; @@ -44,6 +45,7 @@ export interface VisualizeKibanaServices { chrome: ChromeStart; core: CoreStart; data: DataPublicPluginStart; + dataShim: DataStart; embeddable: IEmbeddableStart; getBasePath: () => string; indexPatterns: IndexPatternsContract; diff --git a/src/legacy/core_plugins/kibana/public/visualize/legacy.ts b/src/legacy/core_plugins/kibana/public/visualize/legacy.ts index bc2d700f6c6a1..75426e4ef89b1 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/legacy.ts +++ b/src/legacy/core_plugins/kibana/public/visualize/legacy.ts @@ -21,6 +21,7 @@ import { PluginInitializerContext } from 'kibana/public'; import { legacyChrome, npSetup, npStart } from './legacy_imports'; import { start as visualizations } from '../../../visualizations/public/np_ready/public/legacy'; import { plugin } from './index'; +import { start as dataShim } from '../../../data/public/legacy'; const instance = plugin({ env: npSetup.plugins.kibanaLegacy.env, @@ -33,5 +34,6 @@ instance.setup(npSetup.core, { }); instance.start(npStart.core, { ...npStart.plugins, + dataShim, visualizations, }); diff --git a/src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/visualization_editor.js b/src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/visualization_editor.js index 8032152f88173..a4177ea9f0318 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/visualization_editor.js +++ b/src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/visualization_editor.js @@ -36,6 +36,7 @@ export function initVisEditorDirective(app, deps) { editor.render({ core: deps.core, data: deps.data, + dataShim: deps.dataShim, embeddable: deps.embeddable, uiState: $scope.uiState, timeRange: $scope.timeRange, diff --git a/src/legacy/core_plugins/kibana/public/visualize/np_ready/types.d.ts b/src/legacy/core_plugins/kibana/public/visualize/np_ready/types.d.ts index 524bc4b3196b7..3e851560b386b 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/np_ready/types.d.ts +++ b/src/legacy/core_plugins/kibana/public/visualize/np_ready/types.d.ts @@ -21,11 +21,13 @@ import { TimeRange, Query, Filter, DataPublicPluginStart } from 'src/plugins/dat import { IEmbeddableStart } from 'src/plugins/embeddable/public'; import { LegacyCoreStart } from 'kibana/public'; import { VisSavedObject, AppState, PersistedState } from '../legacy_imports'; +import { DataStart } from '../../../../data/public'; export interface EditorRenderProps { appState: AppState; core: LegacyCoreStart; data: DataPublicPluginStart; + dataShim: DataStart; embeddable: IEmbeddableStart; filters: Filter[]; uiState: PersistedState; diff --git a/src/legacy/core_plugins/kibana/public/visualize/plugin.ts b/src/legacy/core_plugins/kibana/public/visualize/plugin.ts index 16715677d1e20..612c9ae17ea34 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/plugin.ts +++ b/src/legacy/core_plugins/kibana/public/visualize/plugin.ts @@ -43,9 +43,11 @@ import { } from '../../../../../plugins/home/public'; import { UsageCollectionSetup } from '../../../../../plugins/usage_collection/public'; import { Chrome } from './legacy_imports'; +import { DataStart } from '../../../data/public'; export interface VisualizePluginStartDependencies { data: DataPublicPluginStart; + dataShim: DataStart; embeddable: IEmbeddableStart; navigation: NavigationStart; share: SharePluginStart; @@ -64,6 +66,7 @@ export interface VisualizePluginSetupDependencies { export class VisualizePlugin implements Plugin { private startDependencies: { data: DataPublicPluginStart; + dataShim: DataStart; embeddable: IEmbeddableStart; navigation: NavigationStart; savedObjectsClient: SavedObjectsClientContract; @@ -92,6 +95,7 @@ export class VisualizePlugin implements Plugin { navigation, visualizations, data, + dataShim, share, } = this.startDependencies; @@ -102,6 +106,7 @@ export class VisualizePlugin implements Plugin { core: coreStart, chrome: coreStart.chrome, data, + dataShim, embeddable, getBasePath: core.http.basePath.get, indexPatterns: data.indexPatterns, @@ -142,10 +147,18 @@ export class VisualizePlugin implements Plugin { public start( core: CoreStart, - { embeddable, navigation, data, share, visualizations }: VisualizePluginStartDependencies + { + embeddable, + navigation, + data, + dataShim, + share, + visualizations, + }: VisualizePluginStartDependencies ) { this.startDependencies = { data, + dataShim, embeddable, navigation, savedObjectsClient: core.savedObjects.client, diff --git a/src/legacy/core_plugins/vis_default_editor/public/components/agg_params.tsx b/src/legacy/core_plugins/vis_default_editor/public/components/agg_params.tsx index e9583ab4cec79..56785db6902e7 100644 --- a/src/legacy/core_plugins/vis_default_editor/public/components/agg_params.tsx +++ b/src/legacy/core_plugins/vis_default_editor/public/components/agg_params.tsx @@ -40,6 +40,8 @@ import { } from './agg_params_state'; import { DefaultEditorCommonProps } from './agg_common_props'; import { EditorParamConfig, TimeIntervalParam, FixedParam, getEditorConfig } from './utils'; +import { useKibana } from '../../../../../plugins/kibana_react/public'; +import { VisDefaultEditorKibanaServices } from '../types'; const FIXED_VALUE_PROP = 'fixedValue'; const DEFAULT_PROP = 'default'; @@ -76,11 +78,19 @@ function DefaultEditorAggParams({ setTouched, setValidity, }: DefaultEditorAggParamsProps) { - const groupedAggTypeOptions = useMemo(() => getAggTypeOptions(agg, indexPattern, groupName), [ - agg, - indexPattern, - groupName, - ]); + const { + services: { + dataShim: { + search: { + aggs: { types: aggTypes, aggTypeFieldFilters }, + }, + }, + }, + } = useKibana(); + const groupedAggTypeOptions = useMemo( + () => getAggTypeOptions(aggTypes, agg, indexPattern, groupName), + [agg, indexPattern, groupName, aggTypes] + ); const error = aggIsTooLow ? i18n.translate('visDefaultEditor.aggParams.errors.aggWrongRunOrderErrorMessage', { defaultMessage: '"{schema}" aggs must run before all other buckets!', @@ -94,12 +104,10 @@ function DefaultEditorAggParams({ aggTypeName, fieldName, ]); - const params = useMemo(() => getAggParamsToRender({ agg, editorConfig, metricAggs, state }), [ - agg, - editorConfig, - metricAggs, - state, - ]); + const params = useMemo( + () => getAggParamsToRender({ agg, editorConfig, metricAggs, state }, aggTypeFieldFilters), + [agg, editorConfig, metricAggs, state, aggTypeFieldFilters] + ); const allParams = [...params.basic, ...params.advanced]; const [paramsState, onChangeParamsState] = useReducer( aggParamsReducer, diff --git a/src/legacy/core_plugins/vis_default_editor/public/components/agg_params_helper.test.ts b/src/legacy/core_plugins/vis_default_editor/public/components/agg_params_helper.test.ts index f3bee80baa1ba..6d2eee043ee12 100644 --- a/src/legacy/core_plugins/vis_default_editor/public/components/agg_params_helper.test.ts +++ b/src/legacy/core_plugins/vis_default_editor/public/components/agg_params_helper.test.ts @@ -17,7 +17,7 @@ * under the License. */ -import { IndexPattern } from 'src/plugins/data/public'; +import { IndexPattern, IndexPatternField } from 'src/plugins/data/public'; import { VisState } from 'src/legacy/core_plugins/visualizations/public'; import { IAggConfig, IAggType, AggGroupNames, BUCKET_TYPES } from '../legacy_imports'; import { @@ -34,6 +34,12 @@ jest.mock('../utils', () => ({ jest.mock('ui/new_platform'); +const mockFilter = { + filter(fields: IndexPatternField[]): IndexPatternField[] { + return fields; + }, +}; + describe('DefaultEditorAggParams helpers', () => { describe('getAggParamsToRender', () => { let agg: IAggConfig; @@ -52,14 +58,14 @@ describe('DefaultEditorAggParams helpers', () => { }, schema: {}, } as IAggConfig; - const params = getAggParamsToRender({ agg, editorConfig, metricAggs, state }); + const params = getAggParamsToRender({ agg, editorConfig, metricAggs, state }, mockFilter); expect(params).toEqual(emptyParams); }); it('should not create any param if there is no agg type', () => { agg = {} as IAggConfig; - const params = getAggParamsToRender({ agg, editorConfig, metricAggs, state }); + const params = getAggParamsToRender({ agg, editorConfig, metricAggs, state }, mockFilter); expect(params).toEqual(emptyParams); }); @@ -75,7 +81,7 @@ describe('DefaultEditorAggParams helpers', () => { hidden: true, }, }; - const params = getAggParamsToRender({ agg, editorConfig, metricAggs, state }); + const params = getAggParamsToRender({ agg, editorConfig, metricAggs, state }, mockFilter); expect(params).toEqual(emptyParams); }); @@ -89,7 +95,7 @@ describe('DefaultEditorAggParams helpers', () => { hideCustomLabel: true, }, } as IAggConfig; - const params = getAggParamsToRender({ agg, editorConfig, metricAggs, state }); + const params = getAggParamsToRender({ agg, editorConfig, metricAggs, state }, mockFilter); expect(params).toEqual(emptyParams); }); @@ -128,7 +134,7 @@ describe('DefaultEditorAggParams helpers', () => { field: 'field', }, } as any) as IAggConfig; - const params = getAggParamsToRender({ agg, editorConfig, metricAggs, state }); + const params = getAggParamsToRender({ agg, editorConfig, metricAggs, state }, mockFilter); expect(params).toEqual({ basic: [ @@ -162,7 +168,7 @@ describe('DefaultEditorAggParams helpers', () => { describe('getAggTypeOptions', () => { it('should return agg type options grouped by subtype', () => { const indexPattern = {} as IndexPattern; - const aggs = getAggTypeOptions({} as IAggConfig, indexPattern, 'metrics'); + const aggs = getAggTypeOptions({ metrics: [] }, {} as IAggConfig, indexPattern, 'metrics'); expect(aggs).toEqual(['indexedFields']); }); diff --git a/src/legacy/core_plugins/vis_default_editor/public/components/agg_params_helper.ts b/src/legacy/core_plugins/vis_default_editor/public/components/agg_params_helper.ts index 0c0726ec67d50..5a92d48e64862 100644 --- a/src/legacy/core_plugins/vis_default_editor/public/components/agg_params_helper.ts +++ b/src/legacy/core_plugins/vis_default_editor/public/components/agg_params_helper.ts @@ -25,16 +25,9 @@ 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 { - aggTypeFilters, - aggTypeFieldFilters, - aggTypes, - IAggConfig, - AggParam, - IFieldParamType, - IAggType, -} from '../legacy_imports'; +import { aggTypeFilters, IAggConfig, AggParam, IFieldParamType, IAggType } from '../legacy_imports'; import { EditorConfig } from './utils'; +import { AggConfig } from '../../../data/public/search/aggs'; interface ParamInstanceBase { agg: IAggConfig; @@ -50,7 +43,12 @@ export interface ParamInstance extends ParamInstanceBase { value: unknown; } -function getAggParamsToRender({ agg, editorConfig, metricAggs, state }: ParamInstanceBase) { +function getAggParamsToRender( + { agg, editorConfig, metricAggs, state }: ParamInstanceBase, + aggTypeFieldFilters: { + filter(fields: IndexPatternField[], aggConfig: AggConfig): IndexPatternField[]; + } +) { const params = { basic: [] as ParamInstance[], advanced: [] as ParamInstance[], @@ -117,6 +115,7 @@ function getAggParamsToRender({ agg, editorConfig, metricAggs, state }: ParamIns } function getAggTypeOptions( + aggTypes: any, agg: IAggConfig, indexPattern: IndexPattern, groupName: string diff --git a/src/legacy/core_plugins/vis_default_editor/public/components/sidebar/state/index.ts b/src/legacy/core_plugins/vis_default_editor/public/components/sidebar/state/index.ts index df5ba3f6121c7..df736cfc2db55 100644 --- a/src/legacy/core_plugins/vis_default_editor/public/components/sidebar/state/index.ts +++ b/src/legacy/core_plugins/vis_default_editor/public/components/sidebar/state/index.ts @@ -24,12 +24,15 @@ import { Vis, VisState, VisParams } from 'src/legacy/core_plugins/visualizations import { editorStateReducer, initEditorState } from './reducers'; import { EditorStateActionTypes } from './constants'; import { EditorAction, updateStateParams } from './actions'; +import { useKibana } from '../../../../../../../plugins/kibana_react/public'; +import { VisDefaultEditorKibanaServices } from '../../../types'; export * from './editor_form_state'; export * from './actions'; export function useEditorReducer(vis: Vis): [VisState, React.Dispatch] { - const [state, dispatch] = useReducer(editorStateReducer, vis, initEditorState); + const { services } = useKibana(); + const [state, dispatch] = useReducer(editorStateReducer(services.dataShim), vis, initEditorState); useEffect(() => { const handleVisUpdate = (params: VisParams) => { diff --git a/src/legacy/core_plugins/vis_default_editor/public/components/sidebar/state/reducers.ts b/src/legacy/core_plugins/vis_default_editor/public/components/sidebar/state/reducers.ts index 6591aa5fb53d5..5ba908031c05e 100644 --- a/src/legacy/core_plugins/vis_default_editor/public/components/sidebar/state/reducers.ts +++ b/src/legacy/core_plugins/vis_default_editor/public/components/sidebar/state/reducers.ts @@ -20,16 +20,21 @@ import { cloneDeep } from 'lodash'; import { Vis, VisState } from 'src/legacy/core_plugins/visualizations/public'; -import { AggConfigs, IAggConfig, AggGroupNames } from '../../../legacy_imports'; +import { IAggConfig, AggGroupNames } from '../../../legacy_imports'; import { EditorStateActionTypes } from './constants'; import { getEnabledMetricAggsCount } from '../../agg_group_helper'; import { EditorAction } from './actions'; +import { DataStart } from '../../../../../data/public'; function initEditorState(vis: Vis) { return vis.copyCurrentState(true); } -function editorStateReducer(state: VisState, action: EditorAction): VisState { +const editorStateReducer = ({ + search: { + aggs: { AggConfigs }, + }, +}: DataStart) => (state: VisState, action: EditorAction): VisState => { switch (action.type) { case EditorStateActionTypes.ADD_NEW_AGG: { const aggConfig = state.aggs.createAggConfig(action.payload as IAggConfig, { @@ -176,6 +181,6 @@ function editorStateReducer(state: VisState, action: EditorAction): VisState { }; } } -} +}; export { editorStateReducer, initEditorState }; diff --git a/src/legacy/core_plugins/vis_default_editor/public/default_editor.tsx b/src/legacy/core_plugins/vis_default_editor/public/default_editor.tsx index 32ea71c0bc005..48873ddeb30ad 100644 --- a/src/legacy/core_plugins/vis_default_editor/public/default_editor.tsx +++ b/src/legacy/core_plugins/vis_default_editor/public/default_editor.tsx @@ -38,7 +38,7 @@ function DefaultEditor({ appState, optionTabs, query, -}: DefaultEditorControllerState & Omit) { +}: DefaultEditorControllerState & Omit) { const visRef = useRef(null); const visHandler = useRef(null); const [isCollapsed, setIsCollapsed] = useState(false); diff --git a/src/legacy/core_plugins/vis_default_editor/public/default_editor_controller.tsx b/src/legacy/core_plugins/vis_default_editor/public/default_editor_controller.tsx index d3090d277aef9..bf6ff8e9e886e 100644 --- a/src/legacy/core_plugins/vis_default_editor/public/default_editor_controller.tsx +++ b/src/legacy/core_plugins/vis_default_editor/public/default_editor_controller.tsx @@ -76,7 +76,7 @@ class DefaultEditorController { }; } - render({ data, core, ...props }: EditorRenderProps) { + render({ data, dataShim, core, ...props }: EditorRenderProps) { render( diff --git a/src/legacy/core_plugins/vis_default_editor/public/legacy_imports.ts b/src/legacy/core_plugins/vis_default_editor/public/legacy_imports.ts index 5e547eed1c957..6f07ce369cdc2 100644 --- a/src/legacy/core_plugins/vis_default_editor/public/legacy_imports.ts +++ b/src/legacy/core_plugins/vis_default_editor/public/legacy_imports.ts @@ -19,34 +19,33 @@ /* `ui/agg_types` dependencies */ export { - AggType, IAggType, IAggConfig, - AggConfigs, IAggConfigs, AggParam, AggGroupNames, aggGroupNamesMap, - aggTypes, - FieldParamType, IFieldParamType, BUCKET_TYPES, METRIC_TYPES, ISchemas, Schema, termsAggFilter, -} from 'ui/agg_types'; -export { aggTypeFilters, propFilter } from 'ui/agg_types'; -export { aggTypeFieldFilters } from 'ui/agg_types'; -export { AggParamType } from 'ui/agg_types'; -export { MetricAggType, IMetricAggType } from 'ui/agg_types'; -export { parentPipelineType } from 'ui/agg_types'; -export { siblingPipelineType } from 'ui/agg_types'; -export { isType, isStringType } from 'ui/agg_types'; -export { OptionedValueProp, OptionedParamEditorProps, OptionedParamType } from 'ui/agg_types'; -export { isValidJson, isValidInterval } from 'ui/agg_types'; -export { AggParamOption } from 'ui/agg_types'; -export { CidrMask } from 'ui/agg_types'; + aggTypeFilters, + propFilter, + AggParamType, + IMetricAggType, + parentPipelineType, + siblingPipelineType, + isType, + isStringType, + OptionedValueProp, + OptionedParamEditorProps, + OptionedParamType, + isValidJson, + isValidInterval, + AggParamOption, + CidrMask, +} from '../../data/public'; export { PersistedState } from 'ui/persisted_state'; -export * from 'ui/vis/lib'; diff --git a/src/legacy/core_plugins/vis_default_editor/public/types.ts b/src/legacy/core_plugins/vis_default_editor/public/types.ts new file mode 100644 index 0000000000000..ec1bdde79c93a --- /dev/null +++ b/src/legacy/core_plugins/vis_default_editor/public/types.ts @@ -0,0 +1,26 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { DataPublicPluginStart } from '../../../../plugins/data/public'; +import { DataStart } from '../../data/public'; + +export interface VisDefaultEditorKibanaServices { + data: DataPublicPluginStart; + dataShim: DataStart; +} diff --git a/src/legacy/core_plugins/vis_type_metric/public/legacy_imports.ts b/src/legacy/core_plugins/vis_type_metric/public/legacy_imports.ts index b769030a04fb1..61aab0a3789cd 100644 --- a/src/legacy/core_plugins/vis_type_metric/public/legacy_imports.ts +++ b/src/legacy/core_plugins/vis_type_metric/public/legacy_imports.ts @@ -18,4 +18,4 @@ */ export { getFormat } from 'ui/visualize/loader/pipeline_helpers/utilities'; -export { AggGroupNames, Schemas } from 'ui/agg_types'; +export { AggGroupNames, Schemas } from '../../data/public'; diff --git a/src/legacy/core_plugins/vis_type_table/public/get_inner_angular.ts b/src/legacy/core_plugins/vis_type_table/public/get_inner_angular.ts index 6fb5658d8e815..4bed51ba18909 100644 --- a/src/legacy/core_plugins/vis_type_table/public/get_inner_angular.ts +++ b/src/legacy/core_plugins/vis_type_table/public/get_inner_angular.ts @@ -26,13 +26,15 @@ import { i18nDirective, i18nFilter, I18nProvider } from '@kbn/i18n/angular'; import { CoreStart, LegacyCoreStart, IUiSettingsClient } from 'kibana/public'; import { PrivateProvider, - PaginateDirectiveProvider, - PaginateControlsDirectiveProvider, watchMultiDecorator, KbnAccessibleClickProvider, configureAppAngularModule, } from './legacy_imports'; -import { initAngularBootstrap } from '../../../../plugins/kibana_legacy/public'; +import { + initAngularBootstrap, + PaginateDirectiveProvider, + PaginateControlsDirectiveProvider, +} from '../../../../plugins/kibana_legacy/public'; initAngularBootstrap(); diff --git a/src/legacy/core_plugins/vis_type_table/public/legacy_imports.ts b/src/legacy/core_plugins/vis_type_table/public/legacy_imports.ts index cb44814897bcf..ba1a29a93d00e 100644 --- a/src/legacy/core_plugins/vis_type_table/public/legacy_imports.ts +++ b/src/legacy/core_plugins/vis_type_table/public/legacy_imports.ts @@ -19,11 +19,7 @@ export { npSetup, npStart } from 'ui/new_platform'; export { getFormat } from 'ui/visualize/loader/pipeline_helpers/utilities'; -export { IAggConfig, AggGroupNames, Schemas } from 'ui/agg_types'; -// @ts-ignore -export { PaginateDirectiveProvider } from 'ui/directives/paginate'; -// @ts-ignore -export { PaginateControlsDirectiveProvider } from 'ui/directives/paginate'; +export { IAggConfig, AggGroupNames, Schemas } from '../../data/public'; export { tabifyGetColumns } from 'ui/agg_response/tabify/_get_columns'; // @ts-ignore export { tabifyAggResponse } from 'ui/agg_response/tabify'; diff --git a/src/legacy/core_plugins/vis_type_tagcloud/public/legacy_imports.ts b/src/legacy/core_plugins/vis_type_tagcloud/public/legacy_imports.ts index d5b442bc5b346..452ebbc15c2f1 100644 --- a/src/legacy/core_plugins/vis_type_tagcloud/public/legacy_imports.ts +++ b/src/legacy/core_plugins/vis_type_tagcloud/public/legacy_imports.ts @@ -17,6 +17,6 @@ * under the License. */ -export { Schemas } from 'ui/agg_types'; +export { Schemas } from '../../data/public'; export { ValidatedDualRange } from 'ui/validated_range'; export { getFormat } from 'ui/visualize/loader/pipeline_helpers/utilities'; diff --git a/src/legacy/core_plugins/vis_type_vislib/public/legacy_imports.ts b/src/legacy/core_plugins/vis_type_vislib/public/legacy_imports.ts index 3d04c04f9b1a6..8eff4f8ebf6b6 100644 --- a/src/legacy/core_plugins/vis_type_vislib/public/legacy_imports.ts +++ b/src/legacy/core_plugins/vis_type_vislib/public/legacy_imports.ts @@ -17,7 +17,7 @@ * under the License. */ -export { AggType, AggGroupNames, IAggConfig, IAggType, Schemas } from 'ui/agg_types'; +export { AggGroupNames, IAggConfig, IAggType, Schemas } from '../../data/public'; export { getFormat, getTableAggs } from 'ui/visualize/loader/pipeline_helpers/utilities'; // @ts-ignore export { tabifyAggResponse } from 'ui/agg_response/tabify'; diff --git a/src/legacy/ui/public/directives/paginate.js b/src/legacy/ui/public/directives/paginate.js index 802aaaf453751..549ac52ccd8d5 100644 --- a/src/legacy/ui/public/directives/paginate.js +++ b/src/legacy/ui/public/directives/paginate.js @@ -17,218 +17,11 @@ * under the License. */ -import _ from 'lodash'; -import { i18n } from '@kbn/i18n'; -import { uiModules } from '../modules'; -import paginateControlsTemplate from './partials/paginate_controls.html'; - -export function PaginateDirectiveProvider($parse, $compile) { - return { - restrict: 'E', - scope: true, - link: { - pre: function($scope, $el, attrs) { - if (_.isUndefined(attrs.bottomControls)) attrs.bottomControls = true; - if ($el.find('paginate-controls.paginate-bottom').length === 0 && attrs.bottomControls) { - $el.append($compile('')($scope)); - } - }, - post: function($scope, $el, attrs) { - if (_.isUndefined(attrs.topControls)) attrs.topControls = false; - if ($el.find('paginate-controls.paginate-top').length === 0 && attrs.topControls) { - $el.prepend($compile('')($scope)); - } - - const paginate = $scope.paginate; - - // add some getters to the controller powered by attributes - paginate.getList = $parse(attrs.list); - paginate.perPageProp = attrs.perPageProp; - - if (attrs.perPage) { - paginate.perPage = attrs.perPage; - $scope.showSelector = false; - } else { - $scope.showSelector = true; - } - - paginate.otherWidthGetter = $parse(attrs.otherWidth); - - paginate.init(); - }, - }, - controllerAs: 'paginate', - controller: function($scope, $document) { - const self = this; - const ALL = 0; - const allSizeTitle = i18n.translate( - 'common.ui.directives.paginate.size.allDropDownOptionLabel', - { - defaultMessage: 'All', - } - ); - - self.sizeOptions = [ - { title: '10', value: 10 }, - { title: '25', value: 25 }, - { title: '100', value: 100 }, - { title: allSizeTitle, value: ALL }, - ]; - - // setup the watchers, called in the post-link function - self.init = function() { - self.perPage = _.parseInt(self.perPage) || $scope[self.perPageProp]; - - $scope.$watchMulti(['paginate.perPage', self.perPageProp, self.otherWidthGetter], function( - vals, - oldVals - ) { - const intChanges = vals[0] !== oldVals[0]; - - if (intChanges) { - if (!setPerPage(self.perPage)) { - // if we are not able to set the external value, - // render now, otherwise wait for the external value - // to trigger the watcher again - self.renderList(); - } - return; - } - - self.perPage = _.parseInt(self.perPage) || $scope[self.perPageProp]; - if (self.perPage == null) { - self.perPage = ALL; - return; - } - - self.renderList(); - }); - - $scope.$watch('page', self.changePage); - $scope.$watchCollection(self.getList, function(list) { - $scope.list = list; - self.renderList(); - }); - }; - - self.goToPage = function(number) { - if (number) { - if (number.hasOwnProperty('number')) number = number.number; - $scope.page = $scope.pages[number - 1] || $scope.pages[0]; - } - }; - - self.goToTop = function goToTop() { - $document.scrollTop(0); - }; - - self.renderList = function() { - $scope.pages = []; - if (!$scope.list) return; - - const perPage = _.parseInt(self.perPage); - const count = perPage ? Math.ceil($scope.list.length / perPage) : 1; - - _.times(count, function(i) { - let page; - - if (perPage) { - const start = perPage * i; - page = $scope.list.slice(start, start + perPage); - } else { - page = $scope.list.slice(0); - } - - page.number = i + 1; - page.i = i; - - page.count = count; - page.first = page.number === 1; - page.last = page.number === count; - page.firstItem = (page.number - 1) * perPage + 1; - page.lastItem = Math.min(page.number * perPage, $scope.list.length); - - page.prev = $scope.pages[i - 1]; - if (page.prev) page.prev.next = page; - - $scope.pages.push(page); - }); - - // set the new page, or restore the previous page number - if ($scope.page && $scope.page.i < $scope.pages.length) { - $scope.page = $scope.pages[$scope.page.i]; - } else { - $scope.page = $scope.pages[0]; - } - - if ($scope.page && $scope.onPageChanged) { - $scope.onPageChanged($scope.page); - } - }; - - self.changePage = function(page) { - if (!page) { - $scope.otherPages = null; - return; - } - - // setup the list of the other pages to link to - $scope.otherPages = []; - const width = +self.otherWidthGetter($scope) || 5; - let left = page.i - Math.round((width - 1) / 2); - let right = left + width - 1; - - // shift neg count from left to right - if (left < 0) { - right += 0 - left; - left = 0; - } - - // shift extra right nums to left - const lastI = page.count - 1; - if (right > lastI) { - right = lastI; - left = right - width + 1; - } - - for (let i = left; i <= right; i++) { - const other = $scope.pages[i]; - - if (!other) continue; - - $scope.otherPages.push(other); - if (other.last) $scope.otherPages.containsLast = true; - if (other.first) $scope.otherPages.containsFirst = true; - } - - if ($scope.onPageChanged) { - $scope.onPageChanged($scope.page); - } - }; - - function setPerPage(val) { - let $ppParent = $scope; - - while ($ppParent && !_.has($ppParent, self.perPageProp)) { - $ppParent = $ppParent.$parent; - } - - if ($ppParent) { - $ppParent[self.perPageProp] = val; - return true; - } - } - }, - }; -} - -export function PaginateControlsDirectiveProvider() { - // this directive is automatically added by paginate if not found within it's $el - return { - restrict: 'E', - template: paginateControlsTemplate, - }; -} +import { uiModules } from 'ui/modules'; +import { + PaginateControlsDirectiveProvider, + PaginateDirectiveProvider, +} from '../../../../plugins/kibana_legacy/public'; uiModules .get('kibana') diff --git a/src/plugins/kibana_legacy/public/index.ts b/src/plugins/kibana_legacy/public/index.ts index 18f01854de259..75e81b0505747 100644 --- a/src/plugins/kibana_legacy/public/index.ts +++ b/src/plugins/kibana_legacy/public/index.ts @@ -27,6 +27,7 @@ export * from './plugin'; export { kbnBaseUrl } from '../common/kbn_base_url'; export { initAngularBootstrap } from './angular_bootstrap'; +export { PaginateDirectiveProvider, PaginateControlsDirectiveProvider } from './paginate/paginate'; export * from './angular'; export * from './notify'; export * from './utils'; diff --git a/src/plugins/kibana_legacy/public/paginate/paginate.d.ts b/src/plugins/kibana_legacy/public/paginate/paginate.d.ts new file mode 100644 index 0000000000000..7425146887df9 --- /dev/null +++ b/src/plugins/kibana_legacy/public/paginate/paginate.d.ts @@ -0,0 +1,21 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export type PaginateDirectiveProvider = any; +export type PaginateControlsDirectiveProvider = any; diff --git a/src/plugins/kibana_legacy/public/paginate/paginate.js b/src/plugins/kibana_legacy/public/paginate/paginate.js new file mode 100644 index 0000000000000..2a492f3c72f8e --- /dev/null +++ b/src/plugins/kibana_legacy/public/paginate/paginate.js @@ -0,0 +1,230 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import _ from 'lodash'; +import { i18n } from '@kbn/i18n'; +import paginateControlsTemplate from './paginate_controls.html'; + +export function PaginateDirectiveProvider($parse, $compile) { + return { + restrict: 'E', + scope: true, + link: { + pre: function($scope, $el, attrs) { + if (_.isUndefined(attrs.bottomControls)) attrs.bottomControls = true; + if ($el.find('paginate-controls.paginate-bottom').length === 0 && attrs.bottomControls) { + $el.append($compile('')($scope)); + } + }, + post: function($scope, $el, attrs) { + if (_.isUndefined(attrs.topControls)) attrs.topControls = false; + if ($el.find('paginate-controls.paginate-top').length === 0 && attrs.topControls) { + $el.prepend($compile('')($scope)); + } + + const paginate = $scope.paginate; + + // add some getters to the controller powered by attributes + paginate.getList = $parse(attrs.list); + paginate.perPageProp = attrs.perPageProp; + + if (attrs.perPage) { + paginate.perPage = attrs.perPage; + $scope.showSelector = false; + } else { + $scope.showSelector = true; + } + + paginate.otherWidthGetter = $parse(attrs.otherWidth); + + paginate.init(); + }, + }, + controllerAs: 'paginate', + controller: function($scope, $document) { + const self = this; + const ALL = 0; + const allSizeTitle = i18n.translate( + 'common.ui.directives.paginate.size.allDropDownOptionLabel', + { + defaultMessage: 'All', + } + ); + + self.sizeOptions = [ + { title: '10', value: 10 }, + { title: '25', value: 25 }, + { title: '100', value: 100 }, + { title: allSizeTitle, value: ALL }, + ]; + + // setup the watchers, called in the post-link function + self.init = function() { + self.perPage = _.parseInt(self.perPage) || $scope[self.perPageProp]; + + $scope.$watchMulti(['paginate.perPage', self.perPageProp, self.otherWidthGetter], function( + vals, + oldVals + ) { + const intChanges = vals[0] !== oldVals[0]; + + if (intChanges) { + if (!setPerPage(self.perPage)) { + // if we are not able to set the external value, + // render now, otherwise wait for the external value + // to trigger the watcher again + self.renderList(); + } + return; + } + + self.perPage = _.parseInt(self.perPage) || $scope[self.perPageProp]; + if (self.perPage == null) { + self.perPage = ALL; + return; + } + + self.renderList(); + }); + + $scope.$watch('page', self.changePage); + $scope.$watchCollection(self.getList, function(list) { + $scope.list = list; + self.renderList(); + }); + }; + + self.goToPage = function(number) { + if (number) { + if (number.hasOwnProperty('number')) number = number.number; + $scope.page = $scope.pages[number - 1] || $scope.pages[0]; + } + }; + + self.goToTop = function goToTop() { + $document.scrollTop(0); + }; + + self.renderList = function() { + $scope.pages = []; + if (!$scope.list) return; + + const perPage = _.parseInt(self.perPage); + const count = perPage ? Math.ceil($scope.list.length / perPage) : 1; + + _.times(count, function(i) { + let page; + + if (perPage) { + const start = perPage * i; + page = $scope.list.slice(start, start + perPage); + } else { + page = $scope.list.slice(0); + } + + page.number = i + 1; + page.i = i; + + page.count = count; + page.first = page.number === 1; + page.last = page.number === count; + page.firstItem = (page.number - 1) * perPage + 1; + page.lastItem = Math.min(page.number * perPage, $scope.list.length); + + page.prev = $scope.pages[i - 1]; + if (page.prev) page.prev.next = page; + + $scope.pages.push(page); + }); + + // set the new page, or restore the previous page number + if ($scope.page && $scope.page.i < $scope.pages.length) { + $scope.page = $scope.pages[$scope.page.i]; + } else { + $scope.page = $scope.pages[0]; + } + + if ($scope.page && $scope.onPageChanged) { + $scope.onPageChanged($scope.page); + } + }; + + self.changePage = function(page) { + if (!page) { + $scope.otherPages = null; + return; + } + + // setup the list of the other pages to link to + $scope.otherPages = []; + const width = +self.otherWidthGetter($scope) || 5; + let left = page.i - Math.round((width - 1) / 2); + let right = left + width - 1; + + // shift neg count from left to right + if (left < 0) { + right += 0 - left; + left = 0; + } + + // shift extra right nums to left + const lastI = page.count - 1; + if (right > lastI) { + right = lastI; + left = right - width + 1; + } + + for (let i = left; i <= right; i++) { + const other = $scope.pages[i]; + + if (!other) continue; + + $scope.otherPages.push(other); + if (other.last) $scope.otherPages.containsLast = true; + if (other.first) $scope.otherPages.containsFirst = true; + } + + if ($scope.onPageChanged) { + $scope.onPageChanged($scope.page); + } + }; + + function setPerPage(val) { + let $ppParent = $scope; + + while ($ppParent && !_.has($ppParent, self.perPageProp)) { + $ppParent = $ppParent.$parent; + } + + if ($ppParent) { + $ppParent[self.perPageProp] = val; + return true; + } + } + }, + }; +} + +export function PaginateControlsDirectiveProvider() { + // this directive is automatically added by paginate if not found within it's $el + return { + restrict: 'E', + template: paginateControlsTemplate, + }; +} diff --git a/src/legacy/ui/public/directives/partials/paginate_controls.html b/src/plugins/kibana_legacy/public/paginate/paginate_controls.html similarity index 100% rename from src/legacy/ui/public/directives/partials/paginate_controls.html rename to src/plugins/kibana_legacy/public/paginate/paginate_controls.html From f880e2d1a85771083979faaacac917674396dbc2 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Mon, 17 Feb 2020 11:19:31 +0100 Subject: [PATCH 2/4] fix types --- src/plugins/kibana_legacy/public/paginate/paginate.d.ts | 4 ++-- x-pack/legacy/plugins/rollup/public/legacy_imports.ts | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/plugins/kibana_legacy/public/paginate/paginate.d.ts b/src/plugins/kibana_legacy/public/paginate/paginate.d.ts index 7425146887df9..a40b869b2ccbb 100644 --- a/src/plugins/kibana_legacy/public/paginate/paginate.d.ts +++ b/src/plugins/kibana_legacy/public/paginate/paginate.d.ts @@ -17,5 +17,5 @@ * under the License. */ -export type PaginateDirectiveProvider = any; -export type PaginateControlsDirectiveProvider = any; +export function PaginateDirectiveProvider($parse: any, $compile: any): any; +export function PaginateControlsDirectiveProvider(): any; diff --git a/x-pack/legacy/plugins/rollup/public/legacy_imports.ts b/x-pack/legacy/plugins/rollup/public/legacy_imports.ts index 07155a4b0a60e..46f6ed892d1bb 100644 --- a/x-pack/legacy/plugins/rollup/public/legacy_imports.ts +++ b/x-pack/legacy/plugins/rollup/public/legacy_imports.ts @@ -7,5 +7,7 @@ // @ts-ignore export { findIllegalCharactersInIndexName, INDEX_ILLEGAL_CHARACTERS_VISIBLE } from 'ui/indices'; -export { AggTypeFilters } from 'ui/agg_types'; -export { AggTypeFieldFilters } from 'ui/agg_types'; +export { + AggTypeFilters, + AggTypeFieldFilters, +} from '../../../../../src/legacy/core_plugins/data/public'; From 7abddc4c9d1434b0a116c4a5716777a2fe9b5554 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Mon, 17 Feb 2020 12:32:00 +0100 Subject: [PATCH 3/4] fix i18n ids --- src/plugins/kibana_legacy/public/paginate/paginate.js | 9 +++------ .../kibana_legacy/public/paginate/paginate_controls.html | 4 ++-- x-pack/plugins/translations/translations/ja-JP.json | 6 +++--- x-pack/plugins/translations/translations/zh-CN.json | 6 +++--- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/plugins/kibana_legacy/public/paginate/paginate.js b/src/plugins/kibana_legacy/public/paginate/paginate.js index 2a492f3c72f8e..f7e623cdabd86 100644 --- a/src/plugins/kibana_legacy/public/paginate/paginate.js +++ b/src/plugins/kibana_legacy/public/paginate/paginate.js @@ -60,12 +60,9 @@ export function PaginateDirectiveProvider($parse, $compile) { controller: function($scope, $document) { const self = this; const ALL = 0; - const allSizeTitle = i18n.translate( - 'common.ui.directives.paginate.size.allDropDownOptionLabel', - { - defaultMessage: 'All', - } - ); + const allSizeTitle = i18n.translate('kibana_legacy.paginate.size.allDropDownOptionLabel', { + defaultMessage: 'All', + }); self.sizeOptions = [ { title: '10', value: 10 }, diff --git a/src/plugins/kibana_legacy/public/paginate/paginate_controls.html b/src/plugins/kibana_legacy/public/paginate/paginate_controls.html index c40021507c233..a553bc2231720 100644 --- a/src/plugins/kibana_legacy/public/paginate/paginate_controls.html +++ b/src/plugins/kibana_legacy/public/paginate/paginate_controls.html @@ -3,7 +3,7 @@ ng-if="linkToTop" ng-click="paginate.goToTop()" data-test-subj="paginateControlsLinkToTop" - i18n-id="common.ui.paginateControls.scrollTopButtonLabel" + i18n-id="kibana_legacy.paginate.controls.scrollTopButtonLabel" i18n-default-message="Scroll to top" > @@ -86,7 +86,7 @@