forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: address feature request elastic#99239
This commit addresses elastic#99239 as a proof of concept. The filter list is now constrained only to geo fields that are actually used within the layer sources. Because the ultimate filter created is independent of the index pattern, the UI instead shows the field type and deduplicates when the same field exist in multiple index pattern. This commit leaves room to refactor out some unneeded types and does not yet add unittests.
- Loading branch information
Showing
9 changed files
with
192 additions
and
42 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
79 changes: 79 additions & 0 deletions
79
x-pack/plugins/maps/public/components/geo_field_select.tsx
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,79 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { EuiFormRow, EuiSuperSelect, EuiTextColor, EuiText } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { GeoFieldWithIndex } from './geo_field_with_index'; | ||
|
||
const OPTION_ID_DELIMITER = '/'; | ||
|
||
function createOptionId(geoField: GeoFieldWithIndex): string { | ||
// Namespace field with indexPatterId to avoid collisions between field names | ||
return `${geoField.geoFieldType}${OPTION_ID_DELIMITER}${geoField.geoFieldName}`; | ||
} | ||
|
||
function splitOptionId(optionId: string) { | ||
const split = optionId.split(OPTION_ID_DELIMITER); | ||
return { | ||
geoFieldType: split[0], | ||
geoFieldName: split[1], | ||
}; | ||
} | ||
|
||
interface Props { | ||
fields: GeoFieldWithIndex[]; | ||
onChange: (newSelectedField: GeoFieldWithIndex | undefined) => void; | ||
selectedField: GeoFieldWithIndex | undefined; | ||
} | ||
|
||
export function GeoFieldSelect({ fields, onChange, selectedField }: Props) { | ||
function onFieldSelect(selectedOptionId: string) { | ||
const { geoFieldType, geoFieldName } = splitOptionId(selectedOptionId); | ||
|
||
const newSelectedField = fields.find((field) => { | ||
return field.geoFieldType === geoFieldType && field.geoFieldName === geoFieldName; | ||
}); | ||
onChange(newSelectedField); | ||
} | ||
|
||
const options = fields.map((geoField: GeoFieldWithIndex) => { | ||
return { | ||
inputDisplay: ( | ||
<EuiText size="s"> | ||
<EuiTextColor color="subdued"> | ||
<small> {geoField.geoFieldType}</small> | ||
</EuiTextColor> | ||
<br /> | ||
{geoField.geoFieldName} | ||
</EuiText> | ||
), | ||
value: createOptionId(geoField), | ||
}; | ||
}); | ||
|
||
return ( | ||
<EuiFormRow | ||
className="mapGeometryFilter__geoFieldSuperSelectWrapper" | ||
label={i18n.translate('xpack.maps.multiIndexFieldSelect.fieldLabel', { | ||
defaultMessage: 'Filtering field', | ||
})} | ||
display="rowCompressed" | ||
> | ||
<EuiSuperSelect | ||
className="mapGeometryFilter__geoFieldSuperSelect" | ||
options={options} | ||
valueOfSelected={selectedField ? createOptionId(selectedField) : ''} | ||
onChange={onFieldSelect} | ||
hasDividers={true} | ||
fullWidth={true} | ||
compressed={true} | ||
itemClassName="mapGeometryFilter__geoFieldItem" | ||
/> | ||
</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
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