Commit 97b9b7d3 authored by drigle's avatar drigle

fix: derive material category tabs from subject config

parent a4933ad8
...@@ -119,7 +119,7 @@ ...@@ -119,7 +119,7 @@
- 备注:匹配 `metadata.remark` - 备注:匹配 `metadata.remark`
- 是否涉密:匹配 `metadata.is_confidential` - 是否涉密:匹配 `metadata.is_confidential`
- 是否审计部材料:匹配 `metadata.is_audit_dept_material` - 是否审计部材料:匹配 `metadata.is_audit_dept_material`
3. 页面提供“全部文件”与“分类快捷标签”两种浏览方式 3. 页面提供“全部文件”与“分类快捷标签”两种浏览方式;分类标签按 Subject 字段 `archive_category.settings.options` 配置展示,顺序为“全部文件”“未分类”、其余配置分类,未分类始终紧邻全部文件
4. 列表固定每页 10 条,不提供每页条数切换,避免分页密度在不同终端间漂移 4. 列表固定每页 10 条,不提供每页条数切换,避免分页密度在不同终端间漂移
5. 用户通过上一页 / 下一页进行分页浏览 5. 用户通过上一页 / 下一页进行分页浏览
6. 在“全部文件”视图下,直接以列表展示当前筛选条件下的全部材料 6. 在“全部文件”视图下,直接以列表展示当前筛选条件下的全部材料
......
...@@ -366,27 +366,6 @@ function sortMaterialsByTime(materials) { ...@@ -366,27 +366,6 @@ function sortMaterialsByTime(materials) {
); );
} }
function mergeCategoryOptions(previousOptions, nextMaterials) {
const optionMap = new Map(
(previousOptions || []).map((item) => [item.key, item]),
);
(nextMaterials || []).forEach((item) => {
const key = item.archiveCategory || UNCATEGORIZED_CATEGORY_LABEL;
const current = optionMap.get(key);
optionMap.set(key, {
key,
label: key,
count: current ? current.count + 1 : 1,
icon: FolderIcon,
});
});
return [...optionMap.values()].sort(
(left, right) => right.count - left.count,
);
}
export default function ResourceBookingPage() { export default function ResourceBookingPage() {
const userInfo = useContext(UserContext); const userInfo = useContext(UserContext);
const [materialSearchForm, setMaterialSearchForm] = useState( const [materialSearchForm, setMaterialSearchForm] = useState(
...@@ -399,7 +378,6 @@ export default function ResourceBookingPage() { ...@@ -399,7 +378,6 @@ export default function ResourceBookingPage() {
const [activeCategory, setActiveCategory] = useState(ALL_CATEGORY_KEY); const [activeCategory, setActiveCategory] = useState(ALL_CATEGORY_KEY);
const [pageSize, setPageSize] = useState(DEFAULT_PAGE_SIZE); const [pageSize, setPageSize] = useState(DEFAULT_PAGE_SIZE);
const [page, setPage] = useState(0); const [page, setPage] = useState(0);
const [categoryOptions, setCategoryOptions] = useState([]);
const [materials, setMaterials] = useState([]); const [materials, setMaterials] = useState([]);
const [dashboard, setDashboard] = useState(() => buildMaterialDashboard([])); const [dashboard, setDashboard] = useState(() => buildMaterialDashboard([]));
const [activeMaterialId, setActiveMaterialId] = useState(""); const [activeMaterialId, setActiveMaterialId] = useState("");
...@@ -502,11 +480,6 @@ export default function ResourceBookingPage() { ...@@ -502,11 +480,6 @@ export default function ResourceBookingPage() {
totalCount: result.total || 0, totalCount: result.total || 0,
}), }),
); );
setCategoryOptions((prev) =>
activeCategory === ALL_CATEGORY_KEY
? mergeCategoryOptions([], result.materials || [])
: prev,
);
setTotal(result.total || 0); setTotal(result.total || 0);
setError(result.error || ""); setError(result.error || "");
setLoading(false); setLoading(false);
...@@ -543,21 +516,31 @@ export default function ResourceBookingPage() { ...@@ -543,21 +516,31 @@ export default function ResourceBookingPage() {
); );
}, [dashboard.sourceSuggestions]); }, [dashboard.sourceSuggestions]);
const categoryTabs = useMemo( const categoryTabs = useMemo(
() => [ () => {
{ const categorizedTabs = archiveCategoryOptions
key: ALL_CATEGORY_KEY, .filter((item) => item.value !== UNCATEGORIZED_CATEGORY_LABEL)
label: "全部文件", .map((item) => ({
count: materials.length, key: item.value,
icon: FolderIcon, label: item.label,
}, icon: FolderIcon,
...categoryOptions.map((item) => ({ }));
key: item.key,
label: item.label, return [
count: item.count, {
icon: item.icon, key: ALL_CATEGORY_KEY,
})), label: "全部文件",
], count: materials.length,
[categoryOptions, materials.length], icon: FolderIcon,
},
{
key: UNCATEGORIZED_CATEGORY_LABEL,
label: UNCATEGORIZED_CATEGORY_LABEL,
icon: FolderIcon,
},
...categorizedTabs,
];
},
[archiveCategoryOptions, materials.length],
); );
useEffect(() => { useEffect(() => {
...@@ -782,11 +765,6 @@ export default function ResourceBookingPage() { ...@@ -782,11 +765,6 @@ export default function ResourceBookingPage() {
totalCount: result.total || 0, totalCount: result.total || 0,
}), }),
); );
setCategoryOptions((prev) =>
activeCategory === ALL_CATEGORY_KEY
? mergeCategoryOptions([], result.materials || [])
: prev,
);
setTotal(result.total || 0); setTotal(result.total || 0);
setError(result.error || ""); setError(result.error || "");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment