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

feat: preview dashboard filter changes #24303

Merged
merged 59 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
c802f65
feat: dashboard preview changes
anirudhpillai Aug 7, 2024
b2d0b3b
moved save/cancel button top right
anirudhpillai Aug 11, 2024
2f859f5
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 11, 2024
849c049
mypy fix type
anirudhpillai Aug 12, 2024
817a6f5
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 12, 2024
ae4a76f
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 12, 2024
3ab10e8
update tests for renamed function
anirudhpillai Aug 12, 2024
0203045
keep double insight call for now
anirudhpillai Aug 14, 2024
c8a42f7
combine layout and preview into edit mode
anirudhpillai Aug 15, 2024
a8b9035
filters override returns overridden filters
anirudhpillai Aug 16, 2024
33889ff
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 16, 2024
b8600d5
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 16, 2024
e0ff8e5
update tests
anirudhpillai Aug 18, 2024
44f8fae
Merge branch 'master' of github.com:PostHog/posthog into feat/dashboa…
anirudhpillai Aug 19, 2024
6019939
recreate dashboardLoading
anirudhpillai Aug 19, 2024
b120485
Merge branch 'feat/dashboard-preview' of github.com:PostHog/posthog i…
anirudhpillai Aug 19, 2024
78d7a21
Merge branch 'master' of github.com:PostHog/posthog into feat/dashboa…
anirudhpillai Aug 19, 2024
0638cde
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 19, 2024
c9ba118
fix tests
anirudhpillai Aug 19, 2024
efa261b
Merge branch 'feat/dashboard-preview' of github.com:PostHog/posthog i…
anirudhpillai Aug 19, 2024
21fb104
merge master
anirudhpillai Aug 20, 2024
85b883b
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 20, 2024
428c150
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 20, 2024
7f5c7b4
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 20, 2024
7138c6e
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 20, 2024
6df1faf
Rename buttons to Cancel/Save
Twixes Aug 20, 2024
33a0d81
Merge branch 'master' into feat/dashboard-preview
Twixes Aug 20, 2024
f1d7729
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 20, 2024
7dc23ff
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 20, 2024
29fb30a
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 20, 2024
97bdeff
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 20, 2024
9f1e936
merge master
anirudhpillai Aug 20, 2024
b808076
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 20, 2024
2393a2f
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 20, 2024
7d96d60
update tests
anirudhpillai Aug 21, 2024
16a5bc3
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 21, 2024
53c7253
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 21, 2024
6dcc6cf
address comments
anirudhpillai Aug 21, 2024
06e7c2f
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 21, 2024
6c5ed57
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 21, 2024
f04828f
Merge branch 'master' into feat/dashboard-preview
anirudhpillai Aug 21, 2024
fec2ef4
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 21, 2024
3b6f7f3
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 21, 2024
6981b1a
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 21, 2024
7f48d9b
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 21, 2024
da2ad54
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 21, 2024
9681530
fix tests
anirudhpillai Aug 21, 2024
667aadf
Merge branch 'master' of github.com:PostHog/posthog into feat/dashboa…
anirudhpillai Aug 21, 2024
dc14b65
Merge branch 'feat/dashboard-preview' of github.com:PostHog/posthog i…
anirudhpillai Aug 21, 2024
83c6f9c
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 21, 2024
fcd67eb
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 21, 2024
37b98b6
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 21, 2024
4ef73ab
Merge branch 'master' of github.com:PostHog/posthog into feat/dashboa…
anirudhpillai Aug 21, 2024
de214c4
merge
anirudhpillai Aug 21, 2024
5f14af9
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 21, 2024
5189d41
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 21, 2024
c105bd1
fix tests
anirudhpillai Aug 22, 2024
acb103b
Merge branch 'feat/dashboard-preview' of github.com:PostHog/posthog i…
anirudhpillai Aug 22, 2024
ee2e5f3
Merge branch 'master' of github.com:PostHog/posthog into feat/dashboa…
anirudhpillai Aug 22, 2024
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
4 changes: 2 additions & 2 deletions cypress/e2e/dashboard.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
// refresh the dashboard by changing date range
cy.get('[data-attr="date-filter"]').click()
cy.contains('span', 'Last 14 days').click()
cy.contains('span', 'Apply and save dashboard').click()
cy.contains('span', 'Save').click()

cy.contains('span[class="text-primary text-sm font-medium"]', 'Refreshing').should('not.exist')
cy.get('span').contains('Refreshing').should('not.exist')
Expand Down Expand Up @@ -163,7 +163,7 @@
cy.get('[data-attr=date-filter]').contains('No date range override').click()
cy.get('div').contains('Yesterday').should('exist').click()
cy.get('[data-attr=date-filter]').contains('Yesterday')
cy.get('button').contains('Apply and save dashboard').click()
cy.get('button').contains('Save').click()
cy.get('.InsightCard h5').should('have.length', 1).contains('Yesterday')
// Cool, now back to A and make sure the insight is still using the original range there, not the one from B
cy.clickNavMenu('dashboards')
Expand Down Expand Up @@ -347,7 +347,7 @@
* This throws the error Code: 386. DB::Exception: There is no supertype for types String, Float64 because some of them are String/FixedString and some of them are not. (NO_COMMON_TYPE)
* All the 'app_ratings' are extracted as strings and 5. is a float
*/
// it('Opens dashboard item in insights', () => {

Check warning on line 350 in cypress/e2e/dashboard.cy.ts

View workflow job for this annotation

GitHub Actions / Code quality checks

Some tests seem to be commented
// cy.get('[data-attr=dashboard-name]').contains('App Analytics').click()
// cy.get('.InsightCard [data-attr=insight-card-title]').first().click()
// cy.location('pathname').should('include', '/insights')
Expand Down
4 changes: 2 additions & 2 deletions cypress/productAnalytics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export const dashboard = {
cy.get('[data-attr="prop-filter-event_properties-0"]').click({ force: true }).wait(1000)
cy.get('.LemonInput').type(value)
cy.contains('.LemonButton__content', value).click({ force: true })
cy.get('button').contains('Apply and save dashboard').click()
cy.get('button').contains('Save').click()
},
addAnyFilter(): void {
cy.get('.PropertyFilterButton').should('have.length', 0)
Expand All @@ -188,7 +188,7 @@ export const dashboard = {
// click .dashboard to blur
cy.get('.dashboard').click({ force: true })
cy.get('.PropertyFilterButton').should('have.length', 1)
cy.get('button').contains('Apply and save dashboard').click()
cy.get('button').contains('Save').click()
},
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/__snapshots__/scenes-app-dashboards--edit--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/__snapshots__/scenes-app-dashboards--show--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/__snapshots__/scenes-app-dashboards--show--light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 0 additions & 4 deletions frontend/src/lib/components/Cards/InsightCard/InsightCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ export interface InsightCardProps extends Resizeable, React.HTMLAttributes<HTMLD
loadingQueued?: boolean
/** Whether the insight is loading. */
loading?: boolean
/** Whether the insight likely showing stale data. */
stale?: boolean
/** Whether an error occurred on the server. */
apiErrored?: boolean
/** Whether the card should be highlighted with a blue border. */
Expand Down Expand Up @@ -71,7 +69,6 @@ function InsightCardInternal(
ribbonColor,
loadingQueued,
loading,
stale,
apiErrored,
timedOut,
highlighted,
Expand Down Expand Up @@ -152,7 +149,6 @@ function InsightCardInternal(
context={{
insightProps: insightLogicProps,
}}
stale={stale}
readOnly
embedded
/>
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/lib/utils/eventUsageLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ import type { eventUsageLogicType } from './eventUsageLogicType'
export enum DashboardEventSource {
LongPress = 'long_press',
MoreDropdown = 'more_dropdown',
DashboardHeader = 'dashboard_header',
DashboardHeaderSaveDashboard = 'dashboard_header_save_dashboard',
DashboardHeaderDiscardChanges = 'dashboard_header_discard_changes',
DashboardHeaderExitFullscreen = 'dashboard_header_exit_fullscreen',
Hotkey = 'hotkey',
InputEnter = 'input_enter',
Toast = 'toast',
Expand Down
6 changes: 1 addition & 5 deletions frontend/src/queries/Query/Query.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { LemonDivider } from 'lib/lemon-ui/LemonDivider'
import { SpinnerOverlay } from 'lib/lemon-ui/Spinner'
import { useEffect, useState } from 'react'
import { HogDebug } from 'scenes/debug/HogDebug'

Expand Down Expand Up @@ -38,14 +37,12 @@ export interface QueryProps<Q extends Node> {
cachedResults?: AnyResponseType
/** Disable any changes to the query */
readOnly?: boolean
/** Show a stale overlay */
stale?: boolean
/** Reduce UI elements to only show data */
embedded?: boolean
}

export function Query<Q extends Node>(props: QueryProps<Q>): JSX.Element | null {
const { query: propsQuery, setQuery: propsSetQuery, readOnly, stale, embedded } = props
const { query: propsQuery, setQuery: propsSetQuery, readOnly, embedded } = props

const [localQuery, localSetQuery] = useState(propsQuery)
useEffect(() => {
Expand Down Expand Up @@ -139,7 +136,6 @@ export function Query<Q extends Node>(props: QueryProps<Q>): JSX.Element | null
</div>
</>
) : null}
{stale && <SpinnerOverlay mode="editing" />}
{component}
</>
</ErrorBoundary>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/scenes/dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ function DashboardScene(): JSX.Element {
>
{[DashboardPlacement.Public].includes(placement) ? (
<LastRefreshText />
) : (
) : !(dashboardMode === DashboardMode.Edit) ? (
<DashboardReloadAction />
)}
) : null}
</div>
</div>
)}
Expand Down
103 changes: 42 additions & 61 deletions frontend/src/scenes/dashboard/DashboardEditBar.tsx
Original file line number Diff line number Diff line change
@@ -1,79 +1,60 @@
import { IconCalendar } from '@posthog/icons'
import { LemonButton, Popover } from '@posthog/lemon-ui'
import clsx from 'clsx'
import { useActions, useValues } from 'kea'
import { DateFilter } from 'lib/components/DateFilter/DateFilter'
import { PropertyFilters } from 'lib/components/PropertyFilters/PropertyFilters'
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
import { dashboardLogic } from 'scenes/dashboard/dashboardLogic'

import { groupsModel } from '~/models/groupsModel'
import { DashboardMode } from '~/types'

export function DashboardEditBar(): JSX.Element {
const { dashboard, canEditDashboard, temporaryFilters, stale } = useValues(dashboardLogic)
const { setDates, setProperties, cancelTemporary, applyTemporary } = useActions(dashboardLogic)
const { dashboard, canEditDashboard, temporaryFilters, dashboardMode } = useValues(dashboardLogic)
const { setDates, setProperties, setDashboardMode } = useActions(dashboardLogic)
const { groupsTaxonomicTypes } = useValues(groupsModel)

const isEditInProgress: boolean = canEditDashboard && stale
const disabledReason = !canEditDashboard ? "You don't have permission to edit this dashboard" : undefined

return (
<Popover
visible={isEditInProgress}
className="z-1" // So that Cancel/Apply isn't above filter popovers
overlay={
<div className="flex items-center gap-2 m-1">
<LemonButton onClick={cancelTemporary} type="secondary" size="small">
Cancel changes
</LemonButton>
<LemonButton
onClick={applyTemporary}
type="primary"
size="small"
disabledReason={!stale ? 'No changes to apply' : undefined}
>
Apply and save dashboard
</LemonButton>
</div>
}
placement="right"
showArrow
>
<div
className={clsx(
'flex gap-2 items-center justify-between flex-wrap border',
isEditInProgress ? '-m-1.5 p-1.5 border-border-bold border-dashed rounded-lg' : 'border-transparent'
<div className="flex gap-2 items-center justify-between flex-wrap">
<DateFilter
showCustom
dateFrom={temporaryFilters.date_from}
dateTo={temporaryFilters.date_to}
onChange={(from_date, to_date) => {
if (dashboardMode !== DashboardMode.Edit) {
setDashboardMode(DashboardMode.Edit, null)
}
setDates(from_date, to_date)
}}
disabledReason={disabledReason}
makeLabel={(key) => (
<>
<IconCalendar />
<span className="hide-when-small"> {key}</span>
</>
)}
>
<DateFilter
showCustom
dateFrom={temporaryFilters.date_from}
dateTo={temporaryFilters.date_to}
onChange={setDates}
disabledReason={disabledReason}
makeLabel={(key) => (
<>
<IconCalendar />
<span className="hide-when-small"> {key}</span>
</>
)}
/>
<PropertyFilters
disabledReason={disabledReason}
onChange={setProperties}
pageKey={'dashboard_' + dashboard?.id}
propertyFilters={temporaryFilters.properties}
taxonomicGroupTypes={[
TaxonomicFilterGroupType.EventProperties,
TaxonomicFilterGroupType.PersonProperties,
TaxonomicFilterGroupType.EventFeatureFlags,
...groupsTaxonomicTypes,
TaxonomicFilterGroupType.Cohorts,
TaxonomicFilterGroupType.Elements,
TaxonomicFilterGroupType.HogQLExpression,
]}
/>
</div>
</Popover>
/>
<PropertyFilters
disabledReason={disabledReason}
onChange={(properties) => {
if (dashboardMode !== DashboardMode.Edit) {
setDashboardMode(DashboardMode.Edit, null)
}
setProperties(properties)
}}
pageKey={'dashboard_' + dashboard?.id}
propertyFilters={temporaryFilters.properties}
taxonomicGroupTypes={[
TaxonomicFilterGroupType.EventProperties,
TaxonomicFilterGroupType.PersonProperties,
TaxonomicFilterGroupType.EventFeatureFlags,
...groupsTaxonomicTypes,
TaxonomicFilterGroupType.Cohorts,
TaxonomicFilterGroupType.Elements,
TaxonomicFilterGroupType.HogQLExpression,
]}
/>
</div>
)
}
34 changes: 24 additions & 10 deletions frontend/src/scenes/dashboard/DashboardHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,33 @@ export function DashboardHeader(): JSX.Element | null {
<PageHeader
buttons={
dashboardMode === DashboardMode.Edit ? (
<LemonButton
data-attr="dashboard-edit-mode-save"
type="primary"
onClick={() => setDashboardMode(null, DashboardEventSource.DashboardHeader)}
tabIndex={10}
disabled={dashboardLoading}
>
Done editing
</LemonButton>
<>
<LemonButton
data-attr="dashboard-edit-mode-discard"
type="secondary"
onClick={() =>
setDashboardMode(null, DashboardEventSource.DashboardHeaderDiscardChanges)
}
tabIndex={9}
>
Cancel
</LemonButton>
<LemonButton
data-attr="dashboard-edit-mode-save"
type="primary"
onClick={() =>
setDashboardMode(null, DashboardEventSource.DashboardHeaderSaveDashboard)
}
tabIndex={10}
disabled={dashboardLoading}
>
Save
</LemonButton>
</>
) : dashboardMode === DashboardMode.Fullscreen ? (
<LemonButton
type="secondary"
onClick={() => setDashboardMode(null, DashboardEventSource.DashboardHeader)}
onClick={() => setDashboardMode(null, DashboardEventSource.DashboardHeaderExitFullscreen)}
data-attr="dashboard-exit-presentation-mode"
disabled={dashboardLoading}
>
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/scenes/dashboard/DashboardItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export function DashboardItems(): JSX.Element {
highlightedInsightId,
refreshStatus,
canEditDashboard,
stale,
itemsLoading,
} = useValues(dashboardLogic)
const {
Expand Down Expand Up @@ -139,7 +138,6 @@ export function DashboardItems(): JSX.Element {
<InsightCard
key={tile.id}
insight={insight}
stale={stale}
loadingQueued={isRefreshingQueued(insight.short_id)}
loading={isRefreshing(insight.short_id)}
apiErrored={refreshStatus[insight.short_id]?.error || false}
Expand Down
30 changes: 10 additions & 20 deletions frontend/src/scenes/dashboard/dashboardLogic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { examples } from '~/queries/examples'
import { getQueryBasedDashboard } from '~/queries/nodes/InsightViz/utils'
import { DashboardFilter, InsightVizNode, TrendsQuery } from '~/queries/schema'
import { initKeaTests } from '~/test/init'
import { DashboardTile, DashboardType, InsightColor, InsightShortId, QueryBasedInsightModel, TileLayout } from '~/types'
import { DashboardTile, DashboardType, InsightColor, InsightShortId, QueryBasedInsightModel } from '~/types'

import _dashboardJson from './__mocks__/dashboard.json'

Expand Down Expand Up @@ -300,11 +300,13 @@ describe('dashboardLogic', () => {
logic.mount()
})

it('saving layouts with no provided tiles updates all tiles', async () => {
it('saving layouts creates api call with all tiles', async () => {
await expectLogic(logic).toFinishAllListeners()

jest.spyOn(api, 'update')

await expectLogic(logic, () => {
logic.actions.saveLayouts()
logic.actions.updateFiltersAndLayouts()
}).toFinishAllListeners()

expect(api.update).toHaveBeenCalledWith(`api/projects/${MOCK_TEAM_ID}/dashboards/5`, {
Expand All @@ -322,23 +324,11 @@ describe('dashboardLogic', () => {
layouts: {},
},
],
})
})

it('saving layouts with provided tiles updates only those tiles', async () => {
jest.spyOn(api, 'update')

await expectLogic(logic, () => {
logic.actions.saveLayouts([{ id: 1, layouts: { sm: {} as TileLayout, xs: {} as TileLayout } }])
}).toFinishAllListeners()

expect(api.update).toHaveBeenCalledWith(`api/projects/${MOCK_TEAM_ID}/dashboards/5`, {
tiles: [
{
id: 1,
layouts: { sm: {} as TileLayout, xs: {} as TileLayout },
},
],
filters: {
date_from: null,
date_to: null,
properties: [],
},
})
})
})
Expand Down
Loading
Loading