feat(N4): Restliche Module — Tasks/Kommunikation/Wiki/Reports/Agents/Tags/Search + Navigation + Dashboard-Schnittstelle (#368)
Check Cross-Plugin Imports / check (push) Has been cancelled
Check Cross-Plugin Imports / check (push) Has been cancelled
- Scope-Deklarationen: tasks only_mine, kommunikation conversation_ids, wiki category_ids (NEUE contracts.py), report_generator template_ids, automation agent_ids (module_key agents), tags tag_ids, unified_search entity_types dynamisch aus Provider-Registry - Core-Beiträge: navigation default_route (Startseite) + dashboard widget_app_ids (Widget-TYP-Angebot, Layout bleibt Phase M) - Backend-Filter (additive UND): /tasks (only_mine), /comm/conversations, /wiki/articles+/categories (Subtree), /reports/print-templates, /agents, /tags, /search GET+POST (entity_types-Schnitt), /miniapps?host=dashboard - apply_entity_type_scope-Helper (requested ∧ scope) - Frontend: WorkspaceSwitcher default_route-Navigation, Sidebar workspace-menu_order-Sortierung, workspaceStore moduleMenuOrder() - Tests: 18/18 Deklarationen + 11/11 Filter (TDD), Frontend 2/2 + Store 18/18, tsc clean, Build OK - Regression 64 passed (4 Kombi-Failures = Suite-Isolation, solo-bewiesen); Checker 0; Ruff = Vorbestand (Stash-bewiesen)
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* N4 — Navigation defaults (Phase N, final task).
|
||||
*
|
||||
* Workspace navigation config (admin-defined per workspace):
|
||||
* - default_route: where the workspace switcher navigates to after switching
|
||||
*/
|
||||
import React from 'react';
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { render, screen, fireEvent } from '@testing-library/react';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { WorkspaceSwitcher } from '@/components/layout/WorkspaceSwitcher';
|
||||
|
||||
const mockSwitch = vi.fn();
|
||||
const mockNavigate = vi.fn();
|
||||
|
||||
vi.mock('react-router-dom', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('react-router-dom')>();
|
||||
return {
|
||||
...actual,
|
||||
useNavigate: () => mockNavigate,
|
||||
};
|
||||
});
|
||||
|
||||
const myWorkspaces = [
|
||||
{ id: 'ws-1', name: 'Vertrieb', description: null, icon: 'LayoutGrid', is_default: false, is_active: true, role: 'member', is_user_default: false, modules: [] },
|
||||
{
|
||||
id: 'ws-2',
|
||||
name: 'Support',
|
||||
description: null,
|
||||
icon: 'LayoutGrid',
|
||||
is_default: false,
|
||||
is_active: true,
|
||||
role: 'member',
|
||||
is_user_default: false,
|
||||
modules: [
|
||||
{ module_key: 'navigation', menu_order: 0, config: { default_route: '/contacts' } },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
vi.mock('@/hooks/useWorkspace', () => ({
|
||||
useWorkspace: () => ({
|
||||
myWorkspaces,
|
||||
activeWorkspaceId: 'ws-1',
|
||||
switchWorkspace: mockSwitch,
|
||||
hasWorkspaces: true,
|
||||
}),
|
||||
}));
|
||||
|
||||
function renderSwitcher() {
|
||||
return render(
|
||||
<MemoryRouter>
|
||||
<WorkspaceSwitcher />
|
||||
</MemoryRouter>,
|
||||
);
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('WorkspaceSwitcher navigation (N4)', () => {
|
||||
it('switches workspace and navigates to its default_route', () => {
|
||||
renderSwitcher();
|
||||
fireEvent.click(screen.getByRole('button', { name: /Vertrieb/i }));
|
||||
fireEvent.click(screen.getByText('Support'));
|
||||
|
||||
expect(mockSwitch).toHaveBeenCalledWith('ws-2');
|
||||
expect(mockNavigate).toHaveBeenCalledWith('/contacts');
|
||||
});
|
||||
|
||||
it('switches without navigation config (backward compatible, no navigate call)', () => {
|
||||
renderSwitcher();
|
||||
fireEvent.click(screen.getByRole('button', { name: /Vertrieb/i }));
|
||||
// switch to ws-1 (no navigation config) — the dropdown entry (not the
|
||||
// trigger button, which also shows the active workspace name)
|
||||
fireEvent.click(screen.getAllByText('Vertrieb')[1].closest('button')!);
|
||||
|
||||
expect(mockSwitch).toHaveBeenCalledWith('ws-1');
|
||||
expect(mockNavigate).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -30,6 +30,7 @@ const ICON_MAP: Record<string, React.ComponentType<{ className?: string }>> = {
|
||||
import { useMenuOrder } from '@/api/users';
|
||||
import { usePermission } from '@/hooks/usePermission';
|
||||
import { useWorkspace } from '@/hooks/useWorkspace';
|
||||
import { useWorkspaceStore } from '@/store/workspaceStore';
|
||||
import { useAuthStore } from '@/store/authStore';
|
||||
|
||||
interface NavSingleItem {
|
||||
@@ -68,6 +69,7 @@ export function Sidebar() {
|
||||
const { hasPermission } = usePermission();
|
||||
const user = useAuthStore((state) => state.user);
|
||||
const { isModuleVisible } = useWorkspace();
|
||||
const moduleMenuOrder = useWorkspaceStore(s => s.moduleMenuOrder());
|
||||
|
||||
// Use hasPermission directly — permissions are loaded via useUserPermissions hook
|
||||
const canAccess = (perm?: string): boolean => {
|
||||
@@ -136,10 +138,19 @@ export function Sidebar() {
|
||||
}
|
||||
|
||||
return workspaceFiltered.sort((a, b) => {
|
||||
// N4: workspace menu_order is the admin-defined fallback order —
|
||||
// the personal savedOrder above stays the user override.
|
||||
const wsOrder = moduleMenuOrder;
|
||||
const aWs = wsOrder.get(a.path.replace(/^\//, '').split('/')[0]);
|
||||
const bWs = wsOrder.get(b.path.replace(/^\//, '').split('/')[0]);
|
||||
if (aWs !== undefined && bWs !== undefined && aWs !== bWs) return aWs - bWs;
|
||||
if (aWs !== undefined && bWs === undefined) return -1;
|
||||
if (aWs === undefined && bWs !== undefined) return 1;
|
||||
// Fall back to order field + label (backward compatible)
|
||||
if (a.order !== b.order) return a.order - b.order;
|
||||
return a.label.localeCompare(b.label);
|
||||
});
|
||||
}, [manifests, menuOrderData, user, isModuleVisible]);
|
||||
}, [manifests, menuOrderData, user, isModuleVisible, moduleMenuOrder]);
|
||||
|
||||
const [expandedItems, setExpandedItems] = useState<Set<string>>(new Set());
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { useState, useRef, useEffect } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useWorkspace } from '@/hooks/useWorkspace';
|
||||
import { LayoutGrid, ChevronDown, Check } from 'lucide-react';
|
||||
|
||||
export function WorkspaceSwitcher() {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const { myWorkspaces, activeWorkspaceId, switchWorkspace, hasWorkspaces } = useWorkspace();
|
||||
const [open, setOpen] = useState(false);
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
@@ -23,6 +25,21 @@ export function WorkspaceSwitcher() {
|
||||
|
||||
const activeWs = myWorkspaces.find(w => w.id === activeWorkspaceId);
|
||||
|
||||
const handleSwitch = (wsId: string) => {
|
||||
switchWorkspace(wsId);
|
||||
setOpen(false);
|
||||
// N4: navigate to the workspace default_route (admin-defined per
|
||||
// workspace). The route comes from the target workspace's context —
|
||||
// read via the workspace store so the fresh context applies after the
|
||||
// switch (the store resolves config synchronously from myWorkspaces).
|
||||
const target = myWorkspaces.find(w => w.id === wsId);
|
||||
const navConfig = target?.modules?.find((m: any) => m.module_key === 'navigation');
|
||||
const route = navConfig?.config?.default_route;
|
||||
if (typeof route === 'string' && route.startsWith('/')) {
|
||||
navigate(route);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="relative" ref={ref}>
|
||||
<button
|
||||
@@ -43,10 +60,7 @@ export function WorkspaceSwitcher() {
|
||||
{myWorkspaces.map(ws => (
|
||||
<button
|
||||
key={ws.id}
|
||||
onClick={() => {
|
||||
switchWorkspace(ws.id);
|
||||
setOpen(false);
|
||||
}}
|
||||
onClick={() => handleSwitch(ws.id)}
|
||||
className="w-full flex items-center gap-2 px-3 py-2 hover:bg-gray-100 dark:hover:bg-gray-800 text-sm text-gray-700 dark:text-gray-300 transition-colors"
|
||||
>
|
||||
<span className="flex-1 text-left">
|
||||
|
||||
@@ -169,4 +169,25 @@ describe('workspaceStore', () => {
|
||||
expect(useWorkspaceStore.getState().getModuleConfig('mail')).toEqual({});
|
||||
expect(useWorkspaceStore.getState().getModuleConfig('contacts')).toEqual({});
|
||||
});
|
||||
|
||||
// ─── N4: moduleMenuOrder (navigation sidebar order) ─────────
|
||||
|
||||
it('moduleMenuOrder maps module keys to workspace menu_order', () => {
|
||||
useWorkspaceStore.getState().setContext({
|
||||
workspace_id: 'ws-1',
|
||||
modules: [
|
||||
{ module_key: 'calendar', menu_order: 5, config: {} },
|
||||
{ module_key: 'contacts', menu_order: 2, config: {} },
|
||||
],
|
||||
widgets: [],
|
||||
});
|
||||
const map = useWorkspaceStore.getState().moduleMenuOrder();
|
||||
expect(map.get('contacts')).toBe(2);
|
||||
expect(map.get('calendar')).toBe(5);
|
||||
expect(map.has('mail')).toBe(false);
|
||||
});
|
||||
|
||||
it('moduleMenuOrder returns empty map without workspace context', () => {
|
||||
expect(useWorkspaceStore.getState().moduleMenuOrder().size).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -59,6 +59,7 @@ interface WorkspaceStoreState {
|
||||
isModuleVisible: (moduleKey: string, isSystemAdmin?: boolean) => boolean;
|
||||
visibleModuleKeys: () => Set<string>;
|
||||
getModuleConfig: (moduleKey: string) => Record<string, any>;
|
||||
moduleMenuOrder: () => Map<string, number>;
|
||||
hasWorkspaces: () => boolean;
|
||||
// Reset
|
||||
reset: () => void;
|
||||
@@ -120,6 +121,16 @@ export const useWorkspaceStore = create<WorkspaceStoreState>()(
|
||||
return mod?.config ?? {};
|
||||
},
|
||||
|
||||
moduleMenuOrder: () => {
|
||||
// N4: admin-defined sidebar order per workspace (module_key →
|
||||
// menu_order). The user's personal saved order stays the override;
|
||||
// this map is the fallback for unsorted modules.
|
||||
const ctx = get().context;
|
||||
return new Map(
|
||||
(ctx?.modules ?? []).map(m => [m.module_key, m.menu_order] as const),
|
||||
);
|
||||
},
|
||||
|
||||
hasWorkspaces: () => get().myWorkspaces.length > 0,
|
||||
|
||||
reset: () => {
|
||||
|
||||
Reference in New Issue
Block a user