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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cancel dashboard queries when changing filters #13041

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
86 changes: 7 additions & 79 deletions frontend/src/scenes/dashboard/dashboardLogic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import {
InsightShortId,
InsightType,
TextModel,
TileLayout,
} from '~/types'
import { resumeKeaLoadersErrors, silenceKeaLoadersErrors } from '~/initKea'
import { useMocks } from '~/mocks/jest'
import { dayjs, now } from 'lib/dayjs'
import { teamLogic } from 'scenes/teamLogic'
import { MOCK_TEAM_ID } from 'lib/api.mock'
import api from 'lib/api'
import { sceneLogic } from 'scenes/sceneLogic'

const dashboardJson = _dashboardJson as any as DashboardType

Expand Down Expand Up @@ -274,6 +274,7 @@ describe('dashboardLogic', () => {
initKeaTests()
dashboardsModel.mount()
insightsModel.mount()
sceneLogic.mount()
})

describe('tile layouts', () => {
Expand All @@ -299,77 +300,6 @@ describe('dashboardLogic', () => {
],
},
})
.toDispatchActions([
// frustratingly the same properties are sent in a different order
// and the matcher cares about the order
logic.actionCreators.saveLayouts([
{
id: 0,
layouts: {
sm: { i: '0', x: 0, y: 0, w: 8, h: 8, minW: 3, minH: 5 },
xs: { i: '0', x: 0, y: 0, w: 1, h: 8, minW: 1, minH: 5 },
},
},
{
id: 1,
layouts: {
sm: { i: '1', x: 0, y: 8, w: 6, h: 5, minW: 3, minH: 5 },
xs: { i: '1', x: 0, y: 8, w: 1, h: 5, minW: 1, minH: 5 },
},
},
{
id: 4,
layouts: {
sm: { i: '4', x: 6, y: 8, w: 6, h: 6, minW: 3, minH: 5 },
xs: { i: '4', x: 0, y: 13, w: 1, h: 6, minW: 1, minH: 5 },
},
},
]),
])
})

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

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

expect(api.update).toHaveBeenCalledWith(`api/projects/${MOCK_TEAM_ID}/dashboards/5`, {
no_items_field: true,
tiles: [
{
id: 9,
layouts: {},
},
{
id: 10,
layouts: {},
},
{
id: 4,
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`, {
no_items_field: true,
tiles: [
{
id: 1,
layouts: { sm: {} as TileLayout, xs: {} as TileLayout },
},
],
})
})
})

Expand Down Expand Up @@ -804,6 +734,7 @@ describe('dashboardLogic', () => {
})
})
})

describe('lastRefreshed', () => {
it('should be the earliest refreshed dashboard', async () => {
logic = dashboardLogic({ id: 5 })
Expand Down Expand Up @@ -891,18 +822,15 @@ describe('dashboardLogic', () => {
beforeEach(async () => {
logic = dashboardLogic({ id: 5 })
logic.mount()
await expectLogic(logic).toFinishAllListeners()
})

it('can remove text tiles', async () => {
await expectLogic(logic, () => {
logic.actions.removeTile(TEXT_TILE)
})
.toFinishAllListeners()
.toDispatchActions([
dashboardsModel.actionTypes.tileRemovedFromDashboard,
logic.actionTypes.removeTileSuccess,
])
}).toDispatchActions([
dashboardsModel.actionTypes.tileRemovedFromDashboard,
logic.actionTypes.removeTileSuccess,
])

expect(logic.values.textTiles).toEqual([])
})
Expand Down