-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Expression datatable formatting hints #43091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
141394c
cb43035
a96d594
dfeb7da
814eafa
8dc7b85
7c55f8f
27a8a40
4738f82
6303a0f
685b64b
80e2022
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,11 +19,10 @@ | |
|
|
||
| import { get } from 'lodash'; | ||
| import { i18n } from '@kbn/i18n'; | ||
| // @ts-ignore | ||
| import { CourierRequestHandlerProvider } from 'ui/vis/request_handlers/courier'; | ||
| // @ts-ignore | ||
| import { AggConfigs } from 'ui/vis/agg_configs.js'; | ||
|
|
||
| import { createFormat } from 'ui/visualize/loader/pipeline_helpers/utilities'; | ||
| import chrome from 'ui/chrome'; | ||
|
|
||
| // need to get rid of angular from these | ||
|
|
@@ -35,7 +34,7 @@ import { IndexPatternsProvider } from '../../../data/public'; | |
| const courierRequestHandlerProvider = CourierRequestHandlerProvider; | ||
| const courierRequestHandler = courierRequestHandlerProvider().handler; | ||
|
|
||
| import { ExpressionFunction } from '../../types'; | ||
| import { ExpressionFunction, KibanaDatatableColumn } from '../../types'; | ||
| import { KibanaContext, KibanaDatatable } from '../../common'; | ||
|
|
||
| const name = 'esaggs'; | ||
|
|
@@ -46,6 +45,7 @@ interface Arguments { | |
| index: string | null; | ||
| metricsAtAllLevels: boolean; | ||
| partialRows: boolean; | ||
| includeFormatHints: boolean; | ||
| aggConfigs: string; | ||
| } | ||
|
|
||
|
|
@@ -76,6 +76,11 @@ export const esaggs = (): ExpressionFunction<typeof name, Context, Arguments, Re | |
| default: false, | ||
| help: '', | ||
| }, | ||
| includeFormatHints: { | ||
| types: ['boolean'], | ||
| default: false, | ||
| help: '', | ||
| }, | ||
| aggConfigs: { | ||
| types: ['string'], | ||
| default: '""', | ||
|
|
@@ -98,26 +103,34 @@ export const esaggs = (): ExpressionFunction<typeof name, Context, Arguments, Re | |
| searchSource.setField('index', indexPattern); | ||
| searchSource.setField('size', 0); | ||
|
|
||
| const response: Pick<KibanaDatatable, 'columns' | 'rows'> = await courierRequestHandler({ | ||
| const response = await courierRequestHandler({ | ||
| searchSource, | ||
| aggs, | ||
| timeRange: get(context, 'timeRange', null), | ||
| query: get(context, 'query', null), | ||
| filters: get(context, 'filters', null), | ||
| timeRange: get(context, 'timeRange', undefined), | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this went in because the existing |
||
| query: get(context, 'query', undefined), | ||
| filters: get(context, 'filters', undefined), | ||
| forceFetch: true, | ||
| metricsAtAllLevels: args.metricsAtAllLevels, | ||
| partialRows: args.partialRows, | ||
| inspectorAdapters: handlers.inspectorAdapters, | ||
| queryFilter, | ||
| }); | ||
|
|
||
| return { | ||
| const table: KibanaDatatable = { | ||
| type: 'kibana_datatable', | ||
| rows: response.rows, | ||
| columns: response.columns.map(column => ({ | ||
| id: column.id, | ||
| name: column.name, | ||
| })), | ||
| columns: response.columns.map(column => { | ||
| const cleanedColumn: KibanaDatatableColumn = { | ||
| id: column.id, | ||
| name: column.name, | ||
| }; | ||
| if (args.includeFormatHints) { | ||
| cleanedColumn.formatHint = createFormat(column.aggConfig); | ||
| } | ||
| return cleanedColumn; | ||
| }), | ||
| }; | ||
|
|
||
| return table; | ||
| }, | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| * 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 { KibanaDatatableRow } from 'src/plugins/data/common'; | ||
| import { AggConfig } from '../agg_config'; | ||
| import { RequestHandler } from './request_handlers'; | ||
|
|
||
| interface CourierResponse { | ||
| rows: KibanaDatatableRow[]; | ||
| columns: Array<{ | ||
| id: string; | ||
| name: string; | ||
| aggConfig: AggConfig; | ||
| }>; | ||
| } | ||
|
|
||
| type CourierRequestHandler = RequestHandler<CourierResponse>; | ||
|
|
||
| export declare function CourierRequestHandlerProvider(): { | ||
| name: 'courier'; | ||
| handler: CourierRequestHandler; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,7 @@ export interface RequestHandlerParams { | |
| visParams?: any; | ||
| } | ||
|
|
||
| export type RequestHandler = <T>(params: RequestHandlerParams) => T; | ||
| export type RequestHandler<T = unknown> = (params: RequestHandlerParams) => T; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moving the type parameter to the outer type to be able to specify it in courier-specific type. Inferred types in other usages should work like before. |
||
|
|
||
| export interface RequestHandlerDescription { | ||
| name: string; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.