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

Consolidate insight api #1498

Merged
merged 104 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
a9ae289
add insight history
EDsCODE Jul 29, 2020
1cac7ce
add table
EDsCODE Jul 29, 2020
e9abb9c
edit format
EDsCODE Jul 29, 2020
a68848d
links working
EDsCODE Jul 30, 2020
9e76ba1
add modal
EDsCODE Jul 30, 2020
a9987f7
add tab switch
EDsCODE Jul 30, 2020
b42be43
saving insights
EDsCODE Jul 30, 2020
c66c894
remove insights model
EDsCODE Jul 30, 2020
7776463
merge master
EDsCODE Jul 30, 2020
a7e3e2f
no model for insight history
EDsCODE Jul 30, 2020
4da8bc6
merge master
EDsCODE Jul 30, 2020
4518f0d
initial working
EDsCODE Jul 30, 2020
25dfa32
working without new model
EDsCODE Jul 30, 2020
7370860
Merge branch 'master' into insight-history
EDsCODE Jul 30, 2020
1798822
remove wrong typegen
EDsCODE Jul 30, 2020
56af887
made the history per user
EDsCODE Jul 31, 2020
0da7bd3
missing param
EDsCODE Jul 31, 2020
f0dcacd
added funnel support
EDsCODE Jul 31, 2020
3412419
add details
EDsCODE Jul 31, 2020
62910be
add delete saved insight functionality
EDsCODE Jul 31, 2020
5f306d9
add line break logic and funnel name
EDsCODE Jul 31, 2020
2e61964
fix reload logic
EDsCODE Jul 31, 2020
2a7fb07
fix rendering error
EDsCODE Jul 31, 2020
d43bd6f
add pagination component
EDsCODE Jul 31, 2020
1824964
fix bugs
EDsCODE Jul 31, 2020
4a49128
add backend tests
EDsCODE Jul 31, 2020
4ad190e
add insight-history-panel check
EDsCODE Jul 31, 2020
65662ef
merge master
EDsCODE Aug 3, 2020
153de85
add drawer and replace table
EDsCODE Aug 3, 2020
0cd92d3
add loading next
EDsCODE Aug 3, 2020
2ae2ea9
add date
EDsCODE Aug 3, 2020
e562685
add callback
EDsCODE Aug 3, 2020
e9c89d4
update test
EDsCODE Aug 3, 2020
1eb1107
use table
EDsCODE Aug 4, 2020
3131d7d
fix spacing
EDsCODE Aug 4, 2020
f921593
merge master
EDsCODE Aug 4, 2020
aeeb375
fix rows
EDsCODE Aug 4, 2020
7cf18ac
adjust spacing
EDsCODE Aug 4, 2020
3a37706
fix spacing and styling
EDsCODE Aug 5, 2020
9c3aec9
fix spacing and styling
EDsCODE Aug 5, 2020
b1b5cc9
main funnel-insight page working
EDsCODE Aug 6, 2020
733fe8a
consolidated funnels
EDsCODE Aug 6, 2020
3064208
refactor funnel dashboard item
EDsCODE Aug 6, 2020
604726c
dashboard modals working
EDsCODE Aug 6, 2020
78d5a92
update demo creation
EDsCODE Aug 7, 2020
c9e7da4
updated migration
EDsCODE Aug 7, 2020
0ef747d
fix frontend for funnels
EDsCODE Aug 7, 2020
b65bc45
remove funnel code and fix bugs
EDsCODE Aug 7, 2020
be985f8
fix test and remove caching temp
EDsCODE Aug 7, 2020
aacf7a6
remove old tests
EDsCODE Aug 7, 2020
2878151
fix types
EDsCODE Aug 7, 2020
b3dfea6
added panel for past funnels
EDsCODE Aug 7, 2020
05924aa
implement polling for funnel refactor
EDsCODE Aug 7, 2020
b26a997
.
EDsCODE Aug 11, 2020
6204d61
merge master
EDsCODE Aug 11, 2020
880c1f3
merged insight-history
EDsCODE Aug 11, 2020
30d3099
fix dashbaord item bug
EDsCODE Aug 11, 2020
12eec1a
add params
EDsCODE Aug 11, 2020
e173378
Merge branch 'funnel-refactor' into poll-funnel-post-refactor
EDsCODE Aug 11, 2020
4b9ab4e
fix params
EDsCODE Aug 11, 2020
4a3d5ba
clean up caching functionality
EDsCODE Aug 11, 2020
1b16cc5
fix types
EDsCODE Aug 11, 2020
53de8da
merge master
EDsCODE Aug 11, 2020
26d3503
merge insight history
EDsCODE Aug 11, 2020
ede3beb
caching working properly
EDsCODE Aug 11, 2020
0254641
fix dashboard update bug
EDsCODE Aug 11, 2020
8777266
fix migrations
EDsCODE Aug 11, 2020
945586c
.
EDsCODE Aug 11, 2020
3448975
fix check
EDsCODE Aug 11, 2020
10414ce
add missing package
EDsCODE Aug 11, 2020
c64efaf
fix packages
EDsCODE Aug 11, 2020
915e83d
update caching to work properly
EDsCODE Aug 12, 2020
23612b4
Fix default
EDsCODE Aug 12, 2020
5573e90
fix api and styling for insight history
EDsCODE Aug 12, 2020
a977ed2
more spacing
EDsCODE Aug 12, 2020
c5eb295
initial refactor paths to queries and consolidate into /insight
EDsCODE Aug 12, 2020
1ae29f7
missing param for paths
EDsCODE Aug 12, 2020
161c125
move path tests
EDsCODE Aug 12, 2020
bed62a7
change frontend endpoints
EDsCODE Aug 12, 2020
1ff00ce
add comments about specific parameters
EDsCODE Aug 12, 2020
62daecd
minor tune up
EDsCODE Aug 12, 2020
b2da95a
fix name
EDsCODE Aug 13, 2020
67af650
typed filter and paths
EDsCODE Aug 13, 2020
88bc419
typed retention
EDsCODE Aug 13, 2020
a3b2cfa
more typing and standardization
EDsCODE Aug 13, 2020
3beb43b
fix tests
EDsCODE Aug 13, 2020
0816a48
cleanup
EDsCODE Aug 13, 2020
bf1aa9f
update funnel automatically
EDsCODE Aug 14, 2020
c02f8cf
update tests
EDsCODE Aug 14, 2020
5b01b85
merge master
EDsCODE Aug 14, 2020
7de63ac
merge insight history
EDsCODE Aug 14, 2020
0bce9b4
fix clear condition
EDsCODE Aug 14, 2020
6624ad3
merge master
EDsCODE Aug 17, 2020
efb11e4
merge insight history
EDsCODE Aug 17, 2020
7a2615c
return save functionality
EDsCODE Aug 18, 2020
d22047a
merge master
EDsCODE Aug 19, 2020
1a1edbb
merge insight-history
EDsCODE Aug 19, 2020
0653b6e
Merge branch 'funnel-refactor' into consolidate-insight-api
EDsCODE Aug 19, 2020
63632aa
merge master
EDsCODE Aug 25, 2020
8716cc1
remove file
EDsCODE Aug 25, 2020
d3b3f54
fix path params and tests
EDsCODE Aug 25, 2020
763b833
merge master
EDsCODE Aug 31, 2020
08a7bc3
add tests
EDsCODE Aug 31, 2020
201c27a
fix type
EDsCODE Aug 31, 2020
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
3 changes: 3 additions & 0 deletions cypress/integration/funnels.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ describe('Funnels', () => {
cy.get('[data-attr=date-filter]').click()
cy.contains('Last 30 days').click()

cy.get('[data-attr=date-filter]').click()
cy.contains('Last 30 days').click()

cy.get('[data-attr=funnel-viz]').should('exist')
})

Expand Down
Binary file added dump.rdb
Binary file not shown.
2 changes: 1 addition & 1 deletion frontend/src/lib/components/AppEditorLink/appUrlsLogic.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const appUrlsLogic = kea({
events: [{ id: '$pageview', name: '$pageview', type: 'events' }],
breakdown: '$current_url',
}
let data = await api.get('api/action/trends/?' + toParams(params))
let data = await api.get('api/insight/trend/?' + toParams(params))
if (data[0]?.count === 0) return []
let domainsSeen = []
return data
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/models/funnelsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import api from 'lib/api'
import { toParams } from 'lib/utils'
import { ViewType } from 'scenes/insights/insightLogic'
import { SavedFunnel } from '~/types'
import { funnelsModelType } from './funnelsModelType'
import { insightHistoryLogic } from 'scenes/insights/InsightHistoryPanel/insightHistoryLogic'
import { funnelLogic } from 'scenes/funnels/funnelLogic'
import { funnelsModelType } from 'types/models/funnelsModelType'

const parseSavedFunnel = (result: Record<string, any>): SavedFunnel => {
return {
Expand All @@ -25,7 +25,7 @@ export const funnelsModel = kea<funnelsModelType<SavedFunnel>>({
__default: [] as SavedFunnel[],
loadFunnels: async () => {
const response = await api.get(
'api/dashboard_item/?' +
'api/insight/?' +
toParams({
order: '-created_at',
saved: true,
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/scenes/funnels/funnelLogic.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ function wait(ms = 1000) {
const SECONDS_TO_POLL = 120

export async function pollFunnel(params = {}) {
let result = await api.get('api/action/funnel/?' + toParams(params))
let result = await api.get('api/insight/funnel/?' + toParams(params))
let count = 0
while (result.loading && count < SECONDS_TO_POLL) {
await wait()
const { refresh: _, ...restParams } = params
result = await api.get('api/action/funnel/?' + toParams(restParams))
result = await api.get('api/insight/funnel/?' + toParams(restParams))
count += 1
}
// if endpoint is still loading after 2 minutes just return default
Expand Down Expand Up @@ -139,7 +139,7 @@ export const funnelLogic = kea({
actions.setSteps(result)
},
saveFunnelInsight: async ({ name }) => {
await api.create('api/dashboard_item', {
await api.create('api/insight', {
filters: values.filters,
name,
saved: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const determineFilters = (
} else if (viewType === ViewType.RETENTION) {
if (filters.target) result.push({ key: 'Target', value: `${filters.target.name}` })
} else if (viewType === ViewType.PATHS) {
if (filters.type) result.push({ key: 'Path Type', value: `${filters.type}` })
if (filters.type) result.push({ key: 'Path Type', value: `${filters.type || filters.path_type}` })
if (filters.start) result.push({ key: 'Start Point', value: `Specified` })
} else if (viewType === ViewType.FUNNELS) {
let count = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const insightHistoryLogic = kea<insightHistoryLogicType<InsightHistory>>(
__default: [] as InsightHistory[],
loadInsights: async () => {
const response = await api.get(
'api/dashboard_item/?' +
'api/insight/?' +
toParams({
order: '-created_at',
limit: 6,
Expand All @@ -57,7 +57,7 @@ export const insightHistoryLogic = kea<insightHistoryLogicType<InsightHistory>>(
__default: [] as InsightHistory[],
loadSavedInsights: async () => {
const response = await api.get(
'api/dashboard_item/?' +
'api/insight/?' +
toParams({
order: '-created_at',
saved: true,
Expand All @@ -75,7 +75,7 @@ export const insightHistoryLogic = kea<insightHistoryLogicType<InsightHistory>>(
__default: [] as InsightHistory[],
loadTeamInsights: async () => {
const response = await api.get(
'api/dashboard_item/?' +
'api/insight/?' +
toParams({
order: '-created_at',
saved: true,
Expand Down Expand Up @@ -156,13 +156,13 @@ export const insightHistoryLogic = kea<insightHistoryLogicType<InsightHistory>>(
}),
listeners: ({ actions, values }) => ({
createInsight: async ({ filters }) => {
await api.create('api/dashboard_item', {
await api.create('api/insight', {
filters,
})
actions.loadInsights()
},
saveInsight: async ({ insight: { id }, name }) => {
await api.update(`api/dashboard_item/${id}`, {
await api.update(`api/insight/${id}`, {
name,
saved: true,
})
Expand All @@ -172,7 +172,7 @@ export const insightHistoryLogic = kea<insightHistoryLogicType<InsightHistory>>(
},
deleteInsight: ({ insight }) => {
deleteWithUndo({
endpoint: 'dashboard_item',
endpoint: 'insight',
object: { name: insight.name, id: insight.id },
callback: () => actions.loadSavedInsights(),
})
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/scenes/insights/InsightTabs/PathTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export function PathTab(): JSX.Element {
<>
<h4 className="secondary">Path Type</h4>
<Select
value={filter?.type || PAGEVIEW}
value={filter?.path_type || PAGEVIEW}
defaultValue={PAGEVIEW}
dropdownMatchSelectWidth={false}
onChange={(value): void => setFilter({ type: value, start: null })}
onChange={(value): void => setFilter({ path_type: value, start_point: null })}
style={{ paddingTop: 2 }}
>
{Object.entries(pathOptionsToLabels).map(([value, name], index) => {
Expand All @@ -39,18 +39,18 @@ export function PathTab(): JSX.Element {
<hr />
<h4 className="secondary">Start Point</h4>
<PropertyValue
endpoint={filter?.type === AUTOCAPTURE && 'api/paths/elements'}
endpoint={filter?.path_type === AUTOCAPTURE && 'api/paths/elements'}
outerOptions={
filter.type === CUSTOM_EVENT &&
customEventNames.map((name) => ({
name,
}))
}
onSet={(value): void => setFilter({ start: value })}
propertyKey={pathOptionsToProperty[filter.type]}
onSet={(value): void => setFilter({ start_point: value })}
propertyKey={pathOptionsToProperty[filter.path_type]}
type="event"
style={{ width: 200, paddingTop: 2 }}
value={filter.start}
value={filter.start_point}
placeholder={'Select start element'}
></PropertyValue>
<hr />
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/scenes/insights/trendsLogic.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ export const trendsLogic = kea({
let response
if (props.view === ViewType.SESSIONS || props.filters?.session) {
response = await api.get(
'api/event/sessions/?' +
'api/insight/session/?' +
(refresh ? 'refresh=true&' : '') +
toAPIParams(filterClientSideParams(values.filters))
)
response = response.result
} else {
response = await api.get(
'api/action/trends/?' +
'api/insight/trend/?' +
(refresh ? 'refresh=true&' : '') +
toAPIParams(filterClientSideParams(values.filters))
)
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/scenes/paths/Paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,14 @@ export function Paths() {
: stripHTTP(d.name)
)
.on('click', async (node) => {
if (filter.type == AUTOCAPTURE) {
if (filter.path_type == AUTOCAPTURE) {
setModalVisible(true)
setEventelements(null)
let result = await api.get('api/event/' + node.id)
setEventelements(result)
}
})
.style('cursor', filter.type == AUTOCAPTURE ? 'pointer' : 'auto')
.style('cursor', filter.path_type == AUTOCAPTURE ? 'pointer' : 'auto')

textSelection
.append('tspan')
Expand All @@ -210,7 +210,9 @@ export function Paths() {

return (
<div>
{filter.type == AUTOCAPTURE && <div style={{ margin: 10 }}>Click on a tag to see related DOM tree</div>}
{filter.path_type == AUTOCAPTURE && (
<div style={{ margin: 10 }}>Click on a tag to see related DOM tree</div>
)}
<div ref={canvas} className="paths" style={{ height: '90vh' }} data-attr="paths-viz">
{!pathsLoading && paths && paths.nodes.length === 0 ? (
<NoData />
Expand Down
18 changes: 9 additions & 9 deletions frontend/src/scenes/paths/pathsLogic.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ function checkRoot(nodeToVerify, paths, start) {

function cleanPathParams(filters, properties) {
return {
start: filters.start,
type: filters.type,
start_point: filters.start_point,
path_type: filters.path_type,
date_from: filters.date_from,
date_to: filters.date_to,
properties: properties,
Expand All @@ -53,12 +53,12 @@ export const pathsLogic = kea({
},
loadPaths: async (_, breakpoint) => {
const params = toParams({ ...values.filter, properties: values.properties })
let paths = await api.get(`api/paths${params ? `/?${params}` : ''}`)
if (values.filter.start) {
let paths = await api.get(`api/insight/path${params ? `/?${params}` : ''}`)
if (values.filter.start_point) {
paths = paths.filter((checkingNode) => {
return (
checkingNode.source.includes(values.filter.start) ||
checkRoot(checkingNode, paths, values.filter.start)
checkingNode.source.includes(values.filter.start_point) ||
checkRoot(checkingNode, paths, values.filter.start_point)
)
})
}
Expand All @@ -81,7 +81,7 @@ export const pathsLogic = kea({
initialPathname: [(state) => router.selectors.location(state).pathname, { noop: (a) => a }],
filter: [
{
type: '$pageview',
path_type: '$pageview',
},
{
setFilter: (state, filter) => ({ ...state, ...filter }),
Expand All @@ -106,8 +106,8 @@ export const pathsLogic = kea({
},
setFilter: () => {
if (
values.filter.type !== AUTOCAPTURE ||
(values.filter.type === AUTOCAPTURE && !isNaN(values.filter.start))
values.filter.path_type !== AUTOCAPTURE ||
(values.filter.path_type === AUTOCAPTURE && !isNaN(values.filter.start_point))
)
actions.loadPaths()

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/scenes/sessions/sessionsTableLogic.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const sessionsTableLogic = kea({
__default: [],
loadSessions: async (selectedDate) => {
const response = await api.get(
'api/event/sessions' + (selectedDate ? '/?date_from=' + values.selectedDateURLparam : '')
'api/insight/session' + (selectedDate ? '/?date_from=' + values.selectedDateURLparam : '')
)
if (response.offset) actions.setOffset(response.offset)
if (response.date_from) actions.setDate(moment(response.date_from).startOf('day'))
Expand Down Expand Up @@ -43,7 +43,7 @@ export const sessionsTableLogic = kea({
listeners: ({ values, actions }) => ({
fetchNextSessions: async () => {
const response = await api.get(
'api/event/sessions/?' + toParams({ date_from: values.selectedDateURLparam, offset: values.offset })
'api/insight/session/?' + toParams({ date_from: values.selectedDateURLparam, offset: values.offset })
)
if (response.offset) actions.setOffset(response.offset)
else actions.setOffset(null)
Expand Down
2 changes: 2 additions & 0 deletions posthog/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
event,
feature_flag,
funnel,
insight,
paths,
person,
personal_api_key,
Expand All @@ -29,3 +30,4 @@
router.register(r"paths", paths.PathsViewSet, basename="paths")
router.register(r"personal_api_keys", personal_api_key.PersonalAPIKeyViewSet, basename="personal_api_keys")
router.register(r"team/user", team_user.TeamUserViewSet)
router.register(r"insight", insight.InsightViewSet)
16 changes: 6 additions & 10 deletions posthog/api/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from rest_framework import exceptions, request, response, serializers, viewsets
from rest_framework.decorators import action

from posthog.constants import DATE_FROM, OFFSET
from posthog.models import (
Action,
Element,
Expand Down Expand Up @@ -269,20 +270,15 @@ def values(self, request: request.Request) -> response.Response:
@action(methods=["GET"], detail=False)
def sessions(self, request: request.Request) -> response.Response:
team = self.request.user.team_set.get()
session_type = self.request.GET.get("session")

filter = Filter(request=request)
result: Dict[str, Any] = {
"result": Sessions().run(
filter, team, session_type=self.request.GET.get("session"), offset=self.request.GET.get("offset")
)
}
result: Dict[str, Any] = {"result": Sessions().run(filter, team)}

# add pagination
if session_type is None:
offset = int(request.GET.get("offset", "0")) + 50
if filter.session_type is None:
offset = filter.offset + 50
if len(result["result"]) > 49:
date_from = result["result"][0]["start_time"].isoformat()
result.update({"offset": offset})
result.update({"date_from": date_from})
result.update({OFFSET: offset})
result.update({DATE_FROM: date_from})
return response.Response(result)
Loading