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

Combine events and actions into select box #2394

Merged
merged 10 commits into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 6 additions & 4 deletions cypress/integration/funnels.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ describe('Funnels', () => {
it('Add 1 action to funnel', () => {
cy.get('[data-attr=add-action-event-button]').click()
cy.get('[data-attr=trend-element-subject-0]').click()
cy.contains('Pageviews').click()

// Double click: https://www.cypress.io/blog/2019/01/22/when-can-the-test-click/
cy.contains('Pageviews').click().click()

cy.get('[data-attr=save-funnel-button]').click()

Expand All @@ -18,7 +20,7 @@ describe('Funnels', () => {
it('Apply date filter to funnel', () => {
cy.get('[data-attr=add-action-event-button]').click()
cy.get('[data-attr=trend-element-subject-0]').click()
cy.contains('Pageviews').click()
cy.contains('Pageviews').click().click()
cy.get('[data-attr=save-funnel-button]').click()

cy.get('[data-attr=date-filter]').click()
Expand All @@ -33,11 +35,11 @@ describe('Funnels', () => {
it('Add 2 actions to funnel', () => {
cy.get('[data-attr=add-action-event-button]').click()
cy.get('[data-attr=trend-element-subject-0]').click()
cy.contains('Pageviews').click()
cy.contains('Pageviews').click().click()

cy.get('[data-attr=add-action-event-button]').click()
cy.get('[data-attr=trend-element-subject-1]').click()
cy.contains('HogFlix homepage view').click()
cy.contains('HogFlix homepage view').click().click()

cy.get('[data-attr=save-funnel-button]').click()

Expand Down
11 changes: 8 additions & 3 deletions ee/clickhouse/process_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,14 @@ def _capture_ee(
for index, el in enumerate(elements)
]

team = Team.objects.only("slack_incoming_webhook", "event_names", "event_properties", "anonymize_ips").get(
pk=team_id
)
team = Team.objects.only(
"slack_incoming_webhook",
"event_names",
"event_properties",
"event_names_with_usage",
"event_properties_with_usage",
"anonymize_ips",
).get(pk=team_id)

if not team.anonymize_ips and "$ip" not in properties:
properties["$ip"] = ip
Expand Down
106 changes: 0 additions & 106 deletions frontend/src/lib/components/ActionSelectBox.js

This file was deleted.

32 changes: 0 additions & 32 deletions frontend/src/lib/components/ActionSelectTab.js

This file was deleted.

51 changes: 51 additions & 0 deletions frontend/src/lib/components/SelectBox.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
.select-box {
position: absolute;
min-width: 620px;
box-shadow: 0 0 8px rgba(0, 0, 0, 0.4);
border-radius: 2px;
border: 1px solid rgba(0, 0, 0, 0.1);
height: 400px;
background: #fff;
z-index: 999;
overflow: visible;
.ant-input {
border-width: 0 0 1px 0;
outline: none;
}
.ant-divider {
margin: 12px 0;
border-width: 2px;
}

.ant-list-item {
padding: 4px 12px;
cursor: pointer;
border: none;

&:hover,
&.selected {
background: rgba(0, 0, 0, 0.1);
}
}
.search-list {
overflow-y: scroll;
height: calc(100% - 32px);
padding-top: 4px;
/* Hide scrollbar for IE, Edge and Firefox */
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */

/* Hide scrollbar for Chrome, Safari and Opera */
::-webkit-scrollbar {
display: none;
}
}
.info-box {
padding: 1rem;
overflow-y: scroll;
height: 100%;
pre {
margin: 0;
}
}
}
144 changes: 144 additions & 0 deletions frontend/src/lib/components/SelectBox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import React, { useRef, useEffect, useState } from 'react'
import { useActions, useValues } from 'kea'
import { Col, Row, Input, Divider } from 'antd'
import { List } from 'antd'
import { DownOutlined, RightOutlined } from '@ant-design/icons'
import { ActionType } from '~/types'
import { searchItems, selectBoxLogic } from 'lib/logic/selectBoxLogic'
import './SelectBox.scss'
import { selectBoxLogicType } from 'types/lib/logic/selectBoxLogicType'

export interface SelectBoxItem {
dataSource: SelectedItem[]
renderInfo({ item }: { item: SelectedItem }): JSX.Element
name: JSX.Element | string
}

export interface SelectedItem {
name: string
key: string
action?: ActionType
event?: string
volume?: number
usage_count?: number
category?: string
}

export function SelectBox({
items,
selectedItemKey,
onSelect,
onDismiss,
}: {
items: SelectBoxItem[]
selectedItemKey: string
onSelect: CallableFunction
onDismiss: CallableFunction
}): JSX.Element {
const dropdownRef = useRef()
const dropdownLogic = selectBoxLogic({ updateFilter: onSelect, items })
const { selectedItem, RenderInfo } = useValues(dropdownLogic)
const { setSearch, setSelectedItem, onKeyDown } = useActions(dropdownLogic)

const deselect = (e): void => {
if (dropdownRef?.current?.contains(e.target)) {
return
}
onDismiss && onDismiss(e)
}

useEffect(() => {
if (selectedItemKey) {
const allSources = items.map((item) => item.dataSource).flat()
setSelectedItem(allSources.filter((item) => item.key === selectedItemKey)[0] || false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the || false needed here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually not sure it is. I ran into this while developing but can't reproduce it anymore. I do still think it's safer, as the alternative is having a complete white-out

const offset = document.querySelector('.search-list [datakey="' + selectedItemKey + '"]')?.offsetTop
document.querySelector('.search-list').scrollTop = offset
}
document.addEventListener('mousedown', deselect)
document.addEventListener('keydown', onKeyDown)
macobo marked this conversation as resolved.
Show resolved Hide resolved
return () => {
document.removeEventListener('mousedown', deselect)
document.removeEventListener('keydown', onKeyDown)
}
}, [])
return (
<div ref={dropdownRef} className="select-box" tabIndex="0">
<Row style={{ height: '100%' }}>
<Col sm={14} style={{ borderRight: '1px solid rgba(0, 0, 0, 0.1)', maxHeight: '100%' }}>
<Input
placeholder="Search events"
autoFocus
onChange={(e) => {
setSearch(e.target.value)
}}
style={{ width: '100%', borderRadius: 0 }}
/>
<div className="search-list">
{items.map((item) => (
<>
<SelectUnit
name={item.name}
dropdownLogic={dropdownLogic}
dataSource={item.dataSource}
/>
<Divider />
</>
))}
</div>
</Col>
<Col sm={10} className="info-box">
{RenderInfo && <RenderInfo item={selectedItem} />}
</Col>
</Row>
</div>
)
}

export function SelectUnit({
name,
dataSource,
dropdownLogic,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Why is this a prop? Could find no other instances where we pass logics around this way besides this PR but I didn't look super hard.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm take a look at PropertyFilter.js for example. It's a way of making sure the props for the logic are passed through correctly everywhere.

}: {
name: string | JSX.Element
dataSource: SelectedItem[]
dropdownLogic: selectBoxLogicType
}): JSX.Element {
const [isCollapsed, setIsCollapsed] = useState(false)
const { setSelectedItem, clickSelectedItem } = useActions(dropdownLogic)
const { selectedItem, search, blockMouseOver } = useValues(dropdownLogic)
const data = !search ? dataSource : searchItems(dataSource, search)
return (
<>
<span onClick={() => setIsCollapsed(!isCollapsed)}>
<h4 style={{ cursor: 'pointer', userSelect: 'none', padding: '4px 12px', marginBottom: 0 }}>
{isCollapsed || data.length === 0 ? <RightOutlined /> : <DownOutlined />} {name}
<span
style={{ float: 'right', fontWeight: search && data.length > 0 ? 700 : 'normal' }}
className="text-small"
>
{data.length} event{data.length !== 1 && 's'}
</span>
</h4>
</span>
{!isCollapsed && data.length > 0 && (
<List
size="small"
bordered={false}
dataSource={data || []}
renderItem={(item: SelectedItem) => (
<List.Item
className={selectedItem.key === item.key && 'selected'}
timgl marked this conversation as resolved.
Show resolved Hide resolved
datakey={item.key}
onClick={() => clickSelectedItem(item)}
onMouseOver={() =>
!blockMouseOver && setSelectedItem({ ...item, key: item.key, category: name })
}
>
{item.name}
</List.Item>
)}
/>
)}
</>
)
}
Loading