mirror of
https://github.com/PostHog/posthog.git
synced 2024-12-01 12:21:02 +01:00
Fix dashboards list after visiting /instance/status (#4429)
This commit is contained in:
parent
f734eb9ab0
commit
cafd6b3aa9
@ -308,7 +308,7 @@ export function objectsEqual(obj1: any, obj2: any): boolean {
|
||||
return JSON.stringify(obj1) === JSON.stringify(obj2)
|
||||
}
|
||||
|
||||
export function idToKey(array: Record<string, any>[], keyField: string = 'id'): any {
|
||||
export function idToKey(array: Record<string, any>[], keyField: string = 'id'): Record<string, any> {
|
||||
const object: Record<string, any> = {}
|
||||
for (const element of array) {
|
||||
object[element[keyField]] = element
|
||||
|
@ -20,15 +20,13 @@ export const dashboardsModel = kea({
|
||||
rawDashboards: [
|
||||
{},
|
||||
{
|
||||
loadDashboards: async (shareToken = undefined, breakpoint) => {
|
||||
await breakpoint(50)
|
||||
try {
|
||||
const { results } = await api.get(`api/dashboard?${toParams({ share_token: shareToken })}`)
|
||||
return idToKey(results)
|
||||
} catch {
|
||||
return {}
|
||||
}
|
||||
},
|
||||
loadDashboards: (_, breakpoint) => loadDashboard(undefined, breakpoint),
|
||||
},
|
||||
],
|
||||
sharedDashboards: [
|
||||
null,
|
||||
{
|
||||
loadSharedDashboard: (shareToken, breakpoint) => loadDashboard(shareToken, breakpoint),
|
||||
},
|
||||
],
|
||||
// We're not using this loader as a reducer per se, but just calling it `dashboard`
|
||||
@ -180,3 +178,13 @@ export const dashboardsModel = kea({
|
||||
'/dashboard/:id': ({ id }) => actions.setLastDashboardId(parseInt(id)),
|
||||
}),
|
||||
})
|
||||
|
||||
async function loadDashboard(shareToken, breakpoint) {
|
||||
await breakpoint(50)
|
||||
try {
|
||||
const { results } = await api.get(`api/dashboard?${toParams({ share_token: shareToken })}`)
|
||||
return idToKey(results)
|
||||
} catch {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
@ -148,8 +148,11 @@ export const dashboardLogic = kea({
|
||||
},
|
||||
],
|
||||
dashboard: [
|
||||
() => [dashboardsModel.selectors.dashboards],
|
||||
(dashboards) => {
|
||||
() => [dashboardsModel.selectors.sharedDashboards, dashboardsModel.selectors.dashboards],
|
||||
(sharedDashboards, dashboards) => {
|
||||
if (sharedDashboards && !!sharedDashboards[props.id]) {
|
||||
return sharedDashboards[props.id]
|
||||
}
|
||||
return dashboards.find((d) => d.id === props.id)
|
||||
},
|
||||
],
|
||||
@ -258,7 +261,7 @@ export const dashboardLogic = kea({
|
||||
actions.loadDashboardItems()
|
||||
if (props.shareToken) {
|
||||
actions.setDashboardMode(DashboardMode.Public, DashboardEventSource.Browser)
|
||||
dashboardsModel.actions.loadDashboards(props.shareToken)
|
||||
dashboardsModel.actions.loadSharedDashboard(props.shareToken)
|
||||
}
|
||||
},
|
||||
beforeUnmount: () => {
|
||||
|
Loading…
Reference in New Issue
Block a user