-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[NP] Remove IndexedArray usage in Schemas #61410
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
Changes from all commits
7948112
e89b8a4
f3fdb95
7e86148
307d727
0b46f76
dfdd6be
b495d47
cc0afc3
97a875d
39f1b1d
3084e2d
b95165b
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 |
|---|---|---|
|
|
@@ -17,11 +17,10 @@ | |
| * under the License. | ||
| */ | ||
|
|
||
| import _ from 'lodash'; | ||
| import _, { defaults } from 'lodash'; | ||
|
|
||
| import { Optional } from '@kbn/utility-types'; | ||
|
|
||
| import { IndexedArray } from 'ui/indexed_array'; | ||
| import { AggGroupNames, AggParam, IAggGroupNames } from '../../../../plugins/data/public'; | ||
|
|
||
| export interface ISchemas { | ||
|
|
@@ -45,9 +44,10 @@ export interface Schema { | |
| aggSettings?: any; | ||
| } | ||
|
|
||
| export class Schemas { | ||
| // @ts-ignore | ||
| all: IndexedArray<Schema>; | ||
| export class Schemas implements ISchemas { | ||
| all: Schema[] = []; | ||
|
Contributor
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. I would specify
Contributor
Author
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. 👍 Done.
Contributor
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. hmm, AFAIK
Contributor
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. @stacey-gammon When I remember correctly you started to remove the types separate to actual class implementations in some places, right? Do you know what the current best practices around this are?
Member
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. For awhile we (app arch) were moving toward an In the meantime, for the cases where we need a separate type in the interim, we have been inconsistent, using
Contributor
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. In that case I like the current solution, once TS 3.8 is merged, we can do a bulk change of the remaining places.
Member
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. For those who want to follow along, here's the PR which is working toward upgrading TS in Kibana: #57774 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. Discussion here if you are interested on the I-prefix: #51674 |
||
| [AggGroupNames.Buckets]: Schema[] = []; | ||
| [AggGroupNames.Metrics]: Schema[] = []; | ||
|
|
||
| constructor( | ||
| schemas: Array< | ||
|
|
@@ -70,7 +70,7 @@ export class Schemas { | |
| ] as AggParam[]; | ||
| } | ||
|
|
||
| _.defaults(schema, { | ||
| defaults(schema, { | ||
| min: 0, | ||
| max: Infinity, | ||
| group: AggGroupNames.Buckets, | ||
|
|
@@ -83,22 +83,12 @@ export class Schemas { | |
| return schema as Schema; | ||
| }) | ||
| .tap((fullSchemas: Schema[]) => { | ||
| this.all = new IndexedArray({ | ||
| index: ['name'], | ||
| group: ['group'], | ||
| immutable: true, | ||
| initialSet: fullSchemas, | ||
| }); | ||
| this.all = fullSchemas; | ||
| }) | ||
| .groupBy('group') | ||
| .forOwn((group, groupName) => { | ||
| // @ts-ignore | ||
| this[groupName] = new IndexedArray({ | ||
| index: ['name'], | ||
| immutable: true, | ||
| // @ts-ignore | ||
| initialSet: group, | ||
| }); | ||
| this[groupName] = group; | ||
| }) | ||
| .commit(); | ||
| } | ||
|
|
@@ -107,7 +97,3 @@ export class Schemas { | |
| export const getSchemaByName = (schemas: Schema[], schemaName?: string) => { | ||
| return schemas.find(s => s.name === schemaName) || ({} as Schema); | ||
| }; | ||
|
|
||
| export const getSchemasByGroup = (schemas: Schema[], schemaGroup?: string) => { | ||
| return schemas.filter(s => s.group === schemaGroup); | ||
| }; | ||
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.
Here
schemashas already contained schemas by group fromgroupName. So we don't need to get them again.