Skip to content

Commit 0db48b5

Browse files
authored
feat(dgeni,docs-utils)!: extract out ToC type (#3397)
BREAKING CHANGE: the ToC types have been trimmed up to only have fields used
1 parent bd26e3d commit 0db48b5

File tree

9 files changed

+29
-28
lines changed

9 files changed

+29
-28
lines changed

apps/daffio/src/app/docs/components/doc-viewer/doc-viewer.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
@if (isGuideDoc) {
3232
<daffio-docs-table-of-contents
3333
class="daffio-doc-viewer__table-of-contents"
34-
[tableOfContents]="doc.tableOfContents.json">
34+
[tableOfContents]="doc.tableOfContents">
3535
</daffio-docs-table-of-contents>
3636
}
3737
</div>

apps/daffio/src/app/docs/components/table-of-contents/table-of-contents.component.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('DaffioDocsTableOfContentsComponent', () => {
3232
fixture = TestBed.createComponent(DaffioDocsTableOfContentsComponent);
3333
component = fixture.componentInstance;
3434
stubDaffioDoc = new DaffioDocsFactory().create();
35-
component.tableOfContents = stubDaffioDoc.tableOfContents.json;
35+
component.tableOfContents = stubDaffioDoc.tableOfContents;
3636
fixture.detectChanges();
3737
});
3838

@@ -42,15 +42,15 @@ describe('DaffioDocsTableOfContentsComponent', () => {
4242

4343
it('should render a .daffio-docs-table-of-contents__item for each entry in the table of contents', () => {
4444
const tocItems = fixture.debugElement.queryAll(By.css('.daffio-docs-table-of-contents__item'));
45-
expect(tocItems.length).toEqual(stubDaffioDoc.tableOfContents.json.length);
45+
expect(tocItems.length).toEqual(stubDaffioDoc.tableOfContents.length);
4646
});
4747

4848
it('should label each item with an indent level based on its toc level', () => {
4949
const tocLevel1 = fixture.debugElement.queryAll(By.css('.daffio-docs-table-of-contents__item--level-1'));
5050
const tocLevel2 = fixture.debugElement.queryAll(By.css('.daffio-docs-table-of-contents__item--level-2'));
5151
const tocLevel3 = fixture.debugElement.queryAll(By.css('.daffio-docs-table-of-contents__item--level-3'));
52-
expect(tocLevel1.length).toEqual(stubDaffioDoc.tableOfContents.json.filter(content => content.lvl === 1).length);
53-
expect(tocLevel2.length).toEqual(stubDaffioDoc.tableOfContents.json.filter(content => content.lvl === 2).length);
54-
expect(tocLevel3.length).toEqual(stubDaffioDoc.tableOfContents.json.filter(content => content.lvl === 3).length);
52+
expect(tocLevel1.length).toEqual(stubDaffioDoc.tableOfContents.filter(content => content.lvl === 1).length);
53+
expect(tocLevel2.length).toEqual(stubDaffioDoc.tableOfContents.filter(content => content.lvl === 2).length);
54+
expect(tocLevel3.length).toEqual(stubDaffioDoc.tableOfContents.filter(content => content.lvl === 3).length);
5555
});
5656
});

apps/daffio/src/app/docs/components/table-of-contents/table-of-contents.component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
Input,
55
} from '@angular/core';
66

7-
import { DaffGuideDoc } from '@daffodil/docs-utils';
7+
import { DaffDocTableOfContents } from '@daffodil/docs-utils';
88

99
@Component({
1010
selector: 'daffio-docs-table-of-contents',
@@ -16,5 +16,5 @@ export class DaffioDocsTableOfContentsComponent {
1616
/**
1717
* The doc to render
1818
*/
19-
@Input() tableOfContents: DaffGuideDoc['tableOfContents']['json'];
19+
@Input() tableOfContents: DaffDocTableOfContents;
2020
}

apps/daffio/src/app/docs/testing/factories/docs.factory.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ describe('DaffioDocsFactory', () => {
1717
expect(Object.keys(doc)).toContain('id');
1818
expect(Object.keys(doc)).toContain('title');
1919
expect(Object.keys(doc)).toContain('contents');
20-
expect(Object.keys(doc.tableOfContents.json[0])).toContain('content');
21-
expect(Object.keys(doc.tableOfContents.json[0])).toContain('lvl');
22-
expect(Object.keys(doc.tableOfContents.json[0])).toContain('slug');
20+
expect(Object.keys(doc.tableOfContents[0])).toContain('content');
21+
expect(Object.keys(doc.tableOfContents[0])).toContain('lvl');
22+
expect(Object.keys(doc.tableOfContents[0])).toContain('slug');
2323
});
2424
});

apps/daffio/src/app/docs/testing/factories/docs.factory.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@ export class MockDoc implements DaffGuideDoc {
1515
contents = faker.lorem.paragraph();
1616
// TODO: implement child models
1717
breadcrumbs = [];
18-
tableOfContents = {
19-
json: [
20-
{
21-
content: faker.lorem.paragraph(),
22-
lvl: faker.datatype.number(),
23-
slug: faker.random.alphaNumeric(),
24-
},
25-
],
26-
};
18+
tableOfContents = [
19+
{
20+
content: faker.lorem.paragraph(),
21+
lvl: faker.datatype.number(),
22+
slug: faker.random.alphaNumeric(),
23+
},
24+
];
2725
};
2826

2927
@Injectable({

libs/docs-utils/src/doc/guide.type.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1+
import { DaffDocTableOfContents } from './toc.type';
12
import { DaffDoc } from './type';
23

34
/**
45
* A guide doc. Includes a table of contents.
56
*/
67
export interface DaffGuideDoc extends DaffDoc {
7-
tableOfContents: {
8-
json: Array<{
9-
content: string;
10-
lvl: number;
11-
slug: string;
12-
}>;
13-
};
8+
tableOfContents: DaffDocTableOfContents;
149
}

libs/docs-utils/src/doc/public_api.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './api.type';
22
export * from './example.type';
33
export * from './guide.type';
4+
export * from './toc.type';
45
export * from './type';

libs/docs-utils/src/doc/toc.type.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export interface DaffDocTableOfContentsEntry {
2+
content: string;
3+
lvl: number;
4+
slug: string;
5+
}
6+
7+
export type DaffDocTableOfContents = Array<DaffDocTableOfContentsEntry>;

tools/dgeni/src/transforms/daffodil-guides-package/reader/guide-file.reader.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function guideFileReaderFactory() {
3535
getDocs: (fileInfo) => fileInfo.content ? [{
3636
docType: 'guide',
3737
title: extractTitle(fileInfo),
38-
tableOfContents: toc(fileInfo.content),
38+
tableOfContents: toc(fileInfo.content).json,
3939
content: fileInfo.content,
4040
}] : [],
4141
};

0 commit comments

Comments
 (0)