fix(workspace): expose last opened in contract (#38323)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
yyh 2026-07-02 19:14:35 +08:00 committed by GitHub
parent 3f92e38616
commit ff56fb7e23
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 10 additions and 9 deletions

View File

@ -102,6 +102,7 @@ class TenantListItemResponse(ResponseModel):
plan: str | None = None plan: str | None = None
status: str | None = None status: str | None = None
created_at: int | None = None created_at: int | None = None
last_opened_at: int | None = None
current: bool current: bool
@field_validator("plan", "status", mode="before") @field_validator("plan", "status", mode="before")
@ -113,9 +114,9 @@ class TenantListItemResponse(ResponseModel):
return value return value
return str(getattr(value, "value", value)) return str(getattr(value, "value", value))
@field_validator("created_at", mode="before") @field_validator("created_at", "last_opened_at", mode="before")
@classmethod @classmethod
def _normalize_created_at(cls, value: datetime | int | None): def _normalize_timestamp(cls, value: datetime | int | None):
return to_timestamp(value) return to_timestamp(value)

View File

@ -21199,6 +21199,7 @@ Tag type
| created_at | integer | | No | | created_at | integer | | No |
| current | boolean | | Yes | | current | boolean | | Yes |
| id | string | | Yes | | id | string | | Yes |
| last_opened_at | integer | | No |
| name | string | | No | | name | string | | No |
| plan | string | | No | | plan | string | | No |
| status | string | | No | | status | string | | No |

View File

@ -939,6 +939,7 @@ export type TenantListItemResponse = {
created_at?: number | null created_at?: number | null
current: boolean current: boolean
id: string id: string
last_opened_at?: number | null
name?: string | null name?: string | null
plan?: string | null plan?: string | null
status?: string | null status?: string | null

View File

@ -684,6 +684,7 @@ export const zTenantListItemResponse = z.object({
created_at: z.int().nullish(), created_at: z.int().nullish(),
current: z.boolean(), current: z.boolean(),
id: z.string(), id: z.string(),
last_opened_at: z.int().nullish(),
name: z.string().nullish(), name: z.string().nullish(),
plan: z.string().nullish(), plan: z.string().nullish(),
status: z.string().nullish(), status: z.string().nullish(),

View File

@ -21,13 +21,10 @@ const workspaceSwitchActionIconClassName = 'size-3.5 shrink-0'
const workspaceSwitchListClassName = 'max-h-[240px] overflow-y-auto overscroll-contain scroll-py-1' const workspaceSwitchListClassName = 'max-h-[240px] overflow-y-auto overscroll-contain scroll-py-1'
const workspaceSwitchI18nKey = (key: string) => key as 'mainNav.workspace.settings' const workspaceSwitchI18nKey = (key: string) => key as 'mainNav.workspace.settings'
type WorkspaceSort = 'lastOpened' | 'createdAt' type WorkspaceSort = 'lastOpened' | 'createdAt'
type WorkspaceListItem = TenantListItemResponse & {
last_opened_at?: number | null
}
const getWorkspaceName = (workspace: WorkspaceListItem) => workspace.name || workspace.id const getWorkspaceName = (workspace: TenantListItemResponse) => workspace.name || workspace.id
const getWorkspaceCreatedAt = (workspace: WorkspaceListItem) => workspace.created_at ?? 0 const getWorkspaceCreatedAt = (workspace: TenantListItemResponse) => workspace.created_at ?? 0
const getWorkspaceLastOpenedAt = (workspace: WorkspaceListItem) => workspace.last_opened_at ?? 0 const getWorkspaceLastOpenedAt = (workspace: TenantListItemResponse) => workspace.last_opened_at ?? 0
function WorkspaceSwitchControls({ function WorkspaceSwitchControls({
searchText, searchText,
@ -123,7 +120,7 @@ function WorkspaceSwitchControls({
} }
type WorkspaceSwitcherProps = { type WorkspaceSwitcherProps = {
workspaces: WorkspaceListItem[] workspaces: TenantListItemResponse[]
onSwitchWorkspace: (workspaceId: string) => void onSwitchWorkspace: (workspaceId: string) => void
} }