Skip to content

Commit

Permalink
[Timelion] Communicate the index pattern to the dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwizp committed Feb 8, 2021
1 parent e4794af commit 330797f
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ snapshots.js
/src/core/lib/kbn_internal_native_observable
/src/legacy/plugin_discovery/plugin_pack/__tests__/fixtures/plugins/broken
/src/plugins/data/common/es_query/kuery/ast/_generated_/**
/src/plugins/vis_type_timelion/public/_generated_/**
/src/plugins/vis_type_timelion/common/_generated_/**
/x-pack/legacy/plugins/**/__tests__/fixtures/**
/x-pack/plugins/apm/e2e/tmp/*
/x-pack/plugins/canvas/canvas_plugin
Expand Down
16 changes: 16 additions & 0 deletions src/plugins/vis_type_timelion/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,19 @@ export interface ITimelionFunction {
[key: string]: TimelionFunctionArgs[];
};
}

export interface TimelionExpressionNamedArgument {
function: string;
type: 'namedArg';
location: {
min: number;
max: number;
};
name: string;
text: string;
value: {
type: string;
value: string;
text: string;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { monaco } from '@kbn/monaco';
import { Parser } from 'pegjs';

// @ts-ignore
import { parse } from '../_generated_/chain';
import { parse } from '../../common/_generated_/chain';

import { ArgValueSuggestions, FunctionArg, Location } from '../helpers/arg_value_suggestions';
import { ITimelionFunction, TimelionFunctionArgs } from '../../common/types';
Expand Down
20 changes: 19 additions & 1 deletion src/plugins/vis_type_timelion/public/timelion_vis_type.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ import { DefaultEditorSize } from '../../vis_default_editor/public';
import { TimelionOptionsProps } from './timelion_options';
import { TimelionVisDependencies } from './plugin';
import { toExpressionAst } from './to_ast';
import { getIndexPatterns } from './helpers/plugin_services';

import { VIS_EVENT_TO_TRIGGER } from '../../visualizations/public';
// @ts-ignore
import { parse } from '../common/_generated_/chain';

import { VIS_EVENT_TO_TRIGGER, VisParams } from '../../visualizations/public';
import { TimelionExpressionNamedArgument } from '../common/types';

const TimelionOptions = lazy(() => import('./timelion_options'));

Expand Down Expand Up @@ -47,6 +52,19 @@ export function getTimelionVisDefinition(dependencies: TimelionVisDependencies)
getSupportedTriggers: () => {
return [VIS_EVENT_TO_TRIGGER.applyFilter];
},
getUsedIndexPattern: (params: VisParams) => {
try {
const args: TimelionExpressionNamedArgument[] = parse(params.expression)?.args ?? [];
const indexArg = args.find((arg) => arg.function === 'es' && arg.name === 'index');

if (indexArg?.value.text) {
return getIndexPatterns().find(indexArg?.value.text);
}
} catch {
// timelion expression is invalid
}
return [];
},
options: {
showIndexSelection: false,
showQueryBar: false,
Expand Down
11 changes: 3 additions & 8 deletions src/plugins/vis_type_timelion/server/handlers/lib/parse_sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@
*/

import { i18n } from '@kbn/i18n';
import fs from 'fs';
import path from 'path';
import _ from 'lodash';
const grammar = fs.readFileSync(path.resolve(__dirname, '../../../common/chain.peg'), 'utf8');
import PEG from 'pegjs';
const Parser = PEG.generate(grammar);
import { parse } from '../../../common/_generated_/chain';

export default function parseSheet(sheet) {
return _.map(sheet, function (plot) {
return sheet.map(function (plot) {
try {
return Parser.parse(plot).tree;
return parse(plot).tree;
} catch (e) {
if (e.expected) {
throw new Error(
Expand Down
4 changes: 2 additions & 2 deletions tasks/config/peg.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
},
},
timelion_chain: {
src: 'src/plugins/vis_type_timelion/public/chain.peg',
dest: 'src/plugins/vis_type_timelion/public/_generated_/chain.js',
src: 'src/plugins/vis_type_timelion/common/chain.peg',
dest: 'src/plugins/vis_type_timelion/common/_generated_/chain.js',
},
};

0 comments on commit 330797f

Please sign in to comment.