Skip to content

Commit 0e8e8c7

Browse files
fix(sidebar): order by created at (#1251)
1 parent 47da5eb commit 0e8e8c7

File tree

5 files changed

+20
-9
lines changed

5 files changed

+20
-9
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/control-bar/control-bar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,11 +1101,11 @@ export function ControlBar({ hasValidationErrors = false }: ControlBarProps) {
11011101
* Get workflows in the exact order they appear in the sidebar
11021102
*/
11031103
const getSidebarOrderedWorkflows = () => {
1104-
// Get and sort regular workflows by name alphabetically for stable ordering
1104+
// Get and sort regular workflows by creation date (newest first) for stable ordering
11051105
const regularWorkflows = Object.values(workflows)
11061106
.filter((workflow) => workflow.workspaceId === workspaceId)
11071107
.filter((workflow) => workflow.marketplaceData?.status !== 'temp')
1108-
.sort((a, b) => a.name.localeCompare(b.name))
1108+
.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime())
11091109

11101110
// Group workflows by folder
11111111
const workflowsByFolder = regularWorkflows.reduce(

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/user-input/user-input.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,11 @@ const UserInput = forwardRef<UserInputRef, UserInputProps>(
393393
const workspaceFiltered = items.filter(
394394
(w: any) => w.workspaceId === workspaceId || !w.workspaceId
395395
)
396-
// Sort by name alphabetically for stable ordering, matching sidebar behavior
396+
// Sort by creation date (newest first) for stable ordering, matching sidebar behavior
397397
const sorted = [...workspaceFiltered].sort((a: any, b: any) => {
398-
return (a.name || 'Untitled Workflow').localeCompare(b.name || 'Untitled Workflow')
398+
const dateA = a.createdAt ? new Date(a.createdAt).getTime() : 0
399+
const dateB = b.createdAt ? new Date(b.createdAt).getTime() : 0
400+
return dateB - dateA // Newest first for stable ordering
399401
})
400402
setWorkflows(
401403
sorted.map((w: any) => ({

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/sidebar.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -691,13 +691,13 @@ export function Sidebar() {
691691
}
692692
})
693693

694-
// Sort by name alphabetically for stable ordering
695-
const sortByName = (a: WorkflowMetadata, b: WorkflowMetadata) => {
696-
return a.name.localeCompare(b.name)
694+
// Sort by creation date (newest first) for stable ordering
695+
const sortByCreatedAt = (a: WorkflowMetadata, b: WorkflowMetadata) => {
696+
return b.createdAt.getTime() - a.createdAt.getTime()
697697
}
698698

699-
regular.sort(sortByName)
700-
temp.sort(sortByName)
699+
regular.sort(sortByCreatedAt)
700+
temp.sort(sortByCreatedAt)
701701
}
702702

703703
return { regularWorkflows: regular, tempWorkflows: temp }

apps/sim/stores/workflows/registry/store.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ async function fetchWorkflowsFromDB(workspaceId?: string): Promise<void> {
109109
description: description || '',
110110
color: color || '#3972F6',
111111
lastModified: createdAt ? new Date(createdAt) : new Date(),
112+
createdAt: createdAt ? new Date(createdAt) : new Date(),
112113
marketplaceData: marketplaceData || null,
113114
workspaceId,
114115
folderId: folderId || null,
@@ -594,6 +595,7 @@ export const useWorkflowRegistry = create<WorkflowRegistry>()(
594595
id: serverWorkflowId,
595596
name: createdWorkflow.name,
596597
lastModified: new Date(),
598+
createdAt: new Date(),
597599
description: createdWorkflow.description,
598600
color: createdWorkflow.color,
599601
marketplaceData: options.marketplaceId
@@ -836,6 +838,7 @@ export const useWorkflowRegistry = create<WorkflowRegistry>()(
836838
id,
837839
name: metadata.name || generateCreativeWorkflowName(),
838840
lastModified: new Date(),
841+
createdAt: new Date(),
839842
description: metadata.description || 'Imported from marketplace',
840843
color: metadata.color || getNextWorkflowColor(),
841844
marketplaceData: { id: marketplaceId, status: 'temp' as const },
@@ -992,6 +995,7 @@ export const useWorkflowRegistry = create<WorkflowRegistry>()(
992995
id,
993996
name: `${sourceWorkflow.name} (Copy)`,
994997
lastModified: new Date(),
998+
createdAt: new Date(),
995999
description: sourceWorkflow.description,
9961000
color: getNextWorkflowColor(),
9971001
workspaceId, // Include the workspaceId in the new workflow
@@ -1322,6 +1326,7 @@ export const useWorkflowRegistry = create<WorkflowRegistry>()(
13221326
...workflow,
13231327
...metadata,
13241328
lastModified: new Date(),
1329+
createdAt: workflow.createdAt, // Preserve creation date
13251330
},
13261331
},
13271332
error: null,
@@ -1354,6 +1359,9 @@ export const useWorkflowRegistry = create<WorkflowRegistry>()(
13541359
color: updatedWorkflow.color,
13551360
folderId: updatedWorkflow.folderId,
13561361
lastModified: new Date(updatedWorkflow.updatedAt),
1362+
createdAt: updatedWorkflow.createdAt
1363+
? new Date(updatedWorkflow.createdAt)
1364+
: state.workflows[id].createdAt,
13571365
},
13581366
},
13591367
}))

apps/sim/stores/workflows/registry/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface WorkflowMetadata {
1414
id: string
1515
name: string
1616
lastModified: Date
17+
createdAt: Date
1718
description?: string
1819
color: string
1920
marketplaceData?: MarketplaceData | null

0 commit comments

Comments
 (0)