1
- import { useQuery } from '@apollo/client'
2
1
import { Box } from 'grommet'
3
2
import { memo , useCallback , useMemo } from 'react'
4
3
import { Date , IconFrame , PageTitle , Table } from '@pluralsh/design-system'
5
4
import { createColumnHelper } from '@tanstack/react-table'
6
5
import isEmpty from 'lodash/isEmpty'
7
6
import { Flex } from 'honorable'
8
7
9
- import { extendConnection } from '../../utils/graphql'
8
+ import { extendConnection , mapExistingNodes } from '../../utils/graphql'
10
9
import LoadingIndicator from '../utils/LoadingIndicator'
11
10
12
11
import { AuditUser } from './AuditUser'
13
12
import { Location } from './Location'
14
- import { LOGINS_Q } from './queries '
13
+ import { useLoginsQuery } from '../../generated/graphql '
15
14
16
15
const FETCH_MARGIN = 30
17
16
@@ -87,12 +86,14 @@ const LoginAuditsTable = memo(({ logins, fetchMoreOnBottomReached }: any) =>
87
86
)
88
87
89
88
export function LoginAudits ( ) {
90
- const { data, loading, fetchMore } = useQuery ( LOGINS_Q , {
89
+ const { data, loading, fetchMore } = useLoginsQuery ( {
91
90
fetchPolicy : 'cache-and-network' ,
92
91
} )
93
92
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
+ )
96
97
97
98
const fetchMoreOnBottomReached = useCallback (
98
99
( element ?: HTMLDivElement | undefined ) => {
@@ -104,10 +105,10 @@ export function LoginAudits() {
104
105
if (
105
106
scrollHeight - scrollTop - clientHeight < FETCH_MARGIN &&
106
107
! loading &&
107
- pageInfo . hasNextPage
108
+ pageInfo ? .hasNextPage
108
109
) {
109
110
fetchMore ( {
110
- variables : { cursor : pageInfo . endCursor } ,
111
+ variables : { cursor : pageInfo ? .endCursor } ,
111
112
updateQuery : ( prev , { fetchMoreResult : { oidcLogins } } ) =>
112
113
extendConnection ( prev , oidcLogins , 'oidcLogins' ) ,
113
114
} )
0 commit comments