feat: Projekt-Verwaltung verbessern — Archivieren, Loeschen, Wiederherstellen
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 35s
CI / test-python-backend-compliance (push) Successful in 38s
CI / test-python-document-crawler (push) Successful in 24s
CI / test-python-dsms-gateway (push) Successful in 24s

- Backend: Restore-Endpoint (POST /projects/{id}/restore) und
  Hard-Delete-Endpoint (DELETE /projects/{id}/permanent) hinzugefuegt
- Frontend: Dreistufiger Dialog (Archivieren / Endgueltig loeschen mit
  Bestaetigungsdialog) statt einfachem Loeschen
- Archivierte Projekte aufklappbar in der Projektliste mit
  Wiederherstellen-Button
- CustomerTypeSelector entfernt (redundant seit Multi-Projekt)
- Default tenantId von 'default' auf UUID geaendert (Backend-400-Fix)
- SQL-Cast :state::jsonb durch CAST(:state AS jsonb) ersetzt (SQLAlchemy-Fix)
- snake_case/camelCase-Mapping fuer Backend-Response (NaN-Datum-Fix)
- projectInfo wird beim Laden vom Backend geholt (Header zeigt Projektname)
- API-Client erzeugt sich on-demand (Race-Condition-Fix fuer Projektliste)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-03-09 17:48:02 +01:00
parent d53cf21b95
commit 09cfb79840
7 changed files with 664 additions and 86 deletions

View File

@@ -600,9 +600,9 @@ export class SDKApiClient {
/**
* List all projects for the current tenant
*/
async listProjects(): Promise<{ projects: ProjectInfo[]; total: number }> {
async listProjects(includeArchived = true): Promise<{ projects: ProjectInfo[]; total: number }> {
const response = await this.fetchWithRetry<{ projects: ProjectInfo[]; total: number }>(
`${this.baseUrl}/projects?tenant_id=${encodeURIComponent(this.tenantId)}`,
`${this.baseUrl}/projects?tenant_id=${encodeURIComponent(this.tenantId)}&include_archived=${includeArchived}`,
{
method: 'GET',
headers: {
@@ -664,6 +664,23 @@ export class SDKApiClient {
return response
}
/**
* Get a single project by ID
*/
async getProject(projectId: string): Promise<ProjectInfo> {
const response = await this.fetchWithRetry<ProjectInfo>(
`${this.baseUrl}/projects/${projectId}?tenant_id=${encodeURIComponent(this.tenantId)}`,
{
method: 'GET',
headers: {
'Content-Type': 'application/json',
'X-Tenant-ID': this.tenantId,
},
}
)
return response
}
/**
* Archive (soft-delete) a project
*/
@@ -680,6 +697,39 @@ export class SDKApiClient {
)
}
/**
* Restore an archived project
*/
async restoreProject(projectId: string): Promise<ProjectInfo> {
const response = await this.fetchWithRetry<ProjectInfo>(
`${this.baseUrl}/projects/${projectId}/restore?tenant_id=${encodeURIComponent(this.tenantId)}`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Tenant-ID': this.tenantId,
},
}
)
return response
}
/**
* Permanently delete a project and all data
*/
async permanentlyDeleteProject(projectId: string): Promise<void> {
await this.fetchWithRetry<{ success: boolean }>(
`${this.baseUrl}/projects/${projectId}/permanent?tenant_id=${encodeURIComponent(this.tenantId)}`,
{
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
'X-Tenant-ID': this.tenantId,
},
}
)
}
/**
* Health check
*/

View File

@@ -560,6 +560,8 @@ interface SDKContextValue {
listProjects: () => Promise<ProjectInfo[]>
switchProject: (projectId: string) => void
archiveProject: (projectId: string) => Promise<void>
restoreProject: (projectId: string) => Promise<ProjectInfo>
permanentlyDeleteProject: (projectId: string) => Promise<void>
}
const SDKContext = createContext<SDKContextValue | null>(null)
@@ -580,7 +582,7 @@ interface SDKProviderProps {
export function SDKProvider({
children,
tenantId = 'default',
tenantId = '9282a473-5c95-4b3a-bf78-0ecc0ec71d3e',
userId = 'default',
projectId,
enableBackendSync = false,
@@ -713,6 +715,16 @@ export function SDKProvider({
}
}
}
// Load project metadata (name, status, etc.) from backend
if (enableBackendSync && projectId && apiClientRef.current) {
try {
const info = await apiClientRef.current.getProject(projectId)
dispatch({ type: 'SET_STATE', payload: { projectInfo: info } })
} catch (err) {
console.warn('Failed to load project info:', err)
}
}
} catch (error) {
console.error('Failed to load SDK state:', error)
}
@@ -1101,6 +1113,9 @@ export function SDKProvider({
// Project Management
const createProject = useCallback(
async (name: string, customerType: CustomerType, copyFromProjectId?: string): Promise<ProjectInfo> => {
if (!apiClientRef.current && enableBackendSync) {
apiClientRef.current = getSDKApiClient(tenantId, projectId)
}
if (!apiClientRef.current) {
throw new Error('Backend sync not enabled')
}
@@ -1110,16 +1125,20 @@ export function SDKProvider({
copy_from_project_id: copyFromProjectId,
})
},
[]
[enableBackendSync, tenantId, projectId]
)
const listProjectsFn = useCallback(async (): Promise<ProjectInfo[]> => {
// Ensure API client exists (may not be set yet if useEffect hasn't fired)
if (!apiClientRef.current && enableBackendSync) {
apiClientRef.current = getSDKApiClient(tenantId, projectId)
}
if (!apiClientRef.current) {
return []
}
const result = await apiClientRef.current.listProjects()
return result.projects
}, [])
}, [enableBackendSync, tenantId, projectId])
const switchProject = useCallback(
(newProjectId: string) => {
@@ -1133,12 +1152,41 @@ export function SDKProvider({
const archiveProjectFn = useCallback(
async (archiveId: string): Promise<void> => {
if (!apiClientRef.current && enableBackendSync) {
apiClientRef.current = getSDKApiClient(tenantId, projectId)
}
if (!apiClientRef.current) {
throw new Error('Backend sync not enabled')
}
await apiClientRef.current.archiveProject(archiveId)
},
[]
[enableBackendSync, tenantId, projectId]
)
const restoreProjectFn = useCallback(
async (restoreId: string): Promise<ProjectInfo> => {
if (!apiClientRef.current && enableBackendSync) {
apiClientRef.current = getSDKApiClient(tenantId, projectId)
}
if (!apiClientRef.current) {
throw new Error('Backend sync not enabled')
}
return apiClientRef.current.restoreProject(restoreId)
},
[enableBackendSync, tenantId, projectId]
)
const permanentlyDeleteProjectFn = useCallback(
async (deleteId: string): Promise<void> => {
if (!apiClientRef.current && enableBackendSync) {
apiClientRef.current = getSDKApiClient(tenantId, projectId)
}
if (!apiClientRef.current) {
throw new Error('Backend sync not enabled')
}
await apiClientRef.current.permanentlyDeleteProject(deleteId)
},
[enableBackendSync, tenantId, projectId]
)
// Export
@@ -1206,6 +1254,8 @@ export function SDKProvider({
listProjects: listProjectsFn,
switchProject,
archiveProject: archiveProjectFn,
restoreProject: restoreProjectFn,
permanentlyDeleteProject: permanentlyDeleteProjectFn,
}
return <SDKContext.Provider value={value}>{children}</SDKContext.Provider>