Skip to content

Commit 59b8544

Browse files
committed
audits
1 parent 6c9d9c5 commit 59b8544

File tree

5 files changed

+192
-54
lines changed

5 files changed

+192
-54
lines changed

www/src/components/audits/AuditChloropleth.tsx

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { useQuery } from '@apollo/client'
21
import { useRef, useState } from 'react'
32

43
import lookup from 'country-code-lookup'
@@ -8,7 +7,10 @@ import { Card, PageTitle, SubTab, TabList } from '@pluralsh/design-system'
87

98
import { Chloropleth } from '../utils/Chloropleth'
109

11-
import { AUDIT_METRICS, LOGIN_METRICS } from './queries'
10+
import {
11+
useAuditMetricsQuery,
12+
useLoginMetricsQuery,
13+
} from '../../generated/graphql'
1214

1315
const DIRECTORY = [
1416
{ key: 'audit-logs', label: 'Audit logs' },
@@ -19,14 +21,13 @@ export function AuditChloropleth() {
1921
const [selectedKey, setSelectedKey] = useState<any>('audit-logs')
2022
const tabStateRef = useRef<any>(null)
2123

22-
const { data } = useQuery(
23-
selectedKey === 'logins' ? LOGIN_METRICS : AUDIT_METRICS,
24-
{ fetchPolicy: 'cache-and-network' }
25-
)
24+
const query =
25+
selectedKey === 'logins' ? useLoginMetricsQuery : useAuditMetricsQuery
26+
const { data } = query({ fetchPolicy: 'cache-and-network' })
2627

2728
if (!data) return null
2829

29-
const results = data.auditMetrics || data.loginMetrics
30+
const results = data['auditMetrics'] || data['loginMetrics']
3031
const metrics = results.map(({ country, count }) => ({
3132
// @ts-expect-error
3233
id: lookup.byIso(country).iso3,

www/src/components/audits/LoginAudits.tsx

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
import { useQuery } from '@apollo/client'
21
import { Box } from 'grommet'
32
import { memo, useCallback, useMemo } from 'react'
43
import { Date, IconFrame, PageTitle, Table } from '@pluralsh/design-system'
54
import { createColumnHelper } from '@tanstack/react-table'
65
import isEmpty from 'lodash/isEmpty'
76
import { Flex } from 'honorable'
87

9-
import { extendConnection } from '../../utils/graphql'
8+
import { extendConnection, mapExistingNodes } from '../../utils/graphql'
109
import LoadingIndicator from '../utils/LoadingIndicator'
1110

1211
import { AuditUser } from './AuditUser'
1312
import { Location } from './Location'
14-
import { LOGINS_Q } from './queries'
13+
import { useLoginsQuery } from '../../generated/graphql'
1514

1615
const FETCH_MARGIN = 30
1716

@@ -87,12 +86,14 @@ const LoginAuditsTable = memo(({ logins, fetchMoreOnBottomReached }: any) =>
8786
)
8887

8988
export function LoginAudits() {
90-
const { data, loading, fetchMore } = useQuery(LOGINS_Q, {
89+
const { data, loading, fetchMore } = useLoginsQuery({
9190
fetchPolicy: 'cache-and-network',
9291
})
9392
const pageInfo = data?.oidcLogins?.pageInfo
94-
const edges = data?.oidcLogins?.edges
95-
const logins = useMemo(() => edges?.map(({ node }) => node) || [], [edges])
93+
const logins = useMemo(
94+
() => mapExistingNodes(data?.oidcLogins) || [],
95+
[data?.oidcLogins]
96+
)
9697

9798
const fetchMoreOnBottomReached = useCallback(
9899
(element?: HTMLDivElement | undefined) => {
@@ -104,10 +105,10 @@ export function LoginAudits() {
104105
if (
105106
scrollHeight - scrollTop - clientHeight < FETCH_MARGIN &&
106107
!loading &&
107-
pageInfo.hasNextPage
108+
pageInfo?.hasNextPage
108109
) {
109110
fetchMore({
110-
variables: { cursor: pageInfo.endCursor },
111+
variables: { cursor: pageInfo?.endCursor },
111112
updateQuery: (prev, { fetchMoreResult: { oidcLogins } }) =>
112113
extendConnection(prev, oidcLogins, 'oidcLogins'),
113114
})

www/src/components/audits/queries.ts

-39
This file was deleted.

0 commit comments

Comments
 (0)