Skip to content

Commit f3a3693

Browse files
show env, org, app names on app logs page
1 parent 7aeb28c commit f3a3693

File tree

1 file changed

+61
-6
lines changed

1 file changed

+61
-6
lines changed

client/packages/lowcoder/src/pages/setting/appUsage/dashboard.tsx

+61-6
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {
1010
} from "../theme/styledComponents";
1111
import { HeaderBack } from "pages/setting/permission/styledComponents";
1212
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";
1515
import { DatePicker } from "antd";
1616
import dayjs, { Dayjs } from "dayjs";
1717
import { Link, useLocation } from "react-router-dom";
@@ -65,6 +65,7 @@ export function AppUsageDashboard() {
6565

6666
const [allLogs, setAllLogs] = useState<AppLog[]>([]);
6767
const [currentPageLogs, setCurrentPageLogs] = useState<AppLog[]>([]);
68+
const [dataMap, setDataMap] = useState<Record<string, any>>({});
6869

6970
// const [logs, setLogs] = useState([]);
7071
const [total, setTotal] = useState(0);
@@ -244,6 +245,8 @@ export function AppUsageDashboard() {
244245
}, [currentUser.currentOrgId]);
245246

246247
const appViews = useMemo(() => {
248+
if (!allLogs?.length) return [];
249+
247250
return allLogs.reduce((acc, e) => {
248251
const environmentId = e.environmentId;
249252
const orgId = e.orgId;
@@ -252,15 +255,57 @@ export function AppUsageDashboard() {
252255
acc[appId] = acc[appId] || { appId, name, orgId, environmentId, count: 0 };
253256
acc[appId].count++;
254257
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+
}>);
256264
}, [allLogs]);
257265

258266
const topApps = useMemo(() => {
267+
if (!Object.keys(appViews)?.length) return [];
268+
259269
return Object.values(appViews)
260270
.sort((a, b) => b.count - a.count)
261271
.slice(0, 10);
262272
}, [appViews]);
263273

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+
264309
const columns = [
265310
{
266311
title: "",
@@ -280,20 +325,30 @@ export function AppUsageDashboard() {
280325
title: "App ID",
281326
dataIndex: "appId",
282327
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+
),
284337
},
285338
{
286339
title: "Org ID",
287340
dataIndex: "orgId",
288341
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+
),
290345
},
291346
{
292347
title: "Environment ID",
293348
dataIndex: "environmentId",
294349
key: "environmentId",
295350
render: (text: string) => (
296-
<a onClick={() => handleClickFilter("environmentId", text)}>{text}</a>
351+
<a onClick={() => handleClickFilter("environmentId", text)}>{dataMap[text] ?? text}</a>
297352
),
298353
},
299354
{

0 commit comments

Comments
 (0)