mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
Index pattern field list - transition away from extending array - introduce and use getAll() (#74718) (#74756)
- Introduce `indexPattern.fields.getAll()` and use where possible - Rename `index_patterns/fields/fields.mocks.ts.ts => index_patterns/fields/fields.mocks.ts` - FieldSpec - make `count` and `scripted` fields optional - use `indexPattern.fields.getByName` instead of filter where possible
This commit is contained in:
parent
b012dfcec2
commit
f4b44c70d6
38 changed files with 143 additions and 165 deletions
|
@ -0,0 +1,11 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [FieldList](./kibana-plugin-plugins-data-public.fieldlist.md) > [getAll](./kibana-plugin-plugins-data-public.fieldlist.getall.md)
|
||||
|
||||
## FieldList.getAll property
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
readonly getAll: () => IndexPatternField[];
|
||||
```
|
|
@ -21,6 +21,7 @@ export declare class FieldList extends Array<IndexPatternField> implements IInde
|
|||
| Property | Modifiers | Type | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [add](./kibana-plugin-plugins-data-public.fieldlist.add.md) | | <code>(field: FieldSpec) => void</code> | |
|
||||
| [getAll](./kibana-plugin-plugins-data-public.fieldlist.getall.md) | | <code>() => IndexPatternField[]</code> | |
|
||||
| [getByName](./kibana-plugin-plugins-data-public.fieldlist.getbyname.md) | | <code>(name: IndexPatternField['name']) => IndexPatternField | undefined</code> | |
|
||||
| [getByType](./kibana-plugin-plugins-data-public.fieldlist.getbytype.md) | | <code>(type: IndexPatternField['type']) => any[]</code> | |
|
||||
| [remove](./kibana-plugin-plugins-data-public.fieldlist.remove.md) | | <code>(field: IFieldType) => void</code> | |
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IIndexPatternFieldList](./kibana-plugin-plugins-data-public.iindexpatternfieldlist.md) > [getAll](./kibana-plugin-plugins-data-public.iindexpatternfieldlist.getall.md)
|
||||
|
||||
## IIndexPatternFieldList.getAll() method
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
getAll(): IndexPatternField[];
|
||||
```
|
||||
<b>Returns:</b>
|
||||
|
||||
`IndexPatternField[]`
|
||||
|
|
@ -15,6 +15,7 @@ export interface IIndexPatternFieldList extends Array<IndexPatternField>
|
|||
| Method | Description |
|
||||
| --- | --- |
|
||||
| [add(field)](./kibana-plugin-plugins-data-public.iindexpatternfieldlist.add.md) | |
|
||||
| [getAll()](./kibana-plugin-plugins-data-public.iindexpatternfieldlist.getall.md) | |
|
||||
| [getByName(name)](./kibana-plugin-plugins-data-public.iindexpatternfieldlist.getbyname.md) | |
|
||||
| [getByType(type)](./kibana-plugin-plugins-data-public.iindexpatternfieldlist.getbytype.md) | |
|
||||
| [remove(field)](./kibana-plugin-plugins-data-public.iindexpatternfieldlist.remove.md) | |
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
import { buildExistsFilter, getExistsFilterField } from './exists_filter';
|
||||
import { IIndexPattern } from '../../index_patterns';
|
||||
import { fields } from '../../index_patterns/fields/fields.mocks.ts';
|
||||
import { fields } from '../../index_patterns/fields/fields.mocks';
|
||||
|
||||
describe('exists filter', function () {
|
||||
const indexPattern: IIndexPattern = ({
|
||||
|
|
|
@ -21,7 +21,7 @@ import { buildPhraseFilter } from './phrase_filter';
|
|||
import { buildQueryFilter } from './query_string_filter';
|
||||
import { getFilterField } from './get_filter_field';
|
||||
import { IIndexPattern } from '../../index_patterns';
|
||||
import { fields } from '../../index_patterns/fields/fields.mocks.ts';
|
||||
import { fields } from '../../index_patterns/fields/fields.mocks';
|
||||
|
||||
describe('getFilterField', function () {
|
||||
const indexPattern: IIndexPattern = ({
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
import { buildPhrasesFilter, getPhrasesFilterField } from './phrases_filter';
|
||||
import { IIndexPattern } from '../../index_patterns';
|
||||
import { fields } from '../../index_patterns/fields/fields.mocks.ts';
|
||||
import { fields } from '../../index_patterns/fields/fields.mocks';
|
||||
|
||||
describe('phrases filter', function () {
|
||||
const indexPattern: IIndexPattern = ({
|
||||
|
|
|
@ -27,6 +27,7 @@ type FieldMap = Map<IndexPatternField['name'], IndexPatternField>;
|
|||
|
||||
export interface IIndexPatternFieldList extends Array<IndexPatternField> {
|
||||
add(field: FieldSpec): void;
|
||||
getAll(): IndexPatternField[];
|
||||
getByName(name: IndexPatternField['name']): IndexPatternField | undefined;
|
||||
getByType(type: IndexPatternField['type']): IndexPatternField[];
|
||||
remove(field: IFieldType): void;
|
||||
|
@ -72,6 +73,7 @@ export class FieldList extends Array<IndexPatternField> implements IIndexPattern
|
|||
specs.map((field) => this.add(field));
|
||||
}
|
||||
|
||||
public readonly getAll = () => [...this.byName.values()];
|
||||
public readonly getByName = (name: IndexPatternField['name']) => this.byName.get(name);
|
||||
public readonly getByType = (type: IndexPatternField['type']) => [
|
||||
...(this.groups.get(type) || new Map()).values(),
|
||||
|
|
|
@ -62,7 +62,7 @@ export class IndexPatternField implements IFieldType {
|
|||
|
||||
// writable attrs
|
||||
public get count() {
|
||||
return this.spec.count;
|
||||
return this.spec.count || 0;
|
||||
}
|
||||
|
||||
public set count(count) {
|
||||
|
@ -107,7 +107,7 @@ export class IndexPatternField implements IFieldType {
|
|||
}
|
||||
|
||||
public get scripted() {
|
||||
return this.spec.scripted;
|
||||
return !!this.spec.scripted;
|
||||
}
|
||||
|
||||
public get searchable() {
|
||||
|
|
|
@ -438,11 +438,11 @@ export class IndexPattern implements IIndexPattern {
|
|||
}
|
||||
|
||||
getNonScriptedFields() {
|
||||
return [...this.fields.filter((field) => !field.scripted)];
|
||||
return [...this.fields.getAll().filter((field) => !field.scripted)];
|
||||
}
|
||||
|
||||
getScriptedFields() {
|
||||
return [...this.fields.filter((field) => field.scripted)];
|
||||
return [...this.fields.getAll().filter((field) => field.scripted)];
|
||||
}
|
||||
|
||||
getIndex() {
|
||||
|
|
|
@ -17,4 +17,4 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
export * from './fields/fields.mocks.ts';
|
||||
export * from './fields/fields.mocks';
|
||||
|
|
|
@ -160,7 +160,7 @@ export interface FieldSpecExportFmt {
|
|||
}
|
||||
|
||||
export interface FieldSpec {
|
||||
count: number;
|
||||
count?: number;
|
||||
script?: string;
|
||||
lang?: string;
|
||||
conflictDescriptions?: Record<string, string[]>;
|
||||
|
@ -169,7 +169,7 @@ export interface FieldSpec {
|
|||
name: string;
|
||||
type: string;
|
||||
esTypes?: string[];
|
||||
scripted: boolean;
|
||||
scripted?: boolean;
|
||||
searchable: boolean;
|
||||
aggregatable: boolean;
|
||||
readFromDocValues?: boolean;
|
||||
|
|
|
@ -585,6 +585,8 @@ export class FieldList extends Array<IndexPatternField> implements IIndexPattern
|
|||
// (undocumented)
|
||||
readonly add: (field: FieldSpec) => void;
|
||||
// (undocumented)
|
||||
readonly getAll: () => IndexPatternField[];
|
||||
// (undocumented)
|
||||
readonly getByName: (name: IndexPatternField['name']) => IndexPatternField | undefined;
|
||||
// (undocumented)
|
||||
readonly getByType: (type: IndexPatternField['type']) => any[];
|
||||
|
@ -881,6 +883,8 @@ export interface IIndexPatternFieldList extends Array<IndexPatternField> {
|
|||
// (undocumented)
|
||||
add(field: FieldSpec): void;
|
||||
// (undocumented)
|
||||
getAll(): IndexPatternField[];
|
||||
// (undocumented)
|
||||
getByName(name: IndexPatternField['name']): IndexPatternField | undefined;
|
||||
// (undocumented)
|
||||
getByType(type: IndexPatternField['type']): IndexPatternField[];
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { difference, map } from 'lodash';
|
||||
import { difference } from 'lodash';
|
||||
import { IndexPattern, IndexPatternField } from 'src/plugins/data/public';
|
||||
|
||||
export function getIndexPatternFieldList(
|
||||
|
@ -26,7 +26,7 @@ export function getIndexPatternFieldList(
|
|||
if (!indexPattern || !fieldCounts) return [];
|
||||
|
||||
const fieldNamesInDocs = Object.keys(fieldCounts);
|
||||
const fieldNamesInIndexPattern = map(indexPattern.fields, 'name');
|
||||
const fieldNamesInIndexPattern = indexPattern.fields.getAll().map((fld) => fld.name);
|
||||
const unknownTypes: IndexPatternField[] = [];
|
||||
|
||||
difference(fieldNamesInDocs, fieldNamesInIndexPattern).forEach((unknownFieldName) => {
|
||||
|
@ -36,5 +36,5 @@ export function getIndexPatternFieldList(
|
|||
} as IndexPatternField);
|
||||
});
|
||||
|
||||
return [...indexPattern.fields, ...unknownTypes];
|
||||
return [...indexPattern.fields.getAll(), ...unknownTypes];
|
||||
}
|
||||
|
|
|
@ -24,45 +24,47 @@ import { DocViewTable } from './table';
|
|||
import { indexPatterns, IndexPattern } from '../../../../../data/public';
|
||||
|
||||
const indexPattern = {
|
||||
fields: [
|
||||
{
|
||||
name: '_index',
|
||||
type: 'string',
|
||||
scripted: false,
|
||||
filterable: true,
|
||||
},
|
||||
{
|
||||
name: 'message',
|
||||
type: 'string',
|
||||
scripted: false,
|
||||
filterable: false,
|
||||
},
|
||||
{
|
||||
name: 'extension',
|
||||
type: 'string',
|
||||
scripted: false,
|
||||
filterable: true,
|
||||
},
|
||||
{
|
||||
name: 'bytes',
|
||||
type: 'number',
|
||||
scripted: false,
|
||||
filterable: true,
|
||||
},
|
||||
{
|
||||
name: 'scripted',
|
||||
type: 'number',
|
||||
scripted: true,
|
||||
filterable: false,
|
||||
},
|
||||
],
|
||||
fields: {
|
||||
getAll: () => [
|
||||
{
|
||||
name: '_index',
|
||||
type: 'string',
|
||||
scripted: false,
|
||||
filterable: true,
|
||||
},
|
||||
{
|
||||
name: 'message',
|
||||
type: 'string',
|
||||
scripted: false,
|
||||
filterable: false,
|
||||
},
|
||||
{
|
||||
name: 'extension',
|
||||
type: 'string',
|
||||
scripted: false,
|
||||
filterable: true,
|
||||
},
|
||||
{
|
||||
name: 'bytes',
|
||||
type: 'number',
|
||||
scripted: false,
|
||||
filterable: true,
|
||||
},
|
||||
{
|
||||
name: 'scripted',
|
||||
type: 'number',
|
||||
scripted: true,
|
||||
filterable: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
metaFields: ['_index', '_score'],
|
||||
flattenHit: undefined,
|
||||
formatHit: jest.fn((hit) => hit._source),
|
||||
} as IndexPattern;
|
||||
|
||||
indexPattern.fields.getByName = (name: string) => {
|
||||
return indexPattern.fields.find((field) => field.name === name);
|
||||
return indexPattern.fields.getAll().find((field) => field.name === name);
|
||||
};
|
||||
|
||||
indexPattern.flattenHit = indexPatterns.flattenHitWrapper(indexPattern, indexPattern.metaFields);
|
||||
|
|
|
@ -104,15 +104,13 @@ export function DocViewTable({
|
|||
// to the index pattern, but that has its own complications which you can read more about in the following
|
||||
// issue: https://github.com/elastic/kibana/issues/54957
|
||||
const isNestedField =
|
||||
!indexPattern.fields.find((patternField) => patternField.name === field) &&
|
||||
!!indexPattern.fields.find((patternField) => {
|
||||
!indexPattern.fields.getByName(field) &&
|
||||
!!indexPattern.fields.getAll().find((patternField) => {
|
||||
// We only want to match a full path segment
|
||||
const nestedRootRegex = new RegExp(escapeRegExp(field) + '(\\.|$)');
|
||||
return nestedRootRegex.test(patternField.subType?.nested?.path ?? '');
|
||||
});
|
||||
const fieldType = isNestedField
|
||||
? 'nested'
|
||||
: indexPattern.fields.find((patternField) => patternField.name === field)?.type;
|
||||
const fieldType = isNestedField ? 'nested' : indexPattern.fields.getByName(field)?.type;
|
||||
|
||||
return (
|
||||
<DocViewTableRow
|
||||
|
|
|
@ -93,14 +93,16 @@ export const EditIndexPattern = withRouter(
|
|||
} = useKibana<IndexPatternManagmentContext>().services;
|
||||
const [fields, setFields] = useState<IndexPatternField[]>(indexPattern.getNonScriptedFields());
|
||||
const [conflictedFields, setConflictedFields] = useState<IndexPatternField[]>(
|
||||
indexPattern.fields.filter((field) => field.type === 'conflict')
|
||||
indexPattern.fields.getAll().filter((field) => field.type === 'conflict')
|
||||
);
|
||||
const [defaultIndex, setDefaultIndex] = useState<string>(uiSettings.get('defaultIndex'));
|
||||
const [tags, setTags] = useState<any[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
setFields(indexPattern.getNonScriptedFields());
|
||||
setConflictedFields(indexPattern.fields.filter((field) => field.type === 'conflict'));
|
||||
setConflictedFields(
|
||||
indexPattern.fields.getAll().filter((field) => field.type === 'conflict')
|
||||
);
|
||||
}, [indexPattern]);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
|
@ -87,7 +87,7 @@ export function Tabs({ indexPattern, fields, history, location }: TabsProps) {
|
|||
const refreshFilters = useCallback(() => {
|
||||
const tempIndexedFieldTypes: string[] = [];
|
||||
const tempScriptedFieldLanguages: string[] = [];
|
||||
indexPattern.fields.forEach((field) => {
|
||||
indexPattern.fields.getAll().forEach((field) => {
|
||||
if (field.scripted) {
|
||||
if (field.lang) {
|
||||
tempScriptedFieldLanguages.push(field.lang);
|
||||
|
|
|
@ -84,9 +84,9 @@ export function getTabs(
|
|||
fieldFilter: string,
|
||||
indexPatternListProvider: IndexPatternManagementStart['list']
|
||||
) {
|
||||
const totalCount = getCounts(indexPattern.fields, indexPattern.getSourceFiltering());
|
||||
const totalCount = getCounts(indexPattern.fields.getAll(), indexPattern.getSourceFiltering());
|
||||
const filteredCount = getCounts(
|
||||
indexPattern.fields,
|
||||
indexPattern.fields.getAll(),
|
||||
indexPattern.getSourceFiltering(),
|
||||
fieldFilter
|
||||
);
|
||||
|
|
|
@ -25,11 +25,10 @@ exports[`FieldEditor should render create new scripted field correctly 1`] = `
|
|||
executeScript={[Function]}
|
||||
indexPattern={
|
||||
Object {
|
||||
"fields": Array [
|
||||
Object {
|
||||
"name": "foobar",
|
||||
},
|
||||
],
|
||||
"fields": Object {
|
||||
"getAll": [Function],
|
||||
"getByName": [Function],
|
||||
},
|
||||
"getFormatterForField": [Function],
|
||||
}
|
||||
}
|
||||
|
@ -261,19 +260,10 @@ exports[`FieldEditor should render edit scripted field correctly 1`] = `
|
|||
executeScript={[Function]}
|
||||
indexPattern={
|
||||
Object {
|
||||
"fields": Array [
|
||||
Object {
|
||||
"name": "foobar",
|
||||
},
|
||||
Object {
|
||||
"format": Format {},
|
||||
"lang": "painless",
|
||||
"name": "test",
|
||||
"script": "doc.test.value",
|
||||
"scripted": true,
|
||||
"type": "number",
|
||||
},
|
||||
],
|
||||
"fields": Object {
|
||||
"getAll": [Function],
|
||||
"getByName": [Function],
|
||||
},
|
||||
"getFormatterForField": [Function],
|
||||
}
|
||||
}
|
||||
|
@ -504,27 +494,10 @@ exports[`FieldEditor should show conflict field warning 1`] = `
|
|||
executeScript={[Function]}
|
||||
indexPattern={
|
||||
Object {
|
||||
"fields": Array [
|
||||
Object {
|
||||
"name": "foobar",
|
||||
},
|
||||
Object {
|
||||
"format": Format {},
|
||||
"lang": "painless",
|
||||
"name": "test",
|
||||
"script": "doc.test.value",
|
||||
"scripted": true,
|
||||
"type": "number",
|
||||
},
|
||||
Object {
|
||||
"format": Format {},
|
||||
"lang": "testlang",
|
||||
"name": "test",
|
||||
"script": "doc.test.value",
|
||||
"scripted": true,
|
||||
"type": "number",
|
||||
},
|
||||
],
|
||||
"fields": Object {
|
||||
"getAll": [Function],
|
||||
"getByName": [Function],
|
||||
},
|
||||
"getFormatterForField": [Function],
|
||||
}
|
||||
}
|
||||
|
@ -784,27 +757,10 @@ exports[`FieldEditor should show deprecated lang warning 1`] = `
|
|||
executeScript={[Function]}
|
||||
indexPattern={
|
||||
Object {
|
||||
"fields": Array [
|
||||
Object {
|
||||
"name": "foobar",
|
||||
},
|
||||
Object {
|
||||
"format": Format {},
|
||||
"lang": "painless",
|
||||
"name": "test",
|
||||
"script": "doc.test.value",
|
||||
"scripted": true,
|
||||
"type": "number",
|
||||
},
|
||||
Object {
|
||||
"format": Format {},
|
||||
"lang": "testlang",
|
||||
"name": "test",
|
||||
"script": "doc.test.value",
|
||||
"scripted": true,
|
||||
"type": "number",
|
||||
},
|
||||
],
|
||||
"fields": Object {
|
||||
"getAll": [Function],
|
||||
"getByName": [Function],
|
||||
},
|
||||
"getFormatterForField": [Function],
|
||||
}
|
||||
}
|
||||
|
@ -1116,27 +1072,10 @@ exports[`FieldEditor should show multiple type field warning with a table contai
|
|||
executeScript={[Function]}
|
||||
indexPattern={
|
||||
Object {
|
||||
"fields": Array [
|
||||
Object {
|
||||
"name": "foobar",
|
||||
},
|
||||
Object {
|
||||
"format": Format {},
|
||||
"lang": "painless",
|
||||
"name": "test",
|
||||
"script": "doc.test.value",
|
||||
"scripted": true,
|
||||
"type": "number",
|
||||
},
|
||||
Object {
|
||||
"format": Format {},
|
||||
"lang": "testlang",
|
||||
"name": "test",
|
||||
"script": "doc.test.value",
|
||||
"scripted": true,
|
||||
"type": "number",
|
||||
},
|
||||
],
|
||||
"fields": Object {
|
||||
"getAll": [Function],
|
||||
"getByName": [Function],
|
||||
},
|
||||
"getFormatterForField": [Function],
|
||||
}
|
||||
}
|
||||
|
|
|
@ -188,6 +188,7 @@ export class TestScript extends Component<TestScriptProps, TestScriptState> {
|
|||
const fields: EuiComboBoxOptionOption[] = [];
|
||||
|
||||
this.props.indexPattern.fields
|
||||
.getAll()
|
||||
.filter((field) => {
|
||||
const isMultiField = field.subType && field.subType.multi;
|
||||
return !field.name.startsWith('_') && !isMultiField && !field.scripted;
|
||||
|
|
|
@ -17,12 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
IndexPattern,
|
||||
IIndexPatternFieldList,
|
||||
IndexPatternField,
|
||||
FieldFormatInstanceType,
|
||||
} from 'src/plugins/data/public';
|
||||
import { IndexPattern, IndexPatternField, FieldFormatInstanceType } from 'src/plugins/data/public';
|
||||
|
||||
jest.mock('brace/mode/groovy', () => ({}));
|
||||
|
||||
|
@ -71,15 +66,19 @@ jest.mock('./components/field_format_editor', () => ({
|
|||
FieldFormatEditor: 'field-format-editor',
|
||||
}));
|
||||
|
||||
const fields: IndexPatternField[] = [
|
||||
const fieldList = [
|
||||
{
|
||||
name: 'foobar',
|
||||
} as IndexPatternField,
|
||||
];
|
||||
|
||||
const fields = {
|
||||
getAll: () => fieldList,
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
fields.getByName = (name: string) => {
|
||||
return fields.find((field) => field.name === name);
|
||||
return fields.getAll().find((field) => field.name === name);
|
||||
};
|
||||
|
||||
class Format {
|
||||
|
@ -112,7 +111,7 @@ describe('FieldEditor', () => {
|
|||
|
||||
beforeEach(() => {
|
||||
indexPattern = ({
|
||||
fields: fields as IIndexPatternFieldList,
|
||||
fields,
|
||||
getFormatterForField: () => ({ params: () => ({}) }),
|
||||
} as unknown) as IndexPattern;
|
||||
});
|
||||
|
@ -139,8 +138,7 @@ describe('FieldEditor', () => {
|
|||
name: 'test',
|
||||
script: 'doc.test.value',
|
||||
};
|
||||
indexPattern.fields.push(testField as IndexPatternField);
|
||||
|
||||
fieldList.push(testField as IndexPatternField);
|
||||
indexPattern.fields.getByName = (name) => {
|
||||
const flds = {
|
||||
[testField.name]: testField,
|
||||
|
@ -170,7 +168,7 @@ describe('FieldEditor', () => {
|
|||
script: 'doc.test.value',
|
||||
lang: 'testlang',
|
||||
};
|
||||
indexPattern.fields.push((testField as unknown) as IndexPatternField);
|
||||
fieldList.push((testField as unknown) as IndexPatternField);
|
||||
indexPattern.fields.getByName = (name) => {
|
||||
const flds = {
|
||||
[testField.name]: testField,
|
||||
|
|
|
@ -155,7 +155,7 @@ export class FieldEditor extends PureComponent<FieldEdiorProps, FieldEditorState
|
|||
scriptingLangs: [],
|
||||
fieldTypes: [],
|
||||
fieldTypeFormats: [],
|
||||
existingFieldNames: indexPattern.fields.map((f: IFieldType) => f.name),
|
||||
existingFieldNames: indexPattern.fields.getAll().map((f: IFieldType) => f.name),
|
||||
fieldFormatId: undefined,
|
||||
fieldFormatParams: {},
|
||||
showScriptingHelp: false,
|
||||
|
@ -197,7 +197,7 @@ export class FieldEditor extends PureComponent<FieldEdiorProps, FieldEditorState
|
|||
|
||||
this.setState({
|
||||
isReady: true,
|
||||
isCreating: !indexPattern.fields.find((f) => f.name === spec.name),
|
||||
isCreating: !indexPattern.fields.getByName(spec.name),
|
||||
isDeprecatedLang: this.deprecatedLangs.includes(spec.lang || ''),
|
||||
errors: [],
|
||||
scriptingLangs,
|
||||
|
@ -804,11 +804,11 @@ export class FieldEditor extends PureComponent<FieldEdiorProps, FieldEditorState
|
|||
}
|
||||
|
||||
const { redirectAway } = this.props.services;
|
||||
const index = indexPattern.fields.findIndex((f: IFieldType) => f.name === field.name);
|
||||
const fieldExists = !!indexPattern.fields.getByName(field.name);
|
||||
|
||||
let oldField: IndexPatternField['spec'];
|
||||
|
||||
if (index > -1) {
|
||||
if (fieldExists) {
|
||||
oldField = indexPattern.fields.getByName(field.name)!.spec;
|
||||
indexPattern.fields.update(field);
|
||||
} else {
|
||||
|
|
|
@ -216,7 +216,7 @@ export async function listControlFactory(
|
|||
// dynamic options are only allowed on String fields but the setting defaults to true so it could
|
||||
// be enabled for non-string fields (since UI input is hidden for non-string fields).
|
||||
// If field is not string, then disable dynamic options.
|
||||
const field = indexPattern.fields.find(({ name }) => name === controlParams.fieldName);
|
||||
const field = indexPattern.fields.getAll().find(({ name }) => name === controlParams.fieldName);
|
||||
if (field && field.type !== 'string') {
|
||||
controlParams.options.dynamicOptions = false;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ fields.push({ name: 'myField' } as any);
|
|||
fields.getByName = (name: any) => {
|
||||
return fields.find(({ name: n }: { name: string }) => n === name);
|
||||
};
|
||||
fields.getAll = () => [...fields];
|
||||
|
||||
export const getDepsMock = ({
|
||||
searchSource = {
|
||||
|
|
|
@ -117,6 +117,7 @@ export function getArgValueSuggestions() {
|
|||
|
||||
const valueSplit = partial.split(':');
|
||||
return indexPattern.fields
|
||||
.getAll()
|
||||
.filter((field) => {
|
||||
return (
|
||||
field.aggregatable &&
|
||||
|
@ -136,6 +137,7 @@ export function getArgValueSuggestions() {
|
|||
}
|
||||
|
||||
return indexPattern.fields
|
||||
.getAll()
|
||||
.filter((field) => {
|
||||
return (
|
||||
field.aggregatable &&
|
||||
|
@ -155,6 +157,7 @@ export function getArgValueSuggestions() {
|
|||
}
|
||||
|
||||
return indexPattern.fields
|
||||
.getAll()
|
||||
.filter((field) => {
|
||||
return (
|
||||
'date' === field.type &&
|
||||
|
|
|
@ -12,7 +12,7 @@ import { EuiComboBox, EuiComboBoxOptionOption } from '@elastic/eui';
|
|||
import {
|
||||
fields,
|
||||
getField,
|
||||
} from '../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks.ts';
|
||||
} from '../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks';
|
||||
import { FieldComponent } from './field';
|
||||
|
||||
describe('FieldComponent', () => {
|
||||
|
|
|
@ -11,7 +11,7 @@ import { EuiComboBox, EuiComboBoxOptionOption } from '@elastic/eui';
|
|||
// we don't have the types for waitFor just yet, so using "as waitFor" until when we do
|
||||
import { wait as waitFor } from '@testing-library/react';
|
||||
|
||||
import { getField } from '../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks.ts';
|
||||
import { getField } from '../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks';
|
||||
import { ListSchema } from '../../../lists_plugin_deps';
|
||||
import { getFoundListSchemaMock } from '../../../../../lists/common/schemas/response/found_list_schema.mock';
|
||||
import { getListResponseMock } from '../../../../../lists/common/schemas/response/list_schema.mock';
|
||||
|
|
|
@ -12,7 +12,7 @@ import { EuiComboBox, EuiComboBoxOptionOption } from '@elastic/eui';
|
|||
import {
|
||||
fields,
|
||||
getField,
|
||||
} from '../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks.ts';
|
||||
} from '../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks';
|
||||
import { AutocompleteFieldMatchComponent } from './field_value_match';
|
||||
import { useFieldValueAutocomplete } from './hooks/use_field_value_autocomplete';
|
||||
jest.mock('./hooks/use_field_value_autocomplete');
|
||||
|
|
|
@ -12,7 +12,7 @@ import { EuiComboBox, EuiComboBoxOptionOption } from '@elastic/eui';
|
|||
import {
|
||||
fields,
|
||||
getField,
|
||||
} from '../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks.ts';
|
||||
} from '../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks';
|
||||
import { AutocompleteFieldMatchAnyComponent } from './field_value_match_any';
|
||||
import { useFieldValueAutocomplete } from './hooks/use_field_value_autocomplete';
|
||||
jest.mock('./hooks/use_field_value_autocomplete');
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
import '../../../common/mock/match_media';
|
||||
import { getField } from '../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks.ts';
|
||||
import { getField } from '../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks';
|
||||
|
||||
import {
|
||||
EXCEPTION_OPERATORS,
|
||||
|
|
|
@ -13,7 +13,7 @@ import {
|
|||
} from './use_field_value_autocomplete';
|
||||
import { useKibana } from '../../../../common/lib/kibana';
|
||||
import { stubIndexPatternWithFields } from '../../../../../../../../src/plugins/data/common/index_patterns/index_pattern.stub';
|
||||
import { getField } from '../../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks.ts';
|
||||
import { getField } from '../../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks';
|
||||
import { OperatorTypeEnum } from '../../../../lists_plugin_deps';
|
||||
|
||||
jest.mock('../../../../common/lib/kibana');
|
||||
|
|
|
@ -9,7 +9,7 @@ import { mount } from 'enzyme';
|
|||
import euiLightVars from '@elastic/eui/dist/eui_theme_light.json';
|
||||
import { EuiComboBox, EuiComboBoxOptionOption } from '@elastic/eui';
|
||||
|
||||
import { getField } from '../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks.ts';
|
||||
import { getField } from '../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks';
|
||||
import { OperatorComponent } from './operator';
|
||||
import { isOperator, isNotOperator } from './operators';
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ import {
|
|||
import {
|
||||
fields,
|
||||
getField,
|
||||
} from '../../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks.ts';
|
||||
} from '../../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks';
|
||||
import { getFoundListSchemaMock } from '../../../../../../lists/common/schemas/response/found_list_schema.mock';
|
||||
import { getEmptyValue } from '../../empty_value';
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import { mount } from 'enzyme';
|
|||
import euiLightVars from '@elastic/eui/dist/eui_theme_light.json';
|
||||
|
||||
import { useKibana } from '../../../../common/lib/kibana';
|
||||
import { fields } from '../../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks.ts';
|
||||
import { fields } from '../../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks';
|
||||
import { getExceptionListItemSchemaMock } from '../../../../../../lists/common/schemas/response/exception_list_item_schema.mock';
|
||||
import { getEntryMatchMock } from '../../../../../../lists/common/schemas/types/entry_match.mock';
|
||||
import { getEntryMatchAnyMock } from '../../../../../../lists/common/schemas/types/entry_match_any.mock';
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
import {
|
||||
fields,
|
||||
getField,
|
||||
} from '../../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks.ts';
|
||||
} from '../../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks';
|
||||
import { getEntryNestedMock } from '../../../../../../lists/common/schemas/types/entry_nested.mock';
|
||||
import { getEntryMatchMock } from '../../../../../../lists/common/schemas/types/entry_match.mock';
|
||||
import { getEntryMatchAnyMock } from '../../../../../../lists/common/schemas/types/entry_match_any.mock';
|
||||
|
|
|
@ -13,7 +13,7 @@ import { wait as waitFor } from '@testing-library/react';
|
|||
import {
|
||||
fields,
|
||||
getField,
|
||||
} from '../../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks.ts';
|
||||
} from '../../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks';
|
||||
import { getExceptionListItemSchemaMock } from '../../../../../../lists/common/schemas/response/exception_list_item_schema.mock';
|
||||
import { getEntryMatchAnyMock } from '../../../../../../lists/common/schemas/types/entry_match_any.mock';
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue