AP1.9a: Arbeitsmodi-Shell mit Scope, Objekt-Routen und Legacy-Redirects.
Deploy Development / deploy (push) Successful in 47s
Test Suite / pytest-backend (push) Failing after 1m46s
Test Suite / k6 /api/health Baseline (push) Has been skipped
Test Suite / playwright-smoke (push) Has been skipped
Test Suite / lint-backend (push) Successful in 2s
Test Suite / compose-smoke (push) Has been skipped
Deploy Development / deploy (push) Successful in 47s
Test Suite / pytest-backend (push) Failing after 1m46s
Test Suite / k6 /api/health Baseline (push) Has been skipped
Test Suite / playwright-smoke (push) Has been skipped
Test Suite / lint-backend (push) Successful in 2s
Test Suite / compose-smoke (push) Has been skipped
Ersetzt die Vorhaben-Tab-Navigation durch Cockpit/Ausführen/Planen/Kontrolle/Team, Deep Links für APs/Projekte/Gates und Programm-Scope im Header. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
33831a8c2c
commit
e42edd86fa
54 files changed
+2489
-150
No files matched your search
@@ -68,12 +68,15 @@ import { listSteeringMethods, updateInitiativeSteeringMethod } from '../api/stee
|
||||
import { useCapabilities } from '../hooks/useCapabilities.js'
|
||||
import { useActors } from '../hooks/useActors.js'
|
||||
import { useSession } from './SessionContext.jsx'
|
||||
import { useOptionalProgramScope } from './ProgramScopeContext.jsx'
|
||||
import { collectProjectSubtreeIds } from '../utils/projectTree.js'
|
||||
|
||||
const InitiativeOperationsContext = createContext(null)
|
||||
|
||||
export function InitiativeOperationsProvider({ children }) {
|
||||
const { id } = useParams()
|
||||
export function InitiativeOperationsProvider({ children, initiativeId: initiativeIdProp }) {
|
||||
const { id: routeId } = useParams()
|
||||
const scope = useOptionalProgramScope()
|
||||
const id = initiativeIdProp || routeId || scope?.initiativeId || null
|
||||
const { context, loading: sessionLoading } = useSession()
|
||||
const { capabilities } = useCapabilities()
|
||||
const actorsState = useActors()
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
import {
|
||||
createContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useState,
|
||||
} from 'react'
|
||||
import { useSearchParams } from 'react-router-dom'
|
||||
import { getInitiative } from '../api/initiatives.js'
|
||||
import { getProject } from '../api/projects.js'
|
||||
import { scopedPath } from '../utils/routes.js'
|
||||
|
||||
const ProgramScopeContext = createContext(null)
|
||||
|
||||
export function ProgramScopeProvider({ children }) {
|
||||
const [searchParams, setSearchParams] = useSearchParams()
|
||||
const initiativeId = searchParams.get('initiative') || ''
|
||||
const projectId = searchParams.get('project') || ''
|
||||
|
||||
const [initiativeTitle, setInitiativeTitle] = useState('')
|
||||
const [projectTitle, setProjectTitle] = useState('')
|
||||
|
||||
useEffect(() => {
|
||||
if (!initiativeId) {
|
||||
setInitiativeTitle('')
|
||||
return
|
||||
}
|
||||
let cancelled = false
|
||||
getInitiative(initiativeId)
|
||||
.then((data) => {
|
||||
if (!cancelled) setInitiativeTitle(data.title || '')
|
||||
})
|
||||
.catch(() => {
|
||||
if (!cancelled) setInitiativeTitle('')
|
||||
})
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [initiativeId])
|
||||
|
||||
useEffect(() => {
|
||||
if (!projectId) {
|
||||
setProjectTitle('')
|
||||
return
|
||||
}
|
||||
let cancelled = false
|
||||
getProject(projectId)
|
||||
.then((data) => {
|
||||
if (!cancelled) setProjectTitle(data.title || '')
|
||||
})
|
||||
.catch(() => {
|
||||
if (!cancelled) setProjectTitle('')
|
||||
})
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [projectId])
|
||||
|
||||
const setScope = useCallback(
|
||||
(next) => {
|
||||
const params = new URLSearchParams(searchParams)
|
||||
if ('initiativeId' in next) {
|
||||
if (next.initiativeId) params.set('initiative', next.initiativeId)
|
||||
else params.delete('initiative')
|
||||
}
|
||||
if ('projectId' in next) {
|
||||
if (next.projectId) params.set('project', next.projectId)
|
||||
else params.delete('project')
|
||||
}
|
||||
if (next.clearProject) params.delete('project')
|
||||
setSearchParams(params, { replace: true })
|
||||
},
|
||||
[searchParams, setSearchParams],
|
||||
)
|
||||
|
||||
const clearScope = useCallback(() => {
|
||||
setSearchParams({}, { replace: true })
|
||||
}, [setSearchParams])
|
||||
|
||||
const applyFromInitiative = useCallback(
|
||||
(id, { keepProject = false } = {}) => {
|
||||
if (!id) return
|
||||
setScope({
|
||||
initiativeId: id,
|
||||
projectId: keepProject ? projectId : '',
|
||||
clearProject: !keepProject,
|
||||
})
|
||||
},
|
||||
[projectId, setScope],
|
||||
)
|
||||
|
||||
const applyFromProject = useCallback(
|
||||
(project) => {
|
||||
if (!project?.initiative_id) return
|
||||
setScope({
|
||||
initiativeId: project.initiative_id,
|
||||
projectId: project.id,
|
||||
})
|
||||
},
|
||||
[setScope],
|
||||
)
|
||||
|
||||
const applyFromAction = useCallback(
|
||||
(action) => {
|
||||
if (!action?.initiative_id) return
|
||||
setScope({
|
||||
initiativeId: action.initiative_id,
|
||||
projectId: action.project_id || '',
|
||||
clearProject: !action.project_id,
|
||||
})
|
||||
},
|
||||
[setScope],
|
||||
)
|
||||
|
||||
const hrefWithScope = useCallback(
|
||||
(path) => scopedPath(path, { initiativeId, projectId }),
|
||||
[initiativeId, projectId],
|
||||
)
|
||||
|
||||
const value = useMemo(
|
||||
() => ({
|
||||
initiativeId,
|
||||
projectId,
|
||||
initiativeTitle,
|
||||
projectTitle,
|
||||
setScope,
|
||||
clearScope,
|
||||
applyFromInitiative,
|
||||
applyFromProject,
|
||||
applyFromAction,
|
||||
hrefWithScope,
|
||||
hasScope: Boolean(initiativeId),
|
||||
}),
|
||||
[
|
||||
initiativeId,
|
||||
projectId,
|
||||
initiativeTitle,
|
||||
projectTitle,
|
||||
setScope,
|
||||
clearScope,
|
||||
applyFromInitiative,
|
||||
applyFromProject,
|
||||
applyFromAction,
|
||||
hrefWithScope,
|
||||
],
|
||||
)
|
||||
|
||||
return (
|
||||
<ProgramScopeContext.Provider value={value}>{children}</ProgramScopeContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export function useProgramScope() {
|
||||
const ctx = useContext(ProgramScopeContext)
|
||||
if (!ctx) {
|
||||
throw new Error('useProgramScope must be used within ProgramScopeProvider')
|
||||
}
|
||||
return ctx
|
||||
}
|
||||
|
||||
export function useOptionalProgramScope() {
|
||||
return useContext(ProgramScopeContext)
|
||||
}
|
||||
Reference in new issue
Block a user