mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
Add support for scripted fields and (#53948)
default index pattern Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
dbe0bfdf79
commit
f08fc201c8
4 changed files with 35 additions and 7 deletions
|
@ -115,8 +115,12 @@ export function getIndexPatternDatasource({
|
|||
const indexPatternDatasource: Datasource<IndexPatternPrivateState, IndexPatternPersistedState> = {
|
||||
id: 'indexpattern',
|
||||
|
||||
initialize(state?: IndexPatternPersistedState) {
|
||||
return loadInitialState({ state, savedObjectsClient });
|
||||
async initialize(state?: IndexPatternPersistedState) {
|
||||
return loadInitialState({
|
||||
state,
|
||||
savedObjectsClient,
|
||||
defaultIndexPatternId: core.uiSettings.get('defaultIndex'),
|
||||
});
|
||||
},
|
||||
|
||||
getPersistableState({ currentIndexPatternId, layers }: IndexPatternPrivateState) {
|
||||
|
|
|
@ -114,8 +114,9 @@ const sampleIndexPatterns = {
|
|||
{
|
||||
name: 'source',
|
||||
type: 'string',
|
||||
aggregatable: true,
|
||||
searchable: true,
|
||||
aggregatable: false,
|
||||
searchable: false,
|
||||
scripted: true,
|
||||
aggregationRestrictions: {
|
||||
terms: {
|
||||
agg: 'terms',
|
||||
|
@ -196,7 +197,7 @@ describe('loader', () => {
|
|||
expect(cache).toMatchObject(sampleIndexPatterns);
|
||||
});
|
||||
|
||||
it('should not allow full text fields', async () => {
|
||||
it('should allow scripted, but not full text fields', async () => {
|
||||
const cache = await loadIndexPatterns({
|
||||
cache: {},
|
||||
patterns: ['a', 'b'],
|
||||
|
@ -286,6 +287,26 @@ describe('loader', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('should use the default index pattern id, if provided', async () => {
|
||||
const state = await loadInitialState({
|
||||
defaultIndexPatternId: 'b',
|
||||
savedObjectsClient: mockClient(),
|
||||
});
|
||||
|
||||
expect(state).toMatchObject({
|
||||
currentIndexPatternId: 'b',
|
||||
indexPatternRefs: [
|
||||
{ id: 'a', title: sampleIndexPatterns.a.title },
|
||||
{ id: 'b', title: sampleIndexPatterns.b.title },
|
||||
],
|
||||
indexPatterns: {
|
||||
b: sampleIndexPatterns.b,
|
||||
},
|
||||
layers: {},
|
||||
showEmptyFields: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('should initialize from saved state', async () => {
|
||||
const savedState: IndexPatternPersistedState = {
|
||||
currentIndexPatternId: 'b',
|
||||
|
|
|
@ -84,9 +84,11 @@ export async function loadIndexPatterns({
|
|||
export async function loadInitialState({
|
||||
state,
|
||||
savedObjectsClient,
|
||||
defaultIndexPatternId,
|
||||
}: {
|
||||
state?: IndexPatternPersistedState;
|
||||
savedObjectsClient: SavedObjectsClient;
|
||||
defaultIndexPatternId?: string;
|
||||
}): Promise<IndexPatternPrivateState> {
|
||||
const indexPatternRefs = await loadIndexPatternRefs(savedObjectsClient);
|
||||
const requiredPatterns = _.unique(
|
||||
|
@ -94,7 +96,7 @@ export async function loadInitialState({
|
|||
? Object.values(state.layers)
|
||||
.map(l => l.indexPatternId)
|
||||
.concat(state.currentIndexPatternId)
|
||||
: [indexPatternRefs[0].id]
|
||||
: [defaultIndexPatternId || indexPatternRefs[0].id]
|
||||
);
|
||||
|
||||
const currentIndexPatternId = requiredPatterns[0];
|
||||
|
@ -280,7 +282,7 @@ function fromSavedObject(
|
|||
type,
|
||||
title: attributes.title,
|
||||
fields: (JSON.parse(attributes.fields) as IndexPatternField[])
|
||||
.filter(({ aggregatable }) => !!aggregatable)
|
||||
.filter(({ aggregatable, scripted }) => !!aggregatable || !!scripted)
|
||||
.concat(documentField),
|
||||
typeMeta: attributes.typeMeta
|
||||
? (JSON.parse(attributes.typeMeta) as SavedRestrictionsInfo)
|
||||
|
|
|
@ -39,6 +39,7 @@ export interface IndexPatternField {
|
|||
type: string;
|
||||
esTypes?: string[];
|
||||
aggregatable: boolean;
|
||||
scripted?: boolean;
|
||||
searchable: boolean;
|
||||
aggregationRestrictions?: AggregationRestrictions;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue