Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Maps] remove VectorSourceSyncMeta type #112333

Merged
merged 5 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
/* eslint-disable @typescript-eslint/consistent-type-definitions */

import type { Query } from 'src/plugins/data/common';
import { SortDirection } from 'src/plugins/data/common/search';
import { RENDER_AS, SCALING_TYPES } from '../constants';
import { MapExtent } from './map_descriptor';
import { Filter, TimeRange } from '../../../../../src/plugins/data/common';
import { ESTermSourceDescriptor } from './source_descriptor_types';

export type Timeslice = {
from: number;
Expand All @@ -32,33 +29,6 @@ export type DataFilters = {
isReadOnly: boolean;
};

export type ESSearchSourceSyncMeta = {
filterByMapBounds: boolean;
sortField: string;
sortOrder: SortDirection;
scalingType: SCALING_TYPES;
topHitsSplitField: string;
topHitsSize: number;
};

type ESGeoGridSourceSyncMeta = {
requestType: RENDER_AS;
};

type ESGeoLineSourceSyncMeta = {
splitField: string;
sortField: string;
};

export type ESTermSourceSyncMeta = Pick<ESTermSourceDescriptor, 'indexPatternId' | 'size' | 'term'>;

export type VectorSourceSyncMeta =
| ESSearchSourceSyncMeta
| ESGeoGridSourceSyncMeta
| ESGeoLineSourceSyncMeta
| ESTermSourceSyncMeta
| null;

export type VectorSourceRequestMeta = DataFilters & {
applyGlobalQuery: boolean;
applyGlobalTime: boolean;
Expand All @@ -67,7 +37,7 @@ export type VectorSourceRequestMeta = DataFilters & {
geogridPrecision?: number;
timesliceMaskField?: string;
sourceQuery?: Query;
sourceMeta: VectorSourceSyncMeta;
sourceMeta: object | null;
isForceRefresh: boolean;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import {
ESGeoGridSourceDescriptor,
MapExtent,
VectorSourceRequestMeta,
VectorSourceSyncMeta,
} from '../../../../common/descriptor_types';
import { ImmutableSourceProperty, SourceEditorArgs } from '../source';
import { ISearchSource } from '../../../../../../../src/plugins/data/common/search/search_source';
Expand All @@ -54,6 +53,8 @@ import { Adapters } from '../../../../../../../src/plugins/inspector/common/adap
import { isValidStringConfig } from '../../util/valid_string_config';
import { ITiledSingleLayerMvtParams } from '../tiled_single_layer_vector_source/tiled_single_layer_vector_source';

type ESGeoGridSourceSyncMeta = Pick<ESGeoGridSourceDescriptor, 'requestType'>;

export const MAX_GEOTILE_LEVEL = 29;

export const clustersTitle = i18n.translate('xpack.maps.source.esGridClustersTitle', {
Expand Down Expand Up @@ -106,7 +107,7 @@ export class ESGeoGridSource extends AbstractESAggSource implements ITiledSingle
);
}

getSyncMeta(): VectorSourceSyncMeta {
getSyncMeta(): ESGeoGridSourceSyncMeta {
return {
requestType: this._descriptor.requestType,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import { esFilters } from '../../../../../../../src/plugins/data/public';
import { getIsGoldPlus } from '../../../licensed_features';
import { LICENSED_FEATURES } from '../../../licensed_features';

type ESGeoLineSourceSyncMeta = Pick<ESGeoLineSourceDescriptor, 'splitField' | 'sortField'>;

const MAX_TRACKS = 250;

export const geoLineTitle = i18n.translate('xpack.maps.source.esGeoLineTitle', {
Expand Down Expand Up @@ -99,7 +101,7 @@ export class ESGeoLineSource extends AbstractESAggSource {
);
}

getSyncMeta() {
getSyncMeta(): ESGeoLineSourceSyncMeta {
return {
splitField: this._descriptor.splitField,
sortField: this._descriptor.sortField,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import {
ESSearchSourceDescriptor,
Timeslice,
VectorSourceRequestMeta,
VectorSourceSyncMeta,
} from '../../../../common/descriptor_types';
import { Adapters } from '../../../../../../../src/plugins/inspector/common/adapters';
import { TimeRange } from '../../../../../../../src/plugins/data/common';
Expand All @@ -74,6 +73,16 @@ import {
getMatchingIndexes,
} from './util/feature_edit';

type ESSearchSourceSyncMeta = Pick<
ESSearchSourceDescriptor,
| 'filterByMapBounds'
| 'sortField'
| 'sortOrder'
| 'scalingType'
| 'topHitsSplitField'
| 'topHitsSize'
>;

export function timerangeToTimeextent(timerange: TimeRange): Timeslice | undefined {
const timeRangeBounds = getTimeFilter().calculateBounds(timerange);
return timeRangeBounds.min !== undefined && timeRangeBounds.max !== undefined
Expand Down Expand Up @@ -714,7 +723,7 @@ export class ESSearchSource extends AbstractESSource implements ITiledSingleLaye
};
}

getSyncMeta(): VectorSourceSyncMeta | null {
getSyncMeta(): ESSearchSourceSyncMeta {
return {
filterByMapBounds: this._descriptor.filterByMapBounds,
sortField: this._descriptor.sortField,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@ import {
} from '../../../../common/elasticsearch_util';
import {
ESTermSourceDescriptor,
ESTermSourceSyncMeta,
VectorJoinSourceRequestMeta,
} from '../../../../common/descriptor_types';
import { Adapters } from '../../../../../../../src/plugins/inspector/common/adapters';
import { PropertiesMap } from '../../../../common/elasticsearch_util';
import { isValidStringConfig } from '../../util/valid_string_config';
import { ITermJoinSource } from '../term_join_source/term_join_source';
import { ITermJoinSource } from '../term_join_source';
import { IField } from '../../fields/field';

const TERMS_AGG_NAME = 'join';
const TERMS_BUCKET_KEYS_TO_IGNORE = ['key', 'doc_count'];

type ESTermSourceSyncMeta = Pick<ESTermSourceDescriptor, 'indexPatternId' | 'size' | 'term'>;

export function extractPropertiesMap(rawEsData: any, countPropertyName: string): PropertiesMap {
const propertiesMap: PropertiesMap = new Map<string, BucketProperties>();
const buckets: any[] = _.get(rawEsData, ['aggregations', TERMS_AGG_NAME, 'buckets'], []);
Expand Down Expand Up @@ -171,7 +172,7 @@ export class ESTermSource extends AbstractESAggSource implements ITermJoinSource
return this.getMetricFields().map((esAggMetricField) => esAggMetricField.getName());
}

getSyncMeta(): ESTermSourceSyncMeta | null {
getSyncMeta(): ESTermSourceSyncMeta {
return {
indexPatternId: this._descriptor.indexPatternId,
size: this._descriptor.size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
MapExtent,
MVTFieldDescriptor,
TiledSingleLayerVectorSourceDescriptor,
VectorSourceSyncMeta,
} from '../../../../common/descriptor_types';
import { MVTField } from '../../fields/mvt_field';
import { UpdateSourceEditor } from './update_source_editor';
Expand Down Expand Up @@ -196,7 +195,7 @@ export class MVTSingleLayerVectorSource
return null;
}

getSyncMeta(): VectorSourceSyncMeta {
getSyncMeta(): null {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
* 2.0.
*/

import type { Query } from 'src/plugins/data/common';
import { TableSource } from './table_source';
import { FIELD_ORIGIN } from '../../../../common/constants';
import {
DataFilters,
VectorJoinSourceRequestMeta,
VectorSourceSyncMeta,
VectorSourceRequestMeta,
} from '../../../../common/descriptor_types';

describe('TableSource', () => {
Expand Down Expand Up @@ -178,14 +176,7 @@ describe('TableSource', () => {
try {
await tableSource.getGeoJsonWithMeta(
'foobar',
({} as unknown) as DataFilters & {
applyGlobalQuery: boolean;
applyGlobalTime: boolean;
fieldNames: string[];
geogridPrecision?: number;
sourceQuery?: Query;
sourceMeta: VectorSourceSyncMeta;
},
({} as unknown) as VectorSourceRequestMeta,
() => {},
() => {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import type { Query } from 'src/plugins/data/common';
import { FIELD_ORIGIN, SOURCE_TYPES, VECTOR_SHAPE_TYPE } from '../../../../common/constants';
import {
MapExtent,
DataFilters,
TableSourceDescriptor,
VectorJoinSourceRequestMeta,
VectorSourceSyncMeta,
VectorSourceRequestMeta,
} from '../../../../common/descriptor_types';
import { Adapters } from '../../../../../../../src/plugins/inspector/common/adapters';
import { ITermJoinSource } from '../term_join_source';
Expand Down Expand Up @@ -55,7 +54,7 @@ export class TableSource extends AbstractVectorSource implements ITermJoinSource
return `table source ${uuid()}`;
}

getSyncMeta(): VectorSourceSyncMeta | null {
getSyncMeta(): null {
return null;
}

Expand Down Expand Up @@ -186,14 +185,7 @@ export class TableSource extends AbstractVectorSource implements ITermJoinSource
// Could be useful to implement, e.g. to preview raw csv data
async getGeoJsonWithMeta(
layerName: string,
searchFilters: DataFilters & {
applyGlobalQuery: boolean;
applyGlobalTime: boolean;
fieldNames: string[];
geogridPrecision?: number;
sourceQuery?: Query;
sourceMeta: VectorSourceSyncMeta;
},
searchFilters: VectorSourceRequestMeta,
registerCancelCallback: (callback: () => void) => void,
isRequestStillActive: () => boolean
): Promise<GeoJsonWithMeta> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
import { GeoJsonProperties } from 'geojson';
import { IField } from '../../fields/field';
import { Query } from '../../../../../../../src/plugins/data/common/query';
import {
VectorJoinSourceRequestMeta,
VectorSourceSyncMeta,
} from '../../../../common/descriptor_types';
import { VectorJoinSourceRequestMeta } from '../../../../common/descriptor_types';
import { PropertiesMap } from '../../../../common/elasticsearch_util';
import { ITooltipProperty } from '../../tooltips/tooltip_property';
import { ISource } from '../source';
Expand All @@ -26,7 +23,13 @@ export interface ITermJoinSource extends ISource {
leftFieldName: string,
registerCancelCallback: (callback: () => void) => void
): Promise<PropertiesMap>;
getSyncMeta(): VectorSourceSyncMeta | null;

/*
* Vector layer avoids unnecessarily re-fetching join data.
* Use getSyncMeta to expose fields that require join data re-fetch when changed.
*/
getSyncMeta(): object | null;

getId(): string;
getRightFields(): IField[];
getTooltipProperties(properties: GeoJsonProperties): Promise<ITooltipProperty[]>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
MapExtent,
Timeslice,
VectorSourceRequestMeta,
VectorSourceSyncMeta,
} from '../../../../common/descriptor_types';
import { DataRequest } from '../../util/data_request';

Expand Down Expand Up @@ -60,7 +59,13 @@ export interface IVectorSource extends ISource {
getFields(): Promise<IField[]>;
getFieldByName(fieldName: string): IField | null;
getLeftJoinFields(): Promise<IField[]>;
getSyncMeta(): VectorSourceSyncMeta | null;

/*
* Vector layer avoids unnecessarily re-fetching source data.
* Use getSyncMeta to expose fields that require source data re-fetch when changed.
*/
getSyncMeta(): object | null;

getFieldNames(): string[];
createField({ fieldName }: { fieldName: string }): IField;
hasTooltipProperties(): boolean;
Expand Down Expand Up @@ -159,7 +164,7 @@ export class AbstractVectorSource extends AbstractSource implements IVectorSourc
return { tooltipContent: null, areResultsTrimmed: false };
}

getSyncMeta(): VectorSourceSyncMeta | null {
getSyncMeta(): object | null {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
import { ESSearchSource } from '../../../../../../classes/sources/es_search_source';
import { VectorLayer } from '../../../../../../classes/layers/vector_layer';
import { SCALING_TYPES, VECTOR_SHAPE_TYPE } from '../../../../../../../common/constants';
import { ESSearchSourceSyncMeta } from '../../../../../../../common/descriptor_types';

export interface Props {
cloneLayer: (layerId: string) => void;
Expand Down Expand Up @@ -85,15 +84,13 @@ export class TOCEntryActionsPopover extends Component<Props, State> {

async _getIsFeatureEditingEnabled(): Promise<boolean> {
const vectorLayer = this.props.layer as VectorLayer;
const layerSource = await this.props.layer.getSource();
const layerSource = this.props.layer.getSource();
if (!(layerSource instanceof ESSearchSource)) {
return false;
}
const isClustered =
(layerSource?.getSyncMeta() as ESSearchSourceSyncMeta)?.scalingType ===
SCALING_TYPES.CLUSTERS;

if (
isClustered ||
(layerSource as ESSearchSource).getSyncMeta().scalingType === SCALING_TYPES.CLUSTERS ||
(await vectorLayer.isFilteredByGlobalTime()) ||
vectorLayer.isPreviewLayer() ||
!vectorLayer.isVisible() ||
Expand Down