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

Use select for numerical properties #2628

Merged
merged 3 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
78 changes: 43 additions & 35 deletions frontend/src/scenes/insights/ActionFilter/ActionFilterRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import React, { useRef, useState } from 'react'
import { useActions, useValues } from 'kea'
import { EntityTypes } from '../trendsLogic'
import { ActionFilterDropdown } from './ActionFilterDropdown'
import { Button, Tooltip, Dropdown, Menu, Col, Row } from 'antd'
import { Button, Tooltip, Dropdown, Menu, Col, Row, Select } from 'antd'
import { PropertyFilters } from 'lib/components/PropertyFilters/PropertyFilters'
import { userLogic } from 'scenes/userLogic'
import { DownOutlined } from '@ant-design/icons'
import { CloseButton } from 'lib/components/CloseButton'
import { SelectGradientOverflow } from 'lib/components/SelectGradientOverflow'
import './ActionFilterRow.scss'

const MATHS = {
total: {
Expand Down Expand Up @@ -280,40 +282,46 @@ function MathPropertySelector(props) {
({ value }) => value[0] !== '$' && value !== 'distinct_id' && value !== 'token'
)

const overlay = () => {
return (
<Menu onClick={({ item }) => props.onMathPropertySelect(props.index, item.props['data-value'])}>
{applicableProperties.map(({ value, label }) => {
return (
<Menu.Item
key={`math-property-${value}-${props.index}`}
data-attr={`math-property-${value}-${props.index}`}
data-value={value}
>
<Tooltip
title={
<>
Calculate {MATHS[props.math].name.toLowerCase()} from property{' '}
<code>{label}</code>. Note that only {props.name} occurences where{' '}
<code>{label}</code> is set and a number will be taken into account.
</>
}
placement="right"
>
{label}
</Tooltip>
</Menu.Item>
)
})}
</Menu>
)
}

return (
<Dropdown overlay={overlay}>
<Button data-attr={`math-property-selector-${props.index}`} style={{ marginTop: 8 }}>
{props.mathProperty || 'Select property'} <DownOutlined />
</Button>
</Dropdown>
<SelectGradientOverflow
showSearch
style={{ width: 150 }}
onChange={(_, payload) => props.onMathPropertySelect(props.index, payload && payload.value)}
className="property-select"
value={props.mathProperty}
onSearch={(input) => {
setInput(input)
if (!optionsCache[input] && !isOperatorFlag(operator)) {
loadPropertyValues(input)
}
}}
data-attr="prop-val"
dropdownMatchSelectWidth={350}
placeholder={'Select property'}
>
{applicableProperties.map(({ value, label }) => {
timgl marked this conversation as resolved.
Show resolved Hide resolved
timgl marked this conversation as resolved.
Show resolved Hide resolved
return (
<Select.Option
key={`math-property-${value}-${props.index}`}
value={value}
data-attr={`math-property-${value}-${props.index}`}
>
<Tooltip
title={
<>
Calculate {MATHS[props.math].name.toLowerCase()} from property <code>{label}</code>.
Note that only {props.name} occurences where <code>{label}</code> is set and a
number will be taken into account.
</>
}
placement="right"
overlayStyle={{ zIndex: 9999999999 }}
>
{label}
</Tooltip>
</Select.Option>
)
})}
</SelectGradientOverflow>
)
}
38 changes: 38 additions & 0 deletions frontend/src/scenes/insights/ActionFilter/ActionFilterRow.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.property-select {
cursor: pointer;
margin-top: 6px;
.ant-select-selector {
border-color: #d9d9d9 !important;
cursor: pointer !important;
}
.ant-select-arrow {
color: #2d2d2d;
font-size: 10px;
}

&:not(.ant-select-open) input {
cursor: pointer !important;
}
&:hover .ant-select-selection-placeholder,
&:hover .ant-select-arrow,
&:hover .ant-select-selection-item {
color: #7d9bff !important;
}
&:hover .ant-select-selector {
border-color: #7d9bff !important;
}

.ant-select-selector,
.ant-select-selection-placeholder,
.ant-select-selection-search-input {
font-size: 13px;
height: 28px !important;
}
.ant-select-selection-item {
line-height: 26px !important;
}
.ant-select-selection-placeholder {
line-height: 24px !important;
color: #2d2d2d;
}
}