Skip to content

Commit

Permalink
remove getByTitle
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwizp committed Nov 30, 2020
1 parent 5c9643a commit d8022ef
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 48 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export declare class IndexPatternsService
| [fieldArrayToMap](./kibana-plugin-plugins-data-public.indexpatternsservice.fieldarraytomap.md) | | <code>(fields: FieldSpec[], fieldAttrs?: FieldAttrs &#124; undefined) =&gt; Record&lt;string, FieldSpec&gt;</code> | Converts field array to map |
| [find](./kibana-plugin-plugins-data-public.indexpatternsservice.find.md) | | <code>(search: string, size?: number) =&gt; Promise&lt;IndexPattern[]&gt;</code> | |
| [get](./kibana-plugin-plugins-data-public.indexpatternsservice.get.md) | | <code>(id: string) =&gt; Promise&lt;IndexPattern&gt;</code> | Get an index pattern by id. Cache optimized |
| [getByTitle](./kibana-plugin-plugins-data-public.indexpatternsservice.getbytitle.md) | | <code>(title: string, refresh?: boolean) =&gt; Promise&lt;IndexPattern &#124; undefined&gt;</code> | Returns an object matching a given title |
| [getCache](./kibana-plugin-plugins-data-public.indexpatternsservice.getcache.md) | | <code>() =&gt; Promise&lt;SavedObject&lt;IndexPatternSavedObjectAttrs&gt;[] &#124; null &#124; undefined&gt;</code> | |
| [getDefault](./kibana-plugin-plugins-data-public.indexpatternsservice.getdefault.md) | | <code>() =&gt; Promise&lt;IndexPattern &#124; null&gt;</code> | Get default index pattern |
| [getFieldsForIndexPattern](./kibana-plugin-plugins-data-public.indexpatternsservice.getfieldsforindexpattern.md) | | <code>(indexPattern: IndexPattern &#124; IndexPatternSpec, options?: GetFieldsOptions &#124; undefined) =&gt; Promise&lt;any&gt;</code> | Get field list by providing an index patttern (or spec) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,21 +168,6 @@ export class IndexPatternsService {
}));
};

/**
* Returns an object matching a given title
*
* @param title {string}
* @returns {Promise<SavedObject|undefined>}
*/
getByTitle = async (title: string, refresh: boolean = false) => {
const idsWithTitle = await this.getIdsWithTitle(refresh);
const item = idsWithTitle.find((i) => i.title === title);

if (item?.id) {
return this.get(item.id);
}
};

/**
* Clear index pattern list cache
* @param id optionally clear a single id
Expand Down
1 change: 0 additions & 1 deletion src/plugins/data/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ const createStartContract = (): Start => {
SearchBar: jest.fn().mockReturnValue(null),
},
indexPatterns: ({
getByTitle: jest.fn((title) => ({ title, id: title })),
createField: jest.fn(() => {}),
createFieldList: jest.fn(() => []),
ensureDefaultIndexPattern: jest.fn(),
Expand Down
1 change: 0 additions & 1 deletion src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,6 @@ export class IndexPatternsService {
// (undocumented)
find: (search: string, size?: number) => Promise<IndexPattern[]>;
get: (id: string) => Promise<IndexPattern>;
getByTitle: (title: string, refresh?: boolean) => Promise<IndexPattern | undefined>;
// Warning: (ae-forgotten-export) The symbol "IndexPatternSavedObjectAttrs" needs to be exported by the entry point index.d.ts
//
// (undocumented)
Expand Down
13 changes: 1 addition & 12 deletions src/plugins/vis_type_timeseries/public/metrics_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import { PANEL_TYPES } from '../common/panel_types';
import { toExpressionAst } from './to_ast';
import { VIS_EVENT_TO_TRIGGER, VisGroups, VisParams } from '../../visualizations/public';
import { getDataStart } from './services';
import { INDEXES_SEPARATOR } from '../common/constants';
import { IndexPattern } from '../../data/public';

export const metricsVisDefinition = {
name: 'metrics',
Expand Down Expand Up @@ -85,16 +83,7 @@ export const metricsVisDefinition = {
inspectorAdapters: {},
getUsedIndexPattern: async (params: VisParams) => {
const { indexPatterns } = getDataStart();
const indexes: string = params.index_pattern;

if (indexes) {
return (
await Promise.all(
indexes.split(INDEXES_SEPARATOR).map((title) => indexPatterns.getByTitle(title))
)
).filter((index) => Boolean(index)) as IndexPattern[];
}

return [];
return params.index_pattern ? await indexPatterns.find(params.index_pattern) : [];
},
};
9 changes: 5 additions & 4 deletions src/plugins/vis_type_vega/public/lib/extract_index_pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

import { flatten } from 'lodash';
import { getData } from '../services';

import type { Data, VegaSpec } from '../data_model/types';
Expand All @@ -32,15 +33,15 @@ export const extractIndexPatternsFromSpec = async (spec: VegaSpec) => {
data = [spec.data];
}

return (
return flatten<IndexPattern>(
await Promise.all(
data.reduce<Data[]>((accumulator, currentValue) => {
data.reduce<Array<Promise<IndexPattern[]>>>((accumulator, currentValue) => {
if (currentValue.url?.index) {
accumulator.push(indexPatterns.getByTitle(currentValue.url.index));
accumulator.push(indexPatterns.find(currentValue.url.index));
}

return accumulator;
}, [])
)
).filter((index) => Boolean(index)) as IndexPattern[];
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class VegaBaseView {
let idxObj;

if (index) {
idxObj = await indexPatterns.getByTitle(index);
idxObj = await indexPatterns.find(index);
if (!idxObj) {
throw new Error(
i18n.translate('visTypeVega.vegaParser.baseView.indexNotFoundErrorMessage', {
Expand Down

0 comments on commit d8022ef

Please sign in to comment.