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] introduce fields (1) #8

Open
wants to merge 132 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
659280e
lint
thomasneirynck Oct 23, 2019
4387b75
delete junk
thomasneirynck Oct 23, 2019
259f727
add ems fields
thomasneirynck Oct 23, 2019
f8df6bf
use fields in the tooltipproperties selector
thomasneirynck Oct 23, 2019
9ffdd30
tooltip props for ems
thomasneirynck Oct 23, 2019
69dba5c
add fields for for es tooltips
thomasneirynck Oct 23, 2019
ced272e
remove logs
thomasneirynck Oct 23, 2019
8089c39
Merge branch 'master' of github.com:elastic/kibana into maps/introduc…
thomasneirynck Oct 23, 2019
99cd384
remove cruft
thomasneirynck Oct 23, 2019
64ceb0d
fields for term sources
thomasneirynck Oct 23, 2019
3cbe940
fieldify left field
thomasneirynck Oct 23, 2019
940abdc
fix test
thomasneirynck Oct 24, 2019
e296bb7
fix tooltip test
thomasneirynck Oct 24, 2019
ab9bd8e
update search source test
thomasneirynck Oct 24, 2019
aabcac0
start on aggmetrics
thomasneirynck Oct 24, 2019
1552260
isolate metrics
thomasneirynck Oct 24, 2019
b6607e4
temp
thomasneirynck Oct 24, 2019
373a362
tmp
thomasneirynck Oct 24, 2019
f883bfc
more IOC
thomasneirynck Oct 24, 2019
f9c82f3
tmp
thomasneirynck Oct 24, 2019
26ff042
tmp
thomasneirynck Oct 24, 2019
850686a
more removal
thomasneirynck Oct 24, 2019
581dc7b
remove dupes
thomasneirynck Oct 24, 2019
4335c71
more removal
thomasneirynck Oct 24, 2019
f984ce9
more removal
thomasneirynck Oct 24, 2019
c52ce3d
rename
thomasneirynck Oct 24, 2019
60c1aa2
tmp
thomasneirynck Oct 24, 2019
d7c4a50
remove shim
thomasneirynck Oct 24, 2019
53957c6
start refactor, this has errors
thomasneirynck Oct 24, 2019
aa66747
fix issues
thomasneirynck Oct 24, 2019
ef97786
add icons
thomasneirynck Oct 24, 2019
4e98af5
move folders
thomasneirynck Oct 27, 2019
24492e6
start refactoring to typed styles
thomasneirynck Oct 28, 2019
645a50b
widths for circles/symbols
thomasneirynck Oct 28, 2019
fe5d460
rename for clarity
thomasneirynck Oct 28, 2019
4cd0a34
fix typo
thomasneirynck Oct 28, 2019
5d166d8
halo color
thomasneirynck Oct 28, 2019
ab7360b
fill color
thomasneirynck Oct 28, 2019
63dd09b
circle color
thomasneirynck Oct 28, 2019
c048cf9
icon color
thomasneirynck Oct 28, 2019
4271357
remove unused
thomasneirynck Oct 28, 2019
34c38bc
orientations
thomasneirynck Oct 28, 2019
3d4eec6
remove comments
thomasneirynck Oct 28, 2019
161d851
clearup
thomasneirynck Oct 29, 2019
276b7c7
start removing hardcoded styles
thomasneirynck Oct 29, 2019
72a8bf3
use stylefields
thomasneirynck Oct 29, 2019
a0bbe1b
cleanup cruft
thomasneirynck Oct 29, 2019
9d6fefb
rename
thomasneirynck Oct 29, 2019
04fd072
start adding fields to styles
thomasneirynck Oct 29, 2019
0590e7e
start field-refactor
thomasneirynck Oct 29, 2019
88c289f
test
thomasneirynck Oct 29, 2019
a70ccff
remove log
thomasneirynck Oct 29, 2019
47f3259
read style
thomasneirynck Oct 30, 2019
ba77ce3
heatmaplayer
thomasneirynck Oct 30, 2019
31b9e88
minor changes
thomasneirynck Oct 30, 2019
27a883d
more changes
thomasneirynck Oct 30, 2019
7804044
more typing
thomasneirynck Oct 30, 2019
4c04d6d
more typing
thomasneirynck Oct 30, 2019
607c801
rename for clarity
thomasneirynck Oct 30, 2019
9e84385
renames
thomasneirynck Oct 30, 2019
6e0e168
fix wonky mistake
thomasneirynck Oct 30, 2019
066865d
add todos
thomasneirynck Oct 30, 2019
d4b1808
Merge branch 'master' into maps/introduce_fields
thomasneirynck Oct 31, 2019
5df73ea
merge in master (start)
thomasneirynck Nov 4, 2019
0ca8b07
add style-type module
thomasneirynck Nov 4, 2019
b585daf
remove logs
thomasneirynck Nov 4, 2019
5edf1f4
Merge branch 'master' into chore/introduce_fields
thomasneirynck Nov 4, 2019
828ea0f
fix counts
thomasneirynck Nov 4, 2019
c8e6198
fix refactor
thomasneirynck Nov 6, 2019
c2648cc
fix test
thomasneirynck Nov 9, 2019
92d905f
Merge branch 'master' into chore/introduce_fields
thomasneirynck Nov 9, 2019
0fc8866
fix tests
thomasneirynck Nov 9, 2019
26328ee
Merge branch 'master' into chore/introduce_fields
elasticmachine Nov 9, 2019
95d8958
start removing usage of field-formatter
thomasneirynck Nov 9, 2019
034bc8b
start more refactors
thomasneirynck Nov 10, 2019
e9476e2
Merge branch 'master' into chore/introduce_fields
elasticmachine Nov 10, 2019
7173e1a
more removal
thomasneirynck Nov 10, 2019
4aa596a
remove hardcoding from heatmap
thomasneirynck Nov 10, 2019
4952b6a
remove getPropertyLabel
thomasneirynck Nov 10, 2019
2218ef3
Merge branch 'master' into chore/introduce_fields
thomasneirynck Nov 11, 2019
c3a63bf
Merge branch 'chore/introduce_fields' of github.com:thomasneirynck/ki…
thomasneirynck Nov 11, 2019
bad52f7
delete unused
thomasneirynck Nov 11, 2019
6d997f6
fix tooltips
thomasneirynck Nov 11, 2019
fd39acc
fix test
thomasneirynck Nov 11, 2019
7e8a1fb
rename for clarity
thomasneirynck Nov 11, 2019
12698fd
add kibana region field
thomasneirynck Nov 11, 2019
22432e8
fix text stub
thomasneirynck Nov 11, 2019
b0c13dd
tmp commit
thomasneirynck Nov 12, 2019
efc022b
Merge branch 'master' of github.com:elastic/kibana into chore/introdu…
thomasneirynck Nov 14, 2019
74be592
review feedback
thomasneirynck Nov 14, 2019
f36e3b9
remove comment
thomasneirynck Nov 14, 2019
e54f86f
field formatter
thomasneirynck Nov 14, 2019
4ab5ce0
remove records
thomasneirynck Nov 14, 2019
788573e
rename for clarity
thomasneirynck Nov 14, 2019
20c00bf
fix jest
thomasneirynck Nov 14, 2019
88e7487
optimize initialization
thomasneirynck Nov 14, 2019
ae8fd4c
lint
thomasneirynck Nov 15, 2019
1681e17
regenerate after rename
thomasneirynck Nov 15, 2019
f278cd5
keep track of object reference
thomasneirynck Nov 15, 2019
2ae2023
remove log
thomasneirynck Nov 15, 2019
6852056
use getter, so count is loaded
thomasneirynck Nov 15, 2019
2768aa1
Merge branch 'master' into chore/introduce_fields
elasticmachine Nov 16, 2019
8d7c777
Merge branch 'master' into chore/introduce_fields
elasticmachine Nov 18, 2019
9cb869c
ensure styleprops get cleared
thomasneirynck Nov 18, 2019
97c85b2
Merge branch 'master' of github.com:elastic/kibana into chore/introdu…
thomasneirynck Nov 18, 2019
b64c6a5
Merge branch 'chore/introduce_fields' of github.com:thomasneirynck/ki…
thomasneirynck Nov 18, 2019
86e0dec
review
thomasneirynck Nov 18, 2019
2e707bc
make state-checking consistent
thomasneirynck Nov 18, 2019
c71be89
fix infinite loop
thomasneirynck Nov 18, 2019
d6745f2
Merge branch 'master' into chore/introduce_fields
thomasneirynck Nov 18, 2019
a586646
fix agg tooltip creation
thomasneirynck Nov 18, 2019
ff424e9
feedback
thomasneirynck Nov 19, 2019
47e98a4
remove field_with_origin
thomasneirynck Nov 19, 2019
ba63cfb
remove style from layer constructor
thomasneirynck Nov 19, 2019
7b918d6
Merge branch 'master' into chore/introduce_fields
elasticmachine Nov 19, 2019
2e0d835
Merge branch 'master' into chore/introduce_fields
elasticmachine Nov 19, 2019
9b5fce9
feedback
thomasneirynck Nov 19, 2019
95ca2ed
Merge branch 'chore/introduce_fields' of github.com:thomasneirynck/ki…
thomasneirynck Nov 19, 2019
69a605c
feedback
thomasneirynck Nov 19, 2019
f51b2c1
feedback
thomasneirynck Nov 20, 2019
6bda091
remove style options
thomasneirynck Nov 20, 2019
b204cfd
Merge branch 'master' into chore/introduce_fields
elasticmachine Nov 20, 2019
590498b
feedback
thomasneirynck Nov 20, 2019
51a4107
operator precedence madness
thomasneirynck Nov 20, 2019
344f12d
Merge branch 'master' of github.com:elastic/kibana into chore/introdu…
thomasneirynck Nov 20, 2019
d812d82
Merge branch 'chore/introduce_fields' of github.com:thomasneirynck/ki…
thomasneirynck Nov 20, 2019
35b4604
feedback
thomasneirynck Nov 20, 2019
e7e79c1
remove cruft
thomasneirynck Nov 20, 2019
8d97ff4
remove dangling i18n translations
thomasneirynck Nov 21, 2019
b925c34
use custom label, if any
thomasneirynck Nov 21, 2019
9ecaf76
improve naming
thomasneirynck Nov 21, 2019
1c50238
fix field-formatter lookup
thomasneirynck Nov 21, 2019
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
13 changes: 13 additions & 0 deletions x-pack/legacy/plugins/maps/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { i18n } from '@kbn/i18n';

export const EMS_CATALOGUE_PATH = 'ems/catalogue';

Expand Down Expand Up @@ -114,3 +115,15 @@ export const METRIC_TYPE = {
SUM: 'sum',
UNIQUE_COUNT: 'cardinality',
};

export const COUNT_AGG_TYPE = METRIC_TYPE.COUNT;
export const COUNT_PROP_LABEL = i18n.translate('xpack.maps.aggs.defaultCountLabel', {
defaultMessage: 'count'
});

export const COUNT_PROP_NAME = 'doc_count';

export const STYLE_TYPE = {
'STATIC': 'STATIC',
'DYNAMIC': 'DYNAMIC'
};
4 changes: 1 addition & 3 deletions x-pack/legacy/plugins/maps/public/actions/map_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -732,9 +732,7 @@ export function clearMissingStyleProperties(layerId) {
return;
}

const dateFields = await targetLayer.getDateFields();
const numberFields = await targetLayer.getNumberFields();
const ordinalFields = [...dateFields, ...numberFields];
const ordinalFields = await targetLayer.getOrdinalFields();
const { hasChanges, nextStyleDescriptor } = style.getDescriptorWithMissingStylePropsRemoved(ordinalFields);
if (hasChanges) {
dispatch(updateLayerStyle(layerId, nextStyleDescriptor));
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

118 changes: 93 additions & 25 deletions x-pack/legacy/plugins/maps/public/components/tooltip_selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,109 @@ const reorder = (list, startIndex, endIndex) => {
return result;
};

const getProps = async field => {
return new Promise(async (resolve, reject) => {
try {
const label = await field.getLabel();
const type = await field.getDataType();
resolve({
label: label,
type: type,
name: field.getName()
});
} catch(e) {
reject(e);
}
});
};

export class TooltipSelector extends Component {

state = {
fieldProps: [],
selectedFieldProps: []
};

constructor() {
super();
this._isMounted = false;
this._previousFields = null;
this._previousSelectedTooltips = null;
}

componentDidMount() {
this._isMounted = true;
this._loadFieldProps();
this._loadTooltipFieldProps();
}

componentWillUnmount() {
this._isMounted = false;
}

componentDidUpdate() {
this._loadTooltipFieldProps();
this._loadFieldProps();
}

async _loadTooltipFieldProps() {

if (!this.props.tooltipFields || this.props.tooltipFields === this._previousSelectedTooltips) {
return;
}

this._previousSelectedTooltips = this.props.tooltipFields;
const selectedProps = this.props.tooltipFields.map(getProps);
const selectedFieldProps = await Promise.all(selectedProps);
if (this._isMounted) {
this.setState({ selectedFieldProps });
}

}

async _loadFieldProps() {

if (!this.props.fields || this.props.fields === this._previousFields) {
return;
}

this._previousFields = this.props.fields;
const props = this.props.fields.map(getProps);
const fieldProps = await Promise.all(props);
if (this._isMounted) {
this.setState({ fieldProps });
}

}

_getPropertyLabel = (propertyName) => {
if (!this.props.fields) {
if (!this.state.fieldProps.length) {
return propertyName;
}

const field = this.props.fields.find(field => {
const prop = this.state.fieldProps.find((field) => {
return field.name === propertyName;
});
return prop.label ? prop.label : propertyName;
}

return field && field.label
? field.label
: propertyName;
_getTooltipProperties() {
return this.props.tooltipFields.map(field => field.getName());
}

_onAdd = (properties) => {
if (!this.props.tooltipProperties) {
if (!this.props.tooltipFields) {
this.props.onChange([...properties]);
} else {
this.props.onChange([...this.props.tooltipProperties, ...properties]);
const existingProperties = this._getTooltipProperties();
this.props.onChange([...existingProperties, ...properties]);
}
}

_removeProperty = (index) => {
if (!this.props.tooltipProperties) {
if (!this.props.tooltipFields) {
this.props.onChange([]);
} else {
const tooltipProperties = [...this.props.tooltipProperties];
const tooltipProperties = this._getTooltipProperties();
tooltipProperties.splice(index, 1);
this.props.onChange(tooltipProperties);
}
Expand All @@ -70,24 +144,24 @@ export class TooltipSelector extends Component {
return;
}

this.props.onChange(reorder(this.props.tooltipProperties, source.index, destination.index));
this.props.onChange(reorder(this._getTooltipProperties(), source.index, destination.index));
};

_renderProperties() {
if (!this.props.tooltipProperties) {
if (!this.state.selectedFieldProps.length) {
return null;
}

return (
<EuiDragDropContext onDragEnd={this._onDragEnd}>
<EuiDroppable droppableId="mapLayerTOC" spacing="none">
{(provided, snapshot) => (
this.props.tooltipProperties.map((propertyName, idx) => (
this.state.selectedFieldProps.map((field, idx) => (
<EuiDraggable
spacing="none"
key={propertyName}
key={field.name}
index={idx}
draggableId={propertyName}
draggableId={field.name}
customDragHandle={true}
disableInteractiveElementBlocking // Allows button to be drag handle
>
Expand All @@ -99,7 +173,7 @@ export class TooltipSelector extends Component {
})}
>
<EuiText className="mapTooltipSelector__propertyContent" size="s">
{this._getPropertyLabel(propertyName)}
{this._getPropertyLabel(field.name)}
</EuiText>
<div className="mapTooltipSelector__propertyIcons">
<EuiButtonIcon
Expand Down Expand Up @@ -137,13 +211,6 @@ export class TooltipSelector extends Component {
}

render() {

const selectedFields = this.props.tooltipProperties
? this.props.tooltipProperties.map(propertyName => {
return { name: propertyName };
})
: [];

return (
<div>
<EuiTitle size="xxs">
Expand All @@ -160,11 +227,12 @@ export class TooltipSelector extends Component {
<EuiTextAlign textAlign="center">
<AddTooltipFieldPopover
onAdd={this._onAdd}
fields={this.props.fields}
selectedFields={selectedFields}
fields={this.state.fieldProps}
selectedFields={this.state.selectedFieldProps}
/>
</EuiTextAlign>
</div>
);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,59 @@ import { shallow } from 'enzyme';

import { TooltipSelector } from './tooltip_selector';


class MockField {
constructor({ name, label, type }) {
this._name = name;
this._label = label;
this._type = type;
}

getName() {
return this._name;
}

async getLabel() {
return this._label || 'foobar_label';
}

async getDataType() {
return this._type || 'foobar_type';
}
}

const defaultProps = {
tooltipProperties: ['iso2'],
tooltipFields: [new MockField({ name: 'iso2' })],
onChange: (()=>{}),
fields: [
{
new MockField({
name: 'iso2',
label: 'ISO 3166-1 alpha-2 code',
type: 'string'
},
{
}),
new MockField({
name: 'iso3',
type: 'string'
},
})
]
};

describe('TooltipSelector', () => {

test('should render component', async () => {

const component = shallow(
<TooltipSelector
{...defaultProps}
/>
);

expect(component)
.toMatchSnapshot();
// Ensure all promises resolve
await new Promise(resolve => process.nextTick(resolve));
// Ensure the state changes are reflected
component.update();
expect(component).toMatchSnapshot();

});

});
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,14 @@ export class Join extends Component {
async _loadLeftFields() {
let leftFields;
try {
leftFields = await this.props.layer.getLeftJoinFields();
const leftFieldsInstances = await this.props.layer.getLeftJoinFields();
const leftFieldPromises = leftFieldsInstances.map(async (field) => {
return {
name: field.getName(),
label: await field.getLabel()
};
});
leftFields = await Promise.all(leftFieldPromises);
} catch (error) {
leftFields = [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export class FeatureProperties extends React.Component {
}

const rows = this.state.properties.map(tooltipProperty => {

const label = tooltipProperty.getPropertyName();
return (
<tr key={label}>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export class TOCEntry extends React.Component {
return null;
}

const tocDetails = this.props.layer.getLegendDetails();
const tocDetails = this.props.layer.renderLegendDetails();
if (!tocDetails) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const LAYER_ID = '1';

const mockLayer = {
getId: () => { return LAYER_ID; },
getLegendDetails: () => { return (<div>TOC details mock</div>); },
renderLegendDetails: () => { return (<div>TOC details mock</div>); },
getDisplayName: () => { return 'layer 1'; },
isVisible: () => { return true; },
showAtZoomLevel: () => { return true; },
Expand Down
Loading