Skip to content

Commit c9f9419

Browse files
fix(contributors): create shape for allTimeData json type
1 parent a19b5bd commit c9f9419

File tree

2 files changed

+90
-37
lines changed

2 files changed

+90
-37
lines changed

src/lib/types.ts

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import type { CallToActionProps } from "@/components/Hero/CallToAction"
1919

2020
import { layoutMapping } from "@/pages/[...slug]"
2121

22+
// Credit: https://stackoverflow.com/a/52331580
23+
export type Unpacked<T> = T extends (infer U)[] ? U : T
24+
2225
export type ChildOnlyProp = { children?: ReactNode }
2326

2427
export type NextPageWithLayout<P = {}, IP = P> = NextPage<P, IP> & {
@@ -354,4 +357,52 @@ export type CommunityConference = {
354357
description: string
355358
startDate: string
356359
endDate: string
357-
}
360+
}
361+
362+
type TranslatedStats = {
363+
tmMatch: number
364+
default: number
365+
total: number
366+
}
367+
368+
export type AllTimeData = {
369+
name: string
370+
url: string
371+
unit: string
372+
dateRange: {
373+
from: string
374+
to: string
375+
}
376+
currency: string
377+
mode: string
378+
totalCosts: number
379+
totalTMSavings: number
380+
totalPreTranslated: number
381+
data: Array<{
382+
user: {
383+
id: number
384+
username: string
385+
fullName: string
386+
userRole: string
387+
avatarUrl: string
388+
preTranslated: number
389+
totalCosts: number
390+
}
391+
languages: Array<{
392+
language: {
393+
id: string
394+
name: string
395+
userRole: string
396+
tmSavings: number
397+
preTranslate: number
398+
totalCosts: number
399+
}
400+
translated: TranslatedStats
401+
targetTranslated: TranslatedStats
402+
translatedByMt: TranslatedStats
403+
approved: TranslatedStats
404+
translationCosts: TranslatedStats
405+
approvalCosts: TranslatedStats
406+
}>
407+
}>
408+
}

src/pages/contributing/translation-program/contributors.tsx

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useRouter } from "next/router"
22
import { GetStaticProps } from "next/types"
3-
import { SSRConfig, useTranslation } from "next-i18next"
3+
import { useTranslation } from "next-i18next"
44
import { serverSideTranslations } from "next-i18next/serverSideTranslations"
55
import {
66
Box,
@@ -12,7 +12,7 @@ import {
1212
UnorderedList,
1313
} from "@chakra-ui/react"
1414

15-
import { BasePageProps } from "@/lib/types"
15+
import { AllTimeData, BasePageProps, Unpacked } from "@/lib/types"
1616

1717
import Breadcrumbs from "@/components/Breadcrumbs"
1818
import FeedbackCard from "@/components/FeedbackCard"
@@ -28,8 +28,11 @@ import { getRequiredNamespacesForPage } from "@/lib/utils/translations"
2828

2929
import allTimeData from "../../../data/translation-reports/alltime/alltime-data.json"
3030

31-
type Props = SSRConfig & {
32-
lastDeployDate: string
31+
type TranslatorDataType = {
32+
user: {
33+
username: Unpacked<AllTimeData["data"]>["user"]["username"]
34+
fullName: Unpacked<AllTimeData["data"]>["user"]["fullName"]
35+
}
3336
}
3437

3538
export const getStaticProps = (async ({ locale }) => {
@@ -65,39 +68,38 @@ const Contributors = () => {
6568
const router = useRouter()
6669

6770
// TODO: Remove specific user checks once Acolad has updated their usernames
68-
const translatorData =
69-
allTimeData.data.flatMap(
70-
// use flatMap to get cleaner object types withouts nulls
71-
(item) => {
72-
const user = item?.user
73-
if (!user) return []
74-
75-
const userName = user.username
76-
if (!userName) return []
77-
78-
const fullName = user.fullName ?? ""
79-
80-
return userName !== "ethdotorg" &&
81-
!userName.includes("LQS_") &&
82-
!userName.includes("REMOVED_USER") &&
83-
!userName.includes("Aco_") &&
84-
!fullName.includes("Aco_") &&
85-
!userName.includes("Acc_") &&
86-
!fullName.includes("Acc_") &&
87-
userName !== "Finnish_Sandberg" &&
88-
userName !== "Norwegian_Sandberg" &&
89-
userName !== "Swedish_Sandberg"
90-
? [
91-
{
92-
user: {
93-
username: userName,
94-
fullName: fullName,
95-
},
71+
const translatorData = (
72+
allTimeData as AllTimeData
73+
).data.flatMap<TranslatorDataType>(
74+
// use flatMap to get cleaner object types withouts nulls
75+
(item) => {
76+
const user = item.user
77+
78+
const userName = user.username
79+
80+
const fullName = user.fullName
81+
82+
return userName !== "ethdotorg" &&
83+
!userName.includes("LQS_") &&
84+
!userName.includes("REMOVED_USER") &&
85+
!userName.includes("Aco_") &&
86+
!fullName.includes("Aco_") &&
87+
!userName.includes("Acc_") &&
88+
!fullName.includes("Acc_") &&
89+
userName !== "Finnish_Sandberg" &&
90+
userName !== "Norwegian_Sandberg" &&
91+
userName !== "Swedish_Sandberg"
92+
? [
93+
{
94+
user: {
95+
username: userName,
96+
fullName: fullName,
9697
},
97-
]
98-
: []
99-
}
100-
) ?? []
98+
},
99+
]
100+
: []
101+
}
102+
)
101103

102104
return (
103105
<Flex direction="column" align="center" w="full">

0 commit comments

Comments
 (0)