From 461bd08a3d59d423414930f310e55c7bacabf4a3 Mon Sep 17 00:00:00 2001 From: DrMint Date: Sat, 14 May 2022 22:47:00 +0200 Subject: [PATCH] Switched to new content data model --- src/components/Library/ContentLine.tsx | 8 +- src/components/Library/ScanSet.tsx | 6 +- src/components/ThumbnailHeader.tsx | 6 +- src/graphql/operations/devGetContents.graphql | 155 ++++--- src/graphql/operations/getContent.graphql | 77 ---- src/graphql/operations/getContentText.graphql | 72 ++-- src/graphql/operations/getContents.graphql | 18 +- src/graphql/operations/getLibraryItem.graphql | 20 +- src/helpers/types.ts | 14 +- src/hooks/useSmartLanguage.tsx | 14 +- src/pages/contents/[slug]/index.tsx | 219 +++++----- src/pages/contents/index.tsx | 22 +- src/pages/dev/checkup/contents.tsx | 398 ++++++++---------- 13 files changed, 461 insertions(+), 568 deletions(-) delete mode 100644 src/graphql/operations/getContent.graphql diff --git a/src/components/Library/ContentLine.tsx b/src/components/Library/ContentLine.tsx index 5df981a..a1af759 100644 --- a/src/components/Library/ContentLine.tsx +++ b/src/components/Library/ContentLine.tsx @@ -39,12 +39,12 @@ export function ContentLine(props: Immutable): JSX.Element { >

setOpened(!opened)}> - {content.attributes.content?.data?.attributes?.titles?.[0] + {content.attributes.content?.data?.attributes?.translations?.[0] ? prettyinlineTitle( - content.attributes.content.data.attributes.titles[0] + content.attributes.content.data.attributes.translations[0] ?.pre_title, - content.attributes.content.data.attributes.titles[0]?.title, - content.attributes.content.data.attributes.titles[0] + content.attributes.content.data.attributes.translations[0]?.title, + content.attributes.content.data.attributes.translations[0] ?.subtitle ) : prettySlug(content.attributes.slug, props.parentSlug)} diff --git a/src/components/Library/ScanSet.tsx b/src/components/Library/ScanSet.tsx index 772a805..9b32509 100644 --- a/src/components/Library/ScanSet.tsx +++ b/src/components/Library/ScanSet.tsx @@ -55,10 +55,10 @@ export function ScanSet(props: Immutable): JSX.Element { const [selectedScan, LanguageSwitcher] = useSmartLanguage({ items: scanSet, languages: languages, - languageExtractor: (item) => item?.language?.data?.attributes?.code, + languageExtractor: (item) => item.language?.data?.attributes?.code, transform: (item) => { - const newItem = { ...item } as Props["scanSet"][number]; - newItem?.pages?.data.sort((a, b) => { + const newItem = { ...item } as Exclude; + newItem.pages?.data.sort((a, b) => { if (a.attributes?.url && b.attributes?.url) { let aName = getAssetFilename(a.attributes.url); let bName = getAssetFilename(b.attributes.url); diff --git a/src/components/ThumbnailHeader.tsx b/src/components/ThumbnailHeader.tsx index 2e82f22..7e8dcc1 100644 --- a/src/components/ThumbnailHeader.tsx +++ b/src/components/ThumbnailHeader.tsx @@ -2,7 +2,7 @@ import { Chip } from "components/Chip"; import { Img } from "components/Img"; import { InsetBox } from "components/InsetBox"; import { Markdawn } from "components/Markdown/Markdawn"; -import { GetContentQuery, UploadImageFragment } from "graphql/generated"; +import { GetContentTextQuery, UploadImageFragment } from "graphql/generated"; import { AppStaticProps } from "graphql/getAppStaticProps"; import { prettyinlineTitle, prettySlug, slugify } from "helpers/formatters"; import { getAssetURL, ImageQuality } from "helpers/img"; @@ -16,14 +16,14 @@ interface Props { description?: string | null | undefined; type?: Exclude< Exclude< - GetContentQuery["contents"], + GetContentTextQuery["contents"], null | undefined >["data"][number]["attributes"], null | undefined >["type"]; categories?: Exclude< Exclude< - GetContentQuery["contents"], + GetContentTextQuery["contents"], null | undefined >["data"][number]["attributes"], null | undefined diff --git a/src/graphql/operations/devGetContents.graphql b/src/graphql/operations/devGetContents.graphql index 8047400..e0cbc78 100644 --- a/src/graphql/operations/devGetContents.graphql +++ b/src/graphql/operations/devGetContents.graphql @@ -1,84 +1,75 @@ query devGetContents { - contents(pagination: { limit: -1 }) { - data { - id - attributes { - slug - categories { - data { - id - } - } - type { - data { - id - } - } - titles { - language { - data { - id - } - } - title - description - } - ranged_contents { - data { - id - } - } - text_set { - language { - data { - id - } - } - source_language { - data { - id - } - } - status - transcribers { - data { - id - } - } - translators { - data { - id - } - } - proofreaders { - data { - id - } - } - text - } - video_set { - id - } - audio_set { - id - } - thumbnail { - data { - id - } - } - next_recommended { - data { - id - } - } - previous_recommended { - data { - id - } - } - } - } - } + contents(pagination: { limit: -1 }) { + data { + id + attributes { + slug + categories { + data { + id + } + } + type { + data { + id + } + } + + ranged_contents { + data { + id + } + } + translations { + language { + data { + id + } + } + title + description + text_set { + source_language { + data { + id + } + } + status + transcribers { + data { + id + } + } + translators { + data { + id + } + } + proofreaders { + data { + id + } + } + text + } + } + + thumbnail { + data { + id + } + } + next_recommended { + data { + id + } + } + previous_recommended { + data { + id + } + } + } + } + } } diff --git a/src/graphql/operations/getContent.graphql b/src/graphql/operations/getContent.graphql deleted file mode 100644 index 1265734..0000000 --- a/src/graphql/operations/getContent.graphql +++ /dev/null @@ -1,77 +0,0 @@ -query getContent($slug: String, $language_code: String) { - contents(filters: { slug: { eq: $slug } }) { - data { - attributes { - slug - titles(filters: { language: { code: { eq: $language_code } } }) { - pre_title - title - subtitle - description - } - categories { - data { - id - attributes { - name - short - } - } - } - type { - data { - attributes { - slug - titles(filters: { language: { code: { eq: $language_code } } }) { - title - } - } - } - } - ranged_contents { - data { - id - attributes { - slug - scan_set { - id - } - library_item { - data { - attributes { - slug - title - subtitle - thumbnail { - data { - attributes { - ...uploadImage - } - } - } - } - } - } - } - } - } - text_set { - id - } - video_set { - id - } - audio_set { - id - } - thumbnail { - data { - attributes { - ...uploadImage - } - } - } - } - } - } -} diff --git a/src/graphql/operations/getContentText.graphql b/src/graphql/operations/getContentText.graphql index c35af05..fda6d27 100644 --- a/src/graphql/operations/getContentText.graphql +++ b/src/graphql/operations/getContentText.graphql @@ -4,12 +4,7 @@ query getContentText($slug: String, $language_code: String) { id attributes { slug - titles { - pre_title - title - subtitle - description - } + categories { data { id @@ -56,9 +51,7 @@ query getContentText($slug: String, $language_code: String) { } } } - text_set { - status - text + translations { language { data { attributes { @@ -66,39 +59,48 @@ query getContentText($slug: String, $language_code: String) { } } } - source_language { - data { - attributes { - code + pre_title + title + subtitle + description + text_set { + status + text + source_language { + data { + attributes { + code + } } } - } - transcribers { - data { - id - attributes { - ...recorderChip + transcribers { + data { + id + attributes { + ...recorderChip + } } } - } - translators { - data { - id - attributes { - ...recorderChip + translators { + data { + id + attributes { + ...recorderChip + } } } - } - proofreaders { - data { - id - attributes { - ...recorderChip + proofreaders { + data { + id + attributes { + ...recorderChip + } } } + notes } - notes } + thumbnail { data { attributes { @@ -110,7 +112,7 @@ query getContentText($slug: String, $language_code: String) { data { attributes { slug - titles(filters: { language: { code: { eq: $language_code } } }) { + translations { pre_title title subtitle @@ -149,7 +151,7 @@ query getContentText($slug: String, $language_code: String) { data { attributes { slug - titles(filters: { language: { code: { eq: $language_code } } }) { + translations { pre_title title subtitle @@ -187,4 +189,4 @@ query getContentText($slug: String, $language_code: String) { } } } -} +} \ No newline at end of file diff --git a/src/graphql/operations/getContents.graphql b/src/graphql/operations/getContents.graphql index 4815202..d58ddb8 100644 --- a/src/graphql/operations/getContents.graphql +++ b/src/graphql/operations/getContents.graphql @@ -4,7 +4,14 @@ query getContents($language_code: String) { id attributes { slug - titles { + translations { + language { + data { + attributes { + code + } + } + } pre_title title subtitle @@ -65,15 +72,6 @@ query getContents($language_code: String) { id } } - text_set { - id - } - video_set { - id - } - audio_set { - id - } thumbnail { data { attributes { diff --git a/src/graphql/operations/getLibraryItem.graphql b/src/graphql/operations/getLibraryItem.graphql index dd20e9f..5f588d6 100644 --- a/src/graphql/operations/getLibraryItem.graphql +++ b/src/graphql/operations/getLibraryItem.graphql @@ -362,22 +362,18 @@ query getLibraryItem($slug: String, $language_code: String) { } } } - titles( - filters: { language: { code: { eq: $language_code } } } - ) { + translations { + language { + data { + attributes { + code + } + } + } pre_title title subtitle } - text_set { - id - } - video_set { - id - } - audio_set { - id - } } } } diff --git a/src/helpers/types.ts b/src/helpers/types.ts index 07ed001..778d7d9 100644 --- a/src/helpers/types.ts +++ b/src/helpers/types.ts @@ -1,4 +1,4 @@ -import { GetPostQuery } from "graphql/generated"; +import { GetContentTextQuery, GetPostQuery } from "graphql/generated"; import React from "react"; type Post = Exclude< @@ -13,6 +13,18 @@ export interface PostWithTranslations extends Omit { translations: Exclude; } +type Content = Exclude< + Exclude< + GetContentTextQuery["contents"], + null | undefined + >["data"][number]["attributes"], + null | undefined +>; + +export interface ContentWithTranslations extends Omit { + translations: Exclude; +} + type ImmutableBlackList = JSX.Element | React.ReactNode | Function; export type Immutable = { diff --git a/src/hooks/useSmartLanguage.tsx b/src/hooks/useSmartLanguage.tsx index baae258..e13ecff 100644 --- a/src/hooks/useSmartLanguage.tsx +++ b/src/hooks/useSmartLanguage.tsx @@ -8,8 +8,12 @@ import { useEffect, useMemo, useState } from "react"; interface Props { items: Immutable; languages: AppStaticProps["languages"]; - languageExtractor: (item: Immutable) => string | undefined; - transform?: (item: Immutable) => Immutable; + languageExtractor: ( + item: Exclude, null | undefined> + ) => string | undefined; + transform?: ( + item: Exclude, null | undefined> + ) => Exclude, null | undefined>; } function getPreferredLanguage( @@ -45,8 +49,10 @@ export function useSmartLanguage( useEffect(() => { items.map((elem, index) => { - const result = languageExtractor(elem); - if (result !== undefined) availableLocales.set(result, index); + if (elem !== null && elem !== undefined) { + const result = languageExtractor(elem); + if (result !== undefined) availableLocales.set(result, index); + } }); }, [availableLocales, items, languageExtractor]); diff --git a/src/pages/contents/[slug]/index.tsx b/src/pages/contents/[slug]/index.tsx index f351343..75bda9b 100644 --- a/src/pages/contents/[slug]/index.tsx +++ b/src/pages/contents/[slug]/index.tsx @@ -13,7 +13,6 @@ import { PreviewLine } from "components/PreviewLine"; import { RecorderChip } from "components/RecorderChip"; import { ThumbnailHeader } from "components/ThumbnailHeader"; import { ToolTip } from "components/ToolTip"; -import { GetContentTextQuery } from "graphql/generated"; import { AppStaticProps, getAppStaticProps } from "graphql/getAppStaticProps"; import { getReadySdk } from "graphql/sdk"; import { @@ -22,7 +21,7 @@ import { prettySlug, } from "helpers/formatters"; import { getStatusDescription } from "helpers/others"; -import { Immutable } from "helpers/types"; +import { ContentWithTranslations, Immutable } from "helpers/types"; import { useMediaMobile } from "hooks/useMediaQuery"; import { useSmartLanguage } from "hooks/useSmartLanguage"; import { @@ -32,28 +31,19 @@ import { } from "next"; interface Props extends AppStaticProps { - content: Exclude< - GetContentTextQuery["contents"], - null | undefined - >["data"][number]["attributes"]; - contentId: Exclude< - GetContentTextQuery["contents"], - null | undefined - >["data"][number]["id"]; + content: ContentWithTranslations; } export default function Content(props: Immutable): JSX.Element { const { langui, content, languages } = props; const isMobile = useMediaMobile(); - const [selectedTextSet, LanguageSwitcher] = useSmartLanguage({ - items: content?.text_set, + const [selectedTranslation, LanguageSwitcher] = useSmartLanguage({ + items: content.translations, languages: languages, - languageExtractor: (item) => item?.language?.data?.attributes?.code, + languageExtractor: (item) => item.language?.data?.attributes?.code, }); - const selectedTitle = content?.titles?.[0]; - const subPanel = ( ): JSX.Element { horizontalLine /> - {selectedTextSet?.source_language?.data?.attributes && ( + {selectedTranslation?.text_set && (

- {selectedTextSet.source_language.data.attributes.code === - selectedTextSet.language?.data?.attributes?.code + {selectedTranslation.text_set.source_language?.data?.attributes + ?.code === selectedTranslation.language?.data?.attributes?.code ? langui.transcript_notice : langui.translation_notice}

- {selectedTextSet.source_language.data.attributes.code !== - selectedTextSet.language?.data?.attributes?.code && ( -
-

{langui.source_language}:

- - {prettyLanguage( - selectedTextSet.source_language.data.attributes.code, - languages - )} - -
- )} + {selectedTranslation.text_set.source_language?.data?.attributes + ?.code && + selectedTranslation.text_set.source_language.data.attributes + .code !== + selectedTranslation.language?.data?.attributes?.code && ( +
+

{langui.source_language}:

+ + {prettyLanguage( + selectedTranslation.text_set.source_language.data.attributes + .code, + languages + )} + +
+ )}

{langui.status}:

- {selectedTextSet.status} + {selectedTranslation.text_set.status}
- {selectedTextSet.transcribers && - selectedTextSet.transcribers.data.length > 0 && ( + {selectedTranslation.text_set.transcribers && + selectedTranslation.text_set.transcribers.data.length > 0 && (

{langui.transcribers}:

- {selectedTextSet.transcribers.data.map((recorder) => ( - <> - {recorder.attributes && ( - - )} - - ))} + {selectedTranslation.text_set.transcribers.data.map( + (recorder) => ( + <> + {recorder.attributes && ( + + )} + + ) + )}
)} - {selectedTextSet.translators && - selectedTextSet.translators.data.length > 0 && ( + {selectedTranslation.text_set.translators && + selectedTranslation.text_set.translators.data.length > 0 && (

{langui.translators}:

- {selectedTextSet.translators.data.map((recorder) => ( - <> - {recorder.attributes && ( - - )} - - ))} + {selectedTranslation.text_set.translators.data.map( + (recorder) => ( + <> + {recorder.attributes && ( + + )} + + ) + )}
)} - {selectedTextSet.proofreaders && - selectedTextSet.proofreaders.data.length > 0 && ( + {selectedTranslation.text_set.proofreaders && + selectedTranslation.text_set.proofreaders.data.length > 0 && (

{langui.proofreaders}:

- {selectedTextSet.proofreaders.data.map((recorder) => ( - <> - {recorder.attributes && ( - - )} - - ))} + {selectedTranslation.text_set.proofreaders.data.map( + (recorder) => ( + <> + {recorder.attributes && ( + + )} + + ) + )}
)} - {selectedTextSet.notes && ( + {selectedTranslation.text_set.notes && (

{"Notes"}:

- +
)}
)} - {selectedTextSet && content?.text_set && selectedTextSet.text && ( + {selectedTranslation?.text_set?.text && ( <> 0 && selectedTitle - ? prettyinlineTitle( - selectedTitle.pre_title, - selectedTitle.title, - selectedTitle.subtitle - ) - : prettySlug(content.slug) - } + text={selectedTranslation.text_set.text} + title={prettyinlineTitle( + selectedTranslation.pre_title, + selectedTranslation.title, + selectedTranslation.subtitle + )} /> )} @@ -190,7 +189,7 @@ export default function Content(props: Immutable): JSX.Element { const contentPanel = ( ): JSX.Element {
): JSX.Element { ): JSX.Element { - + {content.next_recommended?.data?.attributes && ( <> @@ -277,15 +272,17 @@ export default function Content(props: Immutable): JSX.Element { ): JSX.Element { ); let description = ""; - if (content?.type?.data) { + if (content.type?.data) { description += `${langui.type}: `; description += @@ -334,7 +331,7 @@ export default function Content(props: Immutable): JSX.Element { description += "\n"; } - if (content?.categories?.data && content.categories.data.length > 0) { + if (content.categories?.data && content.categories.data.length > 0) { description += `${langui.categories}: `; description += content.categories.data .map((category) => category.attributes?.short) @@ -345,15 +342,15 @@ export default function Content(props: Immutable): JSX.Element { return ( 0 && content.titles[0] + selectedTranslation ? prettyinlineTitle( - content.titles[0].pre_title, - content.titles[0].title, - content.titles[0].subtitle + selectedTranslation.pre_title, + selectedTranslation.title, + selectedTranslation.subtitle ) - : prettySlug(content?.slug) + : prettySlug(content.slug) } - thumbnail={content?.thumbnail?.data?.attributes ?? undefined} + thumbnail={content.thumbnail?.data?.attributes ?? undefined} contentPanel={contentPanel} subPanel={subPanel} description={description} @@ -372,12 +369,12 @@ export async function getStaticProps( language_code: context.locale ?? "en", }); - if (!content.contents || content.contents.data.length === 0) + if (!content.contents || !content.contents.data[0].attributes?.translations) { return { notFound: true }; + } const props: Props = { ...(await getAppStaticProps(context)), - content: content.contents.data[0].attributes, - contentId: content.contents.data[0].id, + content: content.contents.data[0].attributes as ContentWithTranslations, }; return { props: props, diff --git a/src/pages/contents/index.tsx b/src/pages/contents/index.tsx index 07003d0..1ccb40a 100644 --- a/src/pages/contents/index.tsx +++ b/src/pages/contents/index.tsx @@ -111,12 +111,12 @@ export default function Contents(props: Immutable): JSX.Element { { - const titleA = a.attributes?.titles?.[0] + const titleA = a.attributes?.translations?.[0] ? prettyinlineTitle( - a.attributes.titles[0].pre_title, - a.attributes.titles[0].title, - a.attributes.titles[0].subtitle + a.attributes.translations[0].pre_title, + a.attributes.translations[0].title, + a.attributes.translations[0].subtitle ) : a.attributes?.slug ?? ""; - const titleB = b.attributes?.titles?.[0] + const titleB = b.attributes?.translations?.[0] ? prettyinlineTitle( - b.attributes.titles[0].pre_title, - b.attributes.titles[0].title, - b.attributes.titles[0].subtitle + b.attributes.translations[0].pre_title, + b.attributes.translations[0].title, + b.attributes.translations[0].subtitle ) : b.attributes?.slug ?? ""; return titleA.localeCompare(titleB); diff --git a/src/pages/dev/checkup/contents.tsx b/src/pages/dev/checkup/contents.tsx index cff8eb0..9ed7222 100644 --- a/src/pages/dev/checkup/contents.tsx +++ b/src/pages/dev/checkup/contents.tsx @@ -6,10 +6,7 @@ import { ContentPanelWidthSizes, } from "components/Panels/ContentPanel"; import { ToolTip } from "components/ToolTip"; -import { - DevGetContentsQuery, - Enum_Componentsetstextset_Status, -} from "graphql/generated"; +import { DevGetContentsQuery } from "graphql/generated"; import { AppStaticProps, getAppStaticProps } from "graphql/getAppStaticProps"; import { getReadySdk } from "graphql/sdk"; import { Immutable } from "helpers/types"; @@ -196,7 +193,7 @@ function testingContent(contents: Immutable): Report { }); } - if (content.attributes.titles?.length === 0) { + if (content.attributes.translations?.length === 0) { report.lines.push({ subitems: [content.attributes.slug], name: "No Titles", @@ -210,10 +207,10 @@ function testingContent(contents: Immutable): Report { } else { const titleLanguages: string[] = []; - content.attributes.titles?.map((title, titleIndex) => { - if (title && content.attributes) { - if (title.language?.data?.id) { - if (title.language.data.id in titleLanguages) { + content.attributes.translations?.map((translation, titleIndex) => { + if (translation && content.attributes) { + if (translation.language?.data?.id) { + if (translation.language.data.id in titleLanguages) { report.lines.push({ subitems: [ content.attributes.slug, @@ -228,7 +225,7 @@ function testingContent(contents: Immutable): Report { frontendUrl: frontendUrl, }); } else { - titleLanguages.push(title.language.data.id); + titleLanguages.push(translation.language.data.id); } } else { report.lines.push({ @@ -245,7 +242,7 @@ function testingContent(contents: Immutable): Report { frontendUrl: frontendUrl, }); } - if (!title.description) { + if (!translation.description) { report.lines.push({ subitems: [ content.attributes.slug, @@ -260,74 +257,64 @@ function testingContent(contents: Immutable): Report { frontendUrl: frontendUrl, }); } - } - }); - } - if ( - content.attributes.text_set?.length === 0 && - content.attributes.audio_set?.length === 0 && - content.attributes.video_set?.length === 0 - ) { - report.lines.push({ - subitems: [content.attributes.slug], - name: "No Sets", - type: "Missing", - severity: "Medium", - description: "The Content has no Sets.", - recommandation: "", - backendUrl: backendUrl, - frontendUrl: frontendUrl, - }); - } else { - if (content.attributes.video_set?.length === 0) { - report.lines.push({ - subitems: [content.attributes.slug], - name: "No Video Sets", - type: "Missing", - severity: "Very Low", - description: "The Content has no Video Sets.", - recommandation: "", - backendUrl: backendUrl, - frontendUrl: frontendUrl, - }); - } - if (content.attributes.audio_set?.length === 0) { - report.lines.push({ - subitems: [content.attributes.slug], - name: "No Audio Sets", - type: "Missing", - severity: "Very Low", - description: "The Content has no Audio Sets.", - recommandation: "", - backendUrl: backendUrl, - frontendUrl: frontendUrl, - }); - } - if (content.attributes.text_set?.length === 0) { - report.lines.push({ - subitems: [content.attributes.slug], - name: "No Text Set", - type: "Missing", - severity: "Medium", - description: "The Content has no Text Set.", - recommandation: "", - backendUrl: backendUrl, - frontendUrl: frontendUrl, - }); - } else { - const textSetLanguages: string[] = []; + if (translation.text_set) { + report.lines.push({ + subitems: [content.attributes.slug], + name: "No Text Set", + type: "Missing", + severity: "Medium", + description: "The Content has no Text Set.", + recommandation: "", + backendUrl: backendUrl, + frontendUrl: frontendUrl, + }); + } else { + const textSetLanguages: string[] = []; - content.attributes.text_set?.map((textSet, textSetIndex) => { - if (content.attributes && textSet) { - if (textSet.language?.data?.id) { - if (textSet.language.data.id in textSetLanguages) { + /* + if (content.attributes && textSet) { + if (textSet.language?.data?.id) { + if (textSet.language.data.id in textSetLanguages) { + report.lines.push({ + subitems: [ + content.attributes.slug, + `TextSet ${textSetIndex.toString()}`, + ], + name: "Duplicate Language", + type: "Error", + severity: "High", + description: "", + recommandation: "", + backendUrl: backendUrl, + frontendUrl: frontendUrl, + }); + } else { + textSetLanguages.push(textSet.language.data.id); + } + } else { report.lines.push({ subitems: [ content.attributes.slug, `TextSet ${textSetIndex.toString()}`, ], - name: "Duplicate Language", + name: "No Language", + type: "Error", + severity: "Very High", + description: "", + recommandation: "", + backendUrl: backendUrl, + frontendUrl: frontendUrl, + }); + } + + if (!textSet.source_language?.data?.id) { + report.lines.push({ + subitems: [ + content.attributes.slug, + `TextSet ${textSetIndex.toString()}`, + ], + name: "No Source Language", type: "Error", severity: "High", description: "", @@ -335,153 +322,134 @@ function testingContent(contents: Immutable): Report { backendUrl: backendUrl, frontendUrl: frontendUrl, }); + } + + if (textSet.status !== Enum_Componentsetstextset_Status.Done) { + report.lines.push({ + subitems: [ + content.attributes.slug, + `TextSet ${textSetIndex.toString()}`, + ], + name: "Not Done Status", + type: "Improvement", + severity: "Low", + description: "", + recommandation: "", + backendUrl: backendUrl, + frontendUrl: frontendUrl, + }); + } + + if (!textSet.text || textSet.text.length < 10) { + report.lines.push({ + subitems: [ + content.attributes.slug, + `TextSet ${textSetIndex.toString()}`, + ], + name: "No Text", + type: "Missing", + severity: "Medium", + description: "", + recommandation: "", + backendUrl: backendUrl, + frontendUrl: frontendUrl, + }); + } + + if ( + textSet.source_language?.data?.id === + textSet.language?.data?.id + ) { + if (textSet.transcribers?.data.length === 0) { + report.lines.push({ + subitems: [ + content.attributes.slug, + `TextSet ${textSetIndex.toString()}`, + ], + name: "No Transcribers", + type: "Missing", + severity: "High", + description: + "The Content is a Transcription but doesn't credit any Transcribers.", + recommandation: "Add the appropriate Transcribers.", + backendUrl: backendUrl, + frontendUrl: frontendUrl, + }); + } + if ( + textSet.translators?.data && + textSet.translators.data.length > 0 + ) { + report.lines.push({ + subitems: [ + content.attributes.slug, + `TextSet ${textSetIndex.toString()}`, + ], + name: "Credited Translators", + type: "Error", + severity: "High", + description: + "The Content is a Transcription but credits one or more Translators.", + recommandation: + "If appropriate, create a Translation Text Set with the Translator credited there.", + backendUrl: backendUrl, + frontendUrl: frontendUrl, + }); + } } else { - textSetLanguages.push(textSet.language.data.id); - } - } else { - report.lines.push({ - subitems: [ - content.attributes.slug, - `TextSet ${textSetIndex.toString()}`, - ], - name: "No Language", - type: "Error", - severity: "Very High", - description: "", - recommandation: "", - backendUrl: backendUrl, - frontendUrl: frontendUrl, - }); - } - - if (!textSet.source_language?.data?.id) { - report.lines.push({ - subitems: [ - content.attributes.slug, - `TextSet ${textSetIndex.toString()}`, - ], - name: "No Source Language", - type: "Error", - severity: "High", - description: "", - recommandation: "", - backendUrl: backendUrl, - frontendUrl: frontendUrl, - }); - } - - if (textSet.status !== Enum_Componentsetstextset_Status.Done) { - report.lines.push({ - subitems: [ - content.attributes.slug, - `TextSet ${textSetIndex.toString()}`, - ], - name: "Not Done Status", - type: "Improvement", - severity: "Low", - description: "", - recommandation: "", - backendUrl: backendUrl, - frontendUrl: frontendUrl, - }); - } - - if (!textSet.text || textSet.text.length < 10) { - report.lines.push({ - subitems: [ - content.attributes.slug, - `TextSet ${textSetIndex.toString()}`, - ], - name: "No Text", - type: "Missing", - severity: "Medium", - description: "", - recommandation: "", - backendUrl: backendUrl, - frontendUrl: frontendUrl, - }); - } - - if ( - textSet.source_language?.data?.id === textSet.language?.data?.id - ) { - if (textSet.transcribers?.data.length === 0) { - report.lines.push({ - subitems: [ - content.attributes.slug, - `TextSet ${textSetIndex.toString()}`, - ], - name: "No Transcribers", - type: "Missing", - severity: "High", - description: - "The Content is a Transcription but doesn't credit any Transcribers.", - recommandation: "Add the appropriate Transcribers.", - backendUrl: backendUrl, - frontendUrl: frontendUrl, - }); - } - if ( - textSet.translators?.data && - textSet.translators.data.length > 0 - ) { - report.lines.push({ - subitems: [ - content.attributes.slug, - `TextSet ${textSetIndex.toString()}`, - ], - name: "Credited Translators", - type: "Error", - severity: "High", - description: - "The Content is a Transcription but credits one or more Translators.", - recommandation: - "If appropriate, create a Translation Text Set with the Translator credited there.", - backendUrl: backendUrl, - frontendUrl: frontendUrl, - }); - } - } else { - if (textSet.translators?.data.length === 0) { - report.lines.push({ - subitems: [ - content.attributes.slug, - `TextSet ${textSetIndex.toString()}`, - ], - name: "No Translators", - type: "Missing", - severity: "High", - description: - "The Content is a Transcription but doesn't credit any Translators.", - recommandation: "Add the appropriate Translators.", - backendUrl: backendUrl, - frontendUrl: frontendUrl, - }); - } - if ( - textSet.transcribers?.data && - textSet.transcribers.data.length > 0 - ) { - report.lines.push({ - subitems: [ - content.attributes.slug, - `TextSet ${textSetIndex.toString()}`, - ], - name: "Credited Transcribers", - type: "Error", - severity: "High", - description: - "The Content is a Translation but credits one or more Transcribers.", - recommandation: - "If appropriate, create a Transcription Text Set with the Transcribers credited there.", - backendUrl: backendUrl, - frontendUrl: frontendUrl, - }); + if (textSet.translators?.data.length === 0) { + report.lines.push({ + subitems: [ + content.attributes.slug, + `TextSet ${textSetIndex.toString()}`, + ], + name: "No Translators", + type: "Missing", + severity: "High", + description: + "The Content is a Transcription but doesn't credit any Translators.", + recommandation: "Add the appropriate Translators.", + backendUrl: backendUrl, + frontendUrl: frontendUrl, + }); + } + if ( + textSet.transcribers?.data && + textSet.transcribers.data.length > 0 + ) { + report.lines.push({ + subitems: [ + content.attributes.slug, + `TextSet ${textSetIndex.toString()}`, + ], + name: "Credited Transcribers", + type: "Error", + severity: "High", + description: + "The Content is a Translation but credits one or more Transcribers.", + recommandation: + "If appropriate, create a Transcription Text Set with the Transcribers credited there.", + backendUrl: backendUrl, + frontendUrl: frontendUrl, + }); + } } } + */ } - }); - } + + report.lines.push({ + subitems: [content.attributes.slug], + name: "No Sets", + type: "Missing", + severity: "Medium", + description: "The Content has no Sets.", + recommandation: "", + backendUrl: backendUrl, + frontendUrl: frontendUrl, + }); + } + }); } } });