-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
removing schemas from agg configs #58462
Changes from all commits
1c45299
03da927
d3aecb6
36c7bc4
573c7e1
c24a818
2b4fb94
622b14b
34aa486
a255bb3
b14cff4
bf18fee
06af6c4
dec4ac9
338dbf6
a01f9aa
2964295
a3a08dd
7dc487e
fc48c65
e35ffbb
54e0a11
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 |
---|---|---|
|
@@ -20,10 +20,8 @@ | |
import _ from 'lodash'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { IAggType } from './agg_type'; | ||
import { AggGroupNames } from './agg_groups'; | ||
import { writeParams } from './agg_params'; | ||
import { IAggConfigs } from './agg_configs'; | ||
import { Schema } from './schemas'; | ||
import { | ||
ISearchSource, | ||
FetchOptions, | ||
|
@@ -38,37 +36,9 @@ export interface AggConfigOptions { | |
enabled?: boolean; | ||
id?: string; | ||
params?: Record<string, any>; | ||
schema?: string | Schema; | ||
schema?: string; | ||
} | ||
|
||
const unknownSchema: Schema = { | ||
name: 'unknown', | ||
title: 'Unknown', // only here for illustrative purposes | ||
hideCustomLabel: true, | ||
aggFilter: [], | ||
min: 1, | ||
max: 1, | ||
params: [], | ||
defaults: {}, | ||
editor: false, | ||
group: AggGroupNames.Metrics, | ||
aggSettings: { | ||
top_hits: { | ||
allowStrings: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const getSchemaFromRegistry = (schemas: any, schema: string): Schema => { | ||
let registeredSchema = schemas ? schemas.byName[schema] : null; | ||
if (!registeredSchema) { | ||
registeredSchema = Object.assign({}, unknownSchema); | ||
registeredSchema.name = schema; | ||
} | ||
|
||
return registeredSchema; | ||
}; | ||
|
||
/** | ||
* @name AggConfig | ||
* | ||
|
@@ -122,8 +92,8 @@ export class AggConfig { | |
public params: any; | ||
public parent?: IAggConfigs; | ||
public brandNew?: boolean; | ||
public schema?: string; | ||
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. schema is now just a string |
||
|
||
private __schema: Schema; | ||
private __type: IAggType; | ||
private __typeDecorations: any; | ||
private subAggs: AggConfig[] = []; | ||
|
@@ -141,14 +111,12 @@ export class AggConfig { | |
this.setType(opts.type); | ||
|
||
if (opts.schema) { | ||
this.setSchema(opts.schema); | ||
this.schema = opts.schema; | ||
} | ||
|
||
// set the params to the values from opts, or just to the defaults | ||
this.setParams(opts.params || {}); | ||
|
||
// @ts-ignore | ||
this.__schema = this.__schema; | ||
// @ts-ignore | ||
this.__type = this.__type; | ||
} | ||
|
@@ -305,16 +273,13 @@ export class AggConfig { | |
id: this.id, | ||
enabled: this.enabled, | ||
type: this.type && this.type.name, | ||
schema: _.get(this, 'schema.name', this.schema), | ||
schema: this.schema, | ||
params: outParams, | ||
}; | ||
} | ||
|
||
getAggParams() { | ||
return [ | ||
...(_.has(this, 'type.params') ? this.type.params : []), | ||
...(_.has(this, 'schema.params') ? (this.schema as Schema).params : []), | ||
]; | ||
return [...(_.has(this, 'type.params') ? this.type.params : [])]; | ||
} | ||
|
||
getRequestAggs() { | ||
|
@@ -434,9 +399,6 @@ export class AggConfig { | |
|
||
// clear out the previous params except for a few special ones | ||
this.setParams({ | ||
// split row/columns is "outside" of the agg, so don't reset it | ||
row: this.params.row, | ||
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. special parameter used for figuring out if we should do a row or column split (with data table vis). this is not relevant to data querying at all so this setting was moved to vis.params |
||
|
||
// almost every agg has fields, so we try to persist that when type changes | ||
field: availableFields.find((field: any) => field.name === this.getField()), | ||
}); | ||
|
@@ -445,17 +407,4 @@ export class AggConfig { | |
public setType(type: IAggType) { | ||
this.type = type; | ||
} | ||
|
||
public get schema() { | ||
return this.__schema; | ||
} | ||
|
||
public set schema(schema) { | ||
this.__schema = schema; | ||
} | ||
|
||
public setSchema(schema: string | Schema) { | ||
this.schema = | ||
typeof schema === 'string' ? getSchemaFromRegistry(this.aggConfigs.schemas, schema) : schema; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,6 @@ import { Assign } from '@kbn/utility-types'; | |
import { AggConfig, AggConfigOptions, IAggConfig } from './agg_config'; | ||
import { IAggType } from './agg_type'; | ||
import { AggTypesRegistryStart } from './agg_types_registry'; | ||
import { Schema } from './schemas'; | ||
import { AggGroupNames } from './agg_groups'; | ||
import { | ||
IndexPattern, | ||
|
@@ -32,8 +31,6 @@ import { | |
TimeRange, | ||
} from '../../../../../../plugins/data/public'; | ||
|
||
type Schemas = Record<string, any>; | ||
|
||
function removeParentAggs(obj: any) { | ||
for (const prop in obj) { | ||
if (prop === 'parentAggs') delete obj[prop]; | ||
|
@@ -51,7 +48,6 @@ function parseParentAggs(dslLvlCursor: any, dsl: any) { | |
} | ||
|
||
export interface AggConfigsOptions { | ||
schemas?: Schemas; | ||
typesRegistry: AggTypesRegistryStart; | ||
} | ||
|
||
|
@@ -73,7 +69,6 @@ export type IAggConfigs = AggConfigs; | |
|
||
export class AggConfigs { | ||
public indexPattern: IndexPattern; | ||
public schemas: any; | ||
public timeRange?: TimeRange; | ||
private readonly typesRegistry: AggTypesRegistryStart; | ||
|
||
|
@@ -90,37 +85,8 @@ export class AggConfigs { | |
|
||
this.aggs = []; | ||
this.indexPattern = indexPattern; | ||
this.schemas = opts.schemas; | ||
|
||
configStates.forEach((params: any) => this.createAggConfig(params)); | ||
|
||
if (this.schemas) { | ||
this.initializeDefaultsFromSchemas(this.schemas); | ||
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. the defaults are no longer initialized on this level, this is moved into vis_impl.js as its visualization specific |
||
} | ||
} | ||
|
||
// do this wherever the schemas were passed in, & pass in state defaults instead | ||
initializeDefaultsFromSchemas(schemas: Schemas) { | ||
// Set the defaults for any schema which has them. If the defaults | ||
// for some reason has more then the max only set the max number | ||
// of defaults (not sure why a someone define more... | ||
// but whatever). Also if a schema.name is already set then don't | ||
// set anything. | ||
_(schemas) | ||
.filter((schema: Schema) => { | ||
return Array.isArray(schema.defaults) && schema.defaults.length > 0; | ||
}) | ||
.each((schema: any) => { | ||
if (!this.aggs.find((agg: AggConfig) => agg.schema && agg.schema.name === schema.name)) { | ||
// the result here should be passable as a configState | ||
const defaults = schema.defaults.slice(0, schema.max); | ||
_.each(defaults, defaultState => { | ||
const state = _.defaults({ id: AggConfig.nextId(this.aggs) }, defaultState); | ||
this.createAggConfig(state as AggConfigOptions); | ||
}); | ||
} | ||
}) | ||
.commit(); | ||
} | ||
|
||
setTimeRange(timeRange: TimeRange) { | ||
|
@@ -148,7 +114,6 @@ export class AggConfigs { | |
}; | ||
|
||
const aggConfigs = new AggConfigs(this.indexPattern, this.aggs.filter(filterAggs), { | ||
schemas: this.schemas, | ||
typesRegistry: this.typesRegistry, | ||
}); | ||
|
||
|
@@ -271,23 +236,19 @@ export class AggConfigs { | |
} | ||
|
||
byName(name: string) { | ||
return this.aggs.filter(agg => agg.type.name === name); | ||
return this.aggs.filter(agg => agg.type?.name === name); | ||
} | ||
|
||
byType(type: string) { | ||
return this.aggs.filter(agg => agg.type.type === type); | ||
return this.aggs.filter(agg => agg.type?.type === type); | ||
} | ||
|
||
byTypeName(type: string) { | ||
return this.aggs.filter(agg => agg.type.name === type); | ||
return this.byName(type); | ||
} | ||
|
||
bySchemaName(schema: string) { | ||
return this.aggs.filter(agg => agg.schema && agg.schema.name === schema); | ||
} | ||
|
||
bySchemaGroup(group: string) { | ||
return this.aggs.filter(agg => agg.schema && agg.schema.group === group); | ||
return this.aggs.filter(agg => agg.schema === schema); | ||
} | ||
|
||
getRequestAggs(): AggConfig[] { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vis.type.schemas.all were passed in to AggConfigs before, when setting the schema we would look it up in there and assign schema instance to AggConfig. N