@@ -224,6 +224,7 @@ export const LogsToolbar = memo(function LogsToolbar({
224224
225225 const [ datePickerOpen , setDatePickerOpen ] = useState ( false )
226226 const [ previousTimeRange , setPreviousTimeRange ] = useState ( timeRange )
227+ const dateRangeAppliedRef = useRef ( false )
227228 const { data : folders = { } } = useFolderMap ( workspaceId )
228229
229230 const { data : allWorkflowList = [ ] } = useWorkflows ( workspaceId )
@@ -249,11 +250,13 @@ export const LogsToolbar = memo(function LogsToolbar({
249250
250251 const statusOptions : ComboboxOption [ ] = useMemo (
251252 ( ) =>
252- ( Object . keys ( STATUS_CONFIG ) as LogStatus [ ] ) . map ( ( status ) => ( {
253- value : status ,
254- label : STATUS_CONFIG [ status ] . label ,
255- icon : getColorIcon ( STATUS_CONFIG [ status ] . color ) ,
256- } ) ) ,
253+ ( Object . keys ( STATUS_CONFIG ) as LogStatus [ ] )
254+ . filter ( ( status ) => STATUS_CONFIG [ status ] . filterable )
255+ . map ( ( status ) => ( {
256+ value : status ,
257+ label : STATUS_CONFIG [ status ] . label ,
258+ icon : getColorIcon ( STATUS_CONFIG [ status ] . color ) ,
259+ } ) ) ,
257260 [ ]
258261 )
259262
@@ -305,34 +308,29 @@ export const LogsToolbar = memo(function LogsToolbar({
305308 [ setTriggers , workspaceId ]
306309 )
307310
308- const statusDisplayLabel = useMemo ( ( ) => {
309- if ( selectedStatuses . length === 0 ) return 'Status'
310- if ( selectedStatuses . length === 1 ) {
311- const status = statusOptions . find ( ( s ) => s . value === selectedStatuses [ 0 ] )
312- return status ?. label || '1 selected'
313- }
314- return `${ selectedStatuses . length } selected`
315- } , [ selectedStatuses , statusOptions ] )
311+ const statusDisplayLabel =
312+ selectedStatuses . length === 0
313+ ? 'Status'
314+ : selectedStatuses . length === 1
315+ ? ( statusOptions . find ( ( s ) => s . value === selectedStatuses [ 0 ] ) ?. label ?? '1 selected' )
316+ : `${ selectedStatuses . length } selected`
316317
317- const selectedStatusColor = useMemo ( ( ) => {
318- if ( selectedStatuses . length !== 1 ) return null
319- const status = selectedStatuses [ 0 ] as LogStatus
320- return STATUS_CONFIG [ status ] ?. color ?? null
321- } , [ selectedStatuses ] )
318+ const selectedStatusColor =
319+ selectedStatuses . length === 1
320+ ? ( STATUS_CONFIG [ selectedStatuses [ 0 ] as LogStatus ] ?. color ?? null )
321+ : null
322322
323323 const workflowOptions : ComboboxOption [ ] = useMemo (
324324 ( ) => workflows . map ( ( w ) => ( { value : w . id , label : w . name , icon : getColorIcon ( w . color , true ) } ) ) ,
325325 [ workflows ]
326326 )
327327
328- const workflowDisplayLabel = useMemo ( ( ) => {
329- if ( workflowIds . length === 0 ) return 'Workflow'
330- if ( workflowIds . length === 1 ) {
331- const workflow = workflows . find ( ( w ) => w . id === workflowIds [ 0 ] )
332- return workflow ?. name || '1 selected'
333- }
334- return `${ workflowIds . length } workflows`
335- } , [ workflowIds , workflows ] )
328+ const workflowDisplayLabel =
329+ workflowIds . length === 0
330+ ? 'Workflow'
331+ : workflowIds . length === 1
332+ ? ( workflows . find ( ( w ) => w . id === workflowIds [ 0 ] ) ?. name ?? '1 selected' )
333+ : `${ workflowIds . length } workflows`
336334
337335 const selectedWorkflow =
338336 workflowIds . length === 1 ? workflows . find ( ( w ) => w . id === workflowIds [ 0 ] ) : null
@@ -342,14 +340,12 @@ export const LogsToolbar = memo(function LogsToolbar({
342340 [ folderList ]
343341 )
344342
345- const folderDisplayLabel = useMemo ( ( ) => {
346- if ( folderIds . length === 0 ) return 'Folder'
347- if ( folderIds . length === 1 ) {
348- const folder = folderList . find ( ( f ) => f . id === folderIds [ 0 ] )
349- return folder ?. name || '1 selected'
350- }
351- return `${ folderIds . length } folders`
352- } , [ folderIds , folderList ] )
343+ const folderDisplayLabel =
344+ folderIds . length === 0
345+ ? 'Folder'
346+ : folderIds . length === 1
347+ ? ( folderList . find ( ( f ) => f . id === folderIds [ 0 ] ) ?. name ?? '1 selected' )
348+ : `${ folderIds . length } folders`
353349
354350 const triggerOptions : ComboboxOption [ ] = useMemo (
355351 ( ) =>
@@ -361,23 +357,21 @@ export const LogsToolbar = memo(function LogsToolbar({
361357 [ ]
362358 )
363359
364- const triggerDisplayLabel = useMemo ( ( ) => {
365- if ( triggers . length === 0 ) return 'Trigger'
366- if ( triggers . length === 1 ) {
367- const trigger = triggerOptions . find ( ( t ) => t . value === triggers [ 0 ] )
368- return trigger ?. label || '1 selected'
369- }
370- return `${ triggers . length } triggers`
371- } , [ triggers , triggerOptions ] )
372-
373- const timeDisplayLabel = useMemo ( ( ) => {
374- if ( timeRange === 'All time' ) return 'Time'
375- if ( timeRange === 'Custom range' && startDate && endDate ) {
376- return `${ formatDateShort ( startDate ) } - ${ formatDateShort ( endDate ) } `
377- }
378- if ( timeRange === 'Custom range' ) return 'Custom range'
379- return timeRange
380- } , [ timeRange , startDate , endDate ] )
360+ const triggerDisplayLabel =
361+ triggers . length === 0
362+ ? 'Trigger'
363+ : triggers . length === 1
364+ ? ( triggerOptions . find ( ( t ) => t . value === triggers [ 0 ] ) ?. label ?? '1 selected' )
365+ : `${ triggers . length } triggers`
366+
367+ const timeDisplayLabel =
368+ timeRange === 'All time'
369+ ? 'Time'
370+ : timeRange === 'Custom range' && startDate && endDate
371+ ? `${ formatDateShort ( startDate ) } - ${ formatDateShort ( endDate ) } `
372+ : timeRange === 'Custom range'
373+ ? 'Custom range'
374+ : timeRange
381375
382376 /**
383377 * Handles time range selection from combobox.
@@ -405,6 +399,7 @@ export const LogsToolbar = memo(function LogsToolbar({
405399 */
406400 const handleDateRangeApply = useCallback (
407401 ( start : string , end : string ) => {
402+ dateRangeAppliedRef . current = true
408403 setDateRange ( start , end )
409404 setDatePickerOpen ( false )
410405 captureEvent ( posthogRef . current , 'logs_filter_applied' , {
@@ -792,42 +787,38 @@ export const LogsToolbar = memo(function LogsToolbar({
792787 />
793788
794789 { /* Timeline Filter */ }
795- < DropdownMenu open = { datePickerOpen } onOpenChange = { setDatePickerOpen } >
796- < DropdownMenuTrigger asChild >
797- < div >
798- < Combobox
799- options = { TIME_RANGE_OPTIONS as unknown as ComboboxOption [ ] }
800- value = { timeRange }
801- onChange = { handleTimeRangeChange }
802- placeholder = 'Time'
803- overlayContent = {
804- < span className = 'truncate text-[var(--text-primary)]' >
805- { timeDisplayLabel }
806- </ span >
807- }
808- size = 'sm'
809- align = 'end'
810- className = 'h-[32px] w-[120px] rounded-md'
811- />
812- </ div >
813- </ DropdownMenuTrigger >
814- < DropdownMenuContent
815- side = 'bottom'
790+ < div className = 'relative' >
791+ < Combobox
792+ options = { TIME_RANGE_OPTIONS as unknown as ComboboxOption [ ] }
793+ value = { timeRange }
794+ onChange = { handleTimeRangeChange }
795+ placeholder = 'Time'
796+ overlayContent = {
797+ < span className = 'truncate text-[var(--text-primary)]' > { timeDisplayLabel } </ span >
798+ }
799+ size = 'sm'
816800 align = 'end'
817- sideOffset = { 4 }
818- collisionPadding = { 16 }
819- className = 'w-auto p-0'
820- >
821- < DatePicker
822- mode = 'range'
823- startDate = { startDate }
824- endDate = { endDate }
825- onRangeChange = { handleDateRangeApply }
826- onCancel = { handleDatePickerCancel }
827- inline
828- />
829- </ DropdownMenuContent >
830- </ DropdownMenu >
801+ className = 'h-[32px] w-[120px] rounded-md'
802+ />
803+ < DatePicker
804+ mode = 'range'
805+ showTrigger = { false }
806+ open = { datePickerOpen }
807+ onOpenChange = { ( isOpen ) => {
808+ if ( ! isOpen ) {
809+ if ( dateRangeAppliedRef . current ) {
810+ dateRangeAppliedRef . current = false
811+ } else {
812+ handleDatePickerCancel ( )
813+ }
814+ }
815+ } }
816+ startDate = { startDate }
817+ endDate = { endDate }
818+ onRangeChange = { handleDateRangeApply }
819+ onCancel = { handleDatePickerCancel }
820+ />
821+ </ div >
831822 </ div >
832823 </ div >
833824 </ div >
0 commit comments