mirror of
https://github.com/langgenius/dify.git
synced 2026-05-09 21:28:25 +08:00
fix: use literal parser for view param
This commit is contained in:
parent
9c8a5ff527
commit
e03c2be0ad
@ -2,16 +2,16 @@ 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', () => {
|
||||
it('should parse valid view values and serialize them unchanged', () => {
|
||||
expect(parseAsViewType.parse('graph')).toBe(ViewType.graph)
|
||||
expect(parseAsViewType.serialize(ViewType.graph)).toBe('graph')
|
||||
|
||||
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('skill')).toBeNull()
|
||||
expect(parseAsViewType.parse('invalid-view')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
@ -1,17 +1,9 @@
|
||||
import { createParser } from 'nuqs'
|
||||
import { parseAsStringLiteral } from 'nuqs'
|
||||
import { ViewType } from '@/app/components/workflow/types'
|
||||
|
||||
const VIEW_TYPES = Object.values(ViewType) as ViewType[]
|
||||
const VIEW_TYPES = Object.values(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,
|
||||
})
|
||||
export const parseAsViewType = parseAsStringLiteral(VIEW_TYPES)
|
||||
.withDefault(ViewType.graph)
|
||||
.withOptions({
|
||||
history: 'push',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user