[Maps] Remove deprecated usage of indexPattern.title (#143444)

* Remove deprecated usage of indexPattern.title

* Fix mocks in unit tests

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Nick Peihl 2022-10-24 09:30:52 -04:00 committed by GitHub
parent 0ce440c44f
commit 1dda579927
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 23 additions and 27 deletions

View file

@ -40,6 +40,7 @@ describe('ESGeoGridSource', () => {
const mockIndexPatternService = {
get() {
return {
getIndexPattern: () => 'foo-*',
fields: {
getByName() {
return {
@ -310,7 +311,7 @@ describe('ESGeoGridSource', () => {
const tileUrl = await mvtGeogridSource.getTileUrl(vectorSourceRequestMeta, '1234', false);
expect(tileUrl).toEqual(
"rootdir/api/maps/mvt/getGridTile/{z}/{x}/{y}.pbf?geometryFieldName=bar&index=undefined&gridPrecision=8&hasLabels=false&requestBody=(foobar%3AES_DSL_PLACEHOLDER%2Cparams%3A('0'%3A('0'%3Aindex%2C'1'%3A(fields%3A()))%2C'1'%3A('0'%3Asize%2C'1'%3A0)%2C'2'%3A('0'%3Afilter%2C'1'%3A!())%2C'3'%3A('0'%3Aquery)%2C'4'%3A('0'%3Aindex%2C'1'%3A(fields%3A()))%2C'5'%3A('0'%3Aquery%2C'1'%3A(language%3AKQL%2Cquery%3A''))%2C'6'%3A('0'%3Aaggs%2C'1'%3A())))&renderAs=heatmap&token=1234"
"rootdir/api/maps/mvt/getGridTile/{z}/{x}/{y}.pbf?geometryFieldName=bar&index=foo-*&gridPrecision=8&hasLabels=false&requestBody=(foobar%3AES_DSL_PLACEHOLDER%2Cparams%3A('0'%3A('0'%3Aindex%2C'1'%3A(fields%3A()))%2C'1'%3A('0'%3Asize%2C'1'%3A0)%2C'2'%3A('0'%3Afilter%2C'1'%3A!())%2C'3'%3A('0'%3Aquery)%2C'4'%3A('0'%3Aindex%2C'1'%3A(fields%3A()))%2C'5'%3A('0'%3Aquery%2C'1'%3A(language%3AKQL%2Cquery%3A''))%2C'6'%3A('0'%3Aaggs%2C'1'%3A())))&renderAs=heatmap&token=1234"
);
});
});

View file

@ -504,9 +504,9 @@ export class ESGeoGridSource extends AbstractESAggSource implements IMvtVectorSo
refreshToken: string,
hasLabels: boolean
): Promise<string> {
const indexPattern = await this.getIndexPattern();
const dataView = await this.getIndexPattern();
const searchSource = await this.makeSearchSource(searchFilters, 0);
searchSource.setField('aggs', this.getValueAggsDsl(indexPattern));
searchSource.setField('aggs', this.getValueAggsDsl(dataView));
const mvtUrlServicePath = getHttp().basePath.prepend(
`/${GIS_API_PATH}/${MVT_GETGRIDTILE_API_PATH}/{z}/{x}/{y}.pbf`
@ -514,7 +514,7 @@ export class ESGeoGridSource extends AbstractESAggSource implements IMvtVectorSo
return `${mvtUrlServicePath}\
?geometryFieldName=${this._descriptor.geoField}\
&index=${indexPattern.title}\
&index=${dataView.getIndexPattern()}\
&gridPrecision=${this._getGeoGridPrecisionResolutionDelta()}\
&hasLabels=${hasLabels}\
&requestBody=${encodeMvtResponseBody(searchSource.getSearchRequestBody())}\

View file

@ -37,6 +37,7 @@ describe('ESSearchSource', () => {
const mockIndexPatternService = {
get() {
return {
getIndexPattern: () => 'foobar-title-*',
title: 'foobar-title-*',
fields: {
getByName() {

View file

@ -463,12 +463,9 @@ export class ESSearchSource extends AbstractESSource implements IMvtVectorSource
}
async getSourceIndexList(): Promise<string[]> {
await this.getIndexPattern();
if (!(this.indexPattern && this.indexPattern.title)) {
return [];
}
const dataView = await this.getIndexPattern();
try {
const { success, matchingIndexes } = await getMatchingIndexes(this.indexPattern.title);
const { success, matchingIndexes } = await getMatchingIndexes(dataView.getIndexPattern());
return success ? matchingIndexes : [];
} catch (e) {
// Fail silently
@ -497,11 +494,8 @@ export class ESSearchSource extends AbstractESSource implements IMvtVectorSource
}
async _isDrawingIndex(): Promise<boolean> {
await this.getIndexPattern();
if (!(this.indexPattern && this.indexPattern.title)) {
return false;
}
const { success, isDrawingIndex } = await getIsDrawLayer(this.indexPattern.title);
const dataView = await this.getIndexPattern();
const { success, isDrawingIndex } = await getIsDrawLayer(dataView.getIndexPattern());
return success && isDrawingIndex;
}
@ -511,8 +505,8 @@ export class ESSearchSource extends AbstractESSource implements IMvtVectorSource
}
async getMaxResultWindow(): Promise<number> {
const indexPattern = await this.getIndexPattern();
const indexSettings = await loadIndexSettings(indexPattern.title);
const dataView = await this.getIndexPattern();
const indexSettings = await loadIndexSettings(dataView.getIndexPattern());
return indexSettings.maxResultWindow;
}
@ -832,8 +826,8 @@ export class ESSearchSource extends AbstractESSource implements IMvtVectorSource
refreshToken: string,
hasLabels: boolean
): Promise<string> {
const indexPattern = await this.getIndexPattern();
const indexSettings = await loadIndexSettings(indexPattern.title);
const dataView = await this.getIndexPattern();
const indexSettings = await loadIndexSettings(dataView.getIndexPattern());
const searchSource = await this.makeSearchSource(searchFilters, indexSettings.maxResultWindow);
// searchSource calls dataView.getComputedFields to seed docvalueFields
@ -855,7 +849,7 @@ export class ESSearchSource extends AbstractESSource implements IMvtVectorSource
return fieldName !== this._descriptor.geoField;
})
.map((fieldName) => {
const field = indexPattern.fields.getByName(fieldName);
const field = dataView.fields.getByName(fieldName);
return field && field.type === 'date'
? {
field: fieldName,
@ -876,7 +870,7 @@ export class ESSearchSource extends AbstractESSource implements IMvtVectorSource
return `${mvtUrlServicePath}\
?geometryFieldName=${this._descriptor.geoField}\
&index=${indexPattern.title}\
&index=${dataView.getIndexPattern()}\
&hasLabels=${hasLabels}\
&requestBody=${encodeMvtResponseBody(requestBody)}\
&token=${refreshToken}`;

View file

@ -70,8 +70,8 @@ export class TopHitsForm extends Component<Props, State> {
async loadIndexSettings() {
try {
const indexPattern = await getIndexPatternService().get(this.props.indexPatternId);
const { maxInnerResultWindow } = await loadIndexSettings(indexPattern!.title);
const dataView = await getIndexPatternService().get(this.props.indexPatternId);
const { maxInnerResultWindow } = await loadIndexSettings(dataView.getIndexPattern());
if (this._isMounted) {
this.setState({ maxInnerResultWindow });
}

View file

@ -64,8 +64,8 @@ export class ScalingForm extends Component<Props, State> {
async loadIndexSettings() {
try {
const indexPattern = await getIndexPatternService().get(this.props.indexPatternId);
const { maxResultWindow } = await loadIndexSettings(indexPattern!.title);
const dataView = await getIndexPatternService().get(this.props.indexPatternId);
const { maxResultWindow } = await loadIndexSettings(dataView.getIndexPattern());
if (this._isMounted) {
this.setState({ maxResultWindow: maxResultWindow.toLocaleString() });
}

View file

@ -31,7 +31,7 @@ export const getIsCloud = () => isCloudEnabled;
export const getIndexNameFormComponent = () => pluginsStart.fileUpload.IndexNameFormComponent;
export const getFileUploadComponent = () => pluginsStart.fileUpload.FileUploadComponent;
export const getIndexPatternService = () => pluginsStart.data.indexPatterns;
export const getIndexPatternService = () => pluginsStart.data.dataViews;
export const getAutocompleteService = () => pluginsStart.unifiedSearch.autocomplete;
export const getInspector = () => pluginsStart.inspector;
export const getFileUpload = () => pluginsStart.fileUpload;

View file

@ -63,7 +63,7 @@ export const visualizeGeoFieldAction = createAction<VisualizeFieldContext>({
});
const getMapsLink = async (context: VisualizeFieldContext) => {
const indexPattern = await getIndexPatternService().get(context.dataViewSpec.id!);
const dataView = await getIndexPatternService().get(context.dataViewSpec.id!);
// create initial layer descriptor
const hasTooltips =
context?.contextualFields?.length && context?.contextualFields[0] !== '_source';
@ -76,7 +76,7 @@ const getMapsLink = async (context: VisualizeFieldContext) => {
id: uuid(),
type: SOURCE_TYPES.ES_SEARCH,
tooltipProperties: hasTooltips ? context.contextualFields : [],
label: indexPattern.title,
label: dataView.getIndexPattern(),
indexPatternId: context.dataViewSpec.id,
geoField: context.fieldName,
scalingType: SCALING_TYPES.MVT,