Skip to content

Commit

Permalink
[rollup index patterns] don't show fields not present in field caps r…
Browse files Browse the repository at this point in the history
…esponse (#105533)

* remove fields not present in field caps response
  • Loading branch information
mattkime authored Jul 16, 2021
1 parent d0b5c9e commit 2dd3693
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<b>Signature:</b>

```typescript
export declare function getCapabilitiesForRollupIndices(indices: {
[key: string]: any;
}): {
export declare function getCapabilitiesForRollupIndices(indices: Record<string, {
rollup_jobs: any;
}>): {
[key: string]: any;
};
```
Expand All @@ -18,7 +18,7 @@ export declare function getCapabilitiesForRollupIndices(indices: {

| Parameter | Type | Description |
| --- | --- | --- |
| indices | <code>{</code><br/><code> [key: string]: any;</code><br/><code>}</code> | |
| indices | <code>Record&lt;string, {</code><br/><code> rollup_jobs: any;</code><br/><code>}&gt;</code> | |

<b>Returns:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@
```typescript
mergeCapabilitiesWithFields: (rollupIndexCapabilities: {
[key: string]: any;
}, fieldsFromFieldCapsApi: {
[key: string]: any;
}, previousFields?: FieldDescriptor[]) => FieldDescriptor[]
}, fieldsFromFieldCapsApi: Record<string, FieldDescriptor>, previousFields?: FieldDescriptor[]) => FieldDescriptor[]
```
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { mergeJobConfigurations } from './jobs_compatibility';

export function getCapabilitiesForRollupIndices(indices: { [key: string]: any }) {
export function getCapabilitiesForRollupIndices(indices: Record<string, { rollup_jobs: any }>) {
const indexNames = Object.keys(indices);
const capabilities = {} as { [key: string]: any };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { FieldDescriptor } from '../index_patterns_fetcher';

export const mergeCapabilitiesWithFields = (
rollupIndexCapabilities: { [key: string]: any },
fieldsFromFieldCapsApi: { [key: string]: any },
fieldsFromFieldCapsApi: Record<string, FieldDescriptor>,
previousFields: FieldDescriptor[] = []
) => {
const rollupFields = [...previousFields];
Expand Down Expand Up @@ -56,16 +56,21 @@ export const mergeCapabilitiesWithFields = (
rollupFields.push(
...fields
.filter((field) => !rollupFieldNames.includes(field))
.map((field) => {
.reduce<FieldDescriptor[]>((collector, field) => {
// Expand each field into object format that end consumption expects.
const fieldCapsKey = `${field}.${agg}.value`;
rollupFieldNames.push(field);
return {
...fieldsFromFieldCapsApi[fieldCapsKey],
...defaultField,
name: field,
};
})

// only add fields if they are returned from field caps. they won't exist if there's no data
if (fieldsFromFieldCapsApi[fieldCapsKey]) {
collector.push({
...fieldsFromFieldCapsApi[fieldCapsKey],
...defaultField,
name: field,
});
}
return collector;
}, [])
);
}
});
Expand Down
10 changes: 4 additions & 6 deletions src/plugins/data/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,9 @@ export type Filter = {
// Warning: (ae-missing-release-tag) "getCapabilitiesForRollupIndices" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export function getCapabilitiesForRollupIndices(indices: {
[key: string]: any;
}): {
export function getCapabilitiesForRollupIndices(indices: Record<string, {
rollup_jobs: any;
}>): {
[key: string]: any;
};

Expand Down Expand Up @@ -1143,9 +1143,7 @@ export interface KueryNode {
// @public (undocumented)
export const mergeCapabilitiesWithFields: (rollupIndexCapabilities: {
[key: string]: any;
}, fieldsFromFieldCapsApi: {
[key: string]: any;
}, previousFields?: FieldDescriptor[]) => FieldDescriptor[];
}, fieldsFromFieldCapsApi: Record<string, FieldDescriptor>, previousFields?: FieldDescriptor[]) => FieldDescriptor[];

// Warning: (ae-missing-release-tag) "METRIC_TYPES" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import expect from '@kbn/expect';
import { stringify } from 'query-string';
import { registerHelpers } from './rollup.test_helpers';
import { INDEX_TO_ROLLUP_MAPPINGS, INDEX_PATTERNS_EXTENSION_BASE_PATH } from './constants';
import { INDEX_PATTERNS_EXTENSION_BASE_PATH } from './constants';
import { getRandomString } from './lib';

export default function ({ getService }) {
Expand Down Expand Up @@ -65,9 +65,9 @@ export default function ({ getService }) {
const { body } = await supertest.get(uri).expect(200);

// Verify that the fields for wildcard correspond to our declared mappings
const propertiesWithMappings = Object.keys(INDEX_TO_ROLLUP_MAPPINGS.properties);
// noting that testTotalField and testTagField are not shown in the field caps results
const fieldsForWildcard = body.fields.map((field) => field.name);
expect(fieldsForWildcard.sort()).eql(propertiesWithMappings.sort());
expect(fieldsForWildcard.sort()).eql(['testCreatedField']);

// Cleanup
await cleanUp();
Expand Down

0 comments on commit 2dd3693

Please sign in to comment.