AP1.8a: Portfolio-Rang im Cockpit mit Reorder und Next-Action-Sortierung.
Deploy Development / deploy (push) Successful in 50s
Test Suite / pytest-backend (push) Successful in 2m21s
Test Suite / lint-backend (push) Successful in 2s
Test Suite / compose-smoke (push) Has been skipped
Test Suite / k6 /api/health Baseline (push) Successful in 18s
Test Suite / playwright-smoke (push) Successful in 21s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-07-11 09:39:49 +02:00
1 parent d7aefed0de
commit a19c6abd26
16 files changed
+426 -34

No files matched your search

+7
View File
@@ -23,3 +23,10 @@ export function listWorkspaceActiveInitiatives(limit = 5) {
export function getActorWorkload() {
return apiFetch('/api/workspace/actors/workload')
}
export function reorderPortfolio(initiativeIds) {
return apiFetch('/api/workspace/portfolio/reorder', {
method: 'POST',
body: JSON.stringify({ initiative_ids: initiativeIds }),
})
}
+41 -3
View File
@@ -779,6 +779,11 @@
margin-right: 0.35rem;
}
.next-action-portfolio-rank {
font-size: 0.8125rem;
margin-right: 0.35rem;
}
.next-action-kind {
font-size: 0.75rem;
margin-right: 0.35rem;
@@ -1174,10 +1179,43 @@
}
.initiative-portfolio-card {
position: relative;
display: flex;
flex-direction: column;
padding: 0;
transition: border-color 0.15s ease;
}
.initiative-portfolio-card__reorder {
position: absolute;
top: 0.5rem;
right: 0.5rem;
z-index: 1;
}
.initiative-portfolio-card__link {
display: block;
text-decoration: none;
color: inherit;
padding: 1rem;
color: inherit;
text-decoration: none;
}
.initiative-portfolio-card__link:hover {
text-decoration: none;
}
.initiative-portfolio-card__head {
display: flex;
align-items: baseline;
gap: 0.5rem;
padding-right: 3rem;
}
.initiative-portfolio-card__rank {
flex: 0 0 auto;
font-size: 0.75rem;
font-weight: 600;
color: var(--jk-accent, #2563eb);
}
.initiative-portfolio-card:hover {
@@ -1185,7 +1223,7 @@
}
.initiative-portfolio-card-title {
margin: 0 0 0.35rem;
margin: 0;
font-size: 1rem;
}
+24
View File
@@ -0,0 +1,24 @@
/**
* Portfolio-Rang (AP1.8a) — niedrigerer Rank = höhere Aufmerksamkeit.
*/
/**
* @template {{ id: string, portfolio_rank?: number | null }} T
* @param {T[]} items
*/
export function sortByPortfolioRank(items) {
return [...items].sort(
(a, b) =>
(a.portfolio_rank ?? Number.MAX_SAFE_INTEGER) -
(b.portfolio_rank ?? Number.MAX_SAFE_INTEGER) ||
String(a.id).localeCompare(String(b.id)),
)
}
/**
* @param {number | null | undefined} rank
*/
export function formatPortfolioRank(rank) {
if (rank == null || Number.isNaN(rank)) return null
return `#${rank + 1}`
}
+18
View File
@@ -0,0 +1,18 @@
import { describe, expect, it } from 'vitest'
import { formatPortfolioRank, sortByPortfolioRank } from './portfolioRank.js'
describe('portfolioRank', () => {
it('sorts by portfolio_rank ascending', () => {
const items = [
{ id: 'c', portfolio_rank: 2 },
{ id: 'a', portfolio_rank: 0 },
{ id: 'b', portfolio_rank: 1 },
]
expect(sortByPortfolioRank(items).map((i) => i.id)).toEqual(['a', 'b', 'c'])
})
it('formats rank as 1-based display', () => {
expect(formatPortfolioRank(0)).toBe('#1')
expect(formatPortfolioRank(null)).toBeNull()
})
})
@@ -1,20 +1,27 @@
import { useCallback, useEffect, useState } from 'react'
import { useCallback, useEffect, useMemo, useState } from 'react'
import { Link } from 'react-router-dom'
import { listInitiatives } from '../api/initiatives.js'
import { reorderPortfolio } from '../api/workspace.js'
import { StatusBadge } from '../components/StatusBadge.jsx'
import { PriorityBadge } from '../components/PriorityBadge.jsx'
import { EmptyState } from '../components/EmptyState.jsx'
import { ErrorState } from '../components/ErrorState.jsx'
import { LoadingState } from '../components/LoadingState.jsx'
import { ReorderControls } from '../components/ReorderControls.jsx'
import { scopedPath } from '../utils/routes.js'
import { formatPortfolioRank, sortByPortfolioRank } from '../utils/portfolioRank.js'
import { WidgetCard } from '../components/WidgetCard.jsx'
import { ArchetypeBadge } from '../components/ArchetypeBadge.jsx'
import { useEntityArchetypes } from '../hooks/useEntityArchetypes.js'
import { useCapabilities } from '../hooks/useCapabilities.js'
export function InitiativePortfolioWidget() {
const { initiativeArchetypes } = useEntityArchetypes()
const { hasCapability } = useCapabilities()
const canManage = hasCapability('kairo.initiative.manage')
const [initiatives, setInitiatives] = useState([])
const [loading, setLoading] = useState(true)
const [busy, setBusy] = useState(false)
const [error, setError] = useState(null)
const load = useCallback(async () => {
@@ -34,13 +41,42 @@ export function InitiativePortfolioWidget() {
load()
}, [load])
const sortedInitiatives = useMemo(() => sortByPortfolioRank(initiatives), [initiatives])
async function handleMove(itemId, direction) {
const sorted = sortByPortfolioRank(initiatives)
const fromIndex = sorted.findIndex((item) => item.id === itemId)
if (fromIndex < 0) return
const toIndex = direction === 'up' ? fromIndex - 1 : fromIndex + 1
if (toIndex < 0 || toIndex >= sorted.length) return
const next = [...sorted]
const [moved] = next.splice(fromIndex, 1)
next.splice(toIndex, 0, moved)
setBusy(true)
setError(null)
try {
const updated = await reorderPortfolio(next.map((item) => item.id))
setInitiatives(Array.isArray(updated) ? updated : next)
} catch (err) {
setError(err.message)
} finally {
setBusy(false)
}
}
return (
<WidgetCard
title="Portfolio — alle Vorhaben"
subtitle="Querschnitt über deine Initiativen. Klick öffnet die Steuerungs-Übersicht."
subtitle={
canManage
? 'Nach Portfolio-Priorität sortiert — ↑↓ setzt die Aufmerksamkeits-Reihenfolge.'
: 'Querschnitt über deine Initiativen. Klick öffnet die Steuerungs-Übersicht.'
}
className="widget-card--span-full"
actions={
<button type="button" className="btn btn-ghost" onClick={load} disabled={loading}>
<button type="button" className="btn btn-ghost" onClick={load} disabled={loading || busy}>
Aktualisieren
</button>
}
@@ -52,26 +88,48 @@ export function InitiativePortfolioWidget() {
)}
{!loading && !error && initiatives.length > 0 && (
<div className="initiative-portfolio-grid">
{initiatives.map((item) => (
<Link
key={item.id}
to={scopedPath('/control/status', { initiativeId: item.id })}
className="initiative-portfolio-card card"
>
<h3 className="initiative-portfolio-card-title">{item.title}</h3>
{item.goal && (
<p className="initiative-portfolio-card-goal muted">{item.goal}</p>
)}
<div className="initiative-portfolio-card-badges">
<ArchetypeBadge
archetypeKey={item.archetype_key}
archetypes={initiativeArchetypes}
/>
<StatusBadge kind="initiative" status={item.status} />
<PriorityBadge priority={item.priority} />
</div>
</Link>
))}
{sortedInitiatives.map((item, index) => {
const rankLabel = formatPortfolioRank(item.portfolio_rank ?? index)
return (
<article key={item.id} className="initiative-portfolio-card card">
{canManage && (
<div className="initiative-portfolio-card__reorder">
<ReorderControls
itemId={item.id}
canMoveUp={index > 0}
canMoveDown={index < sortedInitiatives.length - 1}
onMove={(direction) => handleMove(item.id, direction)}
busy={busy}
/>
</div>
)}
<Link
to={scopedPath('/control/status', { initiativeId: item.id })}
className="initiative-portfolio-card__link"
>
<div className="initiative-portfolio-card__head">
{rankLabel && (
<span className="initiative-portfolio-card__rank" title="Portfolio-Priorität">
{rankLabel}
</span>
)}
<h3 className="initiative-portfolio-card-title">{item.title}</h3>
</div>
{item.goal && (
<p className="initiative-portfolio-card-goal muted">{item.goal}</p>
)}
<div className="initiative-portfolio-card-badges">
<ArchetypeBadge
archetypeKey={item.archetype_key}
archetypes={initiativeArchetypes}
/>
<StatusBadge kind="initiative" status={item.status} />
<PriorityBadge priority={item.priority} />
</div>
</Link>
</article>
)
})}
</div>
)}
</WidgetCard>
@@ -7,6 +7,7 @@ import { ErrorState } from '../components/ErrorState.jsx'
import { LoadingState } from '../components/LoadingState.jsx'
import { WidgetCard } from '../components/WidgetCard.jsx'
import { actionPath, scopedPath } from '../utils/routes.js'
import { formatPortfolioRank } from '../utils/portfolioRank.js'
function NextActionList({ items, initiativeId, showInitiativeLink = true }) {
if (items.length === 0) {
@@ -43,6 +44,11 @@ function NextActionList({ items, initiativeId, showInitiativeLink = true }) {
>
<div className="list-item-main">
<span className="next-action-rank">{index + 1}</span>
{item.portfolio_rank != null && (
<span className="next-action-portfolio-rank muted" title="Portfolio-Priorität">
{formatPortfolioRank(item.portfolio_rank)}
</span>
)}
<span className="badge status-badge status-active next-action-kind">
{NEXT_ACTION_KIND_LABELS[item.kind] || item.kind}
</span>