Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion app/common/src/services/Backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,7 @@ export interface Asset<Type extends AssetType = AssetType> {
readonly id: IdType[Type]
readonly title: string
readonly modifiedAt: dateTime.Rfc3339DateTime
readonly createdAt: dateTime.Rfc3339DateTime
/**
* This is defined as a generic {@link AssetId} in the backend, however it is more convenient
* (and currently safe) to assume it is always a {@link DirectoryId}.
Expand All @@ -996,6 +997,10 @@ export interface Asset<Type extends AssetType = AssetType> {
readonly virtualParentsPath: VirtualParentsPath
/** The display path. */
readonly ensoPath: EnsoPath
/** The user that created asset. */
readonly createdBy?: User
/** Optional size valid only for projects and files. */
readonly size?: number
}

/** A convenience alias for {@link Asset}<{@link AssetType.directory}>. */
Expand Down Expand Up @@ -1314,7 +1319,11 @@ export interface GetLogEventsRequestParams {
readonly pageSize?: number | null | undefined
}

export type AssetSortExpression = 'asset_id_discriminator_and_modified_at' | 'modified_at' | 'title'
export type AssetSortExpression =
| 'asset_id_discriminator_and_modified_at'
| 'modified_at'
| 'title'
| 'created_at'

export type AssetSortDirection = 'ascending' | 'descending'

Expand Down Expand Up @@ -1474,6 +1483,8 @@ export function compareAssets(
const modifiedAtDelta =
multiplier * (Number(new Date(a.modifiedAt)) - Number(new Date(b.modifiedAt)))
const titleDelta = multiplier * a.title.localeCompare(b.title, 'en-US', { numeric: true })
const createdAtDelta =
multiplier * (Number(new Date(a.createdAt)) - Number(new Date(b.createdAt)))

switch (sortExpression) {
case 'asset_id_discriminator_and_modified_at': {
Expand All @@ -1486,6 +1497,9 @@ export function compareAssets(
case 'modified_at': {
return modifiedAtDelta
}
case 'created_at': {
return createdAtDelta
}
case 'title': {
return titleDelta
}
Expand Down
3 changes: 3 additions & 0 deletions app/common/src/services/LocalBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export class LocalBackend extends backend.Backend {
id,
type: backend.AssetType.directory,
modifiedAt: entry.attributes.lastModifiedTime,
createdAt: entry.attributes.creationTime,
parentId,
title: getFileName(entry.path),
} satisfies backend.DirectoryAsset
Expand All @@ -184,6 +185,7 @@ export class LocalBackend extends backend.Backend {
id: newProjectId(entry.path),
title: entry.metadata.name,
modifiedAt: entry.metadata.lastOpened ?? entry.metadata.created,
createdAt: entry.metadata.created,
parentId,
projectState: {
type:
Expand All @@ -199,6 +201,7 @@ export class LocalBackend extends backend.Backend {
id: newFileId(entry.path),
title: getFileName(entry.path),
modifiedAt: entry.attributes.lastModifiedTime,
createdAt: entry.attributes.creationTime,
parentId,
extension: fileExtension(entry.path),
} satisfies backend.FileAsset
Expand Down
Loading
Loading