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',