From e758e17c546fb0c8b154ebe01fda45dba670bf99 Mon Sep 17 00:00:00 2001 From: Jonas Carlsen Date: Wed, 20 Mar 2024 19:16:25 +0100 Subject: [PATCH 1/2] Do not rely on topic to assert whether a resource is supplementary or not --- src/components/Learningpath/Learningpath.tsx | 3 --- src/components/Learningpath/LearningpathEmbed.tsx | 14 +++----------- src/containers/ArticlePage/ArticlePage.tsx | 3 ++- .../PlainArticlePage/PlainArticleContainer.tsx | 10 +--------- .../components/SharedArticleContainer.tsx | 2 -- src/graphqlTypes.ts | 11 ++++------- src/iframe/IframeArticlePage.tsx | 1 + src/util/getArticleProps.ts | 10 ++-------- 8 files changed, 13 insertions(+), 41 deletions(-) diff --git a/src/components/Learningpath/Learningpath.tsx b/src/components/Learningpath/Learningpath.tsx index dfc354bfa2..5e66f83146 100644 --- a/src/components/Learningpath/Learningpath.tsx +++ b/src/components/Learningpath/Learningpath.tsx @@ -176,7 +176,6 @@ const Learningpath = ({ )} { +const LearningpathEmbed = ({ learningpathStep, skipToContentId, subjectId, breadcrumbItems }: Props) => { const { t, i18n } = useTranslation(); const location = useLocation(); const [taxId, articleId] = @@ -178,7 +176,7 @@ const LearningpathEmbed = ({ learningpathStep, skipToContentId, topic, subjectId id={skipToContentId} article={article} oembed={data?.article?.oembed} - {...getArticleProps(resource, topic)} + {...getArticleProps(resource)} > {path ? : <>} @@ -206,13 +204,6 @@ const articleFragment = gql` `; LearningpathEmbed.fragments = { - topic: gql` - fragment LearningpathEmbed_Topic on Topic { - supplementaryResources(subjectId: $subjectId) { - id - } - } - `, article: articleFragment, learningpathStep: gql` fragment LearningpathEmbed_LearningpathStep on LearningpathStep { @@ -254,6 +245,7 @@ const learningpathStepQuery = gql` resource(id: $resourceId) @include(if: $includeResource) { id path + relevanceId resourceTypes { id name diff --git a/src/containers/ArticlePage/ArticlePage.tsx b/src/containers/ArticlePage/ArticlePage.tsx index 38e4533735..e1fe2d9653 100644 --- a/src/containers/ArticlePage/ArticlePage.tsx +++ b/src/containers/ArticlePage/ArticlePage.tsx @@ -186,7 +186,7 @@ const ArticlePage = ({ subjectId={subject?.id} showFavoriteButton={config.feideEnabled} oembed={article.oembed} - {...getArticleProps(resource, topic)} + {...getArticleProps(resource)} /> {topic && ( @@ -236,6 +236,7 @@ export const articlePageFragments = { name path contentUri + relevanceId article { created updated diff --git a/src/containers/PlainArticlePage/PlainArticleContainer.tsx b/src/containers/PlainArticlePage/PlainArticleContainer.tsx index 64755e8dce..3642db2285 100644 --- a/src/containers/PlainArticlePage/PlainArticleContainer.tsx +++ b/src/containers/PlainArticlePage/PlainArticleContainer.tsx @@ -20,7 +20,6 @@ import AddEmbedToFolder from "../../components/MyNdla/AddEmbedToFolder"; import SocialMediaMetadata from "../../components/SocialMediaMetadata"; import config from "../../config"; import { GQLPlainArticleContainer_ArticleFragment } from "../../graphqlTypes"; -import { getArticleProps } from "../../util/getArticleProps"; import { getArticleScripts } from "../../util/getArticleScripts"; import getStructuredDataFromArticle, { structuredArticleDataFragment } from "../../util/getStructuredDataFromArticle"; import { htmlTitle } from "../../util/titleHelper"; @@ -97,14 +96,7 @@ const PlainArticleContainer = ({ article: propArticle, skipToContentId }: Props) trackableContent={article} /> -
+
); diff --git a/src/containers/SharedFolderPage/components/SharedArticleContainer.tsx b/src/containers/SharedFolderPage/components/SharedArticleContainer.tsx index e6843a69c8..b17b5fe576 100644 --- a/src/containers/SharedFolderPage/components/SharedArticleContainer.tsx +++ b/src/containers/SharedFolderPage/components/SharedArticleContainer.tsx @@ -24,7 +24,6 @@ import { GQLFolderResourceMetaSearchQuery, GQLSharedResourceArticleContainer_ArticleFragment, } from "../../../graphqlTypes"; -import { getArticleProps } from "../../../util/getArticleProps"; import { getArticleScripts } from "../../../util/getArticleScripts"; import { getContentTypeFromResourceTypes } from "../../../util/getContentType"; import { structuredArticleDataFragment } from "../../../util/getStructuredDataFromArticle"; @@ -97,7 +96,6 @@ const SharedArticleContainer = ({ article: propArticle, meta, title }: Props) => id={SKIP_TO_CONTENT_ID} oembed={undefined} article={article} - {...getArticleProps(undefined, undefined)} contentType={contentType?.contentType} label={contentType?.label || ""} /> diff --git a/src/graphqlTypes.ts b/src/graphqlTypes.ts index 0bf372555f..46b411f07a 100644 --- a/src/graphqlTypes.ts +++ b/src/graphqlTypes.ts @@ -2221,8 +2221,7 @@ export type GQLLastLearningpathStepInfo_ResourceTypeDefinitionFragment = { __typename?: "ResourceTypeDefinition"; } & GQLResources_ResourceTypeDefinitionFragment; -export type GQLLearningpath_TopicFragment = { __typename?: "Topic" } & GQLLastLearningpathStepInfo_TopicFragment & - GQLLearningpathEmbed_TopicFragment; +export type GQLLearningpath_TopicFragment = { __typename?: "Topic" } & GQLLastLearningpathStepInfo_TopicFragment; export type GQLLearningpath_ResourceTypeDefinitionFragment = { __typename?: "ResourceTypeDefinition"; @@ -2277,11 +2276,6 @@ export type GQLLearningpathEmbed_ArticleFragment = { } & GQLStructuredArticleDataFragment & GQLArticle_ArticleFragment; -export type GQLLearningpathEmbed_TopicFragment = { - __typename?: "Topic"; - supplementaryResources?: Array<{ __typename?: "Resource"; id: string }>; -}; - export type GQLLearningpathEmbed_LearningpathStepFragment = { __typename?: "LearningpathStep"; resource?: { @@ -2309,6 +2303,7 @@ export type GQLLearningpathStepQuery = { __typename?: "Resource"; id: string; path: string; + relevanceId?: string; resourceTypes?: Array<{ __typename?: "ResourceType"; id: string; name: string }>; }; }; @@ -2502,6 +2497,7 @@ export type GQLArticlePage_ResourceFragment = { name: string; path: string; contentUri?: string; + relevanceId?: string; article?: { __typename?: "Article"; created: string; @@ -4293,6 +4289,7 @@ export type GQLIframeArticlePage_ResourceFragment = { __typename?: "Resource"; id: string; path: string; + relevanceId?: string; resourceTypes?: Array<{ __typename?: "ResourceType"; id: string; name: string }>; }; diff --git a/src/iframe/IframeArticlePage.tsx b/src/iframe/IframeArticlePage.tsx index 10b7719f7b..b5ee34797b 100644 --- a/src/iframe/IframeArticlePage.tsx +++ b/src/iframe/IframeArticlePage.tsx @@ -146,6 +146,7 @@ export const iframeArticlePageFragments = { fragment IframeArticlePage_Resource on Resource { id path + relevanceId resourceTypes { id name diff --git a/src/util/getArticleProps.ts b/src/util/getArticleProps.ts index cc454aa640..39f8619351 100644 --- a/src/util/getArticleProps.ts +++ b/src/util/getArticleProps.ts @@ -9,18 +9,12 @@ import { getContentType } from "./getContentType"; import { GQLResource } from "../graphqlTypes"; -interface Topic { - supplementaryResources?: { id: string }[]; -} -export const getArticleProps = ( - resource: Pick | undefined, - topic?: T, -) => { +export const getArticleProps = (resource: Pick | undefined) => { const hasResourceTypes = resource?.resourceTypes && resource?.resourceTypes?.length > 0; const contentType = hasResourceTypes && resource ? getContentType(resource) : undefined; - const additional = topic?.supplementaryResources?.some((item) => item?.id === resource?.id) ?? false; + const additional = resource?.relevanceId !== "urn:relevance:core"; const label = (hasResourceTypes && resource?.resourceTypes![0]?.name) || ""; return { contentType, label, additional }; From 9754056990c6003adb4d94df53e5a536181337a2 Mon Sep 17 00:00:00 2001 From: Jonas Carlsen Date: Wed, 20 Mar 2024 19:40:00 +0100 Subject: [PATCH 2/2] Reduce subject and topic usage on ResourcePage --- src/containers/ArticlePage/ArticlePage.tsx | 28 ++++++------------- .../ArticlePage/components/ArticleHero.tsx | 12 ++------ 2 files changed, 11 insertions(+), 29 deletions(-) diff --git a/src/containers/ArticlePage/ArticlePage.tsx b/src/containers/ArticlePage/ArticlePage.tsx index e1fe2d9653..d061ce0228 100644 --- a/src/containers/ArticlePage/ArticlePage.tsx +++ b/src/containers/ArticlePage/ArticlePage.tsx @@ -71,7 +71,6 @@ const ArticlePage = ({ const { user, authContextLoaded } = useContext(AuthContext); const { t, i18n } = useTranslation(); const { trackPageView } = useTracker(); - const subjectPageUrl = config.ndlaFrontendDomain; useEffect(() => { if (!loading && authContextLoaded) { @@ -135,32 +134,24 @@ const ArticlePage = ({ const contentType = resource ? getContentType(resource) : undefined; const resourceType = contentType && isHeroContentType(contentType) ? contentType : undefined; - const copyPageUrlLink = topic ? `${subjectPageUrl}${topic.path}/${resource.id.replace("urn:", "")}` : undefined; - const printUrl = `${subjectPageUrl}/article-iframe/${i18n.language}/article/${resource.article.id}`; + const printUrl = `${config.ndlaFrontendDomain}/article-iframe/${i18n.language}/article/${resource.article.id}`; const breadcrumbItems = toBreadcrumbItems(t("breadcrumb.toFrontpage"), [...topicPath, resource]); return (
- + {`${getDocumentTitle(t, resource, subject)}`} {scripts?.map((script) => (