AP2.3c: Slice-bewusstes Laden und hoisted InitiativeOperationsProvider.
Test Suite / pytest-backend (push) Waiting to run
Test Suite / lint-backend (push) Waiting to run
Test Suite / compose-smoke (push) Waiting to run
Test Suite / k6 /api/health Baseline (push) Blocked by required conditions
Test Suite / playwright-smoke (push) Blocked by required conditions
Deploy Development / deploy (push) Has been cancelled
Test Suite / pytest-backend (push) Waiting to run
Test Suite / lint-backend (push) Waiting to run
Test Suite / compose-smoke (push) Waiting to run
Test Suite / k6 /api/health Baseline (push) Blocked by required conditions
Test Suite / playwright-smoke (push) Blocked by required conditions
Deploy Development / deploy (push) Has been cancelled
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
90934453e6
commit
1b55d8558c
6 files changed
+308
-140
No files matched your search
@@ -10,6 +10,7 @@ import { useParams } from 'react-router-dom'
|
||||
import {
|
||||
getInitiative,
|
||||
getInitiativeSteeringSnapshot,
|
||||
getInitiativeOperatingContext,
|
||||
listInitiativeActions,
|
||||
createInitiativeAction,
|
||||
updateInitiative,
|
||||
@@ -86,6 +87,10 @@ import { useOptionalProgramScope } from './ProgramScopeContext.jsx'
|
||||
import { collectProjectSubtreeIds } from '../utils/projectTree.js'
|
||||
import { filterActionsForWorkCycle } from '../utils/workCycleActions.js'
|
||||
import { listFeatureParentActions } from '../utils/actionReferences.js'
|
||||
import {
|
||||
applySliceResults,
|
||||
loadOperatingSlices,
|
||||
} from '../registry/operatingSliceLoaders.js'
|
||||
|
||||
const InitiativeOperationsContext = createContext(null)
|
||||
|
||||
@@ -114,6 +119,7 @@ export function InitiativeOperationsProvider({ children, initiativeId: initiativ
|
||||
const [steeringSnapshotLoading, setSteeringSnapshotLoading] = useState(false)
|
||||
const [steeringSnapshotError, setSteeringSnapshotError] = useState(null)
|
||||
const [steeringMethods, setSteeringMethods] = useState([])
|
||||
const [operatingContext, setOperatingContext] = useState(null)
|
||||
const [methodBusy, setMethodBusy] = useState(false)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [error, setError] = useState(null)
|
||||
@@ -123,62 +129,74 @@ export function InitiativeOperationsProvider({ children, initiativeId: initiativ
|
||||
const [hideDone, setHideDone] = useState(true)
|
||||
const [selectedWorkCycleId, setSelectedWorkCycleId] = useState('')
|
||||
|
||||
const load = useCallback(async ({ silent = false } = {}) => {
|
||||
const sliceSetters = useMemo(
|
||||
() => ({
|
||||
setInitiative,
|
||||
setActions,
|
||||
setBlockers,
|
||||
setBacklogItems,
|
||||
setRoadmapItems,
|
||||
setProjects,
|
||||
setEvidenceItems,
|
||||
setDecisions,
|
||||
setReviews,
|
||||
setRecurringItems,
|
||||
setWorkCycles,
|
||||
setActiveWorkCycle,
|
||||
setSteeringMethods,
|
||||
setSteeringSnapshot,
|
||||
}),
|
||||
[],
|
||||
)
|
||||
|
||||
const reloadSlices = useCallback(
|
||||
async (sliceKeys) => {
|
||||
if (!id || !sliceKeys?.length) return
|
||||
const results = await loadOperatingSlices(id, sliceKeys)
|
||||
applySliceResults(results, sliceSetters)
|
||||
},
|
||||
[id, sliceSetters],
|
||||
)
|
||||
|
||||
const load = useCallback(async ({ silent = false, sliceKeys = null } = {}) => {
|
||||
if (sessionLoading || !id) return
|
||||
if (!silent) setLoading(true)
|
||||
setError(null)
|
||||
try {
|
||||
const [initData, actionData] = await Promise.all([
|
||||
getInitiative(id),
|
||||
listInitiativeActions(id),
|
||||
])
|
||||
setInitiative(initData)
|
||||
setActions(actionData)
|
||||
|
||||
const loads = []
|
||||
const canReadOm =
|
||||
capabilities.has('kairo.initiative.read') ||
|
||||
capabilities.has('kairo.blocker.read')
|
||||
if (canReadOm) {
|
||||
loads.push(listInitiativeBlockers(id).then(setBlockers).catch(() => setBlockers([])))
|
||||
loads.push(listInitiativeBacklog(id).then(setBacklogItems).catch(() => setBacklogItems([])))
|
||||
loads.push(listInitiativeRoadmapItems(id).then(setRoadmapItems).catch(() => setRoadmapItems([])))
|
||||
loads.push(listInitiativeProjects(id).then(setProjects).catch(() => setProjects([])))
|
||||
loads.push(listInitiativeEvidence(id).then(setEvidenceItems).catch(() => setEvidenceItems([])))
|
||||
loads.push(listInitiativeDecisions(id).then(setDecisions).catch(() => setDecisions([])))
|
||||
loads.push(listInitiativeReviews(id).then(setReviews).catch(() => setReviews([])))
|
||||
loads.push(listInitiativeRecurring(id).then(setRecurringItems).catch(() => setRecurringItems([])))
|
||||
loads.push(listInitiativeWorkCycles(id).then(setWorkCycles).catch(() => setWorkCycles([])))
|
||||
loads.push(
|
||||
getActiveWorkCycle(id)
|
||||
.then((item) => setActiveWorkCycle(item || null))
|
||||
.catch(() => setActiveWorkCycle(null))
|
||||
)
|
||||
loads.push(
|
||||
listSteeringMethods().then(setSteeringMethods).catch(() => setSteeringMethods([]))
|
||||
)
|
||||
loads.push(
|
||||
(async () => {
|
||||
setSteeringSnapshotLoading(true)
|
||||
setSteeringSnapshotError(null)
|
||||
try {
|
||||
setSteeringSnapshot(await getInitiativeSteeringSnapshot(id))
|
||||
} catch (err) {
|
||||
setSteeringSnapshot(null)
|
||||
setSteeringSnapshotError(err.message || 'Snapshot fehlgeschlagen')
|
||||
} finally {
|
||||
setSteeringSnapshotLoading(false)
|
||||
}
|
||||
})()
|
||||
)
|
||||
|
||||
let opContext = null
|
||||
if (!sliceKeys) {
|
||||
opContext = await getInitiativeOperatingContext(id).catch(() => null)
|
||||
setOperatingContext(opContext)
|
||||
}
|
||||
|
||||
const omSlices = canReadOm ? opContext?.data_slices || [] : []
|
||||
const keysToLoad = sliceKeys || ['initiative', ...omSlices]
|
||||
|
||||
if (keysToLoad.includes('steering_snapshot')) {
|
||||
setSteeringSnapshotLoading(true)
|
||||
setSteeringSnapshotError(null)
|
||||
}
|
||||
|
||||
const results = await loadOperatingSlices(id, keysToLoad)
|
||||
applySliceResults(results, sliceSetters)
|
||||
|
||||
if (keysToLoad.includes('steering_snapshot') && results.steering_snapshot == null) {
|
||||
setSteeringSnapshotError('Snapshot fehlgeschlagen')
|
||||
}
|
||||
if (keysToLoad.includes('steering_snapshot')) {
|
||||
setSteeringSnapshotLoading(false)
|
||||
}
|
||||
await Promise.all(loads)
|
||||
} catch (err) {
|
||||
setError(err.message)
|
||||
setSteeringSnapshotLoading(false)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [id, capabilities, sessionLoading])
|
||||
}, [id, capabilities, sessionLoading, sliceSetters])
|
||||
|
||||
useEffect(() => {
|
||||
load()
|
||||
@@ -380,6 +398,7 @@ export function InitiativeOperationsProvider({ children, initiativeId: initiativ
|
||||
try {
|
||||
const updated = await updateAction(action.id, { work_cycle_id: targetCycleId })
|
||||
setActions((prev) => prev.map((a) => (a.id === action.id ? updated : a)))
|
||||
await reloadSlices(['work_cycles'])
|
||||
} catch (err) {
|
||||
setError(err.message)
|
||||
} finally {
|
||||
@@ -975,6 +994,8 @@ export function InitiativeOperationsProvider({ children, initiativeId: initiativ
|
||||
steeringSnapshotLoading,
|
||||
steeringSnapshotError,
|
||||
steeringMethods,
|
||||
operatingContext,
|
||||
dataSlices: operatingContext?.data_slices || [],
|
||||
methodBusy,
|
||||
loading,
|
||||
error,
|
||||
@@ -993,6 +1014,7 @@ export function InitiativeOperationsProvider({ children, initiativeId: initiativ
|
||||
actorsUsedFallback: actorsState.usedFallback,
|
||||
reloadActors: actorsState.reload,
|
||||
reload: load,
|
||||
reloadSlices,
|
||||
handleMethodChange,
|
||||
handleMethodProfileChange,
|
||||
handleCreateAction,
|
||||
@@ -1053,8 +1075,12 @@ export function InitiativeOperationsProvider({ children, initiativeId: initiativ
|
||||
)
|
||||
}
|
||||
|
||||
export function useOptionalInitiativeOperations() {
|
||||
return useContext(InitiativeOperationsContext)
|
||||
}
|
||||
|
||||
export function useInitiativeOperations() {
|
||||
const ctx = useContext(InitiativeOperationsContext)
|
||||
const ctx = useOptionalInitiativeOperations()
|
||||
if (!ctx) {
|
||||
throw new Error('useInitiativeOperations must be used within InitiativeOperationsProvider')
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user