Skip to content

Commit

Permalink
refactor: move response wrapping func to utils
Browse files Browse the repository at this point in the history
See: BEDS-481
  • Loading branch information
LuccaBitfly committed Oct 2, 2024
1 parent 09b2451 commit f0174b1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
20 changes: 5 additions & 15 deletions frontend/components/dashboard/table/DashboardTableRewards.vue
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,6 @@ const findNextEpochDuties = (epoch: number) => {
return list.join(', ')
}
const wrappedRewards = computed(() => {
if (!rewards.value) {
return
}
return {
data: rewards.value.data.map(d => ({
...d,
identifier: `${d.epoch}-${d.group_id}`,
})),
paging: rewards.value.paging,
}
})
</script>

<template>
Expand All @@ -168,8 +155,11 @@ const wrappedRewards = computed(() => {
<template #table>
<ClientOnly fallback-tag="span">
<BcTable
:data="wrappedRewards"
data-key="identifier"
:data="wrapWithIdentifier(
rewards,
row => `${row.epoch}-${row.group_id}`,
)"
data-key="wrapped_identifier"
:expandable="true"
class="rewards-table"
:cursor
Expand Down
19 changes: 19 additions & 0 deletions frontend/utils/wrapWithIdentifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { ApiPagingResponse } from '~/types/api/common'
/**
* This function wraps each element in an `ApiPagingResponse` interface with a unique id field `wrapped_identifier`.
* @param response The api response to wrap
* @param getIdFromRow A function that takes a row and builds a unique identifier
* @returns The wrapped response
*/
export function wrapWithIdentifier<T>(response: ApiPagingResponse<T> | undefined, getIdFromRow: (row: T) => string) {
if (!response) {
return
}
return {
data: response.data.map(row => ({
...row,
wrapped_identifier: getIdFromRow(row),
})),
paging: response.paging,
}
}

0 comments on commit f0174b1

Please sign in to comment.