@@ -10,8 +10,8 @@ import {
10
10
} from "../theme/styledComponents" ;
11
11
import { HeaderBack } from "pages/setting/permission/styledComponents" ;
12
12
import { getUser } from "@lowcoder-ee/redux/selectors/usersSelectors" ;
13
- import { getAppUsageLogs } from "api/enterpriseApi" ;
14
- import { debounce } from "lodash" ;
13
+ import { getAppUsageLogs , getEnvironmentsByIds , getMeta } from "api/enterpriseApi" ;
14
+ import { debounce , uniqBy } from "lodash" ;
15
15
import { DatePicker } from "antd" ;
16
16
import dayjs , { Dayjs } from "dayjs" ;
17
17
import { Link , useLocation } from "react-router-dom" ;
@@ -65,6 +65,7 @@ export function AppUsageDashboard() {
65
65
66
66
const [ allLogs , setAllLogs ] = useState < AppLog [ ] > ( [ ] ) ;
67
67
const [ currentPageLogs , setCurrentPageLogs ] = useState < AppLog [ ] > ( [ ] ) ;
68
+ const [ dataMap , setDataMap ] = useState < Record < string , any > > ( { } ) ;
68
69
69
70
// const [logs, setLogs] = useState([]);
70
71
const [ total , setTotal ] = useState ( 0 ) ;
@@ -244,6 +245,8 @@ export function AppUsageDashboard() {
244
245
} , [ currentUser . currentOrgId ] ) ;
245
246
246
247
const appViews = useMemo ( ( ) => {
248
+ if ( ! allLogs ?. length ) return [ ] ;
249
+
247
250
return allLogs . reduce ( ( acc , e ) => {
248
251
const environmentId = e . environmentId ;
249
252
const orgId = e . orgId ;
@@ -252,15 +255,57 @@ export function AppUsageDashboard() {
252
255
acc [ appId ] = acc [ appId ] || { appId, name, orgId, environmentId, count : 0 } ;
253
256
acc [ appId ] . count ++ ;
254
257
return acc ;
255
- } , { } as Record < string , { appId : string , name : string , count : number } > ) ;
258
+ } , { } as Record < string , {
259
+ appId : string , name : string ,
260
+ orgId : string ,
261
+ environmentId : string ,
262
+ count : number
263
+ } > ) ;
256
264
} , [ allLogs ] ) ;
257
265
258
266
const topApps = useMemo ( ( ) => {
267
+ if ( ! Object . keys ( appViews ) ?. length ) return [ ] ;
268
+
259
269
return Object . values ( appViews )
260
270
. sort ( ( a , b ) => b . count - a . count )
261
271
. slice ( 0 , 10 ) ;
262
272
} , [ appViews ] ) ;
263
273
274
+ const findUniqueDataIds = async ( ) => {
275
+ if ( ! topApps . length ) {
276
+ return setDataMap ( { } ) ;
277
+ }
278
+
279
+ const uniqueOrgIds : string [ ] = uniqBy ( topApps , 'orgId' ) . map ( item => item . orgId ) ;
280
+ const uniqueEnvIds : string [ ] = uniqBy ( topApps , 'environmentId' ) . map ( item => item . environmentId ) ;
281
+
282
+ const metaResponse = await getMeta ( {
283
+ orgIds : uniqueOrgIds ,
284
+ userIds : [ ] ,
285
+ appIds : [ ] ,
286
+ groupIds : [ ] ,
287
+ bundleIds : [ ] ,
288
+ datasourceIds : [ ] ,
289
+ folderIds : [ ] ,
290
+ libraryQueryIds : [ ]
291
+ } ) ;
292
+
293
+ const envResponse = await getEnvironmentsByIds ( uniqueEnvIds ) ;
294
+
295
+ const tempDataMap : Record < string , any > = { } ;
296
+ metaResponse . data ?. orgs ?. forEach ( ( org : { id : string ; name : string ; } ) => {
297
+ tempDataMap [ org . id ] = org . name ;
298
+ } ) ;
299
+ envResponse . data ?. forEach ( ( env : { environmentId : string ; environmentType : string ; } ) => {
300
+ tempDataMap [ env . environmentId ] = env . environmentType ;
301
+ } ) ;
302
+ setDataMap ( tempDataMap ) ;
303
+ }
304
+
305
+ useEffect ( ( ) => {
306
+ findUniqueDataIds ( ) ;
307
+ } , [ topApps ] ) ;
308
+
264
309
const columns = [
265
310
{
266
311
title : "" ,
@@ -280,20 +325,30 @@ export function AppUsageDashboard() {
280
325
title : "App ID" ,
281
326
dataIndex : "appId" ,
282
327
key : "appId" ,
283
- render : ( text : string ) => < a onClick = { ( ) => handleClickFilter ( "appId" , text ) } > { text } </ a > ,
328
+ render : ( text : string , record : any ) => (
329
+ < a onClick = { ( ) => handleClickFilter ( "appId" , text ) } >
330
+ {
331
+ record . name
332
+ || record . appId
333
+ || '-'
334
+ }
335
+ </ a >
336
+ ) ,
284
337
} ,
285
338
{
286
339
title : "Org ID" ,
287
340
dataIndex : "orgId" ,
288
341
key : "orgId" ,
289
- render : ( text : string ) => < a onClick = { ( ) => handleClickFilter ( "orgId" , text ) } > { text } </ a > ,
342
+ render : ( text : string ) => (
343
+ < a onClick = { ( ) => handleClickFilter ( "orgId" , text ) } > { dataMap [ text ] ?? text } </ a >
344
+ ) ,
290
345
} ,
291
346
{
292
347
title : "Environment ID" ,
293
348
dataIndex : "environmentId" ,
294
349
key : "environmentId" ,
295
350
render : ( text : string ) => (
296
- < a onClick = { ( ) => handleClickFilter ( "environmentId" , text ) } > { text } </ a >
351
+ < a onClick = { ( ) => handleClickFilter ( "environmentId" , text ) } > { dataMap [ text ] ?? text } </ a >
297
352
) ,
298
353
} ,
299
354
{
0 commit comments