feat(sdk): Multi-Projekt-Architektur — mehrere Projekte pro Tenant
Some checks failed
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-ai-compliance (push) Failing after 33s
CI / test-python-backend-compliance (push) Successful in 34s
CI / test-python-document-crawler (push) Successful in 23s
CI / test-python-dsms-gateway (push) Successful in 19s
Some checks failed
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-ai-compliance (push) Failing after 33s
CI / test-python-backend-compliance (push) Successful in 34s
CI / test-python-document-crawler (push) Successful in 23s
CI / test-python-dsms-gateway (push) Successful in 19s
Jeder Tenant kann jetzt mehrere Compliance-Projekte anlegen (z.B. verschiedene Produkte, Tochterunternehmen). CompanyProfile ist pro Projekt kopierbar und danach unabhaengig editierbar. Multi-Tab-Support via separater BroadcastChannel und localStorage Keys pro Projekt. - Migration 039: compliance_projects Tabelle, sdk_states.project_id - Backend: FastAPI CRUD-Routes fuer Projekte mit Tenant-Isolation - Frontend: ProjectSelector UI, SDKProvider mit projectId, URL ?project= - State API: UPSERT auf (tenant_id, project_id) mit Abwaertskompatibilitaet - Tests: pytest fuer Model-Validierung, Row-Konvertierung, Tenant-Isolation - Docs: MKDocs Seite, CLAUDE.md, Backend README Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
120
admin-compliance/app/api/sdk/v1/projects/[projectId]/route.ts
Normal file
120
admin-compliance/app/api/sdk/v1/projects/[projectId]/route.ts
Normal file
@@ -0,0 +1,120 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
|
||||
const BACKEND_URL = process.env.BACKEND_URL || 'http://backend-compliance:8002'
|
||||
|
||||
/**
|
||||
* Proxy: GET /api/sdk/v1/projects/{projectId} → Backend
|
||||
*/
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ projectId: string }> }
|
||||
) {
|
||||
try {
|
||||
const { projectId } = await params
|
||||
const tenantId = request.headers.get('X-Tenant-ID') ||
|
||||
new URL(request.url).searchParams.get('tenant_id') || ''
|
||||
|
||||
const response = await fetch(
|
||||
`${BACKEND_URL}/api/v1/projects/${projectId}?tenant_id=${encodeURIComponent(tenantId)}`,
|
||||
{
|
||||
headers: { 'X-Tenant-ID': tenantId },
|
||||
}
|
||||
)
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text()
|
||||
return NextResponse.json(
|
||||
{ error: 'Backend error', details: errorText },
|
||||
{ status: response.status }
|
||||
)
|
||||
}
|
||||
|
||||
return NextResponse.json(await response.json())
|
||||
} catch (error) {
|
||||
console.error('Failed to get project:', error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to connect to backend' },
|
||||
{ status: 503 }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxy: PATCH /api/sdk/v1/projects/{projectId} → Backend
|
||||
*/
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ projectId: string }> }
|
||||
) {
|
||||
try {
|
||||
const { projectId } = await params
|
||||
const body = await request.json()
|
||||
const tenantId = body.tenant_id || request.headers.get('X-Tenant-ID') || ''
|
||||
|
||||
const response = await fetch(
|
||||
`${BACKEND_URL}/api/v1/projects/${projectId}?tenant_id=${encodeURIComponent(tenantId)}`,
|
||||
{
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Tenant-ID': tenantId,
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
}
|
||||
)
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text()
|
||||
return NextResponse.json(
|
||||
{ error: 'Backend error', details: errorText },
|
||||
{ status: response.status }
|
||||
)
|
||||
}
|
||||
|
||||
return NextResponse.json(await response.json())
|
||||
} catch (error) {
|
||||
console.error('Failed to update project:', error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to connect to backend' },
|
||||
{ status: 503 }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxy: DELETE /api/sdk/v1/projects/{projectId} → Backend (soft delete)
|
||||
*/
|
||||
export async function DELETE(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ projectId: string }> }
|
||||
) {
|
||||
try {
|
||||
const { projectId } = await params
|
||||
const tenantId = request.headers.get('X-Tenant-ID') ||
|
||||
new URL(request.url).searchParams.get('tenant_id') || ''
|
||||
|
||||
const response = await fetch(
|
||||
`${BACKEND_URL}/api/v1/projects/${projectId}?tenant_id=${encodeURIComponent(tenantId)}`,
|
||||
{
|
||||
method: 'DELETE',
|
||||
headers: { 'X-Tenant-ID': tenantId },
|
||||
}
|
||||
)
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text()
|
||||
return NextResponse.json(
|
||||
{ error: 'Backend error', details: errorText },
|
||||
{ status: response.status }
|
||||
)
|
||||
}
|
||||
|
||||
return NextResponse.json(await response.json())
|
||||
} catch (error) {
|
||||
console.error('Failed to archive project:', error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to connect to backend' },
|
||||
{ status: 503 }
|
||||
)
|
||||
}
|
||||
}
|
||||
75
admin-compliance/app/api/sdk/v1/projects/route.ts
Normal file
75
admin-compliance/app/api/sdk/v1/projects/route.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
|
||||
const BACKEND_URL = process.env.BACKEND_URL || 'http://backend-compliance:8002'
|
||||
|
||||
/**
|
||||
* Proxy: GET /api/sdk/v1/projects → Backend GET /api/v1/projects
|
||||
*/
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const tenantId = searchParams.get('tenant_id') || request.headers.get('X-Tenant-ID') || ''
|
||||
const includeArchived = searchParams.get('include_archived') || 'false'
|
||||
|
||||
const response = await fetch(
|
||||
`${BACKEND_URL}/api/v1/projects?tenant_id=${encodeURIComponent(tenantId)}&include_archived=${includeArchived}`,
|
||||
{
|
||||
headers: { 'X-Tenant-ID': tenantId },
|
||||
}
|
||||
)
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text()
|
||||
return NextResponse.json(
|
||||
{ error: 'Backend error', details: errorText },
|
||||
{ status: response.status }
|
||||
)
|
||||
}
|
||||
|
||||
return NextResponse.json(await response.json())
|
||||
} catch (error) {
|
||||
console.error('Failed to list projects:', error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to connect to backend' },
|
||||
{ status: 503 }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxy: POST /api/sdk/v1/projects → Backend POST /api/v1/projects
|
||||
*/
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
const tenantId = body.tenant_id || request.headers.get('X-Tenant-ID') || ''
|
||||
|
||||
const response = await fetch(
|
||||
`${BACKEND_URL}/api/v1/projects?tenant_id=${encodeURIComponent(tenantId)}`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Tenant-ID': tenantId,
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
}
|
||||
)
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text()
|
||||
return NextResponse.json(
|
||||
{ error: 'Backend error', details: errorText },
|
||||
{ status: response.status }
|
||||
)
|
||||
}
|
||||
|
||||
return NextResponse.json(await response.json(), { status: 201 })
|
||||
} catch (error) {
|
||||
console.error('Failed to create project:', error)
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to connect to backend' },
|
||||
{ status: 503 }
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -2,17 +2,18 @@ import { NextRequest, NextResponse } from 'next/server'
|
||||
import { Pool } from 'pg'
|
||||
|
||||
/**
|
||||
* SDK State Management API
|
||||
* SDK State Management API (Multi-Project)
|
||||
*
|
||||
* GET /api/sdk/v1/state?tenantId=xxx - Load state for a tenant
|
||||
* POST /api/sdk/v1/state - Save state for a tenant
|
||||
* DELETE /api/sdk/v1/state?tenantId=xxx - Clear state for a tenant
|
||||
* GET /api/sdk/v1/state?tenantId=xxx&projectId=yyy - Load state for a tenant+project
|
||||
* POST /api/sdk/v1/state - Save state for a tenant+project
|
||||
* DELETE /api/sdk/v1/state?tenantId=xxx&projectId=yyy - Clear state
|
||||
*
|
||||
* Features:
|
||||
* - Versioning for optimistic locking
|
||||
* - Last-Modified headers
|
||||
* - ETag support for caching
|
||||
* - PostgreSQL persistence (with InMemory fallback)
|
||||
* - projectId support for multi-project architecture
|
||||
*/
|
||||
|
||||
// =============================================================================
|
||||
@@ -32,25 +33,31 @@ interface StoredState {
|
||||
// =============================================================================
|
||||
|
||||
interface StateStore {
|
||||
get(tenantId: string): Promise<StoredState | null>
|
||||
save(tenantId: string, state: unknown, userId?: string, expectedVersion?: number): Promise<StoredState>
|
||||
delete(tenantId: string): Promise<boolean>
|
||||
get(tenantId: string, projectId?: string): Promise<StoredState | null>
|
||||
save(tenantId: string, state: unknown, userId?: string, expectedVersion?: number, projectId?: string): Promise<StoredState>
|
||||
delete(tenantId: string, projectId?: string): Promise<boolean>
|
||||
}
|
||||
|
||||
class InMemoryStateStore implements StateStore {
|
||||
private store: Map<string, StoredState> = new Map()
|
||||
|
||||
async get(tenantId: string): Promise<StoredState | null> {
|
||||
return this.store.get(tenantId) || null
|
||||
private key(tenantId: string, projectId?: string): string {
|
||||
return projectId ? `${tenantId}:${projectId}` : tenantId
|
||||
}
|
||||
|
||||
async get(tenantId: string, projectId?: string): Promise<StoredState | null> {
|
||||
return this.store.get(this.key(tenantId, projectId)) || null
|
||||
}
|
||||
|
||||
async save(
|
||||
tenantId: string,
|
||||
state: unknown,
|
||||
userId?: string,
|
||||
expectedVersion?: number
|
||||
expectedVersion?: number,
|
||||
projectId?: string
|
||||
): Promise<StoredState> {
|
||||
const existing = this.store.get(tenantId)
|
||||
const k = this.key(tenantId, projectId)
|
||||
const existing = this.store.get(k)
|
||||
|
||||
if (expectedVersion !== undefined && existing && existing.version !== expectedVersion) {
|
||||
const error = new Error('Version conflict') as Error & { status: number }
|
||||
@@ -72,12 +79,12 @@ class InMemoryStateStore implements StateStore {
|
||||
updatedAt: now,
|
||||
}
|
||||
|
||||
this.store.set(tenantId, stored)
|
||||
this.store.set(k, stored)
|
||||
return stored
|
||||
}
|
||||
|
||||
async delete(tenantId: string): Promise<boolean> {
|
||||
return this.store.delete(tenantId)
|
||||
async delete(tenantId: string, projectId?: string): Promise<boolean> {
|
||||
return this.store.delete(this.key(tenantId, projectId))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,11 +100,26 @@ class PostgreSQLStateStore implements StateStore {
|
||||
})
|
||||
}
|
||||
|
||||
async get(tenantId: string): Promise<StoredState | null> {
|
||||
const result = await this.pool.query(
|
||||
'SELECT state, version, user_id, created_at, updated_at FROM sdk_states WHERE tenant_id = $1',
|
||||
[tenantId]
|
||||
)
|
||||
async get(tenantId: string, projectId?: string): Promise<StoredState | null> {
|
||||
let result
|
||||
if (projectId) {
|
||||
result = await this.pool.query(
|
||||
'SELECT state, version, user_id, created_at, updated_at FROM sdk_states WHERE tenant_id = $1 AND project_id = $2',
|
||||
[tenantId, projectId]
|
||||
)
|
||||
} else {
|
||||
// Backwards compatibility: find the single active project for this tenant
|
||||
result = await this.pool.query(
|
||||
`SELECT s.state, s.version, s.user_id, s.created_at, s.updated_at
|
||||
FROM sdk_states s
|
||||
LEFT JOIN compliance_projects p ON s.project_id = p.id
|
||||
WHERE s.tenant_id = $1
|
||||
AND (p.status = 'active' OR p.id IS NULL)
|
||||
ORDER BY s.updated_at DESC
|
||||
LIMIT 1`,
|
||||
[tenantId]
|
||||
)
|
||||
}
|
||||
if (result.rows.length === 0) return null
|
||||
const row = result.rows[0]
|
||||
return {
|
||||
@@ -109,25 +131,71 @@ class PostgreSQLStateStore implements StateStore {
|
||||
}
|
||||
}
|
||||
|
||||
async save(tenantId: string, state: unknown, userId?: string, expectedVersion?: number): Promise<StoredState> {
|
||||
async save(tenantId: string, state: unknown, userId?: string, expectedVersion?: number, projectId?: string): Promise<StoredState> {
|
||||
const now = new Date().toISOString()
|
||||
const stateWithTimestamp = {
|
||||
...(state as object),
|
||||
lastModified: now,
|
||||
}
|
||||
|
||||
// Use UPSERT with version check
|
||||
const result = await this.pool.query(`
|
||||
INSERT INTO sdk_states (tenant_id, user_id, state, version, created_at, updated_at)
|
||||
VALUES ($1, $2, $3::jsonb, 1, NOW(), NOW())
|
||||
ON CONFLICT (tenant_id) DO UPDATE SET
|
||||
state = $3::jsonb,
|
||||
user_id = COALESCE($2, sdk_states.user_id),
|
||||
version = sdk_states.version + 1,
|
||||
updated_at = NOW()
|
||||
WHERE ($4::int IS NULL OR sdk_states.version = $4)
|
||||
RETURNING version, user_id, created_at, updated_at
|
||||
`, [tenantId, userId, JSON.stringify(stateWithTimestamp), expectedVersion ?? null])
|
||||
let result
|
||||
|
||||
if (projectId) {
|
||||
// Multi-project: UPSERT on (tenant_id, project_id)
|
||||
result = await this.pool.query(`
|
||||
INSERT INTO sdk_states (tenant_id, project_id, user_id, state, version, created_at, updated_at)
|
||||
VALUES ($1, $5, $2, $3::jsonb, 1, NOW(), NOW())
|
||||
ON CONFLICT (tenant_id, project_id) DO UPDATE SET
|
||||
state = $3::jsonb,
|
||||
user_id = COALESCE($2, sdk_states.user_id),
|
||||
version = sdk_states.version + 1,
|
||||
updated_at = NOW()
|
||||
WHERE ($4::int IS NULL OR sdk_states.version = $4)
|
||||
RETURNING version, user_id, created_at, updated_at
|
||||
`, [tenantId, userId, JSON.stringify(stateWithTimestamp), expectedVersion ?? null, projectId])
|
||||
} else {
|
||||
// Backwards compatibility: find the single project for this tenant
|
||||
// First try to find an existing project
|
||||
const projectResult = await this.pool.query(
|
||||
`SELECT id FROM compliance_projects WHERE tenant_id = $1 AND status = 'active' ORDER BY created_at ASC LIMIT 1`,
|
||||
[tenantId]
|
||||
)
|
||||
|
||||
if (projectResult.rows.length > 0) {
|
||||
const foundProjectId = projectResult.rows[0].id
|
||||
result = await this.pool.query(`
|
||||
INSERT INTO sdk_states (tenant_id, project_id, user_id, state, version, created_at, updated_at)
|
||||
VALUES ($1, $5, $2, $3::jsonb, 1, NOW(), NOW())
|
||||
ON CONFLICT (tenant_id, project_id) DO UPDATE SET
|
||||
state = $3::jsonb,
|
||||
user_id = COALESCE($2, sdk_states.user_id),
|
||||
version = sdk_states.version + 1,
|
||||
updated_at = NOW()
|
||||
WHERE ($4::int IS NULL OR sdk_states.version = $4)
|
||||
RETURNING version, user_id, created_at, updated_at
|
||||
`, [tenantId, userId, JSON.stringify(stateWithTimestamp), expectedVersion ?? null, foundProjectId])
|
||||
} else {
|
||||
// No project exists — create a default one
|
||||
const newProject = await this.pool.query(
|
||||
`INSERT INTO compliance_projects (tenant_id, name, customer_type, status)
|
||||
VALUES ($1, 'Projekt 1', 'new', 'active')
|
||||
RETURNING id`,
|
||||
[tenantId]
|
||||
)
|
||||
const newProjectId = newProject.rows[0].id
|
||||
result = await this.pool.query(`
|
||||
INSERT INTO sdk_states (tenant_id, project_id, user_id, state, version, created_at, updated_at)
|
||||
VALUES ($1, $5, $2, $3::jsonb, 1, NOW(), NOW())
|
||||
ON CONFLICT (tenant_id, project_id) DO UPDATE SET
|
||||
state = $3::jsonb,
|
||||
user_id = COALESCE($2, sdk_states.user_id),
|
||||
version = sdk_states.version + 1,
|
||||
updated_at = NOW()
|
||||
WHERE ($4::int IS NULL OR sdk_states.version = $4)
|
||||
RETURNING version, user_id, created_at, updated_at
|
||||
`, [tenantId, userId, JSON.stringify(stateWithTimestamp), expectedVersion ?? null, newProjectId])
|
||||
}
|
||||
}
|
||||
|
||||
if (result.rows.length === 0) {
|
||||
const error = new Error('Version conflict') as Error & { status: number }
|
||||
@@ -145,11 +213,19 @@ class PostgreSQLStateStore implements StateStore {
|
||||
}
|
||||
}
|
||||
|
||||
async delete(tenantId: string): Promise<boolean> {
|
||||
const result = await this.pool.query(
|
||||
'DELETE FROM sdk_states WHERE tenant_id = $1',
|
||||
[tenantId]
|
||||
)
|
||||
async delete(tenantId: string, projectId?: string): Promise<boolean> {
|
||||
let result
|
||||
if (projectId) {
|
||||
result = await this.pool.query(
|
||||
'DELETE FROM sdk_states WHERE tenant_id = $1 AND project_id = $2',
|
||||
[tenantId, projectId]
|
||||
)
|
||||
} else {
|
||||
result = await this.pool.query(
|
||||
'DELETE FROM sdk_states WHERE tenant_id = $1',
|
||||
[tenantId]
|
||||
)
|
||||
}
|
||||
return (result.rowCount ?? 0) > 0
|
||||
}
|
||||
}
|
||||
@@ -186,6 +262,7 @@ export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const tenantId = searchParams.get('tenantId')
|
||||
const projectId = searchParams.get('projectId') || undefined
|
||||
|
||||
if (!tenantId) {
|
||||
return NextResponse.json(
|
||||
@@ -194,7 +271,7 @@ export async function GET(request: NextRequest) {
|
||||
)
|
||||
}
|
||||
|
||||
const stored = await stateStore.get(tenantId)
|
||||
const stored = await stateStore.get(tenantId, projectId)
|
||||
|
||||
if (!stored) {
|
||||
return NextResponse.json(
|
||||
@@ -216,6 +293,7 @@ export async function GET(request: NextRequest) {
|
||||
success: true,
|
||||
data: {
|
||||
tenantId,
|
||||
projectId: projectId || null,
|
||||
state: stored.state,
|
||||
version: stored.version,
|
||||
lastModified: stored.updatedAt,
|
||||
@@ -241,7 +319,7 @@ export async function GET(request: NextRequest) {
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
const { tenantId, state, version } = body
|
||||
const { tenantId, state, version, projectId } = body
|
||||
|
||||
if (!tenantId) {
|
||||
return NextResponse.json(
|
||||
@@ -261,7 +339,7 @@ export async function POST(request: NextRequest) {
|
||||
const ifMatch = request.headers.get('If-Match')
|
||||
const expectedVersion = ifMatch ? parseInt(ifMatch, 10) : version
|
||||
|
||||
const stored = await stateStore.save(tenantId, state, body.userId, expectedVersion)
|
||||
const stored = await stateStore.save(tenantId, state, body.userId, expectedVersion, projectId || undefined)
|
||||
|
||||
const etag = generateETag(stored.version, stored.updatedAt)
|
||||
|
||||
@@ -270,6 +348,7 @@ export async function POST(request: NextRequest) {
|
||||
success: true,
|
||||
data: {
|
||||
tenantId,
|
||||
projectId: projectId || null,
|
||||
state: stored.state,
|
||||
version: stored.version,
|
||||
lastModified: stored.updatedAt,
|
||||
@@ -309,6 +388,7 @@ export async function DELETE(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const tenantId = searchParams.get('tenantId')
|
||||
const projectId = searchParams.get('projectId') || undefined
|
||||
|
||||
if (!tenantId) {
|
||||
return NextResponse.json(
|
||||
@@ -317,7 +397,7 @@ export async function DELETE(request: NextRequest) {
|
||||
)
|
||||
}
|
||||
|
||||
const deleted = await stateStore.delete(tenantId)
|
||||
const deleted = await stateStore.delete(tenantId, projectId)
|
||||
|
||||
if (!deleted) {
|
||||
return NextResponse.json(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect, useState } from 'react'
|
||||
import { usePathname } from 'next/navigation'
|
||||
import { usePathname, useSearchParams } from 'next/navigation'
|
||||
import { SDKProvider } from '@/lib/sdk'
|
||||
import { SDKSidebar } from '@/components/sdk/Sidebar/SDKSidebar'
|
||||
import { CommandBar } from '@/components/sdk/CommandBar'
|
||||
@@ -36,7 +36,7 @@ const SYNC_STATUS_CONFIG = {
|
||||
} as const
|
||||
|
||||
function SDKHeader({ sidebarCollapsed }: { sidebarCollapsed: boolean }) {
|
||||
const { state, currentStep, setCommandBarOpen, completionPercentage, syncState } = useSDK()
|
||||
const { state, currentStep, setCommandBarOpen, completionPercentage, syncState, projectId } = useSDK()
|
||||
|
||||
const syncConfig = SYNC_STATUS_CONFIG[syncState.status] || SYNC_STATUS_CONFIG.idle
|
||||
|
||||
@@ -47,6 +47,14 @@ function SDKHeader({ sidebarCollapsed }: { sidebarCollapsed: boolean }) {
|
||||
<div className="flex items-center gap-3">
|
||||
<nav className="flex items-center text-sm text-gray-500">
|
||||
<span>SDK</span>
|
||||
{state.projectInfo && (
|
||||
<>
|
||||
<svg className="w-4 h-4 mx-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5l7 7-7 7" />
|
||||
</svg>
|
||||
<span className="text-gray-700 font-medium">{state.projectInfo.name}</span>
|
||||
</>
|
||||
)}
|
||||
<svg className="w-4 h-4 mx-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5l7 7-7 7" />
|
||||
</svg>
|
||||
@@ -102,10 +110,19 @@ function SDKHeader({ sidebarCollapsed }: { sidebarCollapsed: boolean }) {
|
||||
|
||||
{/* Session Info Bar */}
|
||||
<div className="flex items-center gap-4 px-6 py-1.5 bg-gray-50 border-t border-gray-100 text-xs text-gray-500">
|
||||
{/* Projekt + Version */}
|
||||
{/* Projekt-Name */}
|
||||
<span className="text-gray-700 font-medium">
|
||||
{state.companyProfile?.companyName || 'Kein Projekt'}
|
||||
{state.projectInfo?.name || state.companyProfile?.companyName || 'Kein Projekt'}
|
||||
</span>
|
||||
|
||||
{/* Firmenname (falls abweichend vom Projektnamen) */}
|
||||
{state.projectInfo && state.companyProfile?.companyName && state.companyProfile.companyName !== state.projectInfo.name && (
|
||||
<>
|
||||
<span className="text-gray-300">|</span>
|
||||
<span className="text-gray-600">{state.companyProfile.companyName}</span>
|
||||
</>
|
||||
)}
|
||||
|
||||
<span className="font-mono text-gray-400">
|
||||
V{String(state.projectVersion || 1).padStart(3, '0')}
|
||||
</span>
|
||||
@@ -149,7 +166,7 @@ function SDKHeader({ sidebarCollapsed }: { sidebarCollapsed: boolean }) {
|
||||
// =============================================================================
|
||||
|
||||
function SDKInnerLayout({ children }: { children: React.ReactNode }) {
|
||||
const { isCommandBarOpen, setCommandBarOpen } = useSDK()
|
||||
const { isCommandBarOpen, setCommandBarOpen, projectId } = useSDK()
|
||||
const [sidebarCollapsed, setSidebarCollapsed] = useState(false)
|
||||
const pathname = usePathname()
|
||||
|
||||
@@ -172,16 +189,18 @@ function SDKInnerLayout({ children }: { children: React.ReactNode }) {
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-50">
|
||||
{/* Sidebar */}
|
||||
<SDKSidebar
|
||||
collapsed={sidebarCollapsed}
|
||||
onCollapsedChange={handleCollapsedChange}
|
||||
/>
|
||||
{/* Sidebar — only show when a project is selected */}
|
||||
{projectId && (
|
||||
<SDKSidebar
|
||||
collapsed={sidebarCollapsed}
|
||||
onCollapsedChange={handleCollapsedChange}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Main Content - dynamic margin based on sidebar state */}
|
||||
<div className={`${sidebarCollapsed ? 'ml-16' : 'ml-64'} flex flex-col min-h-screen transition-all duration-300`}>
|
||||
{/* Header */}
|
||||
<SDKHeader sidebarCollapsed={sidebarCollapsed} />
|
||||
<div className={`${projectId ? (sidebarCollapsed ? 'ml-16' : 'ml-64') : ''} flex flex-col min-h-screen transition-all duration-300`}>
|
||||
{/* Header — only show when a project is selected */}
|
||||
{projectId && <SDKHeader sidebarCollapsed={sidebarCollapsed} />}
|
||||
|
||||
{/* Page Content */}
|
||||
<main className="flex-1 p-6">{children}</main>
|
||||
@@ -191,10 +210,10 @@ function SDKInnerLayout({ children }: { children: React.ReactNode }) {
|
||||
{isCommandBarOpen && <CommandBar onClose={() => setCommandBarOpen(false)} />}
|
||||
|
||||
{/* Pipeline Sidebar (FAB on mobile/tablet, fixed on desktop xl+) */}
|
||||
<SDKPipelineSidebar />
|
||||
{projectId && <SDKPipelineSidebar />}
|
||||
|
||||
{/* Compliance Advisor Widget */}
|
||||
<ComplianceAdvisorWidget currentStep={currentStep} />
|
||||
{projectId && <ComplianceAdvisorWidget currentStep={currentStep} />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -208,8 +227,11 @@ export default function SDKRootLayout({
|
||||
}: {
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
const searchParams = useSearchParams()
|
||||
const projectId = searchParams.get('project') || undefined
|
||||
|
||||
return (
|
||||
<SDKProvider enableBackendSync={true}>
|
||||
<SDKProvider enableBackendSync={true} projectId={projectId}>
|
||||
<SDKInnerLayout>{children}</SDKInnerLayout>
|
||||
</SDKProvider>
|
||||
)
|
||||
|
||||
@@ -4,6 +4,7 @@ import React from 'react'
|
||||
import Link from 'next/link'
|
||||
import { useSDK, SDK_PACKAGES, getStepsForPackage } from '@/lib/sdk'
|
||||
import { CustomerTypeSelector } from '@/components/sdk/CustomerTypeSelector'
|
||||
import { ProjectSelector } from '@/components/sdk/ProjectSelector/ProjectSelector'
|
||||
import type { CustomerType, SDKPackageId } from '@/lib/sdk/types'
|
||||
|
||||
// =============================================================================
|
||||
@@ -42,15 +43,18 @@ function PackageCard({
|
||||
completion,
|
||||
stepsCount,
|
||||
isLocked,
|
||||
projectId,
|
||||
}: {
|
||||
pkg: (typeof SDK_PACKAGES)[number]
|
||||
completion: number
|
||||
stepsCount: number
|
||||
isLocked: boolean
|
||||
projectId?: string
|
||||
}) {
|
||||
const steps = getStepsForPackage(pkg.id)
|
||||
const firstStep = steps[0]
|
||||
const href = firstStep?.url || '/sdk'
|
||||
const baseHref = firstStep?.url || '/sdk'
|
||||
const href = projectId ? `${baseHref}?project=${projectId}` : baseHref
|
||||
|
||||
const content = (
|
||||
<div
|
||||
@@ -133,16 +137,19 @@ function QuickActionCard({
|
||||
icon,
|
||||
href,
|
||||
color,
|
||||
projectId,
|
||||
}: {
|
||||
title: string
|
||||
description: string
|
||||
icon: React.ReactNode
|
||||
href: string
|
||||
color: string
|
||||
projectId?: string
|
||||
}) {
|
||||
const finalHref = projectId ? `${href}?project=${projectId}` : href
|
||||
return (
|
||||
<Link
|
||||
href={href}
|
||||
href={finalHref}
|
||||
className="flex items-center gap-4 p-4 bg-white rounded-xl border border-gray-200 hover:border-purple-300 hover:shadow-md transition-all"
|
||||
>
|
||||
<div className={`p-3 rounded-lg ${color}`}>{icon}</div>
|
||||
@@ -162,7 +169,12 @@ function QuickActionCard({
|
||||
// =============================================================================
|
||||
|
||||
export default function SDKDashboard() {
|
||||
const { state, packageCompletion, completionPercentage, setCustomerType } = useSDK()
|
||||
const { state, packageCompletion, completionPercentage, setCustomerType, projectId } = useSDK()
|
||||
|
||||
// No project selected → show project list
|
||||
if (!projectId) {
|
||||
return <ProjectSelector />
|
||||
}
|
||||
|
||||
// Calculate total steps
|
||||
const totalSteps = SDK_PACKAGES.reduce((sum, pkg) => {
|
||||
@@ -282,7 +294,7 @@ export default function SDKDashboard() {
|
||||
Laden Sie Ihre vorhandenen Compliance-Dokumente hoch. Unsere KI analysiert sie und zeigt Ihnen, welche Erweiterungen fuer KI-Compliance erforderlich sind.
|
||||
</p>
|
||||
<Link
|
||||
href="/sdk/import"
|
||||
href={projectId ? `/sdk/import?project=${projectId}` : '/sdk/import'}
|
||||
className="inline-flex items-center gap-2 mt-4 px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition-colors"
|
||||
>
|
||||
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
@@ -345,6 +357,7 @@ export default function SDKDashboard() {
|
||||
completion={packageCompletion[pkg.id]}
|
||||
stepsCount={visibleSteps.length}
|
||||
isLocked={isPackageLocked(pkg.id)}
|
||||
projectId={projectId}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
@@ -365,6 +378,7 @@ export default function SDKDashboard() {
|
||||
}
|
||||
href="/sdk/advisory-board"
|
||||
color="bg-purple-50"
|
||||
projectId={projectId}
|
||||
/>
|
||||
<QuickActionCard
|
||||
title="Security Screening"
|
||||
@@ -376,6 +390,7 @@ export default function SDKDashboard() {
|
||||
}
|
||||
href="/sdk/screening"
|
||||
color="bg-red-50"
|
||||
projectId={projectId}
|
||||
/>
|
||||
<QuickActionCard
|
||||
title="DSFA generieren"
|
||||
@@ -387,6 +402,7 @@ export default function SDKDashboard() {
|
||||
}
|
||||
href="/sdk/dsfa"
|
||||
color="bg-blue-50"
|
||||
projectId={projectId}
|
||||
/>
|
||||
<QuickActionCard
|
||||
title="Legal RAG"
|
||||
@@ -398,6 +414,7 @@ export default function SDKDashboard() {
|
||||
}
|
||||
href="/sdk/rag"
|
||||
color="bg-green-50"
|
||||
projectId={projectId}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user