Skip to content

Commit 2a71ea6

Browse files
NXT-163 Adjustments for new indev api data
1 parent 330dc49 commit 2a71ea6

File tree

10 files changed

+74
-34
lines changed

10 files changed

+74
-34
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"_links":{"self":[{}]},"eTag":"01000000-0000-0017-0000-000000000007","pdfLink":null,"content":null,"sections":[]}
1+
{"_links":{"self":[{}]},"eTag":"01000000-0000-0017-0000-000000000007","content":null,"pdfLink":null,"title":"","chapterTitle": "","chapters":[],"sections":[]}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"_links":{"self":[{}]},"eTag":"01000000-0000-0017-0000-000000000007","pdfLink":null,"content":null,"sections":[]}
1+
{"_links":{"self":[{}]},"eTag":"01000000-0000-0017-0000-000000000007","content":null,"pdfLink":null,"title":"","chapterTitle": "","chapters":[],"sections":[]}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"_links":{"self":[{}]},"eTag":"01000000-0000-0017-0000-000000000007","pdfLink":null,"content":null,"sections":[]}
1+
{"_links":{"self":[{}]},"eTag":"01000000-0000-0017-0000-000000000007","content":null,"pdfLink":null,"title":"","chapterTitle": "","chapters":[],"sections":[]}

web/src/__mocks__/__data__/inDev/guidance/gid-dg10086/documents/final-scope-html-conversion/chapter/recommendations.json

Lines changed: 9 additions & 1 deletion
Large diffs are not rendered by default.

web/src/__mocks__/__data__/inDev/guidance/gid-dg10086/documents/final-scope-html-conversion/html.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"eTag": "01000000-0000-0017-0000-000000000007",
44
"content": "<div class=\"chapter\" title=\"Overview\" id=\"0-1-overview\" xmlns=\"http://www.w3.org/1999/xhtml\">\r\n <h2 class=\"title\">\r\n <a id=\"overview\" style=\"position:relative\" class=\"annotator-chapter\" data-heading-type=\"chapter\"></a>Overview<span class=\"annotator-adder\"></span></h2>\r\n <p>This guideline covers care for women of any age (including girls and young women under 18) who request an abortion. It aims to improve the organisation of services and make them easier for women to access. Detailed recommendations on conducting abortions at different gestational stages are also included, to ensure that women get the safest and most effective care possible. </p>\r\n</div>",
55
"pdfLink": "/guidance/GID-DG10086/documents/final-scope-pdf",
6-
"sections": [
6+
"title": "Some document title",
7+
"chapterTitle": "Overview",
8+
"chapters": [
79
{
810
"slug": "overview",
911
"title": "Overview",
@@ -14,5 +16,11 @@
1416
"title": "Recommendations",
1517
"href": "/guidance/GID-DG10086/documents/final-scope-html-conversion/chapter/recommendations"
1618
}
19+
],
20+
"sections": [
21+
{
22+
"slug": "0-1-who-is-it-for",
23+
"title": "Who is it for?"
24+
}
1725
]
1826
}

web/src/components/ProjectDisplayWordConversion/ProjectDisplayWordConversion.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import {
88

99
const props: ProjectDisplayWordConversionProps = {
1010
content: mockConvertedDocumentFeed.content,
11-
sections: mockConvertedDocumentFeed.sections,
11+
chapters: mockConvertedDocumentFeed.chapters,
1212
inPageNavLinks: [],
1313
pdfLink: "/guidance/GID-DG10086/documents/final-scope-pdf",
1414
currentChapter: "",
1515
currentUrl:
1616
"/guidance/topic-selection/gid-dg10086/documents/final-scope-html-conversion",
1717
resourceFileTitle: "Test converted document",
18+
sections: mockConvertedDocumentFeed.sections,
1819
};
1920

2021
describe("ProjectDisplayWordConversion", () => {
@@ -29,7 +30,7 @@ describe("ProjectDisplayWordConversion", () => {
2930
const { getAllByRole } = within(chapterNavList);
3031
const chapterNavListItems = getAllByRole("listitem");
3132
expect(chapterNavList).toBeInTheDocument();
32-
expect(chapterNavListItems.length).toEqual(props.sections.length);
33+
expect(chapterNavListItems.length).toEqual(props.chapters.length);
3334
});
3435

3536
it("should render the first chapter menu item as active with index as slug", () => {

web/src/components/ProjectDisplayWordConversion/ProjectDisplayWordConversion.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ export const ProjectDisplayWordConversion: FC<
2626
ProjectDisplayWordConversionProps
2727
> = ({
2828
content,
29-
sections,
29+
chapters,
3030
inPageNavLinks,
3131
pdfLink,
3232
currentChapter,
3333
currentUrl,
3434
resourceFileTitle,
35+
//sections,
3536
}) => {
3637
// find chapter slug in url string
3738
const currentUrlChapterSlugIndex = currentChapter
@@ -56,9 +57,9 @@ export const ProjectDisplayWordConversion: FC<
5657
const chapterSlug =
5758
prevOrNextArrayIndex === 0
5859
? ""
59-
: `/chapter/${sections[prevOrNextArrayIndex].slug}`;
60+
: `/chapter/${chapters[prevOrNextArrayIndex].slug}`;
6061
const prevOrNextObject = {
61-
text: sections[prevOrNextArrayIndex].title,
62+
text: chapters[prevOrNextArrayIndex].title,
6263
destination: `${currentUrlNoChapter}${chapterSlug}`,
6364
elementType: Link,
6465
};
@@ -86,23 +87,23 @@ export const ProjectDisplayWordConversion: FC<
8687
</Button>
8788
)}
8889
<StackedNav aria-label="chapters">
89-
{sections.map((section, index) => {
90-
const chapterSlug = index === 0 ? "" : `/chapter/${section.slug}`;
90+
{chapters.map((chapter, index) => {
91+
const chapterSlug = index === 0 ? "" : `/chapter/${chapter.slug}`;
9192
const destination = `${currentUrlNoChapter}${chapterSlug}`;
9293
const isCurrentChapter =
93-
section.slug === currentChapter ||
94+
chapter.slug === currentChapter ||
9495
(currentChapter === "" && index === 0);
9596

9697
if (isCurrentChapter) currentChapterArrayIndex = index;
9798

9899
return (
99100
<StackedNavLink
100-
key={section.slug}
101+
key={chapter.slug}
101102
destination={destination}
102103
elementType={Link}
103104
isCurrent={isCurrentChapter}
104105
>
105-
{section.title}
106+
{chapter.title}
106107
</StackedNavLink>
107108
);
108109
})}
@@ -150,12 +151,12 @@ export const ProjectDisplayWordConversion: FC<
150151
<PrevNext
151152
{...generatePrevNextLinks(
152153
currentChapterArrayIndex - 1,
153-
sections.length,
154+
chapters.length,
154155
true
155156
)}
156157
{...generatePrevNextLinks(
157158
currentChapterArrayIndex + 1,
158-
sections.length,
159+
chapters.length,
159160
false
160161
)}
161162
/>

web/src/feeds/inDev/types.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,12 +627,17 @@ export type resourceInPageNavLink = {
627627
title: string;
628628
};
629629

630-
export type niceIndevConvertedDocumentSection = {
630+
export type niceIndevConvertedDocumentChapter = {
631631
slug: string;
632632
title: string;
633633
href: string;
634634
};
635635

636+
export type niceIndevConvertedDocumentSection = {
637+
slug: string;
638+
title: string;
639+
};
640+
636641
export type niceIndevConvertedDocument = {
637642
_links?: {
638643
self: [
@@ -641,8 +646,11 @@ export type niceIndevConvertedDocument = {
641646
}
642647
];
643648
};
644-
pdfLink: string | null;
645649
eTag?: string | null;
646650
content: string;
647-
sections: niceIndevConvertedDocumentSection[];
651+
pdfLink: string | null;
652+
title?: string;
653+
chapterTitle?: string;
654+
chapters: niceIndevConvertedDocumentChapter[];
655+
sections?: niceIndevConvertedDocumentSection[];
648656
};

web/src/pages/indicators/indevelopment/[slug]/documents/[resourceTitleId]/chapter/[chapterSlug].page.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
import {
1717
IndevFileResource,
1818
IndevSchedule,
19-
niceIndevConvertedDocument,
19+
niceIndevConvertedDocumentChapter,
2020
niceIndevConvertedDocumentSection,
2121
ProjectDetail,
2222
resourceInPageNavLink,
@@ -39,8 +39,11 @@ export type DocumentsChapterHTMLPageProps = {
3939
isConvertedDocument: boolean;
4040
resourceFileHTML: string;
4141
resourceFileChapters: {
42-
allChapters: niceIndevConvertedDocumentSection[];
43-
currentChapter: string;
42+
allChapters: niceIndevConvertedDocumentChapter[];
43+
currentChapter: {
44+
title: string;
45+
sections?: niceIndevConvertedDocumentSection[];
46+
};
4447
currentUrl: string;
4548
};
4649
resourceInPageNavLinks: resourceInPageNavLink[];
@@ -109,12 +112,13 @@ export default function DocumentsChapterHTMLPage({
109112
{resource.isConvertedDocument ? (
110113
<ProjectDisplayWordConversion
111114
content={resource.resourceFileHTML}
112-
sections={resource.resourceFileChapters.allChapters}
115+
chapters={resource.resourceFileChapters.allChapters}
113116
inPageNavLinks={resource.resourceInPageNavLinks}
114117
pdfLink={resource.resourceFilePdfLink}
115-
currentChapter={resource.resourceFileChapters.currentChapter}
118+
currentChapter={resource.resourceFileChapters.currentChapter.title}
116119
currentUrl={resource.resourceFileChapters.currentUrl}
117120
resourceFileTitle={resource.resourceFileTitle}
121+
sections={resource.resourceFileChapters.currentChapter.sections}
118122
/>
119123
) : (
120124
<>
@@ -219,8 +223,11 @@ export const getServerSideProps: GetServerSideProps<
219223
}
220224

221225
const resourceFileChapters = {
222-
allChapters: resourceFileHTML.sections || [],
223-
currentChapter: chapterSlug,
226+
allChapters: resourceFileHTML.chapters || [],
227+
currentChapter: {
228+
title: chapterSlug,
229+
sections: resourceFileHTML.sections,
230+
},
224231
currentUrl: `${projectPath}/documents/${params.resourceTitleId}`,
225232
};
226233

web/src/pages/indicators/indevelopment/[slug]/documents/[resourceTitleId]/index.page.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
import {
1717
IndevFileResource,
1818
IndevSchedule,
19-
niceIndevConvertedDocument,
19+
niceIndevConvertedDocumentChapter,
2020
niceIndevConvertedDocumentSection,
2121
ProjectDetail,
2222
resourceInPageNavLink,
@@ -39,8 +39,11 @@ export type DocumentHTMLPageProps = {
3939
isConvertedDocument: boolean;
4040
resourceFileHTML: string;
4141
resourceFileChapters: {
42-
allChapters: niceIndevConvertedDocumentSection[];
43-
currentChapter: string;
42+
allChapters: niceIndevConvertedDocumentChapter[];
43+
currentChapter: {
44+
title: string;
45+
sections?: niceIndevConvertedDocumentSection[];
46+
};
4447
currentUrl: string;
4548
};
4649
resourceInPageNavLinks: resourceInPageNavLink[];
@@ -109,12 +112,13 @@ export default function DocumentsHTMLPage({
109112
{resource.isConvertedDocument ? (
110113
<ProjectDisplayWordConversion
111114
content={resource.resourceFileHTML}
112-
sections={resource.resourceFileChapters.allChapters}
115+
chapters={resource.resourceFileChapters.allChapters}
113116
inPageNavLinks={resource.resourceInPageNavLinks}
114117
pdfLink={resource.resourceFilePdfLink}
115-
currentChapter={resource.resourceFileChapters.currentChapter}
118+
currentChapter={resource.resourceFileChapters.currentChapter.title}
116119
currentUrl={resource.resourceFileChapters.currentUrl}
117120
resourceFileTitle={resource.resourceFileTitle}
121+
sections={resource.resourceFileChapters.currentChapter.sections}
118122
/>
119123
) : (
120124
<>
@@ -208,8 +212,11 @@ export const getServerSideProps: GetServerSideProps<
208212
}
209213

210214
const resourceFileChapters = {
211-
allChapters: resourceFileHTML.sections || [],
212-
currentChapter: "",
215+
allChapters: resourceFileHTML.chapters || [],
216+
currentChapter: {
217+
title: "",
218+
sections: resourceFileHTML.sections,
219+
},
213220
currentUrl: `${projectPath}/documents/${params.resourceTitleId}`,
214221
};
215222

0 commit comments

Comments
 (0)