Skip to content

Commit cd80d0e

Browse files
committed
feat(permissions): move RLS payload display to Resource column
- Remove RLS payload (tags/agents) from Subject column - Add individual badges for each tag and agent in Resource column - Display tags as "key: value" badges in blue - Display agents as "agent: name" badges in gray - Use inline layout for compact display alongside resource info
1 parent f4a6eed commit cd80d0e

File tree

1 file changed

+77
-36
lines changed

1 file changed

+77
-36
lines changed

src/components/Permissions/PermissionsTable.tsx

Lines changed: 77 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,17 @@ import { BsBan } from "react-icons/bs";
1414
import { Link } from "react-router-dom";
1515
import { Badge } from "@flanksource-ui/ui/Badge/Badge";
1616

17+
const formatTagText = (key: string, value: string): string => {
18+
return `${key}: ${value}`;
19+
};
20+
1721
const permissionsTableColumns: MRT_ColumnDef<PermissionAPIResponse>[] = [
1822
{
1923
header: "Subject",
2024
size: 100,
2125
Cell: ({ row }) => {
2226
const { team, group, person, subject, notification, playbook } =
2327
row.original;
24-
const { tags, agents } = row.original;
25-
const rlsFilter = [];
26-
27-
if (tags && Object.keys(tags).length > 0) {
28-
rlsFilter.push(tags);
29-
}
30-
31-
if (agents && agents.length > 0) {
32-
rlsFilter.push({ agents: agents });
33-
}
34-
35-
const rlsPayload = rlsFilter.length > 0 ? JSON.stringify(rlsFilter) : "";
3628

3729
if (group) {
3830
const groupName = group.name || subject;
@@ -43,7 +35,6 @@ const permissionsTableColumns: MRT_ColumnDef<PermissionAPIResponse>[] = [
4335
{groupName}
4436
{/* Add link to permission group when we have a permission group page */}
4537
</span>
46-
{rlsPayload && <Badge text={rlsPayload} color="blue"></Badge>}
4738
</div>
4839
);
4940
}
@@ -53,7 +44,6 @@ const permissionsTableColumns: MRT_ColumnDef<PermissionAPIResponse>[] = [
5344
<div className="flex flex-row items-center gap-2">
5445
<Avatar user={person} />
5546
<span>{person.name}</span>
56-
{rlsPayload && <Badge text={rlsPayload} color="blue"></Badge>}
5747
</div>
5848
);
5949
}
@@ -63,7 +53,6 @@ const permissionsTableColumns: MRT_ColumnDef<PermissionAPIResponse>[] = [
6353
<div className="flex flex-row items-center gap-2">
6454
<Icon name={team.icon} className="h-5 w-5 text-gray-600" />
6555
<span>{team.name}</span>
66-
{rlsPayload && <Badge text={rlsPayload} color="blue"></Badge>}
6756
</div>
6857
);
6958
}
@@ -81,7 +70,6 @@ const permissionsTableColumns: MRT_ColumnDef<PermissionAPIResponse>[] = [
8170
notification.name}
8271
</Link>
8372
</span>
84-
{rlsPayload && <Badge text={rlsPayload} color="blue"></Badge>}
8573
</div>
8674
);
8775
}
@@ -100,7 +88,6 @@ const permissionsTableColumns: MRT_ColumnDef<PermissionAPIResponse>[] = [
10088
</span>
10189
</Link>
10290
</span>
103-
{rlsPayload && <Badge text={rlsPayload} color="blue"></Badge>}
10491
</div>
10592
);
10693
}
@@ -121,36 +108,90 @@ const permissionsTableColumns: MRT_ColumnDef<PermissionAPIResponse>[] = [
121108
const connection = row.original.connection;
122109
const object = row.original.object;
123110
const objectSelector = row.original.object_selector;
111+
const { tags, agents } = row.original;
112+
113+
const renderRlsBadges = (): JSX.Element[] => {
114+
const badges: JSX.Element[] = [];
115+
116+
// Add tag badges
117+
if (tags && Object.keys(tags).length > 0) {
118+
Object.entries(tags).forEach(([key, value]) => {
119+
badges.push(
120+
<Badge
121+
key={`tag-${key}`}
122+
text={formatTagText(key, value)}
123+
color="blue"
124+
/>
125+
);
126+
});
127+
}
128+
129+
// Add agent badges
130+
if (agents && agents.length > 0) {
131+
agents.forEach((agent, index) => {
132+
badges.push(
133+
<Badge
134+
key={`agent-${index}`}
135+
text={`agent: ${agent}`}
136+
color="gray"
137+
/>
138+
);
139+
});
140+
}
141+
142+
return badges;
143+
};
144+
145+
const rlsBadges = renderRlsBadges();
124146

125147
if (objectSelector) {
126148
return (
127-
<span
128-
className="truncate font-mono text-sm"
129-
title={JSON.stringify(objectSelector)} // Provides full text on hover
130-
>
131-
{JSON.stringify(objectSelector)}
132-
</span>
149+
<div className="flex flex-row items-center gap-2">
150+
<span
151+
className="truncate font-mono text-sm"
152+
title={JSON.stringify(objectSelector)} // Provides full text on hover
153+
>
154+
{JSON.stringify(objectSelector)}
155+
</span>
156+
{rlsBadges.length > 0 && (
157+
<div className="flex flex-wrap gap-1">{rlsBadges}</div>
158+
)}
159+
</div>
133160
);
134161
}
135162

136163
if (object) {
137-
return permissionObjectList.find((o) => o.value === object)?.label;
164+
return (
165+
<div className="flex flex-row items-center gap-2">
166+
<span>
167+
{permissionObjectList.find((o) => o.value === object)?.label}
168+
</span>
169+
{rlsBadges.length > 0 && (
170+
<div className="flex flex-wrap gap-1">{rlsBadges}</div>
171+
)}
172+
</div>
173+
);
138174
}
139175

140176
return (
141-
<div className="flex flex-col">
142-
{config && <ConfigLink config={config} />}
143-
{/* {check && <CheckLink check={check} />} */}
144-
{playbook && <PlaybookSpecIcon playbook={playbook} showLabel />}
145-
{component && (
146-
<TopologyLink
147-
topology={component}
148-
className="h-5 w-5 text-gray-600"
149-
linkClassName="text-gray-600"
150-
size="md"
151-
/>
177+
<div className="flex flex-row items-center gap-2">
178+
<div className="flex flex-col">
179+
{config && <ConfigLink config={config} />}
180+
{/* {check && <CheckLink check={check} />} */}
181+
{playbook && <PlaybookSpecIcon playbook={playbook} showLabel />}
182+
{component && (
183+
<TopologyLink
184+
topology={component}
185+
className="h-5 w-5 text-gray-600"
186+
linkClassName="text-gray-600"
187+
size="md"
188+
/>
189+
)}
190+
{connection && <ConnectionIcon connection={connection} showLabel />}
191+
</div>
192+
{rlsBadges.length > 0 && (
193+
<div className="flex flex-wrap gap-1">{rlsBadges}</div>
152194
)}
153-
{connection && <ConnectionIcon connection={connection} showLabel />}
154195
</div>
155196
);
156197
}

0 commit comments

Comments
 (0)