@@ -14,25 +14,17 @@ import { BsBan } from "react-icons/bs";
14
14
import { Link } from "react-router-dom" ;
15
15
import { Badge } from "@flanksource-ui/ui/Badge/Badge" ;
16
16
17
+ const formatTagText = ( key : string , value : string ) : string => {
18
+ return `${ key } : ${ value } ` ;
19
+ } ;
20
+
17
21
const permissionsTableColumns : MRT_ColumnDef < PermissionAPIResponse > [ ] = [
18
22
{
19
23
header : "Subject" ,
20
24
size : 100 ,
21
25
Cell : ( { row } ) => {
22
26
const { team, group, person, subject, notification, playbook } =
23
27
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 ) : "" ;
36
28
37
29
if ( group ) {
38
30
const groupName = group . name || subject ;
@@ -43,7 +35,6 @@ const permissionsTableColumns: MRT_ColumnDef<PermissionAPIResponse>[] = [
43
35
{ groupName }
44
36
{ /* Add link to permission group when we have a permission group page */ }
45
37
</ span >
46
- { rlsPayload && < Badge text = { rlsPayload } color = "blue" > </ Badge > }
47
38
</ div >
48
39
) ;
49
40
}
@@ -53,7 +44,6 @@ const permissionsTableColumns: MRT_ColumnDef<PermissionAPIResponse>[] = [
53
44
< div className = "flex flex-row items-center gap-2" >
54
45
< Avatar user = { person } />
55
46
< span > { person . name } </ span >
56
- { rlsPayload && < Badge text = { rlsPayload } color = "blue" > </ Badge > }
57
47
</ div >
58
48
) ;
59
49
}
@@ -63,7 +53,6 @@ const permissionsTableColumns: MRT_ColumnDef<PermissionAPIResponse>[] = [
63
53
< div className = "flex flex-row items-center gap-2" >
64
54
< Icon name = { team . icon } className = "h-5 w-5 text-gray-600" />
65
55
< span > { team . name } </ span >
66
- { rlsPayload && < Badge text = { rlsPayload } color = "blue" > </ Badge > }
67
56
</ div >
68
57
) ;
69
58
}
@@ -81,7 +70,6 @@ const permissionsTableColumns: MRT_ColumnDef<PermissionAPIResponse>[] = [
81
70
notification . name }
82
71
</ Link >
83
72
</ span >
84
- { rlsPayload && < Badge text = { rlsPayload } color = "blue" > </ Badge > }
85
73
</ div >
86
74
) ;
87
75
}
@@ -100,7 +88,6 @@ const permissionsTableColumns: MRT_ColumnDef<PermissionAPIResponse>[] = [
100
88
</ span >
101
89
</ Link >
102
90
</ span >
103
- { rlsPayload && < Badge text = { rlsPayload } color = "blue" > </ Badge > }
104
91
</ div >
105
92
) ;
106
93
}
@@ -121,36 +108,90 @@ const permissionsTableColumns: MRT_ColumnDef<PermissionAPIResponse>[] = [
121
108
const connection = row . original . connection ;
122
109
const object = row . original . object ;
123
110
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 ( ) ;
124
146
125
147
if ( objectSelector ) {
126
148
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 >
133
160
) ;
134
161
}
135
162
136
163
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
+ ) ;
138
174
}
139
175
140
176
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 >
152
194
) }
153
- { connection && < ConnectionIcon connection = { connection } showLabel /> }
154
195
</ div >
155
196
) ;
156
197
}
0 commit comments