Skip to content

Commit 0ae19da

Browse files
waleedlatif1claude
andauthored
feat(files): default sort by updated and add updated sort option (#4279)
* feat(files): default sort by updated and add updated sort option * feat(files): show Last Updated column Matches the visible-column pattern already used on Knowledge and Tables so users can see the value they're sorting by. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 3b11c81 commit 0ae19da

11 files changed

Lines changed: 15254 additions & 6 deletions

File tree

apps/sim/app/workspace/[workspaceId]/files/files.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ const COLUMNS: ResourceColumn[] = [
9797
{ id: 'type', header: 'Type' },
9898
{ id: 'created', header: 'Created' },
9999
{ id: 'owner', header: 'Owner' },
100+
{ id: 'updated', header: 'Last Updated' },
100101
]
101102

102103
const MIME_TYPE_LABELS: Record<string, string> = {
@@ -249,7 +250,7 @@ export function Files() {
249250
result = result.filter((f) => uploadedByFilter.includes(f.uploadedBy))
250251
}
251252

252-
const col = activeSort?.column ?? 'created'
253+
const col = activeSort?.column ?? 'updated'
253254
const dir = activeSort?.direction ?? 'desc'
254255
return [...result].sort((a, b) => {
255256
let cmp = 0
@@ -266,6 +267,9 @@ export function Files() {
266267
case 'created':
267268
cmp = new Date(a.uploadedAt).getTime() - new Date(b.uploadedAt).getTime()
268269
break
270+
case 'updated':
271+
cmp = new Date(a.updatedAt).getTime() - new Date(b.updatedAt).getTime()
272+
break
269273
case 'owner':
270274
cmp = (members?.find((m) => m.userId === a.uploadedBy)?.name ?? '').localeCompare(
271275
members?.find((m) => m.userId === b.uploadedBy)?.name ?? ''
@@ -310,6 +314,7 @@ export function Files() {
310314
},
311315
created: timeCell(file.uploadedAt),
312316
owner: ownerCell(file.uploadedBy, members),
317+
updated: timeCell(file.updatedAt),
313318
},
314319
}
315320
nextCache.set(file.id, { row, file, members })
@@ -875,6 +880,7 @@ export function Files() {
875880
{ id: 'size', label: 'Size' },
876881
{ id: 'type', label: 'Type' },
877882
{ id: 'created', label: 'Created' },
883+
{ id: 'updated', label: 'Last Updated' },
878884
{ id: 'owner', label: 'Owner' },
879885
],
880886
active: activeSort,

apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/resource-content.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export const ResourceContent = memo(function ResourceContent({
124124
type,
125125
uploadedBy: '',
126126
uploadedAt: STREAMING_EPOCH,
127+
updatedAt: STREAMING_EPOCH,
127128
}
128129
}, [workspaceId, streamFileName])
129130

apps/sim/app/workspace/[workspaceId]/knowledge/knowledge.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export function Knowledge() {
216216
result = result.filter((kb) => ownerFilter.includes(kb.userId))
217217
}
218218

219-
const col = activeSort?.column ?? 'created'
219+
const col = activeSort?.column ?? 'updated'
220220
const dir = activeSort?.direction ?? 'desc'
221221
return [...result].sort((a, b) => {
222222
let cmp = 0

apps/sim/app/workspace/[workspaceId]/tables/tables.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export function Tables() {
123123
if (ownerFilter.length > 0) {
124124
result = result.filter((t) => ownerFilter.includes(t.createdBy))
125125
}
126-
const col = activeSort?.column ?? 'created'
126+
const col = activeSort?.column ?? 'updated'
127127
const dir = activeSort?.direction ?? 'desc'
128128
return [...result].sort((a, b) => {
129129
let cmp = 0

apps/sim/lib/copilot/tools/handlers/materialize-file.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function toFileRecord(row: typeof workspaceFiles.$inferSelect) {
2929
uploadedBy: row.userId,
3030
deletedAt: row.deletedAt,
3131
uploadedAt: row.uploadedAt,
32+
updatedAt: row.updatedAt,
3233
storageContext: 'mothership' as const,
3334
}
3435
}

apps/sim/lib/copilot/tools/handlers/upload-file-reader.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function toWorkspaceFileRecord(row: typeof workspaceFiles.$inferSelect): Workspa
2323
uploadedBy: row.userId,
2424
deletedAt: row.deletedAt,
2525
uploadedAt: row.uploadedAt,
26+
updatedAt: row.updatedAt,
2627
storageContext: 'mothership',
2728
}
2829
}

apps/sim/lib/uploads/contexts/workspace/workspace-file-manager.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export interface WorkspaceFileRecord {
4545
uploadedBy: string
4646
deletedAt?: Date | null
4747
uploadedAt: Date
48+
updatedAt: Date
4849
/** Pass-through to `downloadFile` when not default `workspace` (e.g. chat mothership uploads). */
4950
storageContext?: 'workspace' | 'mothership'
5051
}
@@ -375,6 +376,7 @@ export async function getWorkspaceFileByName(
375376
uploadedBy: file.userId,
376377
deletedAt: file.deletedAt,
377378
uploadedAt: file.uploadedAt,
379+
updatedAt: file.updatedAt,
378380
}
379381
}
380382

@@ -423,6 +425,7 @@ export async function listWorkspaceFiles(
423425
uploadedBy: file.userId,
424426
deletedAt: file.deletedAt,
425427
uploadedAt: file.uploadedAt,
428+
updatedAt: file.updatedAt,
426429
}))
427430
} catch (error) {
428431
logger.error(`Failed to list workspace files for ${workspaceId}:`, error)
@@ -560,6 +563,7 @@ export async function getWorkspaceFile(
560563
uploadedBy: file.userId,
561564
deletedAt: file.deletedAt,
562565
uploadedAt: file.uploadedAt,
566+
updatedAt: file.updatedAt,
563567
}
564568
} catch (error) {
565569
logger.error(`Failed to get workspace file ${fileId}:`, error)
@@ -638,7 +642,7 @@ export async function updateWorkspaceFileContent(
638642

639643
await db
640644
.update(workspaceFiles)
641-
.set({ size: content.length, contentType: nextContentType })
645+
.set({ size: content.length, contentType: nextContentType, updatedAt: new Date() })
642646
.where(
643647
and(
644648
eq(workspaceFiles.id, fileId),
@@ -707,7 +711,7 @@ export async function renameWorkspaceFile(
707711
try {
708712
updated = await db
709713
.update(workspaceFiles)
710-
.set({ originalName: trimmedName })
714+
.set({ originalName: trimmedName, updatedAt: new Date() })
711715
.where(
712716
and(
713717
eq(workspaceFiles.id, fileId),
@@ -807,7 +811,7 @@ export async function restoreWorkspaceFile(workspaceId: string, fileId: string):
807811

808812
await db
809813
.update(workspaceFiles)
810-
.set({ deletedAt: null, originalName: newName })
814+
.set({ deletedAt: null, originalName: newName, updatedAt: new Date() })
811815
.where(
812816
and(
813817
eq(workspaceFiles.id, fileId),
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE "workspace_files" ADD COLUMN "updated_at" timestamp DEFAULT now() NOT NULL;

0 commit comments

Comments
 (0)