chore: skill in query to file

This commit is contained in:
Joel
2026-03-26 16:17:50 +08:00
parent a1a527902b
commit 9c8a5ff527
5 changed files with 32 additions and 5 deletions

View File

@ -0,0 +1,17 @@
import { ViewType } from '@/app/components/workflow/types'
import { parseAsViewType } from '../search-params'
describe('workflow-app search params', () => {
it('should parse the new file view value and keep serializing it as file', () => {
expect(parseAsViewType.parse('file')).toBe(ViewType.file)
expect(parseAsViewType.serialize(ViewType.file)).toBe('file')
})
it('should keep supporting legacy skill view links by mapping them to file', () => {
expect(parseAsViewType.parse('skill')).toBe(ViewType.file)
})
it('should reject unsupported view values', () => {
expect(parseAsViewType.parse('invalid-view')).toBeNull()
})
})

View File

@ -1,7 +1,17 @@
import { parseAsStringEnum } from 'nuqs'
import { createParser } from 'nuqs'
import { ViewType } from '@/app/components/workflow/types'
export const parseAsViewType = parseAsStringEnum<ViewType>(Object.values(ViewType))
const VIEW_TYPES = Object.values(ViewType) as ViewType[]
export const parseAsViewType = createParser<ViewType>({
parse: (value) => {
if (value === 'skill')
return ViewType.file
return VIEW_TYPES.includes(value as ViewType) ? value as ViewType : null
},
serialize: value => value,
})
.withDefault(ViewType.graph)
.withOptions({
history: 'push',

View File

@ -82,7 +82,7 @@ const FilePreviewPanel = ({ resourceId, currentNode, className, style, onClose }
if (!canOpenInEditor)
return
const nextUrl = new URL(window.location.href)
nextUrl.searchParams.set('view', 'skill')
nextUrl.searchParams.set('view', 'file')
nextUrl.searchParams.set('fileId', resourceId)
window.open(nextUrl.toString(), '_blank', 'noopener,noreferrer')
}, [canOpenInEditor, resourceId])

View File

@ -606,6 +606,6 @@ export type Block = {
export const ViewType = {
graph: 'graph',
skill: 'skill',
file: 'file',
} as const
export type ViewType = typeof ViewType[keyof typeof ViewType]

View File

@ -24,7 +24,7 @@ const ViewPicker: FC<ViewPickerProps> = ({
const { t } = useTranslation()
const options = useMemo(() => ([
{ value: ViewType.graph, text: t('viewPicker.graph', { ns: 'workflow' }), disabled: disabled && value !== ViewType.graph },
{ value: ViewType.skill, text: t('viewPicker.file', { ns: 'workflow' }), disabled: disabled && value !== ViewType.skill },
{ value: ViewType.file, text: t('viewPicker.file', { ns: 'workflow' }), disabled: disabled && value !== ViewType.file },
]), [t, disabled, value])
const handleChange = useCallback((nextValue: string | number | symbol) => {