Skip to content

Commit

Permalink
fix: get all request pages
Browse files Browse the repository at this point in the history
  • Loading branch information
gabaldon committed Jan 27, 2025
1 parent 7c17135 commit 7efcfc9
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 37 deletions.
32 changes: 21 additions & 11 deletions packages/api/src/repository/ResultRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Db,
Collection,
WithoutId,
PaginatedRequests,
} from '../../types'
import { containFalsyValues } from './containFalsyValues'

Expand Down Expand Up @@ -51,17 +52,26 @@ export class ResultRequestRepository {
feedFullName: string,
page: number,
size: number,
): Promise<Array<ResultRequestDbObjectNormalized>> {
return (
await this.collection
.find({
feedFullName,
})
.sort({ timestamp: -1 })
.skip(size * (page - 1))
.limit(size)
.toArray()
).map(this.normalizeId)
): Promise<PaginatedRequests> {
return {
requests: (
await this.collection
.find({
feedFullName,
})
.sort({ timestamp: -1 })
.skip(size * (page - 1))
.limit(size)
.toArray()
).map(this.normalizeId),
total: (
await this.collection
.find({
feedFullName,
})
.toArray()
).length,
}
}

async getLastResult(
Expand Down
11 changes: 10 additions & 1 deletion packages/api/src/typeDefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ const typeDefs = gql`
timestamp: String! @column
}
type PaginatedResultRequest {
requests: [ResultRequest]
total: Int!
}
# type DataRequest @entity(embedded: true) {
# retrieval: String! @column
# aggregation: String! @column
Expand All @@ -59,7 +64,11 @@ const typeDefs = gql`
type Query {
feed(feedFullName: String!): Feed
feeds(network: String): FeedsPage!
requests(feedFullName: String!, page: Int!, size: Int!): [ResultRequest]!
requests(
feedFullName: String!
page: Int!
size: Int!
): PaginatedResultRequest!
networks: [NetworksConfig]!
}
`
Expand Down
5 changes: 5 additions & 0 deletions packages/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ export type ResultRequestDbObjectNormalized = ResultRequestDbObject & {
id: string
}

export type PaginatedRequests = {
requests: Array<ResultRequestDbObjectNormalized>
total: number
}

export type Repositories = {
feedRepository: FeedRepository
resultRequestRepository: ResultRequestRepository
Expand Down
15 changes: 10 additions & 5 deletions packages/ui/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import feedQuery from './queries/feed'
import feedsQuery from './queries/feeds'
import networksQuery from './queries/networks'
import feedRequestsQuery from './queries/requests'
import type { Ecosystem, Feed, FeedRequests, Network } from '~/types'
import type { Ecosystem, Feed, FeedRequest, Network } from '~/types'

function getApiEndpoint() {
return useRuntimeConfig().public.apiBase
Expand All @@ -19,7 +19,7 @@ export const getAllFeedsRequests = async ({ network }: { network: string }) =>
},
{ accept: 'application/json' },
)) as {
feeds: FeedRequests[]
feeds: FeedRequest[]
total: number
}

Expand Down Expand Up @@ -68,8 +68,8 @@ export const getFeedRequests = async ({
feedFullName: string
page: number
size: number
}) =>
(await request(
}) => {
const result = (await request(
getApiEndpoint(),
feedRequestsQuery,
{
Expand All @@ -79,5 +79,10 @@ export const getFeedRequests = async ({
},
{ accept: 'application/json' },
)) as {
requests: FeedRequests[]
requests: {
requests: FeedRequest[]
total: number
}
}
return result.requests
}
12 changes: 8 additions & 4 deletions packages/ui/api/queries/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import { gql } from 'graphql-request'
export default gql`
query requests($feedFullName: String!, $page: Int!, $size: Int!) {
requests(feedFullName: $feedFullName, page: $page, size: $size) {
feedFullName
result
drTxHash
timestamp
requests {
feedFullName
result
drTxHash
requestId
timestamp
}
total
}
}
`
19 changes: 7 additions & 12 deletions packages/ui/components/DataFeedDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
>
<DataFeedTriggerParams
:deviation="normalizedFeed.deviation"
:max-time-to-resolve="maxTimeToResolve"
:max-time-to-resolve="maxTimeToResolve ?? 0"
:last-result-timestamp="transactions ? transactions[0].timestamp : ''"
/>
</FieldsetCard>
Expand All @@ -57,8 +57,8 @@
:transactions="transactions"
/>
<PaginationSection
v-if="itemsLength && itemsLength > 25"
:items-length="itemsLength"
v-if="totalItems && totalItems > itemsPerPage"
:items-length="totalItems"
@change-page="handleCurrentChange"
/>
</div>
Expand Down Expand Up @@ -186,9 +186,6 @@ const maxTimeToResolve = computed(() => {
}
})
const itemsLength = computed(() => {
return feed.value?.requests.length
})
const feedName = computed(() => normalizedFeed.value?.name ?? '')
const networkName = computed(() => normalizedFeed.value?.networkName ?? '')
Expand All @@ -209,12 +206,8 @@ const chartData: Ref<AreaData<Time>[]> = computed(() => {
}
})
const transactions = computed(() => {
if (
feed.value &&
store.paginatedFeedRequest &&
store.paginatedFeedRequest.length > 0
) {
return store.paginatedFeedRequest.map((request: any) => ({
if (store.paginatedFeedRequest && store.paginatedFeedRequest.total > 0) {
return store.paginatedFeedRequest.requests.map((request) => ({
witnetLink: getWitnetBlockExplorerLink(request.drTxHash),
drTxHash: request.drTxHash,
data: {
Expand All @@ -228,6 +221,8 @@ const transactions = computed(() => {
return null
}
})
const totalItems = computed(() => store.paginatedFeedRequest?.total ?? 0)
const handleCurrentChange = async (val: number) => {
if (currentPage.value !== val) {
currentPage.value = val
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/stores/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const useStore = defineStore('data', {
page,
size,
})
this.paginatedFeedRequest = result.requests
this.paginatedFeedRequest = result
return this.paginatedFeedRequest
},
updateSelectedNetwork({ networks }: { networks: Network[] | [] }) {
Expand Down
9 changes: 6 additions & 3 deletions packages/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export type Ecosystem = {
total: number
}

export type FeedRequests = {
export type FeedRequest = {
feedFullName: string
result: string
drTxHash: string
Expand All @@ -75,7 +75,7 @@ export type Feed = {
proxyAddress: string
heartbeat: string
finality: string
requests: FeedRequests[]
requests: FeedRequest[]
blockExplorer: string
color: string
logo: string
Expand All @@ -88,5 +88,8 @@ export interface DataStore {
ecosystems: Ecosystem[] | []
totalFeeds: number
feed: Feed | null
paginatedFeedRequest: FeedRequests[] | null
paginatedFeedRequest: {
requests: FeedRequest[]
total: number
} | null
}

0 comments on commit 7efcfc9

Please sign in to comment.