mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
fix(web): share picker titles match sidebar (name before summary) (#1219)
The /share route used a local getSessionTitle that preferred summary.text over metadata.name, so Android share-target rows disagreed with the session sidebar. Reuse @/lib/sessionTitle and lock the precedence with a unit test. Closes tiann/hapi#1218 once upstream PR lands after dogfood. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,38 @@
|
|||||||
|
import { describe, expect, it } from 'vitest'
|
||||||
|
import { getSessionTitle } from './sessionTitle'
|
||||||
|
|
||||||
|
describe('getSessionTitle', () => {
|
||||||
|
it('prefers metadata.name over summary.text (sidebar / share picker parity)', () => {
|
||||||
|
expect(getSessionTitle({
|
||||||
|
id: 'abcdef0123456789',
|
||||||
|
metadata: {
|
||||||
|
name: 'hub runner version governance',
|
||||||
|
summary: { text: 'HAPI Skill Lookup' },
|
||||||
|
path: '/tmp/share-title-parity',
|
||||||
|
},
|
||||||
|
})).toBe('hub runner version governance')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('falls back to summary when name is absent', () => {
|
||||||
|
expect(getSessionTitle({
|
||||||
|
id: 'abcdef0123456789',
|
||||||
|
metadata: {
|
||||||
|
summary: { text: 'HAPI Skill Lookup' },
|
||||||
|
path: '/tmp/share-title-parity',
|
||||||
|
},
|
||||||
|
})).toBe('HAPI Skill Lookup')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('falls back to the last path segment when name and summary are absent', () => {
|
||||||
|
expect(getSessionTitle({
|
||||||
|
id: 'abcdef0123456789',
|
||||||
|
metadata: {
|
||||||
|
path: '/tmp/share-title-parity',
|
||||||
|
},
|
||||||
|
})).toBe('share-title-parity')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('falls back to a short id when metadata is empty', () => {
|
||||||
|
expect(getSessionTitle({ id: 'abcdef0123456789' })).toBe('abcdef01')
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
type ShareTransferPayload,
|
type ShareTransferPayload,
|
||||||
} from '@/lib/shareTransfer'
|
} from '@/lib/shareTransfer'
|
||||||
import { setSharePendingTransfer } from '@/lib/sharePendingState'
|
import { setSharePendingTransfer } from '@/lib/sharePendingState'
|
||||||
|
import { getSessionTitle } from '@/lib/sessionTitle'
|
||||||
import type { SessionSummary } from '@/types/api'
|
import type { SessionSummary } from '@/types/api'
|
||||||
|
|
||||||
type LoadState =
|
type LoadState =
|
||||||
@@ -29,13 +30,6 @@ function formatBytes(n: number): string {
|
|||||||
return `${(n / (1024 * 1024)).toFixed(1)} MB`
|
return `${(n / (1024 * 1024)).toFixed(1)} MB`
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSessionTitle(session: SessionSummary): string {
|
|
||||||
return session.metadata?.summary?.text
|
|
||||||
?? session.metadata?.name
|
|
||||||
?? session.metadata?.path
|
|
||||||
?? session.id.slice(0, 8)
|
|
||||||
}
|
|
||||||
|
|
||||||
function SharePreview(props: { payload: ShareTransferPayload }) {
|
function SharePreview(props: { payload: ShareTransferPayload }) {
|
||||||
const { payload } = props
|
const { payload } = props
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
|||||||
Reference in New Issue
Block a user