[Maps] Remove invisible layers from querybar (#94943)
This commit is contained in:
parent
f4526ad88c
commit
f99d93d506
|
@ -5,7 +5,8 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
jest.mock('../classes/layers/vector_layer', () => {});
|
||||
import { LAYER_STYLE_TYPE, LAYER_TYPE, SOURCE_TYPES } from '../../common';
|
||||
|
||||
jest.mock('../classes/layers/tiled_vector_layer/tiled_vector_layer', () => {});
|
||||
jest.mock('../classes/layers/blended_vector_layer/blended_vector_layer', () => {});
|
||||
jest.mock('../classes/layers/heatmap_layer', () => {});
|
||||
|
@ -23,13 +24,23 @@ jest.mock('../kibana_services', () => ({
|
|||
getMapsCapabilities() {
|
||||
return { save: true };
|
||||
},
|
||||
getIsDarkMode() {
|
||||
return false;
|
||||
},
|
||||
}));
|
||||
|
||||
import { DEFAULT_MAP_STORE_STATE } from '../reducers/store';
|
||||
import { areLayersLoaded, getDataFilters, getTimeFilters } from './map_selectors';
|
||||
import { LayerDescriptor } from '../../common/descriptor_types';
|
||||
import {
|
||||
areLayersLoaded,
|
||||
getDataFilters,
|
||||
getTimeFilters,
|
||||
getQueryableUniqueIndexPatternIds,
|
||||
} from './map_selectors';
|
||||
|
||||
import { LayerDescriptor, VectorLayerDescriptor } from '../../common/descriptor_types';
|
||||
import { ILayer } from '../classes/layers/layer';
|
||||
import { Filter } from '../../../../../src/plugins/data/public';
|
||||
import { ESSearchSource } from '../classes/sources/es_search_source';
|
||||
|
||||
describe('getDataFilters', () => {
|
||||
const mapExtent = {
|
||||
|
@ -193,3 +204,76 @@ describe('areLayersLoaded', () => {
|
|||
expect(areLayersLoaded.resultFunc(layerList, waitingForMapReadyLayerList, zoom)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getQueryableUniqueIndexPatternIds', () => {
|
||||
function createLayerMock({
|
||||
isVisible = true,
|
||||
indexPatterns = [],
|
||||
}: {
|
||||
isVisible?: boolean;
|
||||
indexPatterns?: string[];
|
||||
}) {
|
||||
return ({
|
||||
isVisible: () => {
|
||||
return isVisible;
|
||||
},
|
||||
getQueryableIndexPatternIds: () => {
|
||||
return indexPatterns;
|
||||
},
|
||||
} as unknown) as ILayer;
|
||||
}
|
||||
|
||||
function createWaitLayerDescriptorMock({
|
||||
indexPatternId,
|
||||
visible = true,
|
||||
}: {
|
||||
visible?: boolean;
|
||||
indexPatternId: string;
|
||||
}) {
|
||||
return {
|
||||
type: LAYER_TYPE.VECTOR,
|
||||
style: {
|
||||
type: LAYER_STYLE_TYPE.VECTOR,
|
||||
},
|
||||
visible,
|
||||
sourceDescriptor: ESSearchSource.createDescriptor({
|
||||
type: SOURCE_TYPES.ES_SEARCH,
|
||||
indexPatternId,
|
||||
geoField: 'field',
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
test('should only include visible', () => {
|
||||
const layerList: ILayer[] = [
|
||||
createLayerMock({}),
|
||||
createLayerMock({ indexPatterns: ['foo'] }),
|
||||
createLayerMock({ indexPatterns: ['bar'] }),
|
||||
createLayerMock({ indexPatterns: ['foobar'], isVisible: false }),
|
||||
createLayerMock({ indexPatterns: ['bar'] }),
|
||||
];
|
||||
const waitingForMapReadyLayerList: VectorLayerDescriptor[] = ([] as unknown) as VectorLayerDescriptor[];
|
||||
expect(
|
||||
getQueryableUniqueIndexPatternIds.resultFunc(layerList, waitingForMapReadyLayerList)
|
||||
).toEqual(['foo', 'bar']);
|
||||
});
|
||||
|
||||
test('should only include visible and waitlist should take precedence', () => {
|
||||
const layerList: ILayer[] = [
|
||||
createLayerMock({}),
|
||||
createLayerMock({ indexPatterns: ['foo'] }),
|
||||
createLayerMock({ indexPatterns: ['bar'] }),
|
||||
createLayerMock({ indexPatterns: ['foobar'], isVisible: false }),
|
||||
createLayerMock({ indexPatterns: ['bar'] }),
|
||||
];
|
||||
const waitingForMapReadyLayerList: VectorLayerDescriptor[] = ([
|
||||
createWaitLayerDescriptorMock({ indexPatternId: 'foo' }),
|
||||
createWaitLayerDescriptorMock({ indexPatternId: 'barfoo', visible: false }),
|
||||
createWaitLayerDescriptorMock({ indexPatternId: 'fbr' }),
|
||||
createWaitLayerDescriptorMock({ indexPatternId: 'foo' }),
|
||||
] as unknown) as VectorLayerDescriptor[];
|
||||
expect(
|
||||
getQueryableUniqueIndexPatternIds.resultFunc(layerList, waitingForMapReadyLayerList)
|
||||
).toEqual(['foo', 'fbr']);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -377,16 +377,6 @@ export const getSelectedLayerJoinDescriptors = createSelector(getSelectedLayer,
|
|||
});
|
||||
});
|
||||
|
||||
// Get list of unique index patterns used by all layers
|
||||
export const getUniqueIndexPatternIds = createSelector(getLayerList, (layerList) => {
|
||||
const indexPatternIds: string[] = [];
|
||||
layerList.forEach((layer) => {
|
||||
indexPatternIds.push(...layer.getIndexPatternIds());
|
||||
});
|
||||
return _.uniq(indexPatternIds).sort();
|
||||
});
|
||||
|
||||
// Get list of unique index patterns, excluding index patterns from layers that disable applyGlobalQuery
|
||||
export const getQueryableUniqueIndexPatternIds = createSelector(
|
||||
getLayerList,
|
||||
getWaitingForMapReadyLayerListRaw,
|
||||
|
@ -396,11 +386,15 @@ export const getQueryableUniqueIndexPatternIds = createSelector(
|
|||
if (waitingForMapReadyLayerList.length) {
|
||||
waitingForMapReadyLayerList.forEach((layerDescriptor) => {
|
||||
const layer = createLayerInstance(layerDescriptor);
|
||||
if (layer.isVisible()) {
|
||||
indexPatternIds.push(...layer.getQueryableIndexPatternIds());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
layerList.forEach((layer) => {
|
||||
if (layer.isVisible()) {
|
||||
indexPatternIds.push(...layer.getQueryableIndexPatternIds());
|
||||
}
|
||||
});
|
||||
}
|
||||
return _.uniq(indexPatternIds);
|
||||
|
|
Loading…
Reference in a new issue