From c9c2b82dfb903de13e74c2a78ff35dd631351941 Mon Sep 17 00:00:00 2001 From: fbaligand Date: Tue, 7 Dec 2021 22:55:28 +0100 Subject: [PATCH] fix lint issues --- .eslintrc.yml | 1 + public/agg_table/stream_saver.js | 2 + .../components/enhanced_table_vis_options.tsx | 2 +- public/components/field.tsx | 2 +- public/components/field_column.tsx | 2 +- .../build_tabular_inspector_data.ts | 97 ------------------- .../data_load/kibana_cloned_code/courier.ts | 12 +-- .../kibana_cloned_code/create_filter.ts | 63 ------------ public/data_load/kibana_cloned_code/utils.ts | 4 +- public/data_load/visualization_fn.ts | 12 +-- public/document-table-vis.js | 4 +- public/enhanced-table-vis.js | 6 +- public/legacy.ts | 19 ---- public/plugin.ts | 4 +- public/time_range_computer.ts | 8 +- public/to_ast.ts | 16 +-- public/vis_controller.ts | 10 +- public/vis_legacy_renderer.tsx | 4 +- 18 files changed, 37 insertions(+), 231 deletions(-) delete mode 100644 public/data_load/kibana_cloned_code/build_tabular_inspector_data.ts delete mode 100644 public/data_load/kibana_cloned_code/create_filter.ts delete mode 100644 public/legacy.ts diff --git a/.eslintrc.yml b/.eslintrc.yml index f16a8d99..b69ee700 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -8,6 +8,7 @@ parserOptions: rules: "@kbn/eslint/require-license-header": off "prettier/prettier": off + "import/no-extraneous-dependencies": off "template-curly-spacing" : 0 indent: - off diff --git a/public/agg_table/stream_saver.js b/public/agg_table/stream_saver.js index 0df7e1fb..b4410ae7 100644 --- a/public/agg_table/stream_saver.js +++ b/public/agg_table/stream_saver.js @@ -1,8 +1,10 @@ +/* eslint-disable no-undef */ function initStreamSaver() { const global = typeof window === 'object' ? window : this; let mitmTransporter = null; let supportsTransferable = false; + // eslint-disable-next-line no-empty const test = fn => { try { fn(); } catch (e) {} }; const isSecureContext = global.isSecureContext; // TODO: Must come up with a real detection test (#69) diff --git a/public/components/enhanced_table_vis_options.tsx b/public/components/enhanced_table_vis_options.tsx index 15a8e6be..002a1bd2 100644 --- a/public/components/enhanced_table_vis_options.tsx +++ b/public/components/enhanced_table_vis_options.tsx @@ -88,7 +88,7 @@ function hasSplitColsBucket(aggs: IAggConfigs) { return some(aggs.aggs, function(agg) { return agg.schema === 'splitcols' && agg.enabled; }); -}; +} function EnhancedTableOptions({ aggs, diff --git a/public/components/field.tsx b/public/components/field.tsx index 78b3eecf..fa9a4a13 100644 --- a/public/components/field.tsx +++ b/public/components/field.tsx @@ -22,7 +22,7 @@ export interface FieldParamEditorProps { function createIndexedFields(indexPatternFields: IndexPatternField[]): ComboBoxGroupedOptions { const indexedFields = []; indexPatternFields.forEach(field => { - let indexedField = indexedFields.find(indexedField => indexedField.label === field.type); + let indexedField = indexedFields.find(f => f.label === field.type); if (!indexedField) { indexedField = { label: field.type, options: [] }; indexedFields.push(indexedField); diff --git a/public/components/field_column.tsx b/public/components/field_column.tsx index b8e65d6f..bf986a22 100644 --- a/public/components/field_column.tsx +++ b/public/components/field_column.tsx @@ -1,8 +1,8 @@ import { clone } from 'lodash'; import React, { useEffect } from 'react'; import { i18n } from '@kbn/i18n'; -import { IndexPatternField } from '../../../../src/plugins/data/public'; import { EuiDraggable, EuiIconTip, EuiSpacer, EuiAccordion, EuiToolTip, EuiButtonIcon, EuiButtonIconProps } from '@elastic/eui'; +import { IndexPatternField } from '../../../../src/plugins/data/public'; import { TextInputOption } from './text_input'; import { FieldParamEditor } from './field'; diff --git a/public/data_load/kibana_cloned_code/build_tabular_inspector_data.ts b/public/data_load/kibana_cloned_code/build_tabular_inspector_data.ts deleted file mode 100644 index 347c6b2f..00000000 --- a/public/data_load/kibana_cloned_code/build_tabular_inspector_data.ts +++ /dev/null @@ -1,97 +0,0 @@ -import { set } from '@elastic/safer-lodash-set'; -import { FormattedData } from '../../../../../src/plugins/inspector/public'; -import { FormatFactory } from './utils'; -import { TabbedTable } from '../../../../../src/plugins/data/public'; -import { createFilter } from './create_filter'; - -/** - * Clone of: '../../../../../src/plugins/data/public/search/expressions/build_tabular_inspector_data.ts' - */ - - -/** - * @deprecated - * - * Do not use this function. - * - * @todo This function is used only by Courier. Courier will - * soon be removed, and this function will be deleted, too. If Courier is not removed, - * move this function inside Courier. - * - * --- - * - * This function builds tabular data from the response and attaches it to the - * inspector. It will only be called when the data view in the inspector is opened. - */ -export async function buildTabularInspectorData( - table: TabbedTable, - { - queryFilter, - deserializeFieldFormat, - }: { - queryFilter: { addFilters: (filter: any) => void }; - deserializeFieldFormat: FormatFactory; - } -) { - const aggConfigs = table.columns.map((column) => column.aggConfig); - const rows = table.rows.map((row) => { - return table.columns.reduce>((prev, cur, colIndex) => { - const value = row[cur.id]; - - let format = cur.aggConfig.toSerializedFieldFormat(); - if (Object.keys(format).length < 1) { - // If no format exists, fall back to string as a default - format = { id: 'string' }; - } - const fieldFormatter = deserializeFieldFormat(format); - - prev[`col-${colIndex}-${cur.aggConfig.id}`] = new FormattedData( - value, - fieldFormatter.convert(value) - ); - return prev; - }, {}); - }); - - const columns = table.columns.map((col, colIndex) => { - const field = col.aggConfig.getField(); - const isCellContentFilterable = col.aggConfig.isFilterable() && (!field || field.filterable); - return { - name: col.name, - field: `col-${colIndex}-${col.aggConfig.id}`, - filter: - isCellContentFilterable && - ((value: { raw: unknown }) => { - const rowIndex = rows.findIndex( - (row) => row[`col-${colIndex}-${col.aggConfig.id}`].raw === value.raw - ); - const filter = createFilter(aggConfigs, table, colIndex, rowIndex, value.raw); - - if (filter) { - queryFilter.addFilters(filter); - } - }), - filterOut: - isCellContentFilterable && - ((value: { raw: unknown }) => { - const rowIndex = rows.findIndex( - (row) => row[`col-${colIndex}-${col.aggConfig.id}`].raw === value.raw - ); - const filter = createFilter(aggConfigs, table, colIndex, rowIndex, value.raw); - - if (filter) { - const notOther = value.raw !== '__other__'; - const notMissing = value.raw !== '__missing__'; - if (Array.isArray(filter)) { - filter.forEach((f) => set(f, 'meta.negate', notOther && notMissing)); - } else { - set(filter, 'meta.negate', notOther && notMissing); - } - queryFilter.addFilters(filter); - } - }), - }; - }); - - return { columns, rows }; -} diff --git a/public/data_load/kibana_cloned_code/courier.ts b/public/data_load/kibana_cloned_code/courier.ts index 8775659b..35f3234b 100644 --- a/public/data_load/kibana_cloned_code/courier.ts +++ b/public/data_load/kibana_cloned_code/courier.ts @@ -1,4 +1,3 @@ -import { hasIn } from 'lodash'; import { i18n } from '@kbn/i18n'; import { calculateObjectHash } from '../../../../../src/plugins/kibana_utils/public'; @@ -19,11 +18,6 @@ import { tabifyAggResponse, TimeRange, } from '../../../../../src/plugins/data/common'; -import { FilterManager } from '../../../../../src/plugins/data/public/query'; -import { buildTabularInspectorData } from './build_tabular_inspector_data'; -import { search } from '../../../../../src/plugins/data/public'; - -import { getFormatService as getFieldFormats } from '../../services'; /** * Clone of: ../../../../../src/plugins/data/public/search/expressions/esaggs.ts @@ -38,7 +32,6 @@ interface RequestHandlerParams { query?: Query; filters?: Filter[]; forceFetch: boolean; - filterManager: FilterManager; uiState?: PersistedState; partialRows?: boolean; inspectorAdapters: Adapters; @@ -61,7 +54,6 @@ export const handleCourierRequest = async ({ metricsAtAllLevels, inspectorAdapters, searchSessionId, - filterManager, abortSignal, }: RequestHandlerParams) => { // Create a new search source that inherits the original search source @@ -138,9 +130,9 @@ export const handleCourierRequest = async ({ request.stats(getRequestInspectorStats(requestSearchSource)); try { - const response = await requestSearchSource.fetch({ + const response = await requestSearchSource.fetch({ abortSignal, - sessionId: searchSessionId + sessionId: searchSessionId }); (searchSource as any).lastQuery = queryHash; diff --git a/public/data_load/kibana_cloned_code/create_filter.ts b/public/data_load/kibana_cloned_code/create_filter.ts deleted file mode 100644 index a4bdd137..00000000 --- a/public/data_load/kibana_cloned_code/create_filter.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { IAggConfig } from '../../../../../src/plugins/data/public/search/aggs'; -import { TabbedTable } from '../../../../../src/plugins/data/public'; -import { Filter } from '../../../../../src/plugins/data/common'; - -/** - * Clone of: '../../../../../src/plugins/data/public/search/expressions/create_filter.ts' - */ - -const getOtherBucketFilterTerms = (table: TabbedTable, columnIndex: number, rowIndex: number) => { - if (rowIndex === -1) { - return []; - } - - // get only rows where cell value matches current row for all the fields before columnIndex - const rows = table.rows.filter((row) => { - return table.columns.every((column, i) => { - return row[column.id] === table.rows[rowIndex][column.id] || i >= columnIndex; - }); - }); - const terms = rows.map((row) => row[table.columns[columnIndex].id]); - - return [ - ...new Set( - terms.filter((term) => { - const notOther = term !== '__other__'; - const notMissing = term !== '__missing__'; - return notOther && notMissing; - }) - ), - ]; -}; - -export const createFilter = ( - aggConfigs: IAggConfig[], - table: TabbedTable, - columnIndex: number, - rowIndex: number, - cellValue: any -) => { - const column = table.columns[columnIndex]; - const aggConfig = aggConfigs[columnIndex]; - let filter: Filter[] = []; - const value: any = rowIndex > -1 ? table.rows[rowIndex][column.id] : cellValue; - if (value === null || value === undefined || !aggConfig.isFilterable()) { - return; - } - if (aggConfig.type.name === 'terms' && aggConfig.params.otherBucket) { - const terms = getOtherBucketFilterTerms(table, columnIndex, rowIndex); - filter = aggConfig.createFilter(value, { terms }); - } else { - filter = aggConfig.createFilter(value); - } - - if (!filter) { - return; - } - - if (!Array.isArray(filter)) { - filter = [filter]; - } - - return filter; -}; diff --git a/public/data_load/kibana_cloned_code/utils.ts b/public/data_load/kibana_cloned_code/utils.ts index da240e12..8b28fccf 100644 --- a/public/data_load/kibana_cloned_code/utils.ts +++ b/public/data_load/kibana_cloned_code/utils.ts @@ -8,7 +8,7 @@ export function serializeAggConfig(aggConfig) { const sourceParams = { indexPatternId: aggConfig.getIndexPattern().id, ...aggConfig.serialize() - } + }; return { type: aggConfig.type.name, @@ -17,7 +17,7 @@ export function serializeAggConfig(aggConfig) { source: 'esaggs', sourceParams }; -}; +} /** * Clone of: '../../../../../src/plugins/data/common/field_formats/utils.ts' diff --git a/public/data_load/visualization_fn.ts b/public/data_load/visualization_fn.ts index 584d1f50..a3919319 100644 --- a/public/data_load/visualization_fn.ts +++ b/public/data_load/visualization_fn.ts @@ -1,6 +1,5 @@ import { get } from 'lodash'; import { i18n } from '@kbn/i18n'; -import { PersistedState } from '../../../../src/plugins/visualizations/public'; import { ExpressionFunctionDefinition, Render } from '../../../../src/plugins/expressions/public'; import { getIndexPatterns, getFilterManager, getSearchService, getVisualization } from '../services'; import { enhancedTableRequestHandler } from './enhanced-table-request-handler'; @@ -52,7 +51,7 @@ const expressionFunction = (visName: VisName, responseHandler: ResponseHandler): // TODO: Below `help` keys should be internationalized once this function // TODO: is moved to visualizations plugin. index: { - //types: ['string', 'null'], + // types: ['string', 'null'], types: ['string'], default: '', help: 'Index', @@ -93,24 +92,19 @@ const expressionFunction = (visName: VisName, responseHandler: ResponseHandler): const schemas = args.schemas ? JSON.parse(args.schemas) : {}; const indexPattern = args.index ? await getIndexPatterns().get(args.index) : null; - const uiStateParams = args.uiState ? JSON.parse(args.uiState) : {}; - const uiState = new PersistedState(uiStateParams); - const aggConfigsState = args.aggConfigs ? JSON.parse(args.aggConfigs) : []; const aggs = indexPattern ? getSearchService().aggs.createAggConfigs(indexPattern, aggConfigsState) : undefined; - const visType = getVisualization().get(visName) + const visType = getVisualization().get(visName); input = await enhancedTableRequestHandler({ partialRows: args.partialRows, metricsAtAllLevels: args.metricsAtAllLevels, - //index: indexPattern, visParams: visConfigParams, timeRange: get(input, 'timeRange', null), query: get(input, 'query', null), filters: get(input, 'filters', null), - //uiState, inspectorAdapters, queryFilter: getFilterManager(), aggs, @@ -143,7 +137,7 @@ const expressionFunction = (visName: VisName, responseHandler: ResponseHandler): } const response = await responseHandler(input); - + return { type: 'render', as: visName, diff --git a/public/document-table-vis.js b/public/document-table-vis.js index 63b7abe7..de076212 100644 --- a/public/document-table-vis.js +++ b/public/document-table-vis.js @@ -1,9 +1,6 @@ import { i18n } from '@kbn/i18n'; import tableVisTemplate from './enhanced-table-vis.html'; -import { getEnhancedTableVisualizationController } from './vis_controller'; -import { enhancedTableRequestHandler } from './data_load/enhanced-table-request-handler'; -import { documentTableResponseHandler } from './data_load/document-table-response-handler'; import { DocumentTableData } from './components/document_table_vis_data'; import { EnhancedTableOptions } from './components/enhanced_table_vis_options_lazy'; import { VIS_EVENT_TO_TRIGGER } from '../../../src/plugins/visualizations/public'; @@ -12,6 +9,7 @@ import { DOC_TABLE_VIS_NAME } from './types'; // define the visType object, which kibana will use to display and configure new Vis object of this type. +// eslint-disable-next-line no-unused-vars export function documentTableVisTypeDefinition (core, context) { return { requiresSearch: true, diff --git a/public/enhanced-table-vis.js b/public/enhanced-table-vis.js index c63dadee..dfc82a69 100644 --- a/public/enhanced-table-vis.js +++ b/public/enhanced-table-vis.js @@ -2,17 +2,15 @@ import { i18n } from '@kbn/i18n'; import { AggGroupNames } from '../../../src/plugins/data/public'; import tableVisTemplate from './enhanced-table-vis.html'; -import { getEnhancedTableVisualizationController } from './vis_controller'; -import { enhancedTableRequestHandler } from './data_load/enhanced-table-request-handler'; -import { enhancedTableResponseHandler } from './data_load/enhanced-table-response-handler'; import { EnhancedTableOptions } from './components/enhanced_table_vis_options_lazy'; import { VIS_EVENT_TO_TRIGGER } from '../../../src/plugins/visualizations/public'; -import { ENH_TABLE_VIS_NAME } from './types' +import { ENH_TABLE_VIS_NAME } from './types'; import { enhancedTableToExpressionAst } from './to_ast'; // define the visType object, which kibana will use to display and configure new Vis object of this type. +// eslint-disable-next-line no-unused-vars export function enhancedTableVisTypeDefinition (core, context) { return { requiresSearch: true, diff --git a/public/legacy.ts b/public/legacy.ts deleted file mode 100644 index 43eee8b4..00000000 --- a/public/legacy.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { PluginInitializerContext } from '../../../src/core/public'; -import { npSetup, npStart } from 'ui/new_platform'; -import { plugin } from '.'; - -import { TablePluginSetupDependencies } from './plugin'; -import { TablePluginStartDependencies } from './plugin'; - -const plugins: Readonly = { - visualizations: npSetup.plugins.visualizations, -}; - -const startData: Readonly = { - data: npStart.plugins.data -} - -const pluginInstance = plugin({} as PluginInitializerContext); - -export const setup = pluginInstance.setup(npSetup.core, plugins); -export const start = pluginInstance.start(npStart.core, startData); diff --git a/public/plugin.ts b/public/plugin.ts index de6c5a9f..5fb5c6af 100644 --- a/public/plugin.ts +++ b/public/plugin.ts @@ -6,7 +6,7 @@ import { documentTableVisTypeDefinition } from './document-table-vis'; import { DataPublicPluginStart } from '../../../src/plugins/data/public'; import { setFilterManager, setFormatService, setIndexPatterns, setKibanaLegacy, setNotifications, setQueryService, setSearchService, setVisualization } from './services'; -import { KibanaLegacyStart } from '../../../src/plugins/kibana_legacy/public'; +import { KibanaLegacyStart } from '../../../src/plugins/kibana_legacy/public'; import { Plugin as ExpressionsPublicPlugin } from '../../../src/plugins/expressions/public'; import { getEnhancedTableVisLegacyRenderer, getDocumentTableVisLegacyRenderer } from './vis_legacy_renderer'; @@ -62,6 +62,6 @@ export class EnhancedTablePlugin implements Plugin, void> { setSearchService(deps.data.search); setIndexPatterns(deps.data.indexPatterns); setFilterManager(deps.data.query.filterManager); - setVisualization(deps.visualizations) + setVisualization(deps.visualizations); } } diff --git a/public/time_range_computer.ts b/public/time_range_computer.ts index 942d14b5..1e57b397 100644 --- a/public/time_range_computer.ts +++ b/public/time_range_computer.ts @@ -47,11 +47,11 @@ function parseDathMathExpression(dateMathExpression: string, roundUp: boolean, n const date: Date = new Date(nowReference); // update date with +/- intervals - const matches = dateMathExpression.match(/([\+\-][0-9]+[yMwdHhms])/g); + const matches = dateMathExpression.match(/([+-][0-9]+[yMwdHhms])/g); if (matches) { matches.forEach(match => { - const multiplier = parseInt(match.substring(0, 1) + '1'); - const incrementCount = parseInt(match.substring(1, match.length - 1)) * multiplier; + const multiplier = parseInt(match.substring(0, 1) + '1', 10); + const incrementCount = parseInt(match.substring(1, match.length - 1), 10) * multiplier; const unit = match.substring(match.length - 1); incrementDateUnit(date, incrementCount, unit); }); @@ -189,6 +189,6 @@ export function computeTimeRange(timeRange?: TimeRangeInput, dayOfWeek?: string) duration: computeDuration(from, to), from: computeDateStructure(from), to: computeDateStructure(to) - } + }; } \ No newline at end of file diff --git a/public/to_ast.ts b/public/to_ast.ts index ac170a3d..8e7277e3 100644 --- a/public/to_ast.ts +++ b/public/to_ast.ts @@ -2,24 +2,24 @@ import { buildExpression, buildExpressionFunction, ExpressionAstExpression } fro import { getVisSchemas, VisToExpressionAst } from '../../../src/plugins/visualizations/public'; import { DocumentTableVisDataParams } from './components/document_table_vis_data'; import { CommonExpressionFunctionDefinition } from './data_load/visualization_fn'; -import { DocumentTableVisConfig, EnhancedTableVisConfig, ENH_TABLE_VIS_NAME, VisName } from './types'; -import { DOC_TABLE_VIS_NAME } from './types' +import { DocumentTableVisConfig, EnhancedTableVisConfig, ENH_TABLE_VIS_NAME } from './types'; +import { DOC_TABLE_VIS_NAME } from './types'; import { EnhancedTableVisParams } from './components/enhanced_table_vis_options'; export type CommonVisDataParams = DocumentTableVisDataParams | EnhancedTableVisParams export type CommonVisConfig = DocumentTableVisConfig | EnhancedTableVisConfig -type CommonVisToExpressionAst = (vis, params, name) => ExpressionAstExpression | Promise; +type CommonVisToExpressionAst = (vis, params, name) => ExpressionAstExpression | Promise; export const documentTableToExpressionAst: VisToExpressionAst = (vis,params) => { - return toExpressionAst(vis,params,DOC_TABLE_VIS_NAME) -} + return toExpressionAst(vis,params,DOC_TABLE_VIS_NAME); +}; export const enhancedTableToExpressionAst: VisToExpressionAst = (vis,params) => { - return toExpressionAst(vis,params,ENH_TABLE_VIS_NAME) -} + return toExpressionAst(vis,params,ENH_TABLE_VIS_NAME); +}; -const toExpressionAst: CommonVisToExpressionAst = (vis, params, visName) => { +const toExpressionAst: CommonVisToExpressionAst = (vis, params, visName) => { const schemas = getVisSchemas(vis, params); diff --git a/public/vis_controller.ts b/public/vis_controller.ts index a02cc7f6..13c98a1d 100644 --- a/public/vis_controller.ts +++ b/public/vis_controller.ts @@ -1,13 +1,13 @@ -import { CoreSetup, PluginInitializerContext } from '../../../src/core/public'; import angular, { IModule, auto, IRootScopeService, IScope, ICompileService } from 'angular'; import $ from 'jquery'; +import { CoreSetup, PluginInitializerContext } from '../../../src/core/public'; import { VisParams } from '../../../src/plugins/visualizations/public'; import { getAngularModule } from './get_inner_angular'; import { getKibanaLegacy, getVisualization } from './services'; import { initTableVisLegacyModule } from './table_vis_legacy_module'; // @ts-ignore -import enhancedTableVisTemplate from './enhanced-table-vis.html' +import enhancedTableVisTemplate from './enhanced-table-vis.html'; import { BaseVisType } from '../../../src/plugins/visualizations/public/vis_types'; import { IInterpreterRenderHandlers } from '../../../src/plugins/expressions'; @@ -30,13 +30,13 @@ export function getEnhancedTableVisualizationController( constructor(domeElement: Element, visName: string) { this.el = $(domeElement); - this.vis = getVisualization().get(visName) + this.vis = getVisualization().get(visName); } getInjector() { if (!this.injector) { const mountpoint = document.createElement('div'); - mountpoint.className = "visualization"; + mountpoint.className = 'visualization'; this.injector = angular.bootstrap(mountpoint, [innerAngularName]); this.el.append(mountpoint); } @@ -60,7 +60,7 @@ export function getEnhancedTableVisualizationController( ): Promise { await this.initLocalAngular(); - return new Promise(async (resolve, reject) => { + return new Promise((resolve, reject) => { if (!this.$rootScope) { const $injector = this.getInjector(); this.$rootScope = $injector.get('$rootScope'); diff --git a/public/vis_legacy_renderer.tsx b/public/vis_legacy_renderer.tsx index 7979ad5a..b45c9c6e 100644 --- a/public/vis_legacy_renderer.tsx +++ b/public/vis_legacy_renderer.tsx @@ -11,14 +11,14 @@ export const getEnhancedTableVisLegacyRenderer: ( context: PluginInitializerContext ) => ExpressionRenderDefinition = (core, context) => ({ ...getCommonVisLegacyRenderer(core,context,ENH_TABLE_VIS_NAME) -}) +}); export const getDocumentTableVisLegacyRenderer: ( core: CoreSetup, context: PluginInitializerContext ) => ExpressionRenderDefinition = (core, context) => ({ ...getCommonVisLegacyRenderer(core,context,DOC_TABLE_VIS_NAME) -}) +}); const getCommonVisLegacyRenderer: ( core: CoreSetup,