Skip to content

Commit 28f1d10

Browse files
committed
improvement(logs): fix trigger badge wrapping, time range picker, status filters, and React anti-patterns
1 parent c06361b commit 28f1d10

7 files changed

Lines changed: 285 additions & 249 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { WorkflowLog } from '@/stores/logs/filters/types'
2+
3+
const MOCK_WORKFLOW = {
4+
id: '__mock__',
5+
name: 'mock-workflow',
6+
color: '#6366f1',
7+
}
8+
9+
const base = (overrides: Partial<WorkflowLog>): WorkflowLog => ({
10+
id: `mock-${overrides.trigger}-1`,
11+
workflowId: MOCK_WORKFLOW.id,
12+
executionId: `mock-exec-${overrides.trigger}-1`,
13+
level: 'info',
14+
status: 'success',
15+
duration: '1.2s',
16+
trigger: null,
17+
createdAt: new Date().toISOString(),
18+
workflow: MOCK_WORKFLOW,
19+
cost: { total: 0.001, input: 0.0005, output: 0.0005 },
20+
...overrides,
21+
})
22+
23+
export const DEV_MOCK_LOGS: WorkflowLog[] = [
24+
base({ id: 'mock-gcal-1', trigger: 'google_calendar', executionId: 'mock-exec-gcal-1' }),
25+
base({ id: 'mock-gmail-1', trigger: 'gmail', executionId: 'mock-exec-gmail-1' }),
26+
base({ id: 'mock-slack-1', trigger: 'slack', executionId: 'mock-exec-slack-1' }),
27+
base({
28+
id: 'mock-gh-1',
29+
trigger: 'github',
30+
executionId: 'mock-exec-gh-1',
31+
status: 'failed',
32+
level: 'error',
33+
}),
34+
]

apps/sim/app/workspace/[workspaceId]/logs/components/dashboard/components/line-chart/line-chart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ function LineChartComponent({
293293
className='inline-block h-[6px] w-[6px] rounded-xs'
294294
style={{ backgroundColor: resolvedColors[s.id || ''] || s.color }}
295295
/>
296-
<span style={{ color: 'hsl(var(--muted-foreground))' }}>{s.label}</span>
296+
<span className='text-[var(--text-muted)]'>{s.label}</span>
297297
</button>
298298
)
299299
})}

apps/sim/app/workspace/[workspaceId]/logs/components/logs-toolbar/logs-toolbar.tsx

Lines changed: 69 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,13 @@ export const LogsToolbar = memo(function LogsToolbar({
249249

250250
const statusOptions: ComboboxOption[] = useMemo(
251251
() =>
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-
})),
252+
(Object.keys(STATUS_CONFIG) as LogStatus[])
253+
.filter((status) => STATUS_CONFIG[status].filterable)
254+
.map((status) => ({
255+
value: status,
256+
label: STATUS_CONFIG[status].label,
257+
icon: getColorIcon(STATUS_CONFIG[status].color),
258+
})),
257259
[]
258260
)
259261

@@ -305,34 +307,29 @@ export const LogsToolbar = memo(function LogsToolbar({
305307
[setTriggers, workspaceId]
306308
)
307309

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])
310+
const statusDisplayLabel =
311+
selectedStatuses.length === 0
312+
? 'Status'
313+
: selectedStatuses.length === 1
314+
? (statusOptions.find((s) => s.value === selectedStatuses[0])?.label ?? '1 selected')
315+
: `${selectedStatuses.length} selected`
316316

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])
317+
const selectedStatusColor =
318+
selectedStatuses.length === 1
319+
? (STATUS_CONFIG[selectedStatuses[0] as LogStatus]?.color ?? null)
320+
: null
322321

323322
const workflowOptions: ComboboxOption[] = useMemo(
324323
() => workflows.map((w) => ({ value: w.id, label: w.name, icon: getColorIcon(w.color, true) })),
325324
[workflows]
326325
)
327326

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])
327+
const workflowDisplayLabel =
328+
workflowIds.length === 0
329+
? 'Workflow'
330+
: workflowIds.length === 1
331+
? (workflows.find((w) => w.id === workflowIds[0])?.name ?? '1 selected')
332+
: `${workflowIds.length} workflows`
336333

337334
const selectedWorkflow =
338335
workflowIds.length === 1 ? workflows.find((w) => w.id === workflowIds[0]) : null
@@ -342,14 +339,12 @@ export const LogsToolbar = memo(function LogsToolbar({
342339
[folderList]
343340
)
344341

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])
342+
const folderDisplayLabel =
343+
folderIds.length === 0
344+
? 'Folder'
345+
: folderIds.length === 1
346+
? (folderList.find((f) => f.id === folderIds[0])?.name ?? '1 selected')
347+
: `${folderIds.length} folders`
353348

354349
const triggerOptions: ComboboxOption[] = useMemo(
355350
() =>
@@ -361,23 +356,21 @@ export const LogsToolbar = memo(function LogsToolbar({
361356
[]
362357
)
363358

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])
359+
const triggerDisplayLabel =
360+
triggers.length === 0
361+
? 'Trigger'
362+
: triggers.length === 1
363+
? (triggerOptions.find((t) => t.value === triggers[0])?.label ?? '1 selected')
364+
: `${triggers.length} triggers`
365+
366+
const timeDisplayLabel =
367+
timeRange === 'All time'
368+
? 'Time'
369+
: timeRange === 'Custom range' && startDate && endDate
370+
? `${formatDateShort(startDate)} - ${formatDateShort(endDate)}`
371+
: timeRange === 'Custom range'
372+
? 'Custom range'
373+
: timeRange
381374

382375
/**
383376
* Handles time range selection from combobox.
@@ -792,42 +785,32 @@ export const LogsToolbar = memo(function LogsToolbar({
792785
/>
793786

794787
{/* 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'
788+
<div className='relative'>
789+
<Combobox
790+
options={TIME_RANGE_OPTIONS as unknown as ComboboxOption[]}
791+
value={timeRange}
792+
onChange={handleTimeRangeChange}
793+
placeholder='Time'
794+
overlayContent={
795+
<span className='truncate text-[var(--text-primary)]'>{timeDisplayLabel}</span>
796+
}
797+
size='sm'
816798
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>
799+
className='h-[32px] w-[120px] rounded-md'
800+
/>
801+
<DatePicker
802+
mode='range'
803+
showTrigger={false}
804+
open={datePickerOpen}
805+
onOpenChange={(isOpen) => {
806+
if (!isOpen) handleDatePickerCancel()
807+
}}
808+
startDate={startDate}
809+
endDate={endDate}
810+
onRangeChange={handleDateRangeApply}
811+
onCancel={handleDatePickerCancel}
812+
/>
813+
</div>
831814
</div>
832815
</div>
833816
</div>

0 commit comments

Comments
 (0)