1
+ // config/usergroups.config.tsx
2
+ import React from 'react' ;
3
+ import { Row , Col , Statistic , Tag , Badge } from 'antd' ;
4
+ import { TeamOutlined , UserOutlined } from '@ant-design/icons' ;
5
+ import { getEnvironmentUserGroups } from '../services/environments.service' ;
6
+ import { UserGroup , UserGroupStats } from '../types/userGroup.types' ;
7
+ import { DeployableItemConfig } from '../types/deployable-item.types' ;
8
+
9
+
10
+ const formatDate = ( timestamp : number ) : string => {
11
+ if ( ! timestamp ) return 'N/A' ;
12
+ const date = new Date ( timestamp ) ;
13
+ return `${ date . getMonth ( ) + 1 } /${ date . getDate ( ) } /${ date . getFullYear ( ) } ` ;
14
+ } ;
15
+
16
+
17
+ export const userGroupsConfig : DeployableItemConfig < UserGroup , UserGroupStats > = {
18
+ // Basic info
19
+ type : 'userGroups' ,
20
+ singularLabel : 'User Group' ,
21
+ pluralLabel : 'User Groups' ,
22
+ icon : < TeamOutlined /> ,
23
+ idField : 'id' ,
24
+
25
+ // Navigation - No navigation for user groups, provide a dummy function
26
+ buildDetailRoute : ( ) => '#' ,
27
+
28
+ // Configuration
29
+ requiredEnvProps : [ 'environmentApikey' , 'environmentApiServiceUrl' ] ,
30
+
31
+ // Stats rendering - Custom for user groups
32
+ renderStats : ( stats ) => (
33
+ < Row gutter = { 16 } >
34
+ < Col span = { 8 } >
35
+ < Statistic title = "Total User Groups" value = { stats . total } prefix = { < TeamOutlined /> } />
36
+ </ Col >
37
+ < Col span = { 8 } >
38
+ < Statistic title = "Total Users" value = { stats . totalUsers } prefix = { < UserOutlined /> } />
39
+ </ Col >
40
+ < Col span = { 8 } >
41
+ < Statistic title = "Admin Users" value = { stats . adminUsers } prefix = { < UserOutlined /> } />
42
+ </ Col >
43
+ </ Row >
44
+ ) ,
45
+
46
+ // Stats calculation - Custom for user groups
47
+ calculateStats : ( userGroups ) => {
48
+ const total = userGroups . length ;
49
+ const totalUsers = userGroups . reduce (
50
+ ( sum , group ) => sum + ( group . stats ?. userCount ?? 0 ) ,
51
+ 0
52
+ ) ;
53
+ const adminUsers = userGroups . reduce (
54
+ ( sum , group ) => sum + ( group . stats ?. adminUserCount ?? 0 ) ,
55
+ 0
56
+ ) ;
57
+
58
+ return {
59
+ total,
60
+ managed : 0 , // User groups don't have managed/unmanaged state
61
+ unmanaged : 0 , // User groups don't have managed/unmanaged state
62
+ totalUsers,
63
+ adminUsers
64
+ } ;
65
+ } ,
66
+
67
+ // Table configuration
68
+ columns : [
69
+ {
70
+ title : 'Name' ,
71
+ dataIndex : 'groupName' ,
72
+ key : 'groupName' ,
73
+ render : ( name : string , record : UserGroup ) => (
74
+ < div >
75
+ < span > { record . groupName } </ span >
76
+ { record . allUsersGroup && (
77
+ < Tag color = "blue" style = { { marginLeft : 8 } } > All Users</ Tag >
78
+ ) }
79
+ { record . devGroup && (
80
+ < Tag color = "orange" style = { { marginLeft : 8 } } > Dev</ Tag >
81
+ ) }
82
+ </ div >
83
+ ) ,
84
+ } ,
85
+ {
86
+ title : 'ID' ,
87
+ dataIndex : 'groupId' ,
88
+ key : 'groupId' ,
89
+ ellipsis : true ,
90
+ } ,
91
+ {
92
+ title : 'Users' ,
93
+ key : 'userCount' ,
94
+ render : ( _ , record : UserGroup ) => (
95
+ < div >
96
+ < Badge count = { record . stats . userCount } showZero style = { { backgroundColor : '#52c41a' } } />
97
+ < span style = { { marginLeft : 8 } } >
98
+ ({ record . stats . adminUserCount } admin{ record . stats . adminUserCount !== 1 ? 's' : '' } )
99
+ </ span >
100
+ </ div >
101
+ ) ,
102
+ } ,
103
+ {
104
+ title : 'Created' ,
105
+ key : 'createTime' ,
106
+ render : ( _ , record : UserGroup ) => formatDate ( record . createTime ) ,
107
+ } ,
108
+ {
109
+ title : 'Type' ,
110
+ key : 'type' ,
111
+ render : ( _ , record : UserGroup ) => {
112
+ if ( record . allUsersGroup ) return < Tag color = "blue" > Global</ Tag > ;
113
+ if ( record . devGroup ) return < Tag color = "orange" > Dev</ Tag > ;
114
+ if ( record . syncGroup ) return < Tag color = "purple" > Sync</ Tag > ;
115
+ return < Tag color = "default" > Standard</ Tag > ;
116
+ } ,
117
+ }
118
+ ] ,
119
+
120
+ // No managed status for user groups
121
+ enableManaged : false ,
122
+
123
+ // Service functions
124
+ fetchItems : async ( { environment } ) => {
125
+ const userGroups = await getEnvironmentUserGroups (
126
+ environment . environmentId ,
127
+ environment . environmentApikey ,
128
+ environment . environmentApiServiceUrl !
129
+ ) ;
130
+
131
+ // Map the required properties to satisfy DeployableItem interface
132
+ return userGroups . map ( group => ( {
133
+ ...group ,
134
+ id : group . groupId , // Map groupId to id
135
+ name : group . groupName // Map groupName to name
136
+ } ) ) ;
137
+ } ,
138
+
139
+ // Dummy function for toggleManaged (will never be called since enableManaged is false)
140
+ toggleManaged : async ( ) => {
141
+ return false ;
142
+ }
143
+ } ;
0 commit comments