Ziehe die Struktur enger und merke die Paperless-Auswahl, damit Kapitel ohne Extraeintrag zuklappbar bleiben.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
deb5d662fe
commit
f21c64a944
5 files changed
+97
-34
No files matched your search
@@ -445,6 +445,7 @@ export function MatterDetail() {
|
|||||||
nodes={nodes}
|
nodes={nodes}
|
||||||
chapters={chapters}
|
chapters={chapters}
|
||||||
chapterId={chapterId}
|
chapterId={chapterId}
|
||||||
|
allLabel=""
|
||||||
allCount={(record.bindings || []).length}
|
allCount={(record.bindings || []).length}
|
||||||
chapterHeading={`Kapitel in ${record.title}`}
|
chapterHeading={`Kapitel in ${record.title}`}
|
||||||
onChapter={chooseChapter}
|
onChapter={chooseChapter}
|
||||||
|
|||||||
@@ -135,17 +135,21 @@ function MailForm({ onSaved, onError }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function paperlessLabel(item) {
|
||||||
|
const dated = formatDate(item.document_on);
|
||||||
|
return dated !== "Ohne Datum" ? `${dated} · ${item.title}` : item.title;
|
||||||
|
}
|
||||||
|
|
||||||
export function PaperlessPicker({ context, placement, chapterId = "", chapterTitle = "", targetLabel = "", onDone, onInserted }) {
|
export function PaperlessPicker({ context, placement, chapterId = "", chapterTitle = "", targetLabel = "", onDone, onInserted }) {
|
||||||
const [query, setQuery] = useState("");
|
const [query, setQuery] = useState("");
|
||||||
const [items, setItems] = useState([]);
|
const [items, setItems] = useState([]);
|
||||||
const [picked, setPicked] = useState(() => new Set());
|
const [picked, setPicked] = useState(() => new Map());
|
||||||
const [pending, setPending] = useState(false);
|
const [pending, setPending] = useState(false);
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
|
|
||||||
async function search(event) {
|
async function search(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
setError("");
|
setError("");
|
||||||
setPicked(new Set());
|
|
||||||
try {
|
try {
|
||||||
const data = await api(`/api/v1/sources/paperless/documents?q=${encodeURIComponent(query)}`);
|
const data = await api(`/api/v1/sources/paperless/documents?q=${encodeURIComponent(query)}`);
|
||||||
setItems(data.items);
|
setItems(data.items);
|
||||||
@@ -154,17 +158,18 @@ export function PaperlessPicker({ context, placement, chapterId = "", chapterTit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggle(id) {
|
function toggle(item) {
|
||||||
|
const key = String(item.id);
|
||||||
setPicked((current) => {
|
setPicked((current) => {
|
||||||
const next = new Set(current);
|
const next = new Map(current);
|
||||||
if (next.has(id)) next.delete(id);
|
if (next.has(key)) next.delete(key);
|
||||||
else next.add(id);
|
else next.set(key, item);
|
||||||
return next;
|
return next;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function linkMany() {
|
async function linkMany() {
|
||||||
const chosen = items.filter((item) => picked.has(item.id));
|
const chosen = [...picked.values()];
|
||||||
if (!chosen.length) return;
|
if (!chosen.length) return;
|
||||||
setError("");
|
setError("");
|
||||||
setPending(true);
|
setPending(true);
|
||||||
@@ -191,7 +196,7 @@ export function PaperlessPicker({ context, placement, chapterId = "", chapterTit
|
|||||||
: {}),
|
: {}),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
inserted.push(item.id);
|
inserted.push(String(item.id));
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err.message);
|
setError(err.message);
|
||||||
@@ -199,9 +204,9 @@ export function PaperlessPicker({ context, placement, chapterId = "", chapterTit
|
|||||||
setPending(false);
|
setPending(false);
|
||||||
}
|
}
|
||||||
if (inserted.length) {
|
if (inserted.length) {
|
||||||
setItems((current) => current.filter((item) => !inserted.includes(item.id)));
|
setItems((current) => current.filter((item) => !inserted.includes(String(item.id))));
|
||||||
setPicked((current) => {
|
setPicked((current) => {
|
||||||
const next = new Set(current);
|
const next = new Map(current);
|
||||||
inserted.forEach((id) => next.delete(id));
|
inserted.forEach((id) => next.delete(id));
|
||||||
return next;
|
return next;
|
||||||
});
|
});
|
||||||
@@ -219,16 +224,22 @@ export function PaperlessPicker({ context, placement, chapterId = "", chapterTit
|
|||||||
</form>
|
</form>
|
||||||
<ErrorNote error={error} />
|
<ErrorNote error={error} />
|
||||||
<p className="muted">Die Verbindung richtest du unter <Link to="/sources">Quellen</Link> ein. Mehrere Treffer lassen sich zusammen einfügen.</p>
|
<p className="muted">Die Verbindung richtest du unter <Link to="/sources">Quellen</Link> ein. Mehrere Treffer lassen sich zusammen einfügen.</p>
|
||||||
{items.length ? (
|
{items.length || picked.size ? (
|
||||||
<button type="button" disabled={pending || picked.size === 0} onClick={linkMany}>
|
<button type="button" disabled={pending || picked.size === 0} onClick={linkMany}>
|
||||||
{picked.size ? `${picked.size} Belege einfügen` : "Belege auswählen"}
|
{picked.size ? `${picked.size} Belege einfügen` : "Belege auswählen"}
|
||||||
</button>
|
</button>
|
||||||
) : null}
|
) : null}
|
||||||
<div className="stack">
|
<div className="stack">
|
||||||
|
{[...picked.values()].filter((item) => !items.some((entry) => String(entry.id) === String(item.id))).map((item) => (
|
||||||
|
<label key={`held-${item.id}`} className="paperless-pick">
|
||||||
|
<input type="checkbox" checked disabled={pending} onChange={() => toggle(item)} />
|
||||||
|
<span>{paperlessLabel(item)}</span>
|
||||||
|
</label>
|
||||||
|
))}
|
||||||
{items.map((item) => (
|
{items.map((item) => (
|
||||||
<label key={item.id} className="paperless-pick">
|
<label key={item.id} className="paperless-pick">
|
||||||
<input type="checkbox" checked={picked.has(item.id)} disabled={pending} onChange={() => toggle(item.id)} />
|
<input type="checkbox" checked={picked.has(String(item.id))} disabled={pending} onChange={() => toggle(item)} />
|
||||||
<span>{formatDate(item.document_on) !== "Ohne Datum" ? `${formatDate(item.document_on)} · ` : ""}{item.title}</span>
|
<span>{paperlessLabel(item)}</span>
|
||||||
</label>
|
</label>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -640,6 +640,20 @@ function ChapterHeading({
|
|||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
{real ? (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="chapter-fold"
|
||||||
|
aria-expanded={expanded}
|
||||||
|
aria-label={expanded ? `${section.title} einklappen` : `${section.title} ausklappen`}
|
||||||
|
onClick={(event) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
onToggle();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{expanded ? "▾" : "▸"}
|
||||||
|
</button>
|
||||||
|
) : null}
|
||||||
<h3 className={`chapter-title${section.parentId ? " is-nested" : ""}`}>
|
<h3 className={`chapter-title${section.parentId ? " is-nested" : ""}`}>
|
||||||
{real ? <NavIcon name="chapter" /> : null}
|
{real ? <NavIcon name="chapter" /> : null}
|
||||||
<span>{section.title}</span>
|
<span>{section.title}</span>
|
||||||
|
|||||||
@@ -159,13 +159,15 @@ function scopeContents({ chapters, chapterId, allLabel, overview, onChapter, can
|
|||||||
onSelect: overview.onSelect,
|
onSelect: overview.onSelect,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
items.push({
|
if (allLabel) {
|
||||||
id: "all-contents",
|
items.push({
|
||||||
title: allLabel,
|
id: "all-contents",
|
||||||
kind: "Inhalte",
|
title: allLabel,
|
||||||
current: !chapterId && !overview?.active,
|
kind: "Inhalte",
|
||||||
onSelect: () => onChapter?.(""),
|
current: !chapterId && !overview?.active,
|
||||||
});
|
onSelect: () => onChapter?.(""),
|
||||||
|
});
|
||||||
|
}
|
||||||
const byParent = new Map();
|
const byParent = new Map();
|
||||||
chapters.forEach((chapter) => {
|
chapters.forEach((chapter) => {
|
||||||
const key = chapter.parent_chapter_id || "";
|
const key = chapter.parent_chapter_id || "";
|
||||||
@@ -192,16 +194,23 @@ function scopeContents({ chapters, chapterId, allLabel, overview, onChapter, can
|
|||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
function attachScope(nodes, extras) {
|
function attachScope(nodes, extras, onContainerSelect) {
|
||||||
return (nodes || []).map((node) => {
|
return (nodes || []).map((node) => {
|
||||||
const children = attachScope(node.children, extras);
|
const children = attachScope(node.children, extras, onContainerSelect);
|
||||||
if (!node.current) return { ...node, children };
|
if (!node.current) return { ...node, children };
|
||||||
return { ...node, children: [...extras, ...children] };
|
const nested = [...extras, ...children];
|
||||||
|
const childCurrent = Boolean(onContainerSelect) && nested.some(branchHasCurrent);
|
||||||
|
return {
|
||||||
|
...node,
|
||||||
|
current: onContainerSelect ? !childCurrent : node.current,
|
||||||
|
...(onContainerSelect ? { onSelect: onContainerSelect } : {}),
|
||||||
|
children: nested,
|
||||||
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function treeWithScope(nodes, extras) {
|
function treeWithScope(nodes, extras, onContainerSelect) {
|
||||||
const attached = attachScope(nodes, extras);
|
const attached = attachScope(nodes, extras, onContainerSelect);
|
||||||
if (attached.some(branchHasCurrent)) return attached;
|
if (attached.some(branchHasCurrent)) return attached;
|
||||||
return [...extras, ...attached];
|
return [...extras, ...attached];
|
||||||
}
|
}
|
||||||
@@ -224,7 +233,8 @@ export function StructureNavigator({
|
|||||||
}) {
|
}) {
|
||||||
const [opened, setOpened] = useState(() => new Set());
|
const [opened, setOpened] = useState(() => new Set());
|
||||||
const [closed, setClosed] = useState(() => new Set());
|
const [closed, setClosed] = useState(() => new Set());
|
||||||
const tree = treeWithScope(nodes, scopeContents({ chapters, chapterId, allLabel, overview, onChapter, canReorder, onMoveChapter }));
|
const extras = scopeContents({ chapters, chapterId, allLabel, overview, onChapter, canReorder, onMoveChapter });
|
||||||
|
const tree = treeWithScope(nodes, extras, allLabel ? null : () => onChapter?.(""));
|
||||||
|
|
||||||
function isOpen(node, unfold) {
|
function isOpen(node, unfold) {
|
||||||
if (!node.children?.length) return false;
|
if (!node.children?.length) return false;
|
||||||
|
|||||||
+35
-8
@@ -581,6 +581,24 @@ button.nav-item:active { transform: none; }
|
|||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
}
|
}
|
||||||
.chapter-plus svg { width: 18px; height: 18px; }
|
.chapter-plus svg { width: 18px; height: 18px; }
|
||||||
|
.chapter-fold {
|
||||||
|
width: 28px;
|
||||||
|
min-width: 28px;
|
||||||
|
height: 28px;
|
||||||
|
min-height: 28px;
|
||||||
|
padding: 0;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
flex: none;
|
||||||
|
border: 0;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: transparent;
|
||||||
|
color: var(--brand);
|
||||||
|
font-size: 16px;
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
.chapter-fold:hover, .chapter-fold:focus-visible { background: var(--accent-light); }
|
||||||
.chapter-menu, .record-tools, .chapter-move { display: inline-flex; gap: 0; flex: 0 0 auto; align-items: center; }
|
.chapter-menu, .record-tools, .chapter-move { display: inline-flex; gap: 0; flex: 0 0 auto; align-items: center; }
|
||||||
.icon-button--compact { width: 32px; min-width: 32px; height: 32px; }
|
.icon-button--compact { width: 32px; min-width: 32px; height: 32px; }
|
||||||
.icon-button--compact svg { width: 16px; height: 16px; }
|
.icon-button--compact svg { width: 16px; height: 16px; }
|
||||||
@@ -1256,25 +1274,34 @@ button.hierarchy__row { width: 100%; min-height: 34px; padding: 6px 8px; border:
|
|||||||
}
|
}
|
||||||
.chapter-link__move { display: flex; gap: 2px; flex: none; align-items: center; }
|
.chapter-link__move { display: flex; gap: 2px; flex: none; align-items: center; }
|
||||||
.chapter-link__move button {
|
.chapter-link__move button {
|
||||||
min-height: 44px;
|
min-height: 28px;
|
||||||
width: 44px;
|
width: 28px;
|
||||||
height: 44px;
|
height: 28px;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
font-size: 16px;
|
font-size: 14px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
color: var(--text3);
|
color: var(--text3);
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
}
|
}
|
||||||
.nav-tree__toggle {
|
.nav-tree__toggle {
|
||||||
width: 44px;
|
width: 22px;
|
||||||
min-width: 44px;
|
min-width: 22px;
|
||||||
height: 44px;
|
height: 28px;
|
||||||
|
min-height: 28px;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
border: 0;
|
border: 0;
|
||||||
|
border-radius: 4px;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
color: var(--text2);
|
color: var(--text2);
|
||||||
font-size: 16px;
|
font-size: 13px;
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
.structure .chapter-add {
|
||||||
|
min-height: 32px;
|
||||||
|
padding: 4px 10px;
|
||||||
|
margin-top: 6px;
|
||||||
|
font-size: 13px;
|
||||||
}
|
}
|
||||||
.nav-tree__toggle.is-empty { visibility: hidden; }
|
.nav-tree__toggle.is-empty { visibility: hidden; }
|
||||||
.nav-tree__kind {
|
.nav-tree__kind {
|
||||||
|
|||||||
Reference in new issue
Block a user