Skip to content

Commit

Permalink
[data views] Initial creation of abstract data views class (elastic#1…
Browse files Browse the repository at this point in the history
…61611)

## Summary

Creation of `AbstractDataView` class which provides all functionality
that doesn't expect a full field list upon object creation.

The code remaining in the `DataView` class either loads the field list
or depends upon the loaded field list.

---------

Co-authored-by: Davis McPhee <[email protected]>
  • Loading branch information
mattkime and davismcphee authored Oct 19, 2023
1 parent 7676cc4 commit 60a41ae
Show file tree
Hide file tree
Showing 12 changed files with 504 additions and 379 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ describe('FieldEditor', () => {
fields,
getFormatterForField: () => ({ params: () => ({}) }),
getFormatterForFieldNoDefault: () => ({ params: () => ({}) }),
upsertScriptedField: () => undefined,
setFieldCustomLabel: (name: string, label: string) => {
indexPattern.fields.getByName(name)!.customLabel = label;
},
} as unknown as DataView;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -822,16 +822,9 @@ export class FieldEditor extends PureComponent<FieldEdiorProps, FieldEditorState
}

const { redirectAway, indexPatternService } = this.props.services;
const fieldExists = !!indexPattern.fields.getByName(field.name);

let oldField: DataViewField['spec'];

if (fieldExists) {
oldField = indexPattern.fields.getByName(field.name)!.spec;
indexPattern.fields.update(field);
} else {
indexPattern.fields.add(field);
}
indexPattern.upsertScriptedField(field);

if (fieldFormatId) {
indexPattern.setFieldFormat(field.name, { id: fieldFormatId, params: fieldFormatParams });
Expand All @@ -841,7 +834,7 @@ export class FieldEditor extends PureComponent<FieldEdiorProps, FieldEditorState

if (field.customLabel !== customLabel) {
field.customLabel = customLabel;
indexPattern.fields.update(field);
indexPattern.setFieldCustomLabel(field.name, customLabel);
}

return indexPatternService
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 60a41ae

Please sign in to comment.