Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(views): load the views sidebar from the ordered feed (#111124)

Shy Alter5df27d05a615
diff --git a/frontend/src/layout/today/TodayViewsSidebar.tsx b/frontend/src/layout/today/TodayViewsSidebar.tsx
index fdea172e0c70..0154b4388ab9 100644
--- a/frontend/src/layout/today/TodayViewsSidebar.tsx
+++ b/frontend/src/layout/today/TodayViewsSidebar.tsx
@@ -24,6 +24,7 @@ import { shortTimeAgo } from './todayWorkItems'
export function TodayViewsSidebar(): JSX.Element {
const {
recentViews,
+ recentReady,
recentItems,
recentViewsLoading,
recentUnavailable,
@@ -36,7 +37,7 @@ export function TodayViewsSidebar(): JSX.Element {
const narrowed = recentQuery.trim() !== '' || recentFiltersActive
const { location } = useValues(router)
const path = removeProjectIdIfPresent(location.pathname)
- const failedTypes = recentViews?.failedTypes ?? []
+ const failedTypes = recentViews.failedTypes
const showAll = matchesPaneQuery('All views', recentQuery)
const retryButton = (size: 'sm' | 'xs'): JSX.Element => (
@@ -88,7 +89,7 @@ export function TodayViewsSidebar(): JSX.Element {
dataAttr="today-views-all"
/>
)}
- {!recentViews || (recentViewsLoading && !recentItems.length) ? (
+ {recentUnavailable || !recentReady ? (
recentUnavailable ? (
<div className="TodayPane__state">
<span>Your views didn’t load.</span>
@@ -111,32 +112,20 @@ export function TodayViewsSidebar(): JSX.Element {
Clear filters
</Button>
</div>
- ) : !recentItems.length && !failedTypes.length && !recentUnavailable ? (
+ ) : !recentItems.length && !failedTypes.length ? (
<div className="TodayPane__state">
Canvases, notebooks and dashboards you create show up here.
</div>
) : (
<>
- {(recentUnavailable || failedTypes.length > 0) && (
+ {failedTypes.length > 0 && (
<div className="TodayPane__state">
<span>
- {recentUnavailable
- ? 'Your views didn’t refresh.'
- : `${failedTypes.map((type) => VIEW_TYPE_INFO[type].pluralLabel).join(' and ')} didn’t load.`}
+ {`${failedTypes.map((type) => VIEW_TYPE_INFO[type].pluralLabel).join(' and ')} didn’t load.`}
</span>
{retryButton('xs')}
</div>
)}
- {recentViews.truncated && (
- <div className="TodayPane__state">
- Some views are not shown. Open All views and use search to find them.
- </div>
- )}
- {recentViewsLoading && (
- <div className="TodayPane__state" role="status">
- Loading more views…
- </div>
- )}
{recentItems.map((item) => {
const building = buildingViewIds.includes(item.id)
return (
diff --git a/frontend/src/layout/today/todayViewsLogic.ts b/frontend/src/layout/today/todayViewsLogic.ts
index 736455174111..e2afd0e5b46c 100644
--- a/frontend/src/layout/today/todayViewsLogic.ts
+++ b/frontend/src/layout/today/todayViewsLogic.ts
@@ -5,7 +5,8 @@ import type { LocationChangedPayload } from 'kea-router/lib/types'
import { teamLogic } from 'scenes/teamLogic'
import { userLogic } from 'scenes/userLogic'
-import { ViewItemsPage, fetchViewItems } from 'scenes/views/fetchViewItems'
+import { ViewFeed, ViewFeedQuery, ViewSourceState } from 'scenes/views/viewFeed'
+import { selectViewFeed, viewFeedLogic } from 'scenes/views/viewFeedLogic'
import { ViewItem } from 'scenes/views/viewsUtils'
import type { UserType } from '~/types'
@@ -20,6 +21,7 @@ import { DEFAULT_VIEWS_FILTERS, TodayViewsFilters, filterRecentViews, viewsFilte
// The sidebar shows the most recent views of every type in one list. The Views page lists the rest.
const RECENT_LIMIT = 12
+const ALL_RECENT_QUERY: ViewFeedQuery = { type: 'all', search: '' }
const FIRST_BUILD_POLL_MS = 5000
// pinned: task run statuses from the tasks API
const TERMINAL_RUN_STATUSES = new Set(['completed', 'failed', 'cancelled'])
@@ -35,22 +37,47 @@ export interface todayViewsLogicValues {
currentTeamId: number | null // teamLogic
recentViewEntries: TodayRecentEntry[] // todayRecentsLogic
user: UserType | null // userLogic
+ sources: Record<string, ViewSourceState> // viewFeedLogic
+ spaceNames: Record<string, string> // viewFeedLogic
+ allRecentViews: ViewFeed
buildingViewIds: string[]
firstBuilds: Record<string, FirstBuildState>
firstBuildsLoading: boolean
openCanvasBuilding: Record<string, boolean>
+ recentFeedQuery: ViewFeedQuery
recentFilters: TodayViewsFilters
recentFiltersActive: boolean
recentItems: ViewItem[]
recentQuery: string
+ recentReady: boolean
+ recentSearch: string
recentUnavailable: boolean
- recentViews: ViewItemsPage | null
+ recentViews: ViewFeed
recentViewsLoading: boolean
recentlyViewed: TodayRecentEntry[]
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface todayViewsLogicActions {
+ ensureFeed: (
+ query: ViewFeedQuery,
+ count: number
+ ) => {
+ count: number
+ query: ViewFeedQuery
+ } // viewFeedLogic
+ refreshFeed: (query: ViewFeedQuery) => {
+ query: ViewFeedQuery
+ } // viewFeedLogic
+ sourceRefreshed: (
+ key: string,
+ generation: number,
+ page: null | import('scenes/views/viewFeed').ViewSourcePage
+ ) => {
+ generation: number
+ key: string
+ page: null | import('scenes/views/viewFeed').ViewSourcePage
+ } // viewFeedLogic
clearRecentSearchAndFilters: () => {
value: true
}
@@ -73,23 +100,8 @@ export interface todayViewsLogicActions {
}
payload?: void
}
- loadRecentViews: (_: void) => void
- loadRecentViewsFailure: (
- error: string,
- errorObject?: any
- ) => {
- error: string
- errorObject?: any
- }
- loadRecentViewsSuccess: (
- recentViews: ViewItemsPage | null,
- payload?: void
- ) => {
- recentViews: ViewItemsPage | null
- payload?: void
- }
- receiveRecentViews: (page: ViewItemsPage) => {
- page: ViewItemsPage
+ loadRecentViews: () => {
+ value: true
}
setOpenCanvasBuilding: (
canvasId: string,
@@ -104,6 +116,9 @@ export interface todayViewsLogicActions {
setRecentQuery: (query: string) => {
query: string
}
+ setRecentSearch: (search: string) => {
+ search: string
+ }
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
@@ -111,14 +126,31 @@ export interface todayViewsLogicMeta {
__keaTypeGenInternalSelectorTypes: {
recentlyViewed: (recentViewEntries: TodayRecentEntry[], recentQuery: string) => TodayRecentEntry[]
recentFiltersActive: (recentFilters: TodayViewsFilters) => boolean
+ recentFeedQuery: (recentFilters: TodayViewsFilters, recentSearch: string) => ViewFeedQuery
+ allRecentViews: (
+ sources: Record<string, ViewSourceState>,
+ spaceNames: Record<string, string>,
+ currentTeamId: number | null
+ ) => ViewFeed
+ recentViews: (
+ sources: Record<string, ViewSourceState>,
+ spaceNames: Record<string, string>,
+ currentTeamId: number | null,
+ recentFeedQuery: ViewFeedQuery
+ ) => ViewFeed
+ recentViewsLoading: (recentViews: ViewFeed) => boolean
+ recentUnavailable: (recentViews: ViewFeed) => boolean
+ recentReady: (recentViews: ViewFeed, allRecentViews: ViewFeed) => boolean
recentItems: (
- recentViews: ViewItemsPage | null,
+ recentViews: ViewFeed,
+ allRecentViews: ViewFeed,
+ recentFeedQuery: ViewFeedQuery,
recentQuery: string,
recentFilters: TodayViewsFilters,
user: UserType | null
) => ViewItem[]
buildingViewIds: (
- recentViews: ViewItemsPage | null,
+ allRecentViews: ViewFeed,
firstBuilds: Record<string, FirstBuildState>,
openCanvasBuilding: Record<string, boolean>
) => string[]
@@ -161,38 +193,28 @@ export type todayViewsLogicType = MakeLogicType<
export const todayViewsLogic = kea<todayViewsLogicType>([
path(['layout', 'today', 'todayViewsLogic']),
connect(() => ({
- values: [teamLogic, ['currentTeamId'], userLogic, ['user'], todayRecentsLogic, ['recentViewEntries']],
+ values: [
+ teamLogic,
+ ['currentTeamId'],
+ userLogic,
+ ['user'],
+ todayRecentsLogic,
+ ['recentViewEntries'],
+ viewFeedLogic,
+ ['sources', 'spaceNames'],
+ ],
+ actions: [viewFeedLogic, ['ensureFeed', 'refreshFeed', 'sourceRefreshed']],
})),
actions({
- receiveRecentViews: (page: ViewItemsPage) => ({ page }),
+ loadRecentViews: true,
setRecentQuery: (query: string) => ({ query }),
+ setRecentSearch: (search: string) => ({ search }),
setRecentFilters: (filters: TodayViewsFilters) => ({ filters }),
clearRecentSearchAndFilters: true,
/** The open canvas reports whether its agent or a build is at work, which it knows exactly. Null when it closes. */
setOpenCanvasBuilding: (canvasId: string, building: boolean | null) => ({ canvasId, building }),
}),
- loaders(({ values, actions }) => ({
- recentViews: [
- null as ViewItemsPage | null,
- {
- loadRecentViews: async (_: void, breakpoint) => {
- // Navigation reloads the list, so a burst of route changes costs one request.
- await breakpoint(100)
- if (!values.currentTeamId) {
- return values.recentViews
- }
- const teamId = values.currentTeamId
- const page = await fetchViewItems(String(teamId), '', (page) => {
- breakpoint()
- if (values.currentTeamId === teamId) {
- actions.receiveRecentViews(page)
- }
- })
- breakpoint()
- return values.currentTeamId === teamId ? page : values.recentViews
- },
- },
- ],
+ loaders(({ values }) => ({
// A canvas on its first build has nothing to show until its first version, so until then its run
// says whether the agent is building it. Later runs stay open after the agent's turn, so they cannot.
firstBuilds: [
@@ -200,7 +222,7 @@ export const todayViewsLogic = kea<todayViewsLogicType>([
{
loadFirstBuilds: async (_: void, breakpoint) => {
const projectId = values.currentTeamId ? String(values.currentTeamId) : null
- const pending = (values.recentViews?.items ?? []).filter((item) => item.firstBuildTaskId)
+ const pending = values.allRecentViews.items.filter((item) => item.firstBuildTaskId)
if (!projectId || !pending.length) {
return {}
}
@@ -226,11 +248,8 @@ export const todayViewsLogic = kea<todayViewsLogicType>([
],
})),
reducers({
- recentViews: {
- receiveRecentViews: (_, { page }) => page,
- },
- recentUnavailable: [false, { loadRecentViews: () => false, loadRecentViewsFailure: () => true }],
recentQuery: ['', { setRecentQuery: (_, { query }) => query, clearRecentSearchAndFilters: () => '' }],
+ recentSearch: ['', { setRecentSearch: (_, { search }) => search, clearRecentSearchAndFilters: () => '' }],
recentFilters: [
DEFAULT_VIEWS_FILTERS,
{ persist: true },
@@ -259,30 +278,64 @@ export const todayViewsLogic = kea<todayViewsLogicType>([
(s) => [s.recentFilters],
(recentFilters: TodayViewsFilters): boolean => viewsFiltersActive(recentFilters),
],
+ recentFeedQuery: [
+ (s) => [s.recentFilters, s.recentSearch],
+ (recentFilters: TodayViewsFilters, recentSearch: string): ViewFeedQuery => ({
+ type: recentFilters.type,
+ search: recentSearch.trim(),
+ }),
+ ],
+ allRecentViews: [
+ (s) => [s.sources, s.spaceNames, s.currentTeamId],
+ (
+ sources: Record<string, ViewSourceState>,
+ spaceNames: Record<string, string>,
+ currentTeamId: number | null
+ ): ViewFeed => selectViewFeed(sources, spaceNames, currentTeamId, ALL_RECENT_QUERY),
+ ],
+ recentViews: [
+ (s) => [s.sources, s.spaceNames, s.currentTeamId, s.recentFeedQuery],
+ (
+ sources: Record<string, ViewSourceState>,
+ spaceNames: Record<string, string>,
+ currentTeamId: number | null,
+ recentFeedQuery: ViewFeedQuery
+ ): ViewFeed => selectViewFeed(sources, spaceNames, currentTeamId, recentFeedQuery),
+ ],
+ recentViewsLoading: [(s) => [s.recentViews], (recentViews: ViewFeed): boolean => recentViews.loading],
+ recentUnavailable: [(s) => [s.recentViews], (recentViews: ViewFeed): boolean => recentViews.loadFailed],
+ recentReady: [
+ (s) => [s.recentViews, s.allRecentViews],
+ (recentViews: ViewFeed, allRecentViews: ViewFeed): boolean =>
+ recentViews.initialized || allRecentViews.initialized,
+ ],
recentItems: [
- (s) => [s.recentViews, s.recentQuery, s.recentFilters, s.user],
- // The items arrive newest first across every type. A search or filter looks past the first few.
+ (s) => [s.recentViews, s.allRecentViews, s.recentFeedQuery, s.recentQuery, s.recentFilters, s.user],
(
- recentViews: ViewItemsPage | null,
+ recentViews: ViewFeed,
+ allRecentViews: ViewFeed,
+ recentFeedQuery: ViewFeedQuery,
recentQuery: string,
recentFilters: TodayViewsFilters,
user: UserType | null
): ViewItem[] => {
- const items = recentViews?.items ?? []
- if (!recentQuery.trim() && !viewsFiltersActive(recentFilters)) {
- return items.slice(0, RECENT_LIMIT)
+ const userUuid = user?.uuid ?? null
+ if (recentViews.initialized && recentQuery.trim() === recentFeedQuery.search) {
+ return recentFeedQuery.search || viewsFiltersActive(recentFilters)
+ ? filterRecentViews(recentViews.items, '', recentFilters, userUuid)
+ : recentViews.items.slice(0, RECENT_LIMIT)
}
- return filterRecentViews(items, recentQuery, recentFilters, user?.uuid ?? null)
+ return filterRecentViews(allRecentViews.items, recentQuery, recentFilters, userUuid)
},
],
buildingViewIds: [
- (s) => [s.recentViews, s.firstBuilds, s.openCanvasBuilding],
+ (s) => [s.allRecentViews, s.firstBuilds, s.openCanvasBuilding],
(
- recentViews: ViewItemsPage | null,
+ allRecentViews: ViewFeed,
firstBuilds: Record<string, FirstBuildState>,
openCanvasBuilding: Record<string, boolean>
): string[] =>
- (recentViews?.items ?? [])
+ allRecentViews.items
.filter((item) => {
if (item.id in openCanvasBuilding) {
return openCanvasBuilding[item.id]
@@ -300,9 +353,25 @@ export const todayViewsLogic = kea<todayViewsLogicType>([
],
}),
listeners(({ actions, values, cache }) => ({
- loadRecentViewsSuccess: () => {
- actions.loadFirstBuilds()
+ loadRecentViews: () => {
+ actions.refreshFeed(ALL_RECENT_QUERY)
+ if (values.recentFeedQuery.type !== 'all' || values.recentFeedQuery.search) {
+ actions.refreshFeed(values.recentFeedQuery)
+ }
+ },
+ sourceRefreshed: () => {
+ if (values.allRecentViews.initialized && !values.allRecentViews.loading) {
+ actions.loadFirstBuilds()
+ }
+ },
+ setRecentQuery: async ({ query }, breakpoint) => {
+ if (query.trim() !== values.recentSearch) {
+ await breakpoint(query.trim() ? 200 : 0)
+ actions.setRecentSearch(query.trim())
+ }
},
+ setRecentSearch: () => actions.ensureFeed(values.recentFeedQuery, RECENT_LIMIT),
+ setRecentFilters: () => actions.ensureFeed(values.recentFeedQuery, RECENT_LIMIT),
loadFirstBuildsSuccess: ({ firstBuilds }) => {
const building = Object.values(firstBuilds).filter(
(build) => !build.hasVersion && !!build.runStatus && !TERMINAL_RUN_STATUSES.has(build.runStatus)
@@ -312,7 +381,7 @@ export const todayViewsLogic = kea<todayViewsLogicType>([
actions.loadRecentViews()
return
}
- if (building.length && !values.recentViewsLoading) {
+ if (building.length && !values.allRecentViews.loading) {
cache.disposables.add(() => {
const id = setTimeout(() => actions.loadFirstBuilds(), FIRST_BUILD_POLL_MS)
return () => clearTimeout(id)
diff --git a/frontend/src/scenes/project-homepage/today/Today.stories.tsx b/frontend/src/scenes/project-homepage/today/Today.stories.tsx
index f0aa68bc449d..b56816cb1e18 100644
--- a/frontend/src/scenes/project-homepage/today/Today.stories.tsx
+++ b/frontend/src/scenes/project-homepage/today/Today.stories.tsx
@@ -589,7 +589,9 @@ const meta: Meta = {
? channel === 'space-checkout'
? CANVASES
: []
- : VIEW_CANVASES.filter((canvas) => canvas.kind === params.get('kind'))
+ : VIEW_CANVASES.filter((canvas) => canvas.kind === params.get('kind')).sort((first, second) =>
+ second.updated_at.localeCompare(first.updated_at)
+ )
return [200, { results, count: results.length, next: null, previous: null }]
},
'/api/projects/:team_id/task_activity/': {