Resumen de los cambios del fix de navegación:
Some checks failed
/ Deploy to Cloudflare Pages (push) Has been cancelled
Some checks failed
/ Deploy to Cloudflare Pages (push) Has been cancelled
LibraryPage.tsx:778 — reemplazó useSearch({ from: '/' }) por useRouterState + URLSearchParams. Ahora funciona tanto desde / como desde /library.
WorkspacePage.tsx:206-209 — handleBack() navega a /library (con o sin ?org=uuid) en lugar de /.
workspace-back-button.test.ts — backTo actualizado a /library y /library?org=... en los 6 tests.
library-ui.test.tsx — mock de useSearch → useRouterState (devuelve { location: { search: '' } }).
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { useEffect, useState, useRef, useCallback } from 'react'
|
import { useEffect, useState, useRef, useCallback } from 'react'
|
||||||
import { useNavigate, useSearch } from '@tanstack/react-router'
|
import { useNavigate, useRouterState } from '@tanstack/react-router'
|
||||||
import {
|
import {
|
||||||
Upload, Search, Plus, Building2, FolderX, GitBranch,
|
Upload, Search, Plus, Building2, FolderX, GitBranch,
|
||||||
Clock, TrendingUp, BarChart2, FileX2, X, Settings,
|
Clock, TrendingUp, BarChart2, FileX2, X, Settings,
|
||||||
@@ -775,7 +775,8 @@ export function LibraryPage() {
|
|||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const { load, processes, groups, settings, isLoading } = useLibraryStore()
|
const { load, processes, groups, settings, isLoading } = useLibraryStore()
|
||||||
const { user, isProfileLoaded } = useAuth()
|
const { user, isProfileLoaded } = useAuth()
|
||||||
const { org: orgParam } = useSearch({ from: '/' }) as { org?: string }
|
const searchStr = useRouterState({ select: (s) => s.location.search })
|
||||||
|
const orgParam = new URLSearchParams(searchStr).get('org')
|
||||||
const [view, setView] = useState<'home' | 'group'>('home')
|
const [view, setView] = useState<'home' | 'group'>('home')
|
||||||
const [activeGroupId, setActiveGroupId] = useState<string | null>(null)
|
const [activeGroupId, setActiveGroupId] = useState<string | null>(null)
|
||||||
const [transitioning, setTransitioning] = useState(false)
|
const [transitioning, setTransitioning] = useState(false)
|
||||||
|
|||||||
@@ -203,9 +203,9 @@ export function WorkspacePage() {
|
|||||||
function handleBack() {
|
function handleBack() {
|
||||||
const orgId = currentProcess?.orgId
|
const orgId = currentProcess?.orgId
|
||||||
if (orgId && !isClientRole) {
|
if (orgId && !isClientRole) {
|
||||||
void navigate({ to: '/', search: { org: orgId } })
|
void navigate({ to: '/library', search: { org: orgId } as never })
|
||||||
} else {
|
} else {
|
||||||
void navigate({ to: '/' })
|
void navigate({ to: '/library' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -103,6 +103,12 @@ const indexRoute = createRoute({
|
|||||||
component: LibraryPage,
|
component: LibraryPage,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const libraryRoute = createRoute({
|
||||||
|
getParentRoute: () => rootRoute,
|
||||||
|
path: '/library',
|
||||||
|
component: LibraryPage,
|
||||||
|
})
|
||||||
|
|
||||||
const importRoute = createRoute({
|
const importRoute = createRoute({
|
||||||
getParentRoute: () => rootRoute,
|
getParentRoute: () => rootRoute,
|
||||||
path: '/import',
|
path: '/import',
|
||||||
@@ -170,6 +176,7 @@ const routeTree = rootRoute.addChildren([
|
|||||||
resetPasswordRoute,
|
resetPasswordRoute,
|
||||||
confirmInviteRoute,
|
confirmInviteRoute,
|
||||||
indexRoute,
|
indexRoute,
|
||||||
|
libraryRoute,
|
||||||
importRoute,
|
importRoute,
|
||||||
workspaceRoute,
|
workspaceRoute,
|
||||||
reportRoute,
|
reportRoute,
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ vi.mock('@/components/AppHeader', () => ({ AppHeader: () => null }))
|
|||||||
|
|
||||||
vi.mock('@tanstack/react-router', () => ({
|
vi.mock('@tanstack/react-router', () => ({
|
||||||
useNavigate: () => vi.fn(),
|
useNavigate: () => vi.fn(),
|
||||||
useSearch: () => ({}),
|
useRouterState: () => ({ location: { search: '' } }),
|
||||||
Link: ({ children }: { children: React.ReactNode }) => <>{children}</>,
|
Link: ({ children }: { children: React.ReactNode }) => <>{children}</>,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|||||||
@@ -17,44 +17,44 @@ function resolveBackButton(
|
|||||||
: orgId
|
: orgId
|
||||||
? (orgName ?? 'Volver')
|
? (orgName ?? 'Volver')
|
||||||
: 'Biblioteca'
|
: 'Biblioteca'
|
||||||
const backTo = orgId && !isClientRole ? `/?org=${orgId}` : '/'
|
const backTo = orgId && !isClientRole ? `/library?org=${orgId}` : '/library'
|
||||||
return { backLabel, backTo }
|
return { backLabel, backTo }
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('workspace back button — lógica de backLabel y backTo', () => {
|
describe('workspace back button — lógica de backLabel y backTo', () => {
|
||||||
it('1. admin con proceso de cliente → muestra nombre de org y navega a /?org=uuid', () => {
|
it('1. admin con proceso de cliente → muestra nombre de org y navega a /library?org=uuid', () => {
|
||||||
const { backLabel, backTo } = resolveBackButton('platform_admin', 'org-uuid-123', 'Solar Banco')
|
const { backLabel, backTo } = resolveBackButton('platform_admin', 'org-uuid-123', 'Solar Banco')
|
||||||
expect(backLabel).toBe('Solar Banco')
|
expect(backLabel).toBe('Solar Banco')
|
||||||
expect(backTo).toBe('/?org=org-uuid-123')
|
expect(backTo).toBe('/library?org=org-uuid-123')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('2. admin con proceso de cliente mientras orgName carga → muestra "Volver" como fallback', () => {
|
it('2. admin con proceso de cliente mientras orgName carga → muestra "Volver" como fallback', () => {
|
||||||
const { backLabel, backTo } = resolveBackButton('platform_admin', 'org-uuid-123', null)
|
const { backLabel, backTo } = resolveBackButton('platform_admin', 'org-uuid-123', null)
|
||||||
expect(backLabel).toBe('Volver')
|
expect(backLabel).toBe('Volver')
|
||||||
expect(backTo).toBe('/?org=org-uuid-123')
|
expect(backTo).toBe('/library?org=org-uuid-123')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('3. admin sin org asignada → muestra "Biblioteca" y navega a /', () => {
|
it('3. admin sin org asignada → muestra "Biblioteca" y navega a /library', () => {
|
||||||
const { backLabel, backTo } = resolveBackButton('platform_admin', null, null)
|
const { backLabel, backTo } = resolveBackButton('platform_admin', null, null)
|
||||||
expect(backLabel).toBe('Biblioteca')
|
expect(backLabel).toBe('Biblioteca')
|
||||||
expect(backTo).toBe('/')
|
expect(backTo).toBe('/library')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('4. member sin org → igual que platform_admin', () => {
|
it('4. member sin org → igual que platform_admin', () => {
|
||||||
const { backLabel, backTo } = resolveBackButton('member', null, null)
|
const { backLabel, backTo } = resolveBackButton('member', null, null)
|
||||||
expect(backLabel).toBe('Biblioteca')
|
expect(backLabel).toBe('Biblioteca')
|
||||||
expect(backTo).toBe('/')
|
expect(backTo).toBe('/library')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('5. client_editor con proceso de cliente → muestra "Procesos" y navega a /', () => {
|
it('5. client_editor con proceso de cliente → muestra "Procesos" y navega a /library', () => {
|
||||||
const { backLabel, backTo } = resolveBackButton('client_editor', 'org-uuid-123', 'Solar Banco')
|
const { backLabel, backTo } = resolveBackButton('client_editor', 'org-uuid-123', 'Solar Banco')
|
||||||
expect(backLabel).toBe('Procesos')
|
expect(backLabel).toBe('Procesos')
|
||||||
expect(backTo).toBe('/')
|
expect(backTo).toBe('/library')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('6. client_viewer con proceso de cliente → muestra "Procesos" y navega a /', () => {
|
it('6. client_viewer con proceso de cliente → muestra "Procesos" y navega a /library', () => {
|
||||||
const { backLabel, backTo } = resolveBackButton('client_viewer', 'org-uuid-123', 'Solar Banco')
|
const { backLabel, backTo } = resolveBackButton('client_viewer', 'org-uuid-123', 'Solar Banco')
|
||||||
expect(backLabel).toBe('Procesos')
|
expect(backLabel).toBe('Procesos')
|
||||||
expect(backTo).toBe('/')
|
expect(backTo).toBe('/library')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user