forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Maps] move apply global filter settting from layer to source (elasti…
…c#50523) * [Maps] move apply global filter settting from layer to source * add checkbox to join UI * update edit UI for grid and pew-pew source * add migrations * update docs * remove setting of applyGlobalQuery from geojson upload * upgrade SIEM layer descriptors * fix jest tests and api integration tests * fix functional tests * fix functional test * i18n * review feedback * doc re-wording * i18n fixes
- Loading branch information
Showing
36 changed files
with
343 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
x-pack/legacy/plugins/maps/common/migrations/move_apply_global_query.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import _ from 'lodash'; | ||
import { | ||
ES_GEO_GRID, | ||
ES_PEW_PEW, | ||
ES_SEARCH, | ||
} from '../constants'; | ||
|
||
function isEsSource(layerDescriptor) { | ||
const sourceType = _.get(layerDescriptor, 'sourceDescriptor.type'); | ||
return [ES_GEO_GRID, ES_PEW_PEW, ES_SEARCH].includes(sourceType); | ||
} | ||
|
||
// Migration to move applyGlobalQuery from layer to sources. | ||
// Moving to source to provide user the granularity needed to apply global filter per source. | ||
export function moveApplyGlobalQueryToSources({ attributes }) { | ||
if (!attributes.layerListJSON) { | ||
return attributes; | ||
} | ||
|
||
const layerList = JSON.parse(attributes.layerListJSON); | ||
layerList.forEach((layerDescriptor) => { | ||
|
||
const applyGlobalQuery = _.get(layerDescriptor, 'applyGlobalQuery', true); | ||
delete layerDescriptor.applyGlobalQuery; | ||
|
||
if (isEsSource(layerDescriptor)) { | ||
layerDescriptor.sourceDescriptor.applyGlobalQuery = applyGlobalQuery; | ||
} | ||
|
||
if (_.has(layerDescriptor, 'joins')) { | ||
layerDescriptor.joins.forEach(joinDescriptor => { | ||
if (_.has(joinDescriptor, 'right')) { | ||
// joinDescriptor.right is ES_TERM_SOURCE source descriptor | ||
joinDescriptor.right.applyGlobalQuery = applyGlobalQuery; | ||
} | ||
}); | ||
} | ||
|
||
}); | ||
|
||
return { | ||
...attributes, | ||
layerListJSON: JSON.stringify(layerList), | ||
}; | ||
} |
109 changes: 109 additions & 0 deletions
109
x-pack/legacy/plugins/maps/common/migrations/move_apply_global_query.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
/* eslint max-len: 0 */ | ||
|
||
import { moveApplyGlobalQueryToSources } from './move_apply_global_query'; | ||
|
||
describe('moveApplyGlobalQueryToSources', () => { | ||
|
||
test('Should handle missing layerListJSON attribute', () => { | ||
const attributes = { | ||
title: 'my map', | ||
}; | ||
expect(moveApplyGlobalQueryToSources({ attributes })).toEqual({ | ||
title: 'my map', | ||
}); | ||
}); | ||
|
||
test('Should ignore layers without ES sources', () => { | ||
const layerListJSON = JSON.stringify([ | ||
{ | ||
type: 'TILE', | ||
sourceDescriptor: { | ||
type: 'EMS_TMS' | ||
} | ||
} | ||
]); | ||
const attributes = { | ||
title: 'my map', | ||
layerListJSON | ||
}; | ||
expect(moveApplyGlobalQueryToSources({ attributes })).toEqual({ | ||
title: 'my map', | ||
layerListJSON, | ||
}); | ||
}); | ||
|
||
test('Should move applyGlobalQuery from layer to source', () => { | ||
const layerListJSON = JSON.stringify([ | ||
{ | ||
type: 'HEATMAP', | ||
applyGlobalQuery: false, | ||
sourceDescriptor: { | ||
type: 'ES_GEO_GRID' | ||
} | ||
} | ||
]); | ||
const attributes = { | ||
title: 'my map', | ||
layerListJSON | ||
}; | ||
expect(moveApplyGlobalQueryToSources({ attributes })).toEqual({ | ||
title: 'my map', | ||
layerListJSON: '[{\"type\":\"HEATMAP\",\"sourceDescriptor\":{\"type\":\"ES_GEO_GRID\",\"applyGlobalQuery\":false}}]', | ||
}); | ||
}); | ||
|
||
test('Should move applyGlobalQuery from layer to join', () => { | ||
const layerListJSON = JSON.stringify([ | ||
{ | ||
type: 'VECTOR', | ||
applyGlobalQuery: false, | ||
sourceDescriptor: { | ||
type: 'EMS_FILE' | ||
}, | ||
joins: [ | ||
{ | ||
right: {} | ||
} | ||
] | ||
} | ||
]); | ||
const attributes = { | ||
title: 'my map', | ||
layerListJSON | ||
}; | ||
expect(moveApplyGlobalQueryToSources({ attributes })).toEqual({ | ||
title: 'my map', | ||
layerListJSON: '[{\"type\":\"VECTOR\",\"sourceDescriptor\":{\"type\":\"EMS_FILE\"},\"joins\":[{\"right\":{\"applyGlobalQuery\":false}}]}]', | ||
}); | ||
}); | ||
|
||
test('Should set applyGlobalQuery to true sources when no value is provided in layer', () => { | ||
const layerListJSON = JSON.stringify([ | ||
{ | ||
type: 'VECTOR', | ||
sourceDescriptor: { | ||
type: 'ES_GEO_GRID' | ||
}, | ||
joins: [ | ||
{ | ||
right: {} | ||
} | ||
] | ||
} | ||
]); | ||
const attributes = { | ||
title: 'my map', | ||
layerListJSON | ||
}; | ||
expect(moveApplyGlobalQueryToSources({ attributes })).toEqual({ | ||
title: 'my map', | ||
layerListJSON: '[{\"type\":\"VECTOR\",\"sourceDescriptor\":{\"type\":\"ES_GEO_GRID\",\"applyGlobalQuery\":true},\"joins\":[{\"right\":{\"applyGlobalQuery\":true}}]}]', | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
x-pack/legacy/plugins/maps/public/components/global_filter_checkbox.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { EuiFormRow, EuiSwitch } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
const label = i18n.translate('xpack.maps.layerPanel.applyGlobalQueryCheckboxLabel', { | ||
defaultMessage: `Apply global filter to source`, | ||
}); | ||
|
||
export function GlobalFilterCheckbox({ applyGlobalQuery, customLabel, setApplyGlobalQuery }) { | ||
const onApplyGlobalQueryChange = event => { | ||
setApplyGlobalQuery(event.target.checked); | ||
}; | ||
|
||
return ( | ||
<EuiFormRow | ||
display="columnCompressedSwitch" | ||
> | ||
<EuiSwitch | ||
label={customLabel ? customLabel : label} | ||
checked={applyGlobalQuery} | ||
onChange={onApplyGlobalQueryChange} | ||
data-test-subj="mapLayerPanelApplyGlobalQueryCheckbox" | ||
compressed | ||
/> | ||
</EuiFormRow> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.