Skip to content

Commit d5db66e

Browse files
committed
Do not rely on topic to assert whether a resource is supplementary or
not
1 parent c2dfeeb commit d5db66e

File tree

8 files changed

+13
-41
lines changed

8 files changed

+13
-41
lines changed

src/components/Learningpath/Learningpath.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ const Learningpath = ({
176176
)}
177177
<LearningpathEmbed
178178
skipToContentId={!learningpathStep.showTitle ? skipToContentId : undefined}
179-
topic={topic}
180179
subjectId={subject?.id}
181180
learningpathStep={learningpathStep}
182181
breadcrumbItems={breadcrumbItems}
@@ -227,9 +226,7 @@ Learningpath.fragments = {
227226
topic: gql`
228227
fragment Learningpath_Topic on Topic {
229228
...LastLearningpathStepInfo_Topic
230-
...LearningpathEmbed_Topic
231229
}
232-
${LearningpathEmbed.fragments.topic}
233230
${LastLearningpathStepInfo.fragments.topic}
234231
`,
235232
resourceType: gql`

src/components/Learningpath/LearningpathEmbed.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import config from "../../config";
2121
import ErrorPage from "../../containers/ErrorPage";
2222
import {
2323
GQLLearningpathEmbed_LearningpathStepFragment,
24-
GQLLearningpathEmbed_TopicFragment,
2524
GQLLearningpathStepQuery,
2625
GQLLearningpathStepQueryVariables,
2726
} from "../../graphqlTypes";
@@ -72,12 +71,11 @@ const converterComponents: DynamicComponents = {
7271

7372
interface Props {
7473
learningpathStep: GQLLearningpathEmbed_LearningpathStepFragment;
75-
topic?: GQLLearningpathEmbed_TopicFragment;
7674
skipToContentId?: string;
7775
breadcrumbItems: Breadcrumb[];
7876
subjectId?: string;
7977
}
80-
const LearningpathEmbed = ({ learningpathStep, skipToContentId, topic, subjectId, breadcrumbItems }: Props) => {
78+
const LearningpathEmbed = ({ learningpathStep, skipToContentId, subjectId, breadcrumbItems }: Props) => {
8179
const { t, i18n } = useTranslation();
8280
const location = useLocation();
8381
const [taxId, articleId] =
@@ -178,7 +176,7 @@ const LearningpathEmbed = ({ learningpathStep, skipToContentId, topic, subjectId
178176
id={skipToContentId}
179177
article={article}
180178
oembed={data?.article?.oembed}
181-
{...getArticleProps(resource, topic)}
179+
{...getArticleProps(resource)}
182180
>
183181
{path ? <CreatedBy name={t("createdBy.content")} description={t("createdBy.text")} url={contentUrl} /> : <></>}
184182
</Article>
@@ -206,13 +204,6 @@ const articleFragment = gql`
206204
`;
207205

208206
LearningpathEmbed.fragments = {
209-
topic: gql`
210-
fragment LearningpathEmbed_Topic on Topic {
211-
supplementaryResources(subjectId: $subjectId) {
212-
id
213-
}
214-
}
215-
`,
216207
article: articleFragment,
217208
learningpathStep: gql`
218209
fragment LearningpathEmbed_LearningpathStep on LearningpathStep {
@@ -254,6 +245,7 @@ const learningpathStepQuery = gql`
254245
resource(id: $resourceId) @include(if: $includeResource) {
255246
id
256247
path
248+
relevanceId
257249
resourceTypes {
258250
id
259251
name

src/containers/ArticlePage/ArticlePage.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ const ArticlePage = ({
186186
subjectId={subject?.id}
187187
showFavoriteButton={config.feideEnabled}
188188
oembed={article.oembed}
189-
{...getArticleProps(resource, topic)}
189+
{...getArticleProps(resource)}
190190
/>
191191
{topic && (
192192
<LayoutItem layout="extend">
@@ -236,6 +236,7 @@ export const articlePageFragments = {
236236
name
237237
path
238238
contentUri
239+
relevanceId
239240
article {
240241
created
241242
updated

src/containers/PlainArticlePage/PlainArticleContainer.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import AddEmbedToFolder from "../../components/MyNdla/AddEmbedToFolder";
2020
import SocialMediaMetadata from "../../components/SocialMediaMetadata";
2121
import config from "../../config";
2222
import { GQLPlainArticleContainer_ArticleFragment } from "../../graphqlTypes";
23-
import { getArticleProps } from "../../util/getArticleProps";
2423
import { getArticleScripts } from "../../util/getArticleScripts";
2524
import getStructuredDataFromArticle, { structuredArticleDataFragment } from "../../util/getStructuredDataFromArticle";
2625
import { htmlTitle } from "../../util/titleHelper";
@@ -97,14 +96,7 @@ const PlainArticleContainer = ({ article: propArticle, skipToContentId }: Props)
9796
trackableContent={article}
9897
/>
9998
<OneColumn>
100-
<Article
101-
contentTransformed
102-
isPlainArticle
103-
id={skipToContentId}
104-
article={article}
105-
oembed={undefined}
106-
{...getArticleProps(undefined, undefined)}
107-
/>
99+
<Article contentTransformed isPlainArticle id={skipToContentId} article={article} oembed={undefined} label="" />
108100
</OneColumn>
109101
</div>
110102
);

src/containers/SharedFolderPage/components/SharedArticleContainer.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {
2424
GQLFolderResourceMetaSearchQuery,
2525
GQLSharedResourceArticleContainer_ArticleFragment,
2626
} from "../../../graphqlTypes";
27-
import { getArticleProps } from "../../../util/getArticleProps";
2827
import { getArticleScripts } from "../../../util/getArticleScripts";
2928
import { getContentTypeFromResourceTypes } from "../../../util/getContentType";
3029
import { structuredArticleDataFragment } from "../../../util/getStructuredDataFromArticle";
@@ -97,7 +96,6 @@ const SharedArticleContainer = ({ article: propArticle, meta, title }: Props) =>
9796
id={SKIP_TO_CONTENT_ID}
9897
oembed={undefined}
9998
article={article}
100-
{...getArticleProps(undefined, undefined)}
10199
contentType={contentType?.contentType}
102100
label={contentType?.label || ""}
103101
/>

src/graphqlTypes.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,8 +2221,7 @@ export type GQLLastLearningpathStepInfo_ResourceTypeDefinitionFragment = {
22212221
__typename?: "ResourceTypeDefinition";
22222222
} & GQLResources_ResourceTypeDefinitionFragment;
22232223

2224-
export type GQLLearningpath_TopicFragment = { __typename?: "Topic" } & GQLLastLearningpathStepInfo_TopicFragment &
2225-
GQLLearningpathEmbed_TopicFragment;
2224+
export type GQLLearningpath_TopicFragment = { __typename?: "Topic" } & GQLLastLearningpathStepInfo_TopicFragment;
22262225

22272226
export type GQLLearningpath_ResourceTypeDefinitionFragment = {
22282227
__typename?: "ResourceTypeDefinition";
@@ -2277,11 +2276,6 @@ export type GQLLearningpathEmbed_ArticleFragment = {
22772276
} & GQLStructuredArticleDataFragment &
22782277
GQLArticle_ArticleFragment;
22792278

2280-
export type GQLLearningpathEmbed_TopicFragment = {
2281-
__typename?: "Topic";
2282-
supplementaryResources?: Array<{ __typename?: "Resource"; id: string }>;
2283-
};
2284-
22852279
export type GQLLearningpathEmbed_LearningpathStepFragment = {
22862280
__typename?: "LearningpathStep";
22872281
resource?: {
@@ -2309,6 +2303,7 @@ export type GQLLearningpathStepQuery = {
23092303
__typename?: "Resource";
23102304
id: string;
23112305
path: string;
2306+
relevanceId?: string;
23122307
resourceTypes?: Array<{ __typename?: "ResourceType"; id: string; name: string }>;
23132308
};
23142309
};
@@ -2502,6 +2497,7 @@ export type GQLArticlePage_ResourceFragment = {
25022497
name: string;
25032498
path: string;
25042499
contentUri?: string;
2500+
relevanceId?: string;
25052501
article?: {
25062502
__typename?: "Article";
25072503
created: string;
@@ -4293,6 +4289,7 @@ export type GQLIframeArticlePage_ResourceFragment = {
42934289
__typename?: "Resource";
42944290
id: string;
42954291
path: string;
4292+
relevanceId?: string;
42964293
resourceTypes?: Array<{ __typename?: "ResourceType"; id: string; name: string }>;
42974294
};
42984295

src/iframe/IframeArticlePage.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export const iframeArticlePageFragments = {
146146
fragment IframeArticlePage_Resource on Resource {
147147
id
148148
path
149+
relevanceId
149150
resourceTypes {
150151
id
151152
name

src/util/getArticleProps.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,12 @@
99
import { getContentType } from "./getContentType";
1010
import { GQLResource } from "../graphqlTypes";
1111

12-
interface Topic {
13-
supplementaryResources?: { id: string }[];
14-
}
15-
export const getArticleProps = <T extends Topic>(
16-
resource: Pick<GQLResource, "resourceTypes" | "id"> | undefined,
17-
topic?: T,
18-
) => {
12+
export const getArticleProps = (resource: Pick<GQLResource, "resourceTypes" | "id" | "relevanceId"> | undefined) => {
1913
const hasResourceTypes = resource?.resourceTypes && resource?.resourceTypes?.length > 0;
2014

2115
const contentType = hasResourceTypes && resource ? getContentType(resource) : undefined;
2216

23-
const additional = topic?.supplementaryResources?.some((item) => item?.id === resource?.id) ?? false;
17+
const additional = resource?.relevanceId !== "urn:relevance:core";
2418

2519
const label = (hasResourceTypes && resource?.resourceTypes![0]?.name) || "";
2620
return { contentType, label, additional };

0 commit comments

Comments
 (0)