Add hierarchical role permission controls

Make parent menus gate child permissions and cascade select or clear actions through descendants. Update role detail rendering for nested menus and the revised API shape, with related RBAC UI and sidebar adjustments.
This commit is contained in:
Ichsan Kurniawan
2026-11-05 21:59:25 +07:00
parent 66b23eecca
commit b149903b2e
10 changed files with 304 additions and 98 deletions
@@ -155,7 +155,7 @@ const ComponentPermissionPage: FC<Props> = ({ data }) => {
<div className="flex flex-1 items-center space-x-2 w-full sm:w-auto">
<Input
placeholder="Search permissions..."
className="h-8 w-full sm:w-64"
className="h-8 w-full sm:w-64 md:w-72"
value={searchText}
onChange={handleSearch}
/>
+3 -3
View File
@@ -174,7 +174,7 @@ const ComponentMenuPage: FC<Props> = ({ data }) => {
},
},
{
title: 'Permissions',
title: 'Permissions List',
dataIndex: 'action',
key: 'action',
render: (actions?: string[]) => {
@@ -182,7 +182,7 @@ const ComponentMenuPage: FC<Props> = ({ data }) => {
return <span className="text-xs text-muted-foreground italic">No permissions assigned</span>;
}
return (
<div className="flex flex-wrap gap-1 max-w-md">
<div className="flex flex-wrap gap-x-1 gap-y-1.5 max-w-md">
{actions.map((act) => (
<RbacBadge key={act} permission={act} size="sm" />
))}
@@ -262,7 +262,7 @@ const ComponentMenuPage: FC<Props> = ({ data }) => {
<div className="flex flex-1 items-center space-x-2 w-full sm:w-auto">
<Input
placeholder="Search menu, path, or permissions..."
className="h-8 w-full sm:w-64"
className="h-8 w-full sm:w-64 md:w-72"
value={searchText}
onChange={handleSearch}
/>
+70 -31
View File
@@ -4,8 +4,9 @@ import Link from 'next/link';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import fetchData from '@/lib/fetchData';
import { Button } from '@/components/ui/button';
import { type IRole, type IRoleDetail } from '../component/type';
import { type IRole } from '../component/type';
import RolePermissionRow from "../component/role-permission-row";
import { PencilLine } from 'lucide-react';
export const dynamic = 'force-dynamic';
@@ -41,18 +42,54 @@ const UserRoleDetailPage: FC<Props> = async ({ params }) => {
const { id } = await params;
const data: IRole | undefined = await getRoleData(id);
const isAdminAllowed = Boolean(data?.allow_admin_panel ?? data?.allow_admin);
const roleDetails: IRoleDetail[] = Array.isArray(data?.role_detail)
? data.role_detail
: Array.isArray(data?.privilege)
? data.privilege.map((p: any) => ({
menu_id: p.menu_id || p.id,
menu_name: p.menu_name || p.name,
menu_path: p.menu_path || p.path || '#',
is_admin_menu: Boolean(p.is_admin_menu ?? p.is_menu_admin),
action: Array.isArray(p.action) ? p.action : [],
}))
: [];
const isAdminAllowed = Boolean(data?.allow_admin_panel);
const rawList = Array.isArray(data?.role_detail) ? data.role_detail : [];
const normalizedDetails = rawList.map((item: any) => {
const menuObj = item.menu || {};
return {
pemrission_id: item.id,
id: menuObj.id,
name: menuObj.name ?? '',
path_url: menuObj.path_url ?? '#',
icon: menuObj.icon ?? '',
is_admin_menu: Boolean(menuObj.is_admin_menu),
menu_parent_id: menuObj.menu_parent_id ?? null,
action: Array.isArray(item.action) ? item.action : [],
};
});
// Build hierarchy map so parent-child relationships are preserved with indentation
const detailMap = new Map<number, any>();
normalizedDetails.forEach(d => { if (d.id !== undefined) detailMap.set(d.id, d); });
const getLevel = (item: any): number => {
if (!item.menu_parent_id || !detailMap.has(item.menu_parent_id)) return 0;
return getLevel(detailMap.get(item.menu_parent_id)) + 1;
};
// Arrange items hierarchically: root menus first, followed immediately by their children
function sortHierarchical(items: any[]): any[] {
const roots = items.filter(i => !i.menu_parent_id || !detailMap.has(i.menu_parent_id));
const result: any[] = [];
function appendNode(node: any) {
result.push({ ...node, level: getLevel(node) });
const children = items.filter(c => c.menu_parent_id === node.id);
children.forEach(appendNode);
}
roots.forEach(appendNode);
items.forEach(item => {
if (!result.some(r => r.id === item.id)) {
result.push({ ...item, level: getLevel(item) });
}
});
return result;
}
const orderedDetails = sortHierarchical(normalizedDetails);
return (
<div className="flex flex-col space-y-6 pb-12">
@@ -74,14 +111,14 @@ const UserRoleDetailPage: FC<Props> = async ({ params }) => {
</div>
<Link href={`/admin/rbac/user-role/edit/${id}`}>
<Button className="bg-his hover:bg-his/90 text-white font-medium">
<i className="ti ti-edit mr-2 text-base" /> Edit Role
<PencilLine /> Edit Role
</Button>
</Link>
</CardHeader>
<CardContent>
<div className="grid grid-cols-1 md:grid-cols-2 gap-6 p-4 rounded-lg bg-zinc-50/60 dark:bg-zinc-900/40 border border-zinc-200 dark:border-zinc-800">
<div className="grid grid-cols-1 md:grid-cols-2 gap-6 p-4 md:p-6 rounded-lg bg-zinc-50/60 dark:bg-zinc-900/40 border border-zinc-200 dark:border-zinc-800">
<div className="flex flex-col space-y-1">
<span className="text-xs text-muted-foreground uppercase tracking-wider font-semibold">
<span className="text-xs text-muted-foreground tracking-wider font-semibold">
Role Code
</span>
<span className="font-mono font-bold text-sm text-zinc-900 dark:text-zinc-100">
@@ -89,22 +126,22 @@ const UserRoleDetailPage: FC<Props> = async ({ params }) => {
</span>
</div>
<div className="flex flex-col space-y-1">
<span className="text-xs text-muted-foreground uppercase tracking-wider font-semibold">
<span className="text-xs text-muted-foreground tracking-wider font-semibold">
Role Name
</span>
<span className="font-bold text-sm text-zinc-900 dark:text-zinc-100 uppercase">
<span className="font-bold text-sm text-zinc-900 dark:text-zinc-100">
{data?.name || '-'}
</span>
</div>
<div className="flex flex-col space-y-1">
<span className="text-xs text-muted-foreground uppercase tracking-wider font-semibold">
<span className="text-xs text-muted-foreground tracking-wider font-semibold">
Admin Panel Access
</span>
<div>
{isAdminAllowed ? (
<span className="inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full text-xs font-semibold bg-emerald-500/10 text-emerald-600 border border-emerald-500/20 dark:bg-emerald-500/20 dark:text-emerald-300">
<span className="w-1.5 h-1.5 rounded-full bg-emerald-500" />
Web CMS & Admin Panel
Admin Panel
</span>
) : (
<span className="inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full text-xs font-semibold bg-zinc-500/10 text-zinc-500 border border-zinc-500/20 dark:bg-zinc-500/20 dark:text-zinc-400">
@@ -115,18 +152,18 @@ const UserRoleDetailPage: FC<Props> = async ({ params }) => {
</div>
</div>
<div className="flex flex-col space-y-1">
<span className="text-xs text-muted-foreground uppercase tracking-wider font-semibold">
<span className="text-xs text-muted-foreground tracking-wider font-semibold">
Status
</span>
<div>
<span className="inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full text-xs font-semibold bg-green-500/10 text-green-600 border border-green-500/20">
<span className="w-1.5 h-1.5 rounded-full bg-green-500" />
{data?.status?.name || 'Active'}
{data?.status?.name}
</span>
</div>
</div>
<div className="flex flex-col space-y-1 md:col-span-2">
<span className="text-xs text-muted-foreground uppercase tracking-wider font-semibold">
<span className="text-xs text-muted-foreground tracking-wider font-semibold">
Description
</span>
<span className="text-sm text-zinc-700 dark:text-zinc-300">
@@ -144,23 +181,25 @@ const UserRoleDetailPage: FC<Props> = async ({ params }) => {
<div className="flex items-center gap-2">
<i className="ti ti-checklist text-lg text-his" />
<CardTitle className="text-base font-semibold">
Authorized Menu Permissions ({roleDetails.length} Menus Allowed)
Authorized Menu Permissions ({orderedDetails.length} Menus Allowed)
</CardTitle>
</div>
</div>
</CardHeader>
<CardContent className="p-0">
{roleDetails.length > 0 ? (
{orderedDetails.length > 0 ? (
<div className="divide-y divide-zinc-200/80 dark:divide-zinc-800/80">
{roleDetails.map((detail, idx) => (
{orderedDetails.map((detail, idx) => (
<RolePermissionRow
key={detail.menu_id || idx}
key={detail.id || idx}
node={{
id: detail.menu_id,
name: detail.menu_name,
path_url: detail.menu_path,
id: detail.id!,
name: detail.name!,
path_url: detail.path_url,
icon: detail.icon,
is_menu_admin: detail.is_admin_menu,
level: 0,
level: detail.level,
hasChildren: normalizedDetails.some(c => c.menu_parent_id === detail.id),
action: detail.action,
}}
mode="readonly"
@@ -14,6 +14,8 @@ export interface IMenuPermissionTreeProps {
onPermissionToggle: (menuId: number, actionName: string, checked: boolean) => void;
onMenuSelectAll: (menuId: number, allActions: string[]) => void;
onMenuClearAll: (menuId: number) => void;
onBatchSelectAll?: (updates: Record<number, string[]>) => void;
onBatchClearAll?: (menuIds: number[]) => void;
}
interface TreeNode extends IMenu {
@@ -52,6 +54,8 @@ export const MenuPermissionTree: FC<IMenuPermissionTreeProps> = ({
onPermissionToggle,
onMenuSelectAll,
onMenuClearAll,
onBatchSelectAll,
onBatchClearAll,
}) => {
const [searchQuery, setSearchQuery] = useState('');
const [collapsedIds, setCollapsedIds] = useState<Set<number>>(new Set());
@@ -68,6 +72,41 @@ export const MenuPermissionTree: FC<IMenuPermissionTreeProps> = ({
});
};
// Group all menus by ID for quick ancestor & descendant traversal
const menuMap = useMemo(() => {
const map = new Map<number, IMenu>();
menus.forEach(m => {
if (m.id !== undefined) map.set(m.id, m);
});
return map;
}, [menus]);
// Helper: get all descendants recursively for a menu ID
const getDescendants = (menuId: number): IMenu[] => {
const list: IMenu[] = [];
const directChildren = menus.filter(m => m.menu_parent_id === menuId && m.id !== undefined);
directChildren.forEach(child => {
list.push(child);
list.push(...getDescendants(child.id!));
});
return list;
};
// Helper: is a menu considered "checked" (has at least 1 action or is explicitly marked)
const isMenuChecked = (menuId: number): boolean => {
const acts = selectedPermissions[menuId];
return Boolean(acts && acts.length > 0);
};
// Helper: check if a menu is enabled (all ancestors must be checked)
const isMenuEnabled = (node: TreeNode | IMenu): boolean => {
if (!node.menu_parent_id) return true; // Root menu is always enabled
const parent = menuMap.get(node.menu_parent_id);
if (!parent || parent.id === undefined) return true;
// Parent must be checked AND parent must be enabled
return isMenuChecked(parent.id) && isMenuEnabled(parent);
};
// Separate Non-Admin and Admin menus
const { nonAdminTree, adminTree } = useMemo(() => {
const nonAdminList = menus.filter(m => !(m.is_admin_menu));
@@ -105,6 +144,66 @@ export const MenuPermissionTree: FC<IMenuPermissionTreeProps> = ({
return matches;
}, [menus, searchQuery]);
// Helper: compute aggregate isAllChecked and isIndeterminate for a node (including its descendants)
const computeNodeSelectionState = (node: TreeNode) => {
const descendants = getDescendants(node.id!);
const allNodes = [node, ...descendants];
let totalActionsCount = 0;
let selectedActionsCount = 0;
let hasAnyActionSelected = false;
allNodes.forEach(m => {
const valid = m.action && m.action.length > 0 ? m.action : ['__CHECKED__'];
totalActionsCount += valid.length;
const cur = selectedPermissions[m.id!] || [];
const matching = cur.filter(a => valid.includes(a));
selectedActionsCount += matching.length;
if (matching.length > 0) hasAnyActionSelected = true;
});
const isAllChecked = totalActionsCount > 0 && selectedActionsCount === totalActionsCount;
const isIndeterminate = hasAnyActionSelected && !isAllChecked;
return { isAllChecked, isIndeterminate };
};
// When selecting a node: select all actions of the node AND all of its descendants
const handleNodeSelectAll = (node: TreeNode) => {
const descendants = getDescendants(node.id!);
const allNodes = [node, ...descendants];
const updates: Record<number, string[]> = {};
allNodes.forEach(m => {
if (m.id !== undefined) {
const actions = m.action && m.action.length > 0 ? [...m.action] : ['__CHECKED__'];
updates[m.id] = actions;
}
});
if (onBatchSelectAll) {
onBatchSelectAll(updates);
} else {
Object.entries(updates).forEach(([idStr, acts]) => {
onMenuSelectAll(Number(idStr), acts);
});
}
};
// When clearing a node: clear the node AND all of its descendants
const handleNodeClearAll = (node: TreeNode) => {
const descendants = getDescendants(node.id!);
const allIds = [node.id!, ...descendants.map(d => d.id!).filter(Boolean) as number[]];
if (onBatchClearAll) {
onBatchClearAll(allIds);
} else {
allIds.forEach(id => {
onMenuClearAll(id);
});
}
};
// Renders a single menu row and recursively its children using unified RolePermissionRow
const renderNode = (node: TreeNode) => {
if (node.id === undefined) return null;
@@ -116,6 +215,8 @@ export const MenuPermissionTree: FC<IMenuPermissionTreeProps> = ({
const hasChildren = Boolean(node.children && node.children.length > 0);
const assignedActions = node.action || [];
const currentSelectedActions = selectedPermissions[node.id] || [];
const isEnabled = isMenuEnabled(node);
const { isAllChecked, isIndeterminate } = computeNodeSelectionState(node);
return (
<React.Fragment key={node.id}>
@@ -132,13 +233,16 @@ export const MenuPermissionTree: FC<IMenuPermissionTreeProps> = ({
action: assignedActions,
}}
mode="interactive"
disabled={!isEnabled}
isAllChecked={isAllChecked}
isIndeterminate={isIndeterminate}
selectedActions={currentSelectedActions}
onToggleCollapse={() => toggleCollapse(node.id!)}
onPermissionToggle={(actionName, checked) =>
onPermissionToggle(node.id!, actionName, checked)
}
onSelectAll={() => onMenuSelectAll(node.id!, assignedActions)}
onClearAll={() => onMenuClearAll(node.id!)}
onSelectAll={() => handleNodeSelectAll(node)}
onClearAll={() => handleNodeClearAll(node)}
/>
{/* Render children recursively if not collapsed */}
+58 -24
View File
@@ -29,6 +29,17 @@ type Props = {
initialData?: IRole;
};
// Helper to collect all descendant IDs of a menu
function getDescendantIds(targetId: number, allMenus: IMenu[]): number[] {
const ids: number[] = [];
const direct = allMenus.filter(m => m.menu_parent_id === targetId && m.id !== undefined);
direct.forEach(c => {
ids.push(c.id!);
ids.push(...getDescendantIds(c.id!, allMenus));
});
return ids;
}
export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
const [isLoading, setIsLoading] = useState(false);
const [showConfirm, setShowConfirm] = useState(false);
@@ -55,7 +66,7 @@ export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
useEffect(() => {
if (initialData) {
const isAdminAllowed = Boolean(
initialData.allow_admin_panel ?? initialData.allow_admin ?? false
initialData.allow_admin_panel ?? false
);
setAllowAdminPanel(isAdminAllowed);
@@ -68,22 +79,20 @@ export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
// Map existing permissions into selectedPermissions dictionary
const initialSelection: Record<number, string[]> = {};
if (Array.isArray(initialData.role_detail) && initialData.role_detail.length > 0) {
initialData.role_detail.forEach((item: IRoleDetail) => {
if (item.menu_id && Array.isArray(item.action)) {
initialSelection[item.menu_id] = item.action;
}
});
} else if (Array.isArray(initialData.privilege) && initialData.privilege.length > 0) {
initialData.privilege.forEach((item: any) => {
const mId = item.menu_id || item.id;
if (mId && Array.isArray(item.action)) {
initialSelection[mId] = item.action.map((a: any) =>
typeof a === 'string' ? a : a.name || a.code || String(a)
);
}
});
}
const rawDetails = Array.isArray(initialData.role_detail)
? initialData.role_detail
: Array.isArray(initialData.privilege)
? initialData.privilege
: [];
rawDetails.forEach((item: any) => {
// Support both new API format (item.menu.id) and legacy format (item.menu_id)
const mId = item.menu?.id ?? item.menu_id ?? (typeof item.menu === 'number' ? item.menu : undefined);
const actions = Array.isArray(item.action) ? item.action : [];
if (mId !== undefined && actions.length > 0) {
initialSelection[mId] = actions;
}
});
setSelectedPermissions(initialSelection);
} else {
@@ -132,16 +141,20 @@ export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
nextActions = currentActions.filter((a) => a !== actionName);
}
const next = { ...prev };
if (nextActions.length === 0) {
const copy = { ...prev };
delete copy[menuId];
return copy;
delete next[menuId];
// When parent loses all actions, all descendants are also cleared
const descendantIds = getDescendantIds(menuId, menus);
descendantIds.forEach((dId) => {
delete next[dId];
});
} else {
next[menuId] = nextActions;
}
return {
...prev,
[menuId]: nextActions,
};
return next;
});
};
@@ -162,6 +175,25 @@ export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
});
};
// Batch select all actions on multiple menu rows (parent + descendants)
const handleBatchSelectAll = (updates: Record<number, string[]>) => {
setSelectedPermissions((prev) => ({
...prev,
...updates,
}));
};
// Batch clear actions on multiple menu rows (parent + descendants)
const handleBatchClearAll = (menuIds: number[]) => {
setSelectedPermissions((prev) => {
const next = { ...prev };
menuIds.forEach((id) => {
delete next[id];
});
return next;
});
};
// Final payload construction according to backend contract
const handleSubmit = async () => {
try {
@@ -379,6 +411,8 @@ export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
onPermissionToggle={handlePermissionToggle}
onMenuSelectAll={handleMenuSelectAll}
onMenuClearAll={handleMenuClearAll}
onBatchSelectAll={handleBatchSelectAll}
onBatchClearAll={handleBatchClearAll}
/>
)}
</CardContent>
+4 -4
View File
@@ -96,7 +96,7 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
align: 'center',
width: 160,
render: (_val, record: IRole) => {
const isAllowed = Boolean(record.allow_admin_panel ?? record.allow_admin);
const isAllowed = Boolean(record.allow_admin_panel);
return isAllowed ? (
<span className="inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full text-xs font-semibold bg-emerald-500/10 text-emerald-600 border border-emerald-500/20 dark:bg-emerald-500/20 dark:text-emerald-300 dark:border-emerald-500/30">
<span className="w-1.5 h-1.5 rounded-full bg-emerald-500" />
@@ -119,8 +119,8 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
const count = Array.isArray(details)
? details.length
: Array.isArray(record.privilege)
? record.privilege.length
: 0;
? record.privilege.length
: 0;
return (
<span className="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-zinc-100 dark:bg-zinc-800 text-zinc-700 dark:text-zinc-300">
{count} menus
@@ -201,7 +201,7 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
<div className="flex flex-1 items-center space-x-2 w-full sm:w-auto">
<Input
placeholder="Search role name, code, description..."
className="h-8 w-full sm:w-[280px]"
className="h-8 w-full sm:w-64 md:w-72"
value={searchText}
onChange={handleSearch}
/>
@@ -24,6 +24,9 @@ export interface IRolePermissionRowProps {
mode?: 'interactive' | 'readonly';
selectedActions?: string[];
index?: number;
disabled?: boolean;
isAllChecked?: boolean;
isIndeterminate?: boolean;
onToggleCollapse?: () => void;
onPermissionToggle?: (actionName: string, checked: boolean) => void;
onSelectAll?: () => void;
@@ -35,6 +38,9 @@ export const RolePermissionRow: FC<IRolePermissionRowProps> = ({
mode = 'interactive',
selectedActions = [],
index,
disabled = false,
isAllChecked: isAllCheckedProp,
isIndeterminate: isIndeterminateProp,
onToggleCollapse,
onPermissionToggle,
onSelectAll,
@@ -44,9 +50,12 @@ export const RolePermissionRow: FC<IRolePermissionRowProps> = ({
const assignedActions = node.action || [];
const currentSelected = selectedActions;
const isAllSelected = assignedActions.length > 0 && assignedActions.every(a => currentSelected.includes(a));
const isNodeAllSelected = assignedActions.length > 0 && assignedActions.every(a => currentSelected.includes(a));
const hasAnySelected = currentSelected.length > 0;
const isIndeterminate = hasAnySelected && !isAllSelected;
const isNodeIndeterminate = hasAnySelected && !isNodeAllSelected;
const effectiveAllSelected = isAllCheckedProp !== undefined ? isAllCheckedProp : isNodeAllSelected;
const effectiveIndeterminate = isIndeterminateProp !== undefined ? isIndeterminateProp : isNodeIndeterminate;
const indentPx = node.level * 22;
const actionsIndentPx = indentPx + (isInteractive ? 40 : 28);
@@ -57,7 +66,8 @@ export const RolePermissionRow: FC<IRolePermissionRowProps> = ({
'flex flex-col py-3 px-3 sm:px-4 border-b border-zinc-200/80 dark:border-zinc-800/80 transition-colors',
node.level === 0
? 'bg-zinc-50/70 dark:bg-zinc-900/50'
: 'bg-white dark:bg-zinc-950/40 hover:bg-zinc-50/40 dark:hover:bg-zinc-900/20'
: 'bg-white dark:bg-zinc-950/40 hover:bg-zinc-50/40 dark:hover:bg-zinc-900/20',
disabled && 'opacity-60 bg-zinc-50/40 dark:bg-zinc-950/20'
)}
>
{/* Top row: Hierarchy, Menu Identifier & Row Actions */}
@@ -89,11 +99,13 @@ export const RolePermissionRow: FC<IRolePermissionRowProps> = ({
{/* Checkbox (interactive) or Row Index (readonly) */}
{isInteractive ? (
assignedActions.length > 0 && (
(assignedActions.length > 0 || node.hasChildren) && (
<Checkbox
checked={isAllSelected}
indeterminate={isIndeterminate}
disabled={disabled}
checked={effectiveAllSelected}
indeterminate={effectiveIndeterminate}
onChange={(e) => {
if (disabled) return;
if (e.target.checked) {
onSelectAll?.();
} else {
@@ -103,13 +115,14 @@ export const RolePermissionRow: FC<IRolePermissionRowProps> = ({
className="shrink-0"
/>
)
) : (
index !== undefined && (
<span className="text-xs font-mono font-medium text-muted-foreground w-6 text-center shrink-0">
{index + 1}
</span>
)
)}
) :
// index !== undefined && (
// <span className="text-xs font-mono font-medium text-muted-foreground w-6 text-center shrink-0">
// {index + 1}
// </span>
// )
null
}
{/* Icon, Title, Path & Admin Badge */}
<div className="flex items-center gap-2 min-w-0 flex-wrap">
@@ -123,13 +136,16 @@ export const RolePermissionRow: FC<IRolePermissionRowProps> = ({
</span>
)}
<span className="text-sm font-semibold text-zinc-900 dark:text-zinc-100 truncate">
<span className={cn(
"text-sm font-semibold truncate",
disabled ? "text-zinc-400 dark:text-zinc-500" : "text-zinc-900 dark:text-zinc-100"
)}>
{node.name}
</span>
{node.path_url && (
<span className="text-xs font-mono text-muted-foreground truncate">
{node.path_url}
`{node.path_url}`
</span>
)}
@@ -138,13 +154,19 @@ export const RolePermissionRow: FC<IRolePermissionRowProps> = ({
Admin
</span>
)}
{disabled && (
<span className="text-[11px] text-zinc-400 dark:text-zinc-500 italic font-normal shrink-0">
(Enable parent first)
</span>
)}
</div>
</div>
{/* Right: Summary Count & Row Select/Clear Action */}
<div className="flex items-center gap-2 shrink-0">
{isInteractive ? (
assignedActions.length > 0 && (
(assignedActions.length > 0 || node.hasChildren) && (
<>
<span className="hidden sm:inline-block text-xs font-mono text-muted-foreground">
{currentSelected.length} / {assignedActions.length} selected
@@ -153,16 +175,18 @@ export const RolePermissionRow: FC<IRolePermissionRowProps> = ({
type="button"
variant="outline"
size="sm"
disabled={disabled}
className="h-7 text-xs px-2.5 font-medium"
onClick={() => {
if (isAllSelected) {
if (disabled) return;
if (effectiveAllSelected) {
onClearAll?.();
} else {
onSelectAll?.();
}
}}
>
{isAllSelected ? 'Clear All' : 'Select All'}
{effectiveAllSelected ? 'Clear All' : 'Select All'}
</Button>
</>
)
@@ -189,15 +213,21 @@ export const RolePermissionRow: FC<IRolePermissionRowProps> = ({
<label
key={action}
className={cn(
'inline-flex items-center gap-1.5 px-2.5 py-1 rounded border text-xs cursor-pointer select-none transition-all',
isChecked
? 'bg-zinc-100/90 dark:bg-zinc-800/90 border-zinc-300 dark:border-zinc-700 shadow-xs'
: 'bg-transparent border-zinc-200/60 dark:border-zinc-800/80 hover:border-zinc-300 dark:hover:border-zinc-700 opacity-80 hover:opacity-100'
'inline-flex items-center gap-1.5 px-2.5 py-1 rounded border text-xs select-none transition-all',
disabled
? 'opacity-40 cursor-not-allowed bg-zinc-50 dark:bg-zinc-900 border-zinc-200 dark:border-zinc-800'
: isChecked
? 'bg-zinc-100/90 dark:bg-zinc-800/90 border-zinc-300 dark:border-zinc-700 shadow-xs cursor-pointer'
: 'bg-transparent border-zinc-200/60 dark:border-zinc-800/80 hover:border-zinc-300 dark:hover:border-zinc-700 opacity-80 hover:opacity-100 cursor-pointer'
)}
>
<Checkbox
disabled={disabled}
checked={isChecked}
onChange={(e) => onPermissionToggle?.(action, e.target.checked)}
onChange={(e) => {
if (disabled) return;
onPermissionToggle?.(action, e.target.checked);
}}
/>
<RbacBadge permission={action} size="sm" />
</label>
-5
View File
@@ -68,11 +68,6 @@ const SIDEBAR_MENU = [
Icon: <Settings size={18} />,
path: '/global-parameter'
},
{
title: "Menu",
Icon: <MenuSquare size={18} />,
path: '/menu'
},
{
title: "Day Off",
Icon: <CalendarX2 size={18} />,
+2
View File
@@ -49,6 +49,7 @@ export const TABLER_ICON_OPTIONS: ITablerIconOption[] = [
{ label: 'Briefcase', value: 'ti ti-briefcase', category: 'Operations' },
{ label: 'Calendar Event', value: 'ti ti-calendar-event', category: 'Operations' },
{ label: 'Calendar Time', value: 'ti ti-calendar-time', category: 'Operations' },
{ label: 'Calendar Off', value: 'ti ti-calendar-x', category: 'Operations' },
{ label: 'Clock', value: 'ti ti-clock', category: 'Operations' },
{ label: 'Checklist', value: 'ti ti-checklist', category: 'Operations' },
@@ -68,5 +69,6 @@ export const TABLER_ICON_OPTIONS: ITablerIconOption[] = [
{ label: 'Face id', value: 'ti ti-face-id', category: 'Security' },
{ label: 'Fingerprint', value: 'ti ti-fingerprint', category: 'Security' },
{ label: 'Bell', value: 'ti ti-bell', category: 'General' },
{ label: 'Information Circle', value: 'ti ti-info-circle', category: 'General' },
];
+7 -5
View File
@@ -31,10 +31,13 @@ export interface IMenu {
}
export interface IRoleDetail {
menu_id: number;
menu_name: string;
menu_path: string;
is_admin_menu: boolean;
id?: number;
role_id?: number;
menu_id?: number;
menu_name?: string;
menu_path?: string;
is_admin_menu?: boolean;
menu?: IMenu;
action: string[];
}
@@ -44,7 +47,6 @@ export interface IRole {
name: string;
description?: string;
allow_admin_panel?: boolean;
allow_admin?: boolean;
role_detail?: IRoleDetail[];
privilege?: any[];
status?: {