@@ -33,8 +33,14 @@ import { ChannelBackRow } from "@posthog/ui/features/canvas/components/ChannelBa
3333import { ChannelItemRow } from "@posthog/ui/features/canvas/components/ChannelItemRow" ;
3434import { ChannelsFab } from "@posthog/ui/features/canvas/components/ChannelsFab" ;
3535import { useChannelItems } from "@posthog/ui/features/canvas/hooks/useChannelItems" ;
36+ import { useCommandCenterStore } from "@posthog/ui/features/command-center/commandCenterStore" ;
3637import { useFeatureFlag } from "@posthog/ui/features/feature-flags/useFeatureFlag" ;
3738import { SidebarItem } from "@posthog/ui/features/sidebar/components/SidebarItem" ;
39+ import { useTaskContextMenu } from "@posthog/ui/features/tasks/useTaskContextMenu" ;
40+ import { useRenameTask } from "@posthog/ui/features/tasks/useTaskMutations" ;
41+ import { useTasks } from "@posthog/ui/features/tasks/useTasks" ;
42+ import { navigateToCommandCenter } from "@posthog/ui/router/navigationBridge" ;
43+ import { logger } from "@posthog/ui/shell/logger" ;
3844import { useNavigate , useRouterState } from "@tanstack/react-router" ;
3945import { type ReactNode , useMemo , useState } from "react" ;
4046
@@ -52,6 +58,7 @@ const cnHeaderButton = (active: boolean) =>
5258 cn ( HEADER_ICON_BUTTON_CLASS , active && "bg-fill-selected text-foreground" ) ;
5359
5460const RECENTS_CAP = 30 ;
61+ const log = logger . scope ( "channel-sidebar" ) ;
5562
5663function RecentSectionHeader ( {
5764 searchOpen,
@@ -199,6 +206,18 @@ export function ChannelSidebar({ channelId }: { channelId: string }) {
199206
200207 const { items, actions, me, isLoading, channelMissing } =
201208 useChannelItems ( channelId ) ;
209+ const { showContextMenu, editingTaskId, setEditingTaskId } =
210+ useTaskContextMenu ( ) ;
211+ const { renameTask } = useRenameTask ( ) ;
212+ const commandCenterCells = useCommandCenterStore ( ( state ) => state . cells ) ;
213+ const assignTaskToCommandCenter = useCommandCenterStore (
214+ ( state ) => state . assignTask ,
215+ ) ;
216+ const { data : allTasks = [ ] } = useTasks ( { showAllUsers : true } ) ;
217+ const allTaskIds = useMemo (
218+ ( ) => new Set ( allTasks . map ( ( task ) => task . id ) ) ,
219+ [ allTasks ] ,
220+ ) ;
202221
203222 const [ searchOpen , setSearchOpen ] = useState ( false ) ;
204223 const [ query , setQuery ] = useState ( "" ) ;
@@ -227,6 +246,56 @@ export function ChannelSidebar({ channelId }: { channelId: string }) {
227246 [ items , query , createdByFilter , statusFilter , me ] ,
228247 ) ;
229248
249+ const taskRow = ( item : ( typeof items ) [ number ] ) => (
250+ < ChannelItemRow
251+ key = { item . key }
252+ item = { item }
253+ isActive = { item . key === activeKey }
254+ actions = { actions }
255+ isEditing = { item . kind === "task" && editingTaskId === item . id }
256+ onContextMenu = {
257+ item . kind === "task"
258+ ? ( event ) =>
259+ void showContextMenu ( item , event , {
260+ isPinned : item . pinned ,
261+ isInCommandCenter : commandCenterCells . includes ( item . id ) ,
262+ hasEmptyCommandCenterCell : commandCenterCells . some (
263+ ( taskId ) => taskId == null || ! allTaskIds . has ( taskId ) ,
264+ ) ,
265+ showArchivePrior : false ,
266+ onTogglePin : ( ) => actions . togglePin ( item ) ,
267+ onArchive : ( ) => actions . archive ( item ) ,
268+ onAddToCommandCenter : ( ) => {
269+ const cellIndex = commandCenterCells . findIndex (
270+ ( taskId ) => taskId == null || ! allTaskIds . has ( taskId ) ,
271+ ) ;
272+ if ( cellIndex === - 1 ) return ;
273+ assignTaskToCommandCenter ( cellIndex , item . id ) ;
274+ navigateToCommandCenter ( ) ;
275+ } ,
276+ } )
277+ : undefined
278+ }
279+ onEditSubmit = {
280+ item . kind === "task"
281+ ? async ( newTitle ) => {
282+ setEditingTaskId ( null ) ;
283+ try {
284+ await renameTask ( {
285+ taskId : item . id ,
286+ currentTitle : item . title ,
287+ newTitle,
288+ } ) ;
289+ } catch ( error ) {
290+ log . error ( "Failed to rename task" , error ) ;
291+ }
292+ }
293+ : undefined
294+ }
295+ onEditCancel = { ( ) => setEditingTaskId ( null ) }
296+ />
297+ ) ;
298+
230299 const sectionRow = (
231300 label : string ,
232301 icon : ReactNode ,
@@ -313,14 +382,7 @@ export function ChannelSidebar({ channelId }: { channelId: string }) {
313382 < >
314383 < MenuLabel > Pinned</ MenuLabel >
315384 < div className = "flex flex-col gap-px" >
316- { pinnedItems . map ( ( item ) => (
317- < ChannelItemRow
318- key = { item . key }
319- item = { item }
320- isActive = { item . key === activeKey }
321- actions = { actions }
322- />
323- ) ) }
385+ { pinnedItems . map ( taskRow ) }
324386 </ div >
325387 </ >
326388 ) }
@@ -343,14 +405,7 @@ export function ChannelSidebar({ channelId }: { channelId: string }) {
343405 />
344406 { recentItems . length > 0 ? (
345407 < div className = "flex flex-col gap-px" >
346- { recentItems . map ( ( item ) => (
347- < ChannelItemRow
348- key = { item . key }
349- item = { item }
350- isActive = { item . key === activeKey }
351- actions = { actions }
352- />
353- ) ) }
408+ { recentItems . map ( taskRow ) }
354409 </ div >
355410 ) : (
356411 < Empty className = "border-0 py-6" >
0 commit comments