Skip to content

Commit

Permalink
Fix duplicating fields
Browse files Browse the repository at this point in the history
  • Loading branch information
sulemanof committed Apr 30, 2020
1 parent 3eca079 commit e9620fe
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/plugins/data/public/index_patterns/fields/field_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ export type CreateIndexPatternFieldList = (
export const getIndexPatternFieldListCreator: (
dependencies: FieldListDependencies
) => CreateIndexPatternFieldList = ({ fieldFormats, toastNotifications }) => (
indexPattern,
specs = [],
shortDotsEnable = false
...fieldListParams
) => {
class FieldList extends Array<Field> implements IIndexPatternFieldList {
private byName: FieldMap = new Map();
private groups: Map<Field['type'], FieldMap> = new Map();
private indexPattern: IndexPattern;
private shortDotsEnable: boolean;
private setByName = (field: Field) => this.byName.set(field.name, field);
private setByGroup = (field: Field) => {
if (typeof this.groups.get(field.type) === 'undefined') {
Expand All @@ -64,16 +64,18 @@ export const getIndexPatternFieldListCreator: (
};
private removeByGroup = (field: IFieldType) => this.groups.get(field.type)!.delete(field.name);

constructor() {
constructor(indexPattern: IndexPattern, specs: FieldSpec[] = [], shortDotsEnable = false) {
super();
this.indexPattern = indexPattern;
this.shortDotsEnable = shortDotsEnable;

specs.map(field => this.add(field));
}

getByName = (name: Field['name']) => this.byName.get(name);
getByType = (type: Field['type']) => [...(this.groups.get(type) || new Map()).values()];
add = (field: FieldSpec) => {
const newField = new Field(indexPattern, field, shortDotsEnable, {
const newField = new Field(this.indexPattern, field, this.shortDotsEnable, {
fieldFormats,
toastNotifications,
});
Expand All @@ -91,7 +93,7 @@ export const getIndexPatternFieldListCreator: (
};

update = (field: FieldSpec) => {
const newField = new Field(indexPattern, field, shortDotsEnable, {
const newField = new Field(this.indexPattern, field, this.shortDotsEnable, {
fieldFormats,
toastNotifications,
});
Expand All @@ -103,5 +105,5 @@ export const getIndexPatternFieldListCreator: (
};
}

return new FieldList();
return new FieldList(...fieldListParams);
};

0 comments on commit e9620fe

Please sign in to comment.