Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosant committed Aug 27, 2020
1 parent b4ede0e commit 0ad40f8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ interface ValueClickTriggerEventScope {
negate: boolean;
}
interface RangeSelectTriggerEventScope {
key?: string;
key: string;
from?: string | number;
to?: string | number;
}
Expand All @@ -147,7 +147,7 @@ async function getEventScopeFromRangeSelectTriggerContext(
const { table, column: columnIndex, range } = eventScopeInput.data;
const column = table.columns[columnIndex];
return cleanEmptyKeys({
key: toPrimitiveOrUndefined(column?.meta?.aggConfigParams?.field) as string | undefined,
key: toPrimitiveOrUndefined(column?.meta?.aggConfigParams?.field) as string,
from: toPrimitiveOrUndefined(range[0]) as string | number | undefined,
to: toPrimitiveOrUndefined(range[range.length - 1]) as string | number | undefined,
});
Expand Down Expand Up @@ -180,14 +180,14 @@ async function getEventScopeFromValueClickTriggerContext(
export function getMockEventScope([trigger]: UrlTrigger[]): UrlDrilldownEventScope {
if (trigger === SELECT_RANGE_TRIGGER) {
return {
key: '__testKey__',
key: 'event.key',
from: new Date(Date.now() - 15 * 60 * 1000).toISOString(), // 15 minutes ago
to: new Date().toISOString(),
};
} else {
return {
key: '__testKey__',
value: '__testValue__',
key: 'event.key',
value: 'event.value',
negate: false,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ test('buildScopeSuggestions', () => {
)
).toMatchInlineSnapshot(`
Array [
"kibanaUrl",
"context.filters",
"context.query.query",
"context.query.language",
"event.key",
"event.value",
"context.filters",
"context.query.language",
"context.query.query",
"kibanaUrl",
]
`);
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import partition from 'lodash/partition';
import { UrlDrilldownGlobalScope, UrlDrilldownScope } from './types';
import { getFlattenedObject } from '../../../../../../src/core/public';

Expand All @@ -26,6 +27,13 @@ export function buildScope<
};
}

/**
* Builds list of variables for suggestion from scope
* keys sorted alphabetically, except {{event.$}} variables are pulled to the top
* @param scope
*/
export function buildScopeSuggestions(scope: UrlDrilldownGlobalScope): string[] {
return Object.keys(getFlattenedObject(scope));
const allKeys = Object.keys(getFlattenedObject(scope)).sort();
const [eventKeys, otherKeys] = partition(allKeys, (key) => key.startsWith('event'));
return [...eventKeys, ...otherKeys];
}

0 comments on commit 0ad40f8

Please sign in to comment.