[CLAUDE] FE-Admin+Domain+Infra+App: Workflows tab → sidebar menu items
All checks were successful
Deploy SOLUTION_ERP / build-deploy (push) Successful in 2m37s

User request: 7 tab trong /system/workflows thành menu items riêng.

Domain:
- MenuKeys.WorkflowTypeLeaf(code) helper — `Wf_<TypeCode>` pattern

Infrastructure (DbInitializer):
- Seed 7 leaves dưới Workflows group (order 95..101), label matches
  ContractType (HĐ Thầu phụ / Giao khoán / NCC / Dịch vụ / Mua bán /
  Nguyên tắc NCC / Nguyên tắc Dịch vụ). Idempotent.

Application (GetMyMenuTreeQuery):
- Generalized inherit-perm logic: descendants of Contracts AND Workflows
  inherit parent CanRead flag. Single Workflows.Read grant → all 7
  Wf_* leaves visible; no per-leaf permission rows needed.

FE Layout (admin):
- resolvePath: Wf_<Code> → /system/workflows/<code>. Ct_* still hidden
  on admin side.

FE App.tsx:
- New route /system/workflows/:typeCode?

FE WorkflowsPage:
- Removed horizontal tab bar; type selection now comes từ URL param.
- Landing view (no param): 3-col grid card per type với active version
  badge — so admin có visual overview khi click top-level Workflows
  group without selecting a type.
- TYPE_CODE_TO_INT map drives URL→int conversion.

Result: click `Quy trình HĐ > HĐ Mua bán` trong sidebar → opens
/system/workflows/MuaBan directly với designer scoped.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
pqhuy1987
2026-04-22 09:49:42 +07:00
parent 29dbac2051
commit f216169039
6 changed files with 90 additions and 42 deletions

View File

@ -37,6 +37,7 @@ function App() {
<Route path="/system/users" element={<UsersPage />} /> <Route path="/system/users" element={<UsersPage />} />
<Route path="/system/permissions" element={<PermissionsPage />} /> <Route path="/system/permissions" element={<PermissionsPage />} />
<Route path="/system/workflows" element={<WorkflowsPage />} /> <Route path="/system/workflows" element={<WorkflowsPage />} />
<Route path="/system/workflows/:typeCode" element={<WorkflowsPage />} />
<Route path="/forms" element={<FormsPage />} /> <Route path="/forms" element={<FormsPage />} />
<Route path="/contracts" element={<ContractsListPage />} /> <Route path="/contracts" element={<ContractsListPage />} />
<Route path="/contracts/new" element={<ContractCreatePage />} /> <Route path="/contracts/new" element={<ContractCreatePage />} />

View File

@ -52,11 +52,19 @@ function resolvePath(key: string): string | null {
if (action === 'Create') return `/contracts/new?type=${typeInt}` if (action === 'Create') return `/contracts/new?type=${typeInt}`
if (action === 'Pending') return `/contracts?type=${typeInt}&pendingMe=1` if (action === 'Pending') return `/contracts?type=${typeInt}&pendingMe=1`
} }
// Workflow admin per ContractType: Wf_<Code> → /system/workflows/<code>
const wfMatch = key.match(/^Wf_(.+)$/)
if (wfMatch) {
const code = wfMatch[1]
if (TYPE_CODE_TO_INT[code]) return `/system/workflows/${code}`
}
return null return null
} }
// Admin side: hide the per-ContractType submenu (Ct_*) — that's a user-app // Admin side: hide the per-ContractType contract submenu (Ct_*) — that's a
// concern. Admin manages workflow config via /system/workflows instead. // user-app concern. Keep Wf_* workflow-admin leaves.
function isAdminHidden(key: string): boolean { function isAdminHidden(key: string): boolean {
return key.startsWith('Ct_') return key.startsWith('Ct_')
} }

View File

@ -1,4 +1,5 @@
import { useMemo, useState, type FormEvent } from 'react' import { useMemo, useState, type FormEvent } from 'react'
import { useParams } from 'react-router-dom'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { GitBranch, Plus, Trash2, CheckCircle2, Info, History } from 'lucide-react' import { GitBranch, Plus, Trash2, CheckCircle2, Info, History } from 'lucide-react'
import { toast } from 'sonner' import { toast } from 'sonner'
@ -63,16 +64,31 @@ function copyFromDefinition(d: DefinitionDto): EditStep[] {
// ===== Page ===== // ===== Page =====
// Map URL type code → int. Mirror Wf_<Code> menu key.
const TYPE_CODE_TO_INT: Record<string, number> = {
ThauPhu: 1,
GiaoKhoan: 2,
NhaCungCap: 3,
DichVu: 4,
MuaBan: 5,
NguyenTacNcc: 6,
NguyenTacDv: 7,
}
export function WorkflowsPage() { export function WorkflowsPage() {
const qc = useQueryClient() const qc = useQueryClient()
const { typeCode } = useParams<{ typeCode?: string }>()
const overview = useQuery({ const overview = useQuery({
queryKey: ['workflow-overview'], queryKey: ['workflow-overview'],
queryFn: async () => (await api.get<{ types: TypeSummaryDto[] }>('/workflows')).data, queryFn: async () => (await api.get<{ types: TypeSummaryDto[] }>('/workflows')).data,
}) })
const [activeType, setActiveType] = useState<number | null>(null) // URL drives which type to show. `/system/workflows` (no param) → show
const tab = activeType ?? overview.data?.types[0]?.contractType ?? 1 // landing hint to pick from sidebar; `/system/workflows/<code>` → open that.
const currentType = overview.data?.types.find(t => t.contractType === tab) const selectedTypeInt = typeCode ? TYPE_CODE_TO_INT[typeCode] : null
const currentType = selectedTypeInt
? overview.data?.types.find(t => t.contractType === selectedTypeInt)
: null
return ( return (
<div className="p-6"> <div className="p-6">
@ -80,38 +96,41 @@ export function WorkflowsPage() {
title={ title={
<span className="flex items-center gap-2"> <span className="flex items-center gap-2">
<GitBranch className="h-5 w-5" /> <GitBranch className="h-5 w-5" />
Quy trình duyệt hợp đng {currentType ? `Quy trình: ${currentType.contractTypeLabel}` : 'Quy trình duyệt hợp đồng'}
</span> </span>
} }
description="Mỗi loại HĐ có quy trình riêng, hỗ trợ versioning. Tạo version mới → HĐ tương lai chạy theo. HĐ cũ vẫn giữ quy trình cũ." description={
currentType
? 'Tạo version mới → HĐ tương lai dùng. HĐ đã tạo giữ version cũ (pinned lúc tạo).'
: 'Chọn loại HĐ từ menu bên trái để xem + chỉnh quy trình duyệt.'
}
/> />
{/* Tabs */} {overview.isLoading && <div className="text-sm text-slate-500">Đang tải</div>}
{overview.data && (
<div className="mb-5 flex gap-1 overflow-x-auto border-b border-slate-200"> {/* Landing: no type picked yet */}
{overview.data && !currentType && (
<div className="grid grid-cols-1 gap-3 md:grid-cols-2 lg:grid-cols-3">
{overview.data.types.map(t => ( {overview.data.types.map(t => (
<button <div key={t.contractType} className="rounded-xl border border-slate-200 bg-white p-4 shadow-sm">
key={t.contractType} <div className="flex items-center justify-between">
onClick={() => setActiveType(t.contractType)} <h3 className="text-sm font-semibold text-slate-800">{t.contractTypeLabel}</h3>
className={`shrink-0 border-b-2 px-4 py-2 text-sm font-medium transition ${ {t.active && (
tab === t.contractType <span className="rounded bg-brand-50 px-2 py-0.5 font-mono text-[10px] font-medium text-brand-700">
? 'border-brand-600 text-brand-700' {t.active.code} v{String(t.active.version).padStart(2, '0')}
: 'border-transparent text-slate-500 hover:text-slate-800' </span>
}`} )}
> </div>
{t.contractTypeLabel} <div className="mt-2 text-xs text-slate-500">
{t.active && ( {t.active
<span className="ml-2 rounded bg-brand-50 px-1.5 py-0.5 font-mono text-[10px] text-brand-700"> ? `${t.active.steps.length} bước · ${t.history.length} version${t.history.length > 1 ? 's' : ''}`
v{String(t.active.version).padStart(2, '0')} : 'Chưa có quy trình'}
</span> </div>
)} </div>
</button>
))} ))}
</div> </div>
)} )}
{overview.isLoading && <div className="text-sm text-slate-500">Đang tải</div>}
{currentType && <TypePanel type={currentType} onSaved={() => qc.invalidateQueries({ queryKey: ['workflow-overview'] })} />} {currentType && <TypePanel type={currentType} onSaved={() => qc.invalidateQueries({ queryKey: ['workflow-overview'] })} />}
</div> </div>
) )

View File

@ -46,31 +46,38 @@ public class GetMyMenuTreeQueryHandler(
Update: g.Any(p => p.CanUpdate), Update: g.Any(p => p.CanUpdate),
Delete: g.Any(p => p.CanDelete))); Delete: g.Any(p => p.CanDelete)));
// Build tree. Children of `Contracts` (type submenu) inherit parent's // Build tree. Descendants of certain roots inherit parent perms so
// permission so we don't need per-subitem permission rows. This keeps // we don't add per-subitem permission rows for pure-navigation menus.
// the permission matrix clean while allowing deep menu structures for // Keys: `Contracts` (Ct_* subitems) and `Workflows` (Wf_* subitems).
// pure navigation. (bool Read, bool Create, bool Update, bool Delete) GetFlags(string key) =>
var (contractsRead, contractsCreate, contractsUpdate, contractsDelete) = resolved.TryGetValue(key, out var f) ? f : (false, false, false, false);
resolved.TryGetValue(MenuKeys.Contracts, out var cf) ? cf : (false, false, false, false);
List<MenuNodeDto> BuildChildren(string? parentKey, bool inheritContractsPerm) => menus var contractsFlags = GetFlags(MenuKeys.Contracts);
var workflowsFlags = GetFlags(MenuKeys.Workflows);
List<MenuNodeDto> BuildChildren(string? parentKey, string? inheritFromKey) => menus
.Where(m => m.ParentKey == parentKey) .Where(m => m.ParentKey == parentKey)
.Select(m => .Select(m =>
{ {
var flags = resolved.TryGetValue(m.Key, out var f) ? f : (false, false, false, false); var flags = resolved.TryGetValue(m.Key, out var f) ? f : (false, false, false, false);
// If this node is a descendant of Contracts and has no explicit if (inheritFromKey is not null && !resolved.ContainsKey(m.Key))
// perms, take parent Contracts perms. {
if (inheritContractsPerm && !resolved.ContainsKey(m.Key)) flags = inheritFromKey == MenuKeys.Contracts ? contractsFlags : workflowsFlags;
flags = (contractsRead, contractsCreate, contractsUpdate, contractsDelete); }
// Propagate inheritance downward from Contracts/Workflows roots
var nextInherit = inheritFromKey
?? (m.Key == MenuKeys.Contracts ? MenuKeys.Contracts
: m.Key == MenuKeys.Workflows ? MenuKeys.Workflows
: null);
var childInherits = inheritContractsPerm || m.Key == MenuKeys.Contracts;
return new MenuNodeDto(m.Key, m.Label, m.ParentKey, m.Order, m.Icon, return new MenuNodeDto(m.Key, m.Label, m.ParentKey, m.Order, m.Icon,
flags.Item1, flags.Item2, flags.Item3, flags.Item4, flags.Item1, flags.Item2, flags.Item3, flags.Item4,
BuildChildren(m.Key, childInherits)); BuildChildren(m.Key, nextInherit));
}) })
.ToList(); .ToList();
var tree = BuildChildren(null, inheritContractsPerm: false); var tree = BuildChildren(null, inheritFromKey: null);
// Filter: chỉ trả về node có CanRead=true (hoặc có child CanRead=true) // Filter: chỉ trả về node có CanRead=true (hoặc có child CanRead=true)
static bool HasAccess(MenuNodeDto n) => n.CanRead || n.Children.Any(HasAccess); static bool HasAccess(MenuNodeDto n) => n.CanRead || n.Children.Any(HasAccess);

View File

@ -31,6 +31,10 @@ public static class MenuKeys
public static string ContractTypeCreate(string typeCode) => $"Ct_{typeCode}_Create"; public static string ContractTypeCreate(string typeCode) => $"Ct_{typeCode}_Create";
public static string ContractTypePending(string typeCode) => $"Ct_{typeCode}_Pending"; public static string ContractTypePending(string typeCode) => $"Ct_{typeCode}_Pending";
// Workflow admin per ContractType — sub-menu dưới `Workflows`, click leaf
// → mở /system/workflows/{typeCode} (filter theo type thay vì tab).
public static string WorkflowTypeLeaf(string typeCode) => $"Wf_{typeCode}";
public static readonly string[] All = public static readonly string[] All =
[ [
Dashboard, Dashboard,

View File

@ -207,6 +207,15 @@ public static class DbInitializer
tree.Add((MenuKeys.ContractTypePending(code),"Duyệt", MenuKeys.ContractTypeGroup(code), order++, "CheckCircle2")); tree.Add((MenuKeys.ContractTypePending(code),"Duyệt", MenuKeys.ContractTypeGroup(code), order++, "CheckCircle2"));
} }
// Per-type workflow admin leaves dưới `Workflows` — mỗi loại là 1
// menu item, click vào → mở designer scoped cho loại đó.
var wfOrder = 95;
foreach (var code in MenuKeys.ContractTypeCodes)
{
var label = typeLabels.GetValueOrDefault(code, code);
tree.Add((MenuKeys.WorkflowTypeLeaf(code), label, MenuKeys.Workflows, wfOrder++, "FileText"));
}
var existingKeys = await db.MenuItems.Select(m => m.Key).ToListAsync(); var existingKeys = await db.MenuItems.Select(m => m.Key).ToListAsync();
var added = 0; var added = 0;
foreach (var (key, label, parent, o, icon) in tree) foreach (var (key, label, parent, o, icon) in tree)