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

fix(dashboards): Move generated dashboards to bottom by default #17070

Merged
merged 40 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
480d96d
fix(dashboards): Move generated dashboards to bottom by default
neilkakkar Aug 17, 2023
1cf66b1
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 17, 2023
49a3c6d
fix
neilkakkar Aug 17, 2023
34fd3a6
remove generated dashboards from list
neilkakkar Aug 21, 2023
bf371cb
merge
neilkakkar Aug 21, 2023
b096d47
tweak
neilkakkar Aug 21, 2023
75d5a83
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 21, 2023
bf432f2
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 21, 2023
a40c399
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 21, 2023
61cacc6
address
neilkakkar Aug 21, 2023
de2c10b
Merge branch 'gen-dash' of github.com:PostHog/posthog into gen-dash
neilkakkar Aug 21, 2023
fdeb00e
revert lockfile
neilkakkar Aug 21, 2023
55152b1
merge
neilkakkar Aug 21, 2023
bbc1e35
oops
neilkakkar Aug 21, 2023
cf9dc75
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 21, 2023
127cc00
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 21, 2023
ad623e8
merge
neilkakkar Aug 22, 2023
db54897
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 22, 2023
f0d727e
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 22, 2023
13a8827
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 22, 2023
87de9ea
Update UI snapshots for `chromium` (2)
github-actions[bot] Aug 22, 2023
45b6ab3
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 22, 2023
221d68e
Update UI snapshots for `chromium` (2)
github-actions[bot] Aug 22, 2023
a937ab9
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 22, 2023
fe0d65c
Update UI snapshots for `chromium` (2)
github-actions[bot] Aug 22, 2023
f11d5a3
Update UI snapshots for `chromium` (2)
github-actions[bot] Aug 22, 2023
91b0a79
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 22, 2023
9e8d3d8
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 22, 2023
75e85cb
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 22, 2023
71720ce
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 22, 2023
36c2af6
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 22, 2023
a849c52
wtf
neilkakkar Aug 22, 2023
4efeda0
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 22, 2023
73e252f
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 22, 2023
c8aa57c
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 22, 2023
623e455
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 22, 2023
0f66cbe
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 22, 2023
460011f
Merge branch 'master' of github.com:PostHog/posthog into gen-dash
neilkakkar Aug 22, 2023
37eb96a
higher
neilkakkar Aug 22, 2023
acb5c2c
Update UI snapshots for `chromium` (1)
github-actions[bot] Aug 22, 2023
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
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.
2 changes: 2 additions & 0 deletions frontend/src/lib/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,5 @@ export const SESSION_RECORDINGS_PLAYLIST_FREE_COUNT = 5

// If _any_ item on a dashboard is older than this, dashboard is automatically reloaded
export const AUTO_REFRESH_DASHBOARD_THRESHOLD_HOURS = 20

export const GENERATED_DASHBOARD_PREFIX = 'Generated Dashboard'
133 changes: 133 additions & 0 deletions frontend/src/models/dashboardsModel.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import { initKeaTests } from '~/test/init'
import { expectLogic } from 'kea-test-utils'
import { DashboardBasicType } from '~/types'
import { useMocks } from '~/mocks/jest'
import { dashboardsModel, nameCompareFunction } from './dashboardsModel'
import { DashboardPrivilegeLevel, DashboardRestrictionLevel } from 'lib/constants'

const dashboards: Partial<DashboardBasicType>[] = [
{
id: 1,
name: 'Generated Dashboard: 123',
},
{
id: 2,
name: 'Generated Dashboard: 456',
},
{
id: 3,
name: 'Dashboard: 789',
},
{
id: 4,
name: 'Generated Dashboard: 101',
},
{
id: 5,
name: 'Dashboard: 112',
},
{
id: 6,
name: 'Dashboard: 131',
},
{
id: 7,
},
{
id: 8,
name: 'k',
},
]

const basicDashboard: DashboardBasicType = {
id: 1,
name: '',
description: 'This is not a generated dashboard',
pinned: false,
created_at: new Date().toISOString(),
created_by: null,
is_shared: false,
deleted: false,
creation_mode: 'default',
restriction_level: DashboardRestrictionLevel.EveryoneInProjectCanEdit,
effective_restriction_level: DashboardRestrictionLevel.EveryoneInProjectCanEdit,
effective_privilege_level: DashboardPrivilegeLevel.CanEdit,
}

describe('the dashboards model', () => {
let logic: ReturnType<typeof dashboardsModel.build>

beforeEach(async () => {
useMocks({
get: {
'/api/projects/:team_id/dashboards/': () => {
return [
200,
{
count: dashboards.length,
results: dashboards,
next: undefined,
},
]
},
},
})

initKeaTests()
logic = dashboardsModel()
logic.mount()
})

describe('sorting dashboards', () => {
it('can sort dashboards correctly', async () => {
await expectLogic(logic, () => {
logic.actions.loadDashboards()
})
.toDispatchActions(['loadDashboardsSuccess'])
.toMatchValues({
nameSortedDashboards: [
{
id: 5,
name: 'Dashboard: 112',
},
{
id: 6,
name: 'Dashboard: 131',
},
{
id: 3,
name: 'Dashboard: 789',
},
{
id: 8,
name: 'k',
},
{
id: 7,
},
],
})
})

it('compares names correctly', async () => {
const generatedDashboardA = { ...basicDashboard, id: 1, name: 'Generated Dashboard: XYZ' }
const untitledDashboard = { ...basicDashboard, id: 2, name: 'Untitled' }
const randomDashboard = { ...basicDashboard, id: 3, name: 'Random' }
const randomDashboard2 = { ...basicDashboard, id: 3, name: 'Too Random' }
expect(nameCompareFunction(generatedDashboardA, untitledDashboard)).toEqual(-1)
expect(nameCompareFunction(untitledDashboard, generatedDashboardA)).toEqual(1)
expect(nameCompareFunction(generatedDashboardA, randomDashboard)).toEqual(-1)
expect(nameCompareFunction(randomDashboard, generatedDashboardA)).toEqual(1)
expect(nameCompareFunction(generatedDashboardA, randomDashboard2)).toEqual(-1)
expect(nameCompareFunction(randomDashboard2, generatedDashboardA)).toEqual(1)

expect(nameCompareFunction(untitledDashboard, randomDashboard)).toEqual(1)
expect(nameCompareFunction(randomDashboard, untitledDashboard)).toEqual(-1)
expect(nameCompareFunction(untitledDashboard, randomDashboard2)).toEqual(1)
expect(nameCompareFunction(randomDashboard2, untitledDashboard)).toEqual(-1)

expect(nameCompareFunction(randomDashboard2, randomDashboard)).toEqual(1)
expect(nameCompareFunction(randomDashboard, randomDashboard2)).toEqual(-1)
})
})
})
19 changes: 13 additions & 6 deletions frontend/src/models/dashboardsModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { urls } from 'scenes/urls'
import { teamLogic } from 'scenes/teamLogic'
import { lemonToast } from 'lib/lemon-ui/lemonToast'
import { tagsModel } from '~/models/tagsModel'
import { GENERATED_DASHBOARD_PREFIX } from 'lib/constants'

export const dashboardsModel = kea<dashboardsModelType>({
path: ['models', 'dashboardsModel'],
Expand Down Expand Up @@ -237,19 +238,17 @@ export const dashboardsModel = kea<dashboardsModelType>({
nameSortedDashboards: [
() => [selectors.rawDashboards],
(rawDashboards) => {
return [...Object.values(rawDashboards)].sort((a, b) =>
(a.name ?? 'Untitled').localeCompare(b.name ?? 'Untitled')
)
return [...Object.values(rawDashboards)]
.filter((dashboard) => !(dashboard.name ?? 'Untitled').startsWith(GENERATED_DASHBOARD_PREFIX))
Copy link
Member

Choose a reason for hiding this comment

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

Wait, if the ones starting with GENERATED_DASHBOARD_PREFIX are filtered out, it doesn't make sense to sort by that prefix, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not here, but, this isn't the only place the comparison function is used, and I wanted to keep the function standard for sorting wherever you want to sort dashboards, so if, say, you're sorting raw dashboards somewhere, they're still at the end. Seemed less error prone.

Happy to remove generated prefix from the sorting function if you feel strongly about this

Copy link
Member

Choose a reason for hiding this comment

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

Right, but nameSortedDashboards is the source for all our lists of dashboards, so if we filtered out the generated dashboards, they won't be displayed at the bottom anymore – they will be just hidden. From the description of the PR I thought that that's not the intention

Copy link
Contributor Author

Choose a reason for hiding this comment

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

original intention yes, but based on Li's comment, am removing them completely from the list, and adding a link to the usage dashboard to get to the main db, will update description 😅

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I missed that, was still looking at the PR title 😅 In that case nameCompareFunction handling is unused in this PR, so would be better to revert that addition

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd argue that it at least unifies the current 3 places where we manually write the same function again, would you be fine with me removing the generated prefix from it but keeping the function, or do you want me to get rid of it completely?

Copy link
Member

Choose a reason for hiding this comment

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

No, yeah, the function makes sense. Just the prefix handling that's not going to be used

.sort(nameCompareFunction)
},
],
/** Display dashboards are additionally sorted by pin status: pinned first. */
pinSortedDashboards: [
() => [selectors.nameSortedDashboards],
(nameSortedDashboards) => {
return [...nameSortedDashboards].sort(
(a, b) =>
(Number(b.pinned) - Number(a.pinned)) * 10 +
(a.name ?? 'Untitled').localeCompare(b.name ?? 'Untitled')
(a, b) => (Number(b.pinned) - Number(a.pinned)) * 10 + nameCompareFunction(a, b)
)
},
],
Expand Down Expand Up @@ -332,3 +331,11 @@ export const dashboardsModel = kea<dashboardsModelType>({
},
}),
})

export function nameCompareFunction(a: DashboardBasicType, b: DashboardBasicType): number {
// No matter where we're comparing dashboards, we want to sort generated dashboards last
const firstName = a.name ?? 'Untitled'
const secondName = b.name ?? 'Untitled'

return firstName.localeCompare(secondName)
}
8 changes: 7 additions & 1 deletion frontend/src/scenes/dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import { SceneExport } from 'scenes/sceneTypes'
import { InsightErrorState } from 'scenes/insights/EmptyStates'
import { DashboardHeader } from './DashboardHeader'
import { PropertyFilters } from 'lib/components/PropertyFilters/PropertyFilters'
import { LemonDivider } from '@posthog/lemon-ui'
import { LemonButton, LemonDivider } from '@posthog/lemon-ui'
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
import { groupsModel } from '../../models/groupsModel'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { FEATURE_FLAGS } from 'lib/constants'
import { urls } from 'scenes/urls'

interface DashboardProps {
id?: string
Expand Down Expand Up @@ -149,6 +150,11 @@ function DashboardScene(): JSX.Element {
/>
</div>
)}
{placement === DashboardPlacement.FeatureFlag && dashboard?.id && (
<LemonButton type="secondary" size="small" to={urls.dashboard(dashboard.id)}>
Edit dashboard
</LemonButton>
)}
{placement !== DashboardPlacement.Export && (
<div className="flex space-x-4 dashoard-items-actions">
<div
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/scenes/dashboard/dashboards/DashboardsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useActions, useValues } from 'kea'
import { dashboardsModel } from '~/models/dashboardsModel'
import { dashboardsModel, nameCompareFunction } from '~/models/dashboardsModel'
import { DashboardsFilters, dashboardsLogic } from 'scenes/dashboard/dashboards/dashboardsLogic'
import { userLogic } from 'scenes/userLogic'
import { teamLogic } from 'scenes/teamLogic'
Expand Down Expand Up @@ -109,7 +109,7 @@ export function DashboardsTable({
</div>
)
},
sorter: (a, b) => (a.name ?? 'Untitled').localeCompare(b.name ?? 'Untitled'),
sorter: nameCompareFunction,
},
...(hasAvailableFeature(AvailableFeature.TAGGING)
? [
Expand Down
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const config: PlaywrightTestConfig = {
* For example in `await expect(locator).toHaveText();`
*/
timeout: 5000,
toHaveScreenshot: { maxDiffPixelRatio: 0.005 },
toHaveScreenshot: { maxDiffPixelRatio: 0.008 },
},
/* Run tests in files in parallel */
fullyParallel: true,
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.