fix: keep modal rows compact and label project by name

This commit is contained in:
Saberlve 2026-04-15 12:37:59 +08:00
parent ec32d591df
commit a117a29b0d
2 changed files with 17 additions and 4 deletions

View File

@ -400,6 +400,7 @@
const state = { const state = {
projects: [], projects: [],
currentProjectId: null, currentProjectId: null,
currentProjectName: null,
currentCards: [], currentCards: [],
collectionTree: [], collectionTree: [],
isImportModalOpen: false, isImportModalOpen: false,
@ -582,10 +583,21 @@
elements.selectedCount.textContent = `已选 ${state.selectedItemKeys.size} 篇`; elements.selectedCount.textContent = `已选 ${state.selectedItemKeys.size} 篇`;
} }
function syncCurrentProjectLabels() {
if (state.currentProjectName) {
const label = `当前项目:${state.currentProjectName}`;
elements.currentProjectLabel.textContent = label;
elements.importModalProjectLabel.textContent = label;
return;
}
elements.currentProjectLabel.textContent = "当前未选择项目。";
elements.importModalProjectLabel.textContent = "未选择项目";
}
function updateImportActionState() { function updateImportActionState() {
const hasProject = Boolean(state.currentProjectId); const hasProject = Boolean(state.currentProjectId);
const hasSelection = state.selectedItemKeys.size > 0; const hasSelection = state.selectedItemKeys.size > 0;
elements.importModalProjectLabel.textContent = hasProject ? `当前项目:${state.currentProjectId}` : "未选择项目"; syncCurrentProjectLabels();
elements.importSelectedItemsButton.disabled = !hasProject || !hasSelection; elements.importSelectedItemsButton.disabled = !hasProject || !hasSelection;
elements.importSelectedItemsButton.title = !hasProject ? "请先选择项目" : (hasSelection ? "" : "请先选择文献"); elements.importSelectedItemsButton.title = !hasProject ? "请先选择项目" : (hasSelection ? "" : "请先选择文献");
elements.selectDescendantsButton.disabled = !state.visibleCollectionItems.length; elements.selectDescendantsButton.disabled = !state.visibleCollectionItems.length;
@ -709,7 +721,6 @@
<div> <div>
<strong>${item.title}</strong> <strong>${item.title}</strong>
<div class="meta">${item.item_key} · ${item.year || "-"} · ${item.item_type || "-"}</div> <div class="meta">${item.item_key} · ${item.year || "-"} · ${item.item_type || "-"}</div>
<p>${item.abstract || "暂无摘要"}</p>
</div> </div>
`; `;
row.querySelector("input").addEventListener("change", () => toggleItemSelection(item.item_key)); row.querySelector("input").addEventListener("change", () => toggleItemSelection(item.item_key));
@ -843,19 +854,19 @@
if (!state.currentProjectId && projects.length) { if (!state.currentProjectId && projects.length) {
state.currentProjectId = projects[0].id; state.currentProjectId = projects[0].id;
} }
state.currentProjectName = state.projects.find((project) => project.id === state.currentProjectId)?.name || null;
renderProjects(); renderProjects();
updateImportActionState(); updateImportActionState();
if (state.currentProjectId) { if (state.currentProjectId) {
await selectProject(state.currentProjectId, false); await selectProject(state.currentProjectId, false);
return; return;
} }
elements.currentProjectLabel.textContent = "当前未选择项目。";
renderCards([]); renderCards([]);
} }
async function selectProject(projectId, rerender = true) { async function selectProject(projectId, rerender = true) {
state.currentProjectId = projectId; state.currentProjectId = projectId;
elements.currentProjectLabel.textContent = `当前项目:${projectId}`; state.currentProjectName = state.projects.find((project) => project.id === projectId)?.name || projectId;
updateImportActionState(); updateImportActionState();
if (rerender) { if (rerender) {
renderProjects(); renderProjects();

View File

@ -41,7 +41,9 @@ def test_index_contains_import_modal_controls(tmp_path) -> None:
assert 'id="item-preview-popover"' in html assert 'id="item-preview-popover"' in html
assert 'const ABSTRACT_PREVIEW_DELAY_MS = 3000;' in html assert 'const ABSTRACT_PREVIEW_DELAY_MS = 3000;' in html
assert 'isImportModalOpen: false' in html assert 'isImportModalOpen: false' in html
assert "currentProjectName: null" in html
assert "function openImportModal()" in html assert "function openImportModal()" in html
assert "function closeImportModal()" in html assert "function closeImportModal()" in html
assert "function updateImportActionState()" in html assert "function updateImportActionState()" in html
assert 'document.body.classList.toggle("modal-open"' in html assert 'document.body.classList.toggle("modal-open"' in html
assert "${item.abstract" not in html