mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -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> = {
|
const indexPatternDatasource: Datasource<IndexPatternPrivateState, IndexPatternPersistedState> = {
|
||||||
id: 'indexpattern',
|
id: 'indexpattern',
|
||||||
|
|
||||||
initialize(state?: IndexPatternPersistedState) {
|
async initialize(state?: IndexPatternPersistedState) {
|
||||||
return loadInitialState({ state, savedObjectsClient });
|
return loadInitialState({
|
||||||
|
state,
|
||||||
|
savedObjectsClient,
|
||||||
|
defaultIndexPatternId: core.uiSettings.get('defaultIndex'),
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
getPersistableState({ currentIndexPatternId, layers }: IndexPatternPrivateState) {
|
getPersistableState({ currentIndexPatternId, layers }: IndexPatternPrivateState) {
|
||||||
|
|
|
@ -114,8 +114,9 @@ const sampleIndexPatterns = {
|
||||||
{
|
{
|
||||||
name: 'source',
|
name: 'source',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
aggregatable: true,
|
aggregatable: false,
|
||||||
searchable: true,
|
searchable: false,
|
||||||
|
scripted: true,
|
||||||
aggregationRestrictions: {
|
aggregationRestrictions: {
|
||||||
terms: {
|
terms: {
|
||||||
agg: 'terms',
|
agg: 'terms',
|
||||||
|
@ -196,7 +197,7 @@ describe('loader', () => {
|
||||||
expect(cache).toMatchObject(sampleIndexPatterns);
|
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({
|
const cache = await loadIndexPatterns({
|
||||||
cache: {},
|
cache: {},
|
||||||
patterns: ['a', 'b'],
|
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 () => {
|
it('should initialize from saved state', async () => {
|
||||||
const savedState: IndexPatternPersistedState = {
|
const savedState: IndexPatternPersistedState = {
|
||||||
currentIndexPatternId: 'b',
|
currentIndexPatternId: 'b',
|
||||||
|
|
|
@ -84,9 +84,11 @@ export async function loadIndexPatterns({
|
||||||
export async function loadInitialState({
|
export async function loadInitialState({
|
||||||
state,
|
state,
|
||||||
savedObjectsClient,
|
savedObjectsClient,
|
||||||
|
defaultIndexPatternId,
|
||||||
}: {
|
}: {
|
||||||
state?: IndexPatternPersistedState;
|
state?: IndexPatternPersistedState;
|
||||||
savedObjectsClient: SavedObjectsClient;
|
savedObjectsClient: SavedObjectsClient;
|
||||||
|
defaultIndexPatternId?: string;
|
||||||
}): Promise<IndexPatternPrivateState> {
|
}): Promise<IndexPatternPrivateState> {
|
||||||
const indexPatternRefs = await loadIndexPatternRefs(savedObjectsClient);
|
const indexPatternRefs = await loadIndexPatternRefs(savedObjectsClient);
|
||||||
const requiredPatterns = _.unique(
|
const requiredPatterns = _.unique(
|
||||||
|
@ -94,7 +96,7 @@ export async function loadInitialState({
|
||||||
? Object.values(state.layers)
|
? Object.values(state.layers)
|
||||||
.map(l => l.indexPatternId)
|
.map(l => l.indexPatternId)
|
||||||
.concat(state.currentIndexPatternId)
|
.concat(state.currentIndexPatternId)
|
||||||
: [indexPatternRefs[0].id]
|
: [defaultIndexPatternId || indexPatternRefs[0].id]
|
||||||
);
|
);
|
||||||
|
|
||||||
const currentIndexPatternId = requiredPatterns[0];
|
const currentIndexPatternId = requiredPatterns[0];
|
||||||
|
@ -280,7 +282,7 @@ function fromSavedObject(
|
||||||
type,
|
type,
|
||||||
title: attributes.title,
|
title: attributes.title,
|
||||||
fields: (JSON.parse(attributes.fields) as IndexPatternField[])
|
fields: (JSON.parse(attributes.fields) as IndexPatternField[])
|
||||||
.filter(({ aggregatable }) => !!aggregatable)
|
.filter(({ aggregatable, scripted }) => !!aggregatable || !!scripted)
|
||||||
.concat(documentField),
|
.concat(documentField),
|
||||||
typeMeta: attributes.typeMeta
|
typeMeta: attributes.typeMeta
|
||||||
? (JSON.parse(attributes.typeMeta) as SavedRestrictionsInfo)
|
? (JSON.parse(attributes.typeMeta) as SavedRestrictionsInfo)
|
||||||
|
|
|
@ -39,6 +39,7 @@ export interface IndexPatternField {
|
||||||
type: string;
|
type: string;
|
||||||
esTypes?: string[];
|
esTypes?: string[];
|
||||||
aggregatable: boolean;
|
aggregatable: boolean;
|
||||||
|
scripted?: boolean;
|
||||||
searchable: boolean;
|
searchable: boolean;
|
||||||
aggregationRestrictions?: AggregationRestrictions;
|
aggregationRestrictions?: AggregationRestrictions;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue