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.

feat(today): add new session and a space menu to sidebar space rows (#109346)

Shy Alterd521e4c9ec44
diff --git a/frontend/src/layout/today/TodaySpaceActions.tsx b/frontend/src/layout/today/TodaySpaceActions.tsx
new file mode 100644
index 000000000000..478c16fc25b7
--- /dev/null
+++ b/frontend/src/layout/today/TodaySpaceActions.tsx
@@ -0,0 +1,97 @@
+import { useActions, useValues } from 'kea'
+
+import { IconEllipsis, IconGear, IconCopy, IconPlus, IconStar, IconStarFilled } from '@posthog/icons'
+import {
+ Button,
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuSeparator,
+ DropdownMenuTrigger,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+} from '@posthog/quill'
+
+import { LinkPrimitive } from 'lib/lemon-ui/Link'
+import { urls } from 'scenes/urls'
+
+import { ChannelDTOApi } from 'products/tasks/frontend/generated/api.schemas'
+
+import { spaceLabel, spaceNewSessionUrl, todaySpacesLogic } from './todaySpacesLogic'
+
+export function TodaySpaceActions({ space }: { space: ChannelDTOApi }): JSX.Element {
+ const { pendingSpaceIds } = useValues(todaySpacesLogic)
+ const { toggleStar, copySpaceLink } = useActions(todaySpacesLogic)
+ const saving = pendingSpaceIds.includes(space.id)
+ const newSessionLabel = `New session in ${spaceLabel(space)}`
+ const menuLabel = saving ? 'Saving your last change' : 'More actions'
+
+ return (
+ <div className="flex gap-0.5">
+ <Tooltip>
+ <TooltipTrigger
+ delay={0}
+ render={
+ <Button
+ size="icon-xs"
+ aria-label={newSessionLabel}
+ render={<LinkPrimitive to={spaceNewSessionUrl(space.id)} />}
+ data-attr="today-space-row-new-session"
+ />
+ }
+ >
+ <IconPlus />
+ </TooltipTrigger>
+ <TooltipContent>{newSessionLabel}</TooltipContent>
+ </Tooltip>
+ <DropdownMenu>
+ <Tooltip>
+ <TooltipTrigger
+ delay={0}
+ render={
+ <DropdownMenuTrigger
+ render={
+ <Button
+ size="icon-xs"
+ aria-label={menuLabel}
+ loading={saving}
+ data-attr="today-space-row-menu"
+ />
+ }
+ />
+ }
+ >
+ <IconEllipsis />
+ </TooltipTrigger>
+ <TooltipContent>{menuLabel}</TooltipContent>
+ </Tooltip>
+ <DropdownMenuContent align="end" className="w-48">
+ {space.system_role !== 'personal' && (
+ <DropdownMenuItem
+ onClick={() => toggleStar(space.id, !space.starred)}
+ data-attr="today-space-row-star"
+ >
+ {space.starred ? <IconStarFilled /> : <IconStar />}
+ {space.starred ? 'Unstar space' : 'Star space'}
+ </DropdownMenuItem>
+ )}
+ <DropdownMenuItem onClick={() => copySpaceLink(space.id)} data-attr="today-space-row-copy-link">
+ <IconCopy />
+ Copy link
+ </DropdownMenuItem>
+ <DropdownMenuSeparator />
+ <DropdownMenuItem
+ render={
+ <Button size="row" left render={<LinkPrimitive to={urls.taskSpaceSettings(space.id)} />} />
+ }
+ data-attr="today-space-row-settings"
+ >
+ <IconGear />
+ Space settings
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </div>
+ )
+}
diff --git a/frontend/src/layout/today/TodaySpacesRow.tsx b/frontend/src/layout/today/TodaySpacesRow.tsx
index 00e6c6e46f70..15df030dab52 100644
--- a/frontend/src/layout/today/TodaySpacesRow.tsx
+++ b/frontend/src/layout/today/TodaySpacesRow.tsx
@@ -11,9 +11,20 @@ interface TodaySpacesRowProps {
action?: JSX.Element | null
/** Stays visible at the end of the row, after the hover action. */
badge?: JSX.Element | null
+ /** How many icon buttons `action` holds, so the label truncates before them. */
+ actionCount?: 1 | 2
}
-export function TodaySpacesRow({ label, icon, to, active, dataAttr, action, badge }: TodaySpacesRowProps): JSX.Element {
+export function TodaySpacesRow({
+ label,
+ icon,
+ to,
+ active,
+ dataAttr,
+ action,
+ badge,
+ actionCount = 1,
+}: TodaySpacesRowProps): JSX.Element {
return (
<div className="group/row relative flex min-w-0 items-center">
<Button
@@ -25,7 +36,7 @@ export function TodaySpacesRow({ label, icon, to, active, dataAttr, action, badg
className={cn(
'min-w-0 text-muted-foreground',
active && 'bg-fill-selected text-foreground',
- action && !badge && 'pr-8',
+ action && !badge && (actionCount === 2 ? 'pr-12' : 'pr-8'),
badge && 'pr-24'
)}
>
diff --git a/frontend/src/layout/today/TodaySpacesSidebar.tsx b/frontend/src/layout/today/TodaySpacesSidebar.tsx
index d92488b5eb2b..d68292bcd392 100644
--- a/frontend/src/layout/today/TodaySpacesSidebar.tsx
+++ b/frontend/src/layout/today/TodaySpacesSidebar.tsx
@@ -14,6 +14,7 @@ import { TodayPaneSection, TodayPaneSectionProps } from './TodayPaneSection'
import { TodayRecentFilterMenu } from './TodayRecentFilterMenu'
import { TodayRecentSearchField } from './TodayRecentSearchField'
import { TodaySessionRow } from './TodaySessionRow'
+import { TodaySpaceActions } from './TodaySpaceActions'
import { TodayWorkSectionId, isLockedSpace, spaceLabel, todaySpacesLogic } from './todaySpacesLogic'
import { TodaySpacesRow } from './TodaySpacesRow'
import { TodayWorkItem } from './todayWorkItems'
@@ -273,6 +274,8 @@ export function TodaySpacesSidebar(): JSX.Element {
to={urls.taskSpace(space.id)}
active={location.pathname.includes(urls.taskSpace(space.id))}
dataAttr="today-space-row"
+ action={<TodaySpaceActions space={space} />}
+ actionCount={2}
/>
))}
{visibleSpaces.length <= 1 && (
diff --git a/frontend/src/layout/today/todaySpacesLogic.ts b/frontend/src/layout/today/todaySpacesLogic.ts
index dd6de9caef59..33b714750bcd 100644
--- a/frontend/src/layout/today/todaySpacesLogic.ts
+++ b/frontend/src/layout/today/todaySpacesLogic.ts
@@ -1,13 +1,18 @@
-import { MakeLogicType, actions, afterMount, connect, kea, path, reducers, selectors } from 'kea'
+import { MakeLogicType, actions, afterMount, connect, kea, listeners, path, reducers, selectors } from 'kea'
import { loaders } from 'kea-loaders'
+import { combineUrl } from 'kea-router'
+import { toast } from '@posthog/quill'
+
+import { writeToClipboard } from 'lib/utils/writeToClipboard'
import { maxGlobalLogic } from 'scenes/max/maxGlobalLogic'
import { teamLogic } from 'scenes/teamLogic'
+import { urls } from 'scenes/urls'
import { userLogic } from 'scenes/userLogic'
import { ConversationDetail, UserType } from '~/types'
-import { taskChannelsList, tasksList } from 'products/tasks/frontend/generated/api'
+import { taskChannelsList, taskChannelsStarCreate, tasksList } from 'products/tasks/frontend/generated/api'
import { ChannelDTOApi, TaskListItemApi } from 'products/tasks/frontend/generated/api.schemas'
import {
@@ -34,6 +39,13 @@ const RECENT_ITEM_LIMIT = 30
export type TodayWorkSectionId = 'pinned' | 'recent' | 'spaces'
+/** The space page reads this search param once and focuses its new-session composer. */
+export const SPACE_COMPOSE_PARAM = 'compose'
+
+export function spaceNewSessionUrl(spaceId: string): string {
+ return combineUrl(urls.taskSpace(spaceId), { [SPACE_COMPOSE_PARAM]: 1 }).url
+}
+
/** The personal space first, then the team's general space, then starred spaces, then the rest by name. */
export function sortSpaces(spaces: ChannelDTOApi[]): ChannelDTOApi[] {
const rank = (space: ChannelDTOApi): number =>
@@ -81,6 +93,7 @@ export interface todaySpacesLogicValues {
user: UserType | null // userLogic
allRecentItems: TodayWorkItem[]
collapsedSections: TodayWorkSectionId[]
+ pendingSpaceIds: string[]
pinnedItems: TodayWorkItem[]
pinnedTasks: TaskListItemApi[]
pinnedTasksLoading: boolean
@@ -115,6 +128,9 @@ export interface todaySpacesLogicActions {
clearRecentSearchAndFilters: () => {
value: true
}
+ copySpaceLink: (spaceId: string) => {
+ spaceId: string
+ }
loadPinnedTasks: () => any
loadPinnedTasksFailure: (
error: string,
@@ -185,9 +201,19 @@ export interface todaySpacesLogicActions {
setSectionHeights: (heights: Partial<Record<TodayWorkSectionId, number>>) => {
heights: Partial<Record<TodayWorkSectionId, number>>
}
+ starFailed: (spaceId: string) => {
+ spaceId: string
+ }
toggleSection: (sectionId: TodayWorkSectionId) => {
sectionId: TodayWorkSectionId
}
+ toggleStar: (
+ spaceId: string,
+ starred: boolean
+ ) => {
+ spaceId: string
+ starred: boolean
+ }
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
@@ -252,6 +278,9 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([
clearRecentSearchAndFilters: true,
setRecentSort: (sort: TodayRecentSort) => ({ sort }),
setRecentGrouping: (grouping: TodayRecentGrouping) => ({ grouping }),
+ toggleStar: (spaceId: string, starred: boolean) => ({ spaceId, starred }),
+ starFailed: (spaceId: string) => ({ spaceId }),
+ copySpaceLink: (spaceId: string) => ({ spaceId }),
}),
loaders(({ values }) => ({
spaces: [
@@ -345,6 +374,15 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([
{ persist: true },
{ setRecentGrouping: (_, { grouping }) => grouping },
],
+ pendingSpaceIds: [
+ [] as string[],
+ {
+ toggleStar: (state, { spaceId }) => [...state, spaceId],
+ starFailed: (state, { spaceId }) => state.filter((id) => id !== spaceId),
+ loadSpacesSuccess: () => [],
+ loadSpacesFailure: () => [],
+ },
+ ],
spacesUnavailable: [false, { loadSpaces: () => false, loadSpacesFailure: () => true }],
recentTasksUnavailable: [false, { loadRecentTasks: () => false, loadRecentTasksFailure: () => true }],
}),
@@ -420,6 +458,25 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([
recentTasksLoading || conversationHistoryLoading,
],
}),
+ listeners(({ actions, values }) => ({
+ toggleStar: async ({ spaceId, starred }) => {
+ try {
+ await taskChannelsStarCreate(String(values.currentTeamId), spaceId, { starred })
+ actions.loadSpaces()
+ } catch {
+ toast.error({ title: `Couldn’t ${starred ? 'star' : 'unstar'} this space. Try again.` })
+ actions.starFailed(spaceId)
+ }
+ },
+ copySpaceLink: async ({ spaceId }) => {
+ const outcome = await writeToClipboard(urls.absolute(urls.currentProject(urls.taskSpace(spaceId))))
+ if (outcome === 'copied') {
+ toast.success({ title: 'Link copied' })
+ } else {
+ toast.error({ title: 'Couldn’t copy the link. Copy it from the address bar instead.' })
+ }
+ },
+ })),
afterMount(({ actions }) => {
actions.loadSpaces()
actions.loadPinnedTasks()
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/EmbeddedTaskComposerImpl.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/EmbeddedTaskComposerImpl.tsx
index 85923389a9f1..ed57b21c2007 100644
--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/EmbeddedTaskComposerImpl.tsx
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/EmbeddedTaskComposerImpl.tsx
@@ -1,20 +1,21 @@
import { BindLogic } from 'kea'
import { TaskTrackerSceneLogicProps, taskTrackerSceneLogic } from '../taskTrackerSceneLogic'
-import { TaskComposer } from './TaskComposer'
+import { TaskComposer, TaskComposerProps } from './TaskComposer'
export type EmbeddedTaskComposerImplProps = Required<Pick<TaskTrackerSceneLogicProps, 'panelId'>> &
- Pick<TaskTrackerSceneLogicProps, 'channelId' | 'initialRepositoryConfig' | 'composerOverride' | 'onTaskCreated'>
+ Pick<TaskTrackerSceneLogicProps, 'channelId' | 'initialRepositoryConfig' | 'composerOverride' | 'onTaskCreated'> &
+ Pick<TaskComposerProps, 'focusRequest'>
/**
* The new-task composer alone, for a host page that lists tasks itself. It binds an embedded
* `taskTrackerSceneLogic` instance keyed by `panelId`, so it never shares a draft with the `/tasks` scene.
* It never renders the run: the host opens the created task from `onTaskCreated`.
*/
-export function EmbeddedTaskComposerImpl(props: EmbeddedTaskComposerImplProps): JSX.Element {
+export function EmbeddedTaskComposerImpl({ focusRequest, ...props }: EmbeddedTaskComposerImplProps): JSX.Element {
return (
<BindLogic logic={taskTrackerSceneLogic} props={props}>
- <TaskComposer variant="inline" />
+ <TaskComposer variant="inline" focusRequest={focusRequest} />
</BindLogic>
)
}
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskComposer.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskComposer.tsx
index 61a4b995176a..93aa4f2e986c 100644
--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskComposer.tsx
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskComposer.tsx
@@ -1,6 +1,6 @@
import { useActions, useMountedLogic, useValues } from 'kea'
import { router } from 'kea-router'
-import { useMemo, useRef } from 'react'
+import { useEffect, useMemo, useRef } from 'react'
import { AIConsentPopoverWrapper } from 'scenes/settings/organization/AIConsentPopoverWrapper'
import { urls } from 'scenes/urls'
@@ -38,9 +38,11 @@ import { RepositorySelector } from './RepositorySelector'
export interface TaskComposerProps {
/** `inline` drops the welcome header and the full-height centering, for a composer placed inside a host page. */
variant?: 'page' | 'inline'
+ /** A host bumps this number to move focus to the input, for example when the user asks for a new session. */
+ focusRequest?: number
}
-export function TaskComposer({ variant = 'page' }: TaskComposerProps): JSX.Element {
+export function TaskComposer({ variant = 'page', focusRequest = 0 }: TaskComposerProps): JSX.Element {
const inline = variant === 'inline'
const { submitNewTask, setNewTaskData, setActiveSuggestionGroup, applySuggestion, clearConsentBlock } =
useActions(taskTrackerSceneLogic)
@@ -80,6 +82,12 @@ export function TaskComposer({ variant = 'page' }: TaskComposerProps): JSX.Eleme
// The whole input frame is the drop target, so a file dropped anywhere on it attaches.
const frameRef = useRef<HTMLLabelElement>(null)
+ useEffect(() => {
+ if (focusRequest > 0) {
+ textAreaRef.current?.focus()
+ }
+ }, [focusRequest])
+
const handleSelectSuggestion = (item: SuggestionItem): void => {
applySuggestion(item)
if (item.requiresUserInput) {
diff --git a/products/tasks/frontend/spaces/SpaceScene.tsx b/products/tasks/frontend/spaces/SpaceScene.tsx
index 2840283714be..69c52f168938 100644
--- a/products/tasks/frontend/spaces/SpaceScene.tsx
+++ b/products/tasks/frontend/spaces/SpaceScene.tsx
@@ -49,8 +49,16 @@ export const scene: SceneExport<SpaceSceneLogicProps> = {
export function SpaceScene({ id }: SpaceSceneLogicProps): JSX.Element {
const enabled = useFeatureFlag('TODAY_RAIL_NAV')
- const { space, spaceLoading, spaceUnavailable, spaceMissing, activeTab, savingSpace, composerRepositoryConfig } =
- useValues(spaceSceneLogic({ id }))
+ const {
+ space,
+ spaceLoading,
+ spaceUnavailable,
+ spaceMissing,
+ activeTab,
+ savingSpace,
+ composerRepositoryConfig,
+ composerFocusRequest,
+ } = useValues(spaceSceneLogic({ id }))
const { setStarred, loadSpace, sessionStarted } = useActions(spaceSceneLogic({ id }))
if (!enabled || spaceMissing) {
@@ -140,6 +148,7 @@ export function SpaceScene({ id }: SpaceSceneLogicProps): JSX.Element {
initialRepositoryConfig={composerRepositoryConfig}
composerOverride={SPACE_COMPOSER_OVERRIDE}
onTaskCreated={sessionStarted}
+ focusRequest={composerFocusRequest}
/>
</div>
)}
diff --git a/products/tasks/frontend/spaces/spaceSceneLogic.test.ts b/products/tasks/frontend/spaces/spaceSceneLogic.test.ts
index 0fb94da5a408..30f95efe0ac7 100644
--- a/products/tasks/frontend/spaces/spaceSceneLogic.test.ts
+++ b/products/tasks/frontend/spaces/spaceSceneLogic.test.ts
@@ -1,7 +1,10 @@
import { router } from 'kea-router'
import { expectLogic } from 'kea-test-utils'
+import { urls } from 'scenes/urls'
+
import { todaySessionMenuLogic } from '~/layout/today/todaySessionMenuLogic'
+import { spaceNewSessionUrl, todaySpacesLogic } from '~/layout/today/todaySpacesLogic'
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
@@ -9,12 +12,19 @@ import { spaceSceneLogic } from './spaceSceneLogic'
describe('spaceSceneLogic', () => {
let sessionSpace = 'space-a'
+ let starredIds: string[] = []
+ let starRequests: { id: string; starred: boolean }[] = []
beforeEach(() => {
sessionSpace = 'space-a'
+ starredIds = []
+ starRequests = []
useMocks({
get: {
- '/api/projects/:team_id/task_channels/': [],
+ '/api/projects/:team_id/task_channels/': () => [
+ 200,
+ ['space-a', 'space-b'].map((id) => ({ id, name: id, starred: starredIds.includes(id) })),
+ ],
'/api/projects/:team_id/task_channels/:id/': ({ params }) => [
200,
{
@@ -37,6 +47,16 @@ describe('spaceSceneLogic', () => {
return [200, { results, count: results.length }]
},
},
+ post: {
+ '/api/projects/:team_id/task_channels/:id/star/': async ({ params, request }) => {
+ const { starred } = (await request.json()) as { starred: boolean }
+ starRequests.push({ id: String(params.id), starred })
+ starredIds = starred
+ ? [...starredIds, String(params.id)]
+ : starredIds.filter((id) => id !== params.id)
+ return [200, {}]
+ },
+ },
patch: {
'/api/projects/:team_id/task_channels/:id/': async ({ params, request }) => [
200,
@@ -125,4 +145,47 @@ describe('spaceSceneLogic', () => {
expect(logic.values.members.map((member) => member.id)).toEqual([7])
})
+
+ it('stars a space from the sidebar menu and shows it on that space page', async () => {
+ const logic = spaceSceneLogic({ id: 'space-b' })
+ logic.mount()
+ await expectLogic(logic).toFinishAllListeners()
+
+ todaySpacesLogic.actions.toggleStar('space-b', true)
+ await expectLogic(todaySpacesLogic).toDispatchActions(['toggleStar', 'loadSpaces', 'loadSpacesSuccess'])
+
+ expect(starRequests).toEqual([{ id: 'space-b', starred: true }])
+ expect(todaySpacesLogic.values.pendingSpaceIds).toEqual([])
+ expect(logic.values.space?.starred).toBe(true)
+ })
+
+ it('copies the project-scoped link to the space', async () => {
+ const writeText = jest.fn().mockResolvedValue(undefined)
+ Object.defineProperty(navigator, 'clipboard', { value: { writeText }, configurable: true })
+ todaySpacesLogic.mount()
+
+ todaySpacesLogic.actions.copySpaceLink('space-a')
+ await expectLogic(todaySpacesLogic).toFinishAllListeners()
+
+ expect(writeText).toHaveBeenCalledWith(
+ expect.stringMatching(new RegExp(`^${window.location.origin}/project/\\d+/spaces/space-a$`))
+ )
+ })
+
+ it('focuses the composer once when a new session is requested for this space', async () => {
+ const logic = spaceSceneLogic({ id: 'space-a' })
+ const other = spaceSceneLogic({ id: 'space-b' })
+ logic.mount()
+ other.mount()
+
+ router.actions.push(spaceNewSessionUrl('space-a'))
+ await expectLogic(logic).toFinishAllListeners()
+ expect(logic.values.composerFocusRequest).toBe(1)
+ expect(router.values.searchParams).toEqual({})
+
+ router.actions.push(urls.taskSpaceSettings('space-a'))
+ router.actions.push(urls.taskSpace('space-a'))
+ expect(logic.values.composerFocusRequest).toBe(1)
+ expect(other.values.composerFocusRequest).toBe(0)
+ })
})
diff --git a/products/tasks/frontend/spaces/spaceSceneLogic.ts b/products/tasks/frontend/spaces/spaceSceneLogic.ts
index fd524db3a9c8..b95b2ae42fdb 100644
--- a/products/tasks/frontend/spaces/spaceSceneLogic.ts
+++ b/products/tasks/frontend/spaces/spaceSceneLogic.ts
@@ -1,6 +1,6 @@
import { MakeLogicType, actions, afterMount, connect, kea, key, listeners, path, props, reducers, selectors } from 'kea'
import { loaders } from 'kea-loaders'
-import { router } from 'kea-router'
+import { router, urlToAction } from 'kea-router'
import { toast } from '@posthog/quill'
@@ -9,7 +9,7 @@ import { teamLogic } from 'scenes/teamLogic'
import { urls } from 'scenes/urls'
import { todaySessionMenuLogic } from '~/layout/today/todaySessionMenuLogic'
-import { spaceLabel, todaySpacesLogic } from '~/layout/today/todaySpacesLogic'
+import { SPACE_COMPOSE_PARAM, spaceLabel, todaySpacesLogic } from '~/layout/today/todaySpacesLogic'
import { TodayWorkGroup, groupByDay, sessionItem } from '~/layout/today/todayWorkItems'
import { Breadcrumb } from '~/types'
@@ -41,6 +41,7 @@ export interface spaceSceneLogicValues {
currentTeamId: number | null // teamLogic
activeTab: SpaceTab
breadcrumbs: Breadcrumb[]
+ composerFocusRequest: number
composerRepositoryConfig: SpaceComposerRepositoryConfig
feedGroups: TodayWorkGroup[]
members: TaskUserBasicInfoApi[]
@@ -62,9 +63,19 @@ export interface spaceSceneLogicActions {
sessionId: string
} // todaySessionMenuLogic
loadSpaces: () => any // todaySpacesLogic
+ loadSpacesSuccess: (
+ spaces: ChannelDTOApi[],
+ payload?: any
+ ) => {
+ payload?: any
+ spaces: ChannelDTOApi[]
+ } // todaySpacesLogic
deleteSpace: () => {
value: true
}
+ focusComposer: () => {
+ value: true
+ }
loadMembers: () => any
loadMembersFailure: (
error: string,
@@ -167,7 +178,7 @@ export const spaceSceneLogic = kea<spaceSceneLogicType>([
key((props) => props.id),
connect(() => ({
values: [teamLogic, ['currentTeamId']],
- actions: [todaySessionMenuLogic, ['sessionUpdated'], todaySpacesLogic, ['loadSpaces']],
+ actions: [todaySessionMenuLogic, ['sessionUpdated'], todaySpacesLogic, ['loadSpaces', 'loadSpacesSuccess']],
})),
actions({
updateSpace: (patch: PatchedChannelUpdateApi) => ({ patch }),
@@ -176,6 +187,7 @@ export const spaceSceneLogic = kea<spaceSceneLogicType>([
spaceSaved: (space: ChannelDTOApi) => ({ space }),
savingFinished: true,
sessionStarted: (sessionId: string) => ({ sessionId }),
+ focusComposer: true,
}),
loaders(({ props, values }) => ({
space: [
@@ -224,7 +236,14 @@ export const spaceSceneLogic = kea<spaceSceneLogicType>([
space: {
spaceSaved: (_, { space }) => space,
setStarred: (state, { starred }) => (state ? { ...state, starred } : state),
+ // The sidebar can star or unstar this space too, so follow the shared list.
+ loadSpacesSuccess: (state, { spaces }) => {
+ const listed = state && spaces.find((space) => space.id === state.id)
+ return state && listed ? { ...state, starred: listed.starred } : state
+ },
},
+ // Each request bumps the counter, so the composer focuses again even when it is already mounted.
+ composerFocusRequest: [0, { focusComposer: (state) => state + 1 }],
savingSpace: [
false,
{
@@ -331,6 +350,17 @@ export const spaceSceneLogic = kea<spaceSceneLogicType>([
}
},
})),
+ urlToAction(({ actions, props }) => ({
+ [urls.taskSpace(':id')]: ({ id }, searchParams, hashParams) => {
+ if (id !== props.id || !searchParams[SPACE_COMPOSE_PARAM]) {
+ return
+ }
+ actions.focusComposer()
+ // Drop the param, so a reload or a back navigation does not focus the composer again.
+ const { [SPACE_COMPOSE_PARAM]: _compose, ...rest } = searchParams
+ router.actions.replace(urls.taskSpace(props.id), rest, hashParams)
+ },
+ })),
afterMount(({ actions }) => {
actions.loadSpace()
actions.loadSessions()
diff --git a/products/tasks/frontend/spaces/spacesSceneLogic.ts b/products/tasks/frontend/spaces/spacesSceneLogic.ts
index dc7d56af8088..a3dd0eddbd66 100644
--- a/products/tasks/frontend/spaces/spacesSceneLogic.ts
+++ b/products/tasks/frontend/spaces/spacesSceneLogic.ts
@@ -1,15 +1,11 @@
-import { MakeLogicType, actions, connect, kea, listeners, path, reducers, selectors } from 'kea'
-
-import { toast } from '@posthog/quill'
+import { MakeLogicType, actions, connect, kea, path, reducers, selectors } from 'kea'
import { Scene } from 'scenes/sceneTypes'
-import { teamLogic } from 'scenes/teamLogic'
import { urls } from 'scenes/urls'
import { starredSpaces, todaySpacesLogic } from '~/layout/today/todaySpacesLogic'
import { Breadcrumb } from '~/types'
-import { taskChannelsStarCreate } from '../generated/api'
import { ChannelDTOApi } from '../generated/api.schemas'
export interface SpacesIndexLists {
@@ -27,45 +23,27 @@ export function spacesIndexLists(spaces: ChannelDTOApi[], search: string): Space
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface spacesSceneLogicValues {
- currentTeamId: number | null // teamLogic
+ pendingSpaceIds: string[] // todaySpacesLogic
sortedSpaces: ChannelDTOApi[] // todaySpacesLogic
spacesLoading: boolean // todaySpacesLogic
spacesUnavailable: boolean // todaySpacesLogic
breadcrumbs: Breadcrumb[]
lists: SpacesIndexLists
- pendingSpaceIds: string[]
search: string
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface spacesSceneLogicActions {
loadSpaces: () => any // todaySpacesLogic
- loadSpacesFailure: (
- error: string,
- errorObject?: any
- ) => {
- error: string
- errorObject?: any
- } // todaySpacesLogic
- loadSpacesSuccess: (
- spaces: ChannelDTOApi[],
- payload?: any
- ) => {
- payload?: any
- spaces: ChannelDTOApi[]
- } // todaySpacesLogic
- setSearch: (search: string) => {
- search: string
- }
- starFailed: (spaceId: string) => {
- spaceId: string
- }
toggleStar: (
spaceId: string,
starred: boolean
) => {
spaceId: string
starred: boolean
+ } // todaySpacesLogic
+ setSearch: (search: string) => {
+ search: string
}
}
@@ -86,30 +64,14 @@ export type spacesSceneLogicType = MakeLogicType<
export const spacesSceneLogic = kea<spacesSceneLogicType>([
path(['products', 'tasks', 'spaces', 'spacesSceneLogic']),
connect(() => ({
- values: [
- teamLogic,
- ['currentTeamId'],
- todaySpacesLogic,
- ['sortedSpaces', 'spacesLoading', 'spacesUnavailable'],
- ],
- actions: [todaySpacesLogic, ['loadSpaces', 'loadSpacesSuccess', 'loadSpacesFailure']],
+ values: [todaySpacesLogic, ['sortedSpaces', 'spacesLoading', 'spacesUnavailable', 'pendingSpaceIds']],
+ actions: [todaySpacesLogic, ['loadSpaces', 'toggleStar']],
})),
actions({
setSearch: (search: string) => ({ search }),
- toggleStar: (spaceId: string, starred: boolean) => ({ spaceId, starred }),
- starFailed: (spaceId: string) => ({ spaceId }),
}),
reducers({
search: ['', { setSearch: (_, { search }) => search }],
- pendingSpaceIds: [
- [] as string[],
- {
- toggleStar: (state, { spaceId }) => [...state, spaceId],
- starFailed: (state, { spaceId }) => state.filter((id) => id !== spaceId),
- loadSpacesSuccess: () => [],
- loadSpacesFailure: () => [],
- },
- ],
}),
selectors({
lists: [
@@ -121,15 +83,4 @@ export const spacesSceneLogic = kea<spacesSceneLogicType>([
(): Breadcrumb[] => [{ key: Scene.TaskSpaces, name: 'Spaces', path: urls.taskSpaces(), iconType: 'task' }],
],
}),
- listeners(({ actions, values }) => ({
- toggleStar: async ({ spaceId, starred }) => {
- try {
- await taskChannelsStarCreate(String(values.currentTeamId), spaceId, { starred })
- actions.loadSpaces()
- } catch {
- toast.error({ title: `Couldn’t ${starred ? 'star' : 'unstar'} this space. Try again.` })
- actions.starFailed(spaceId)
- }
- },
- })),
])