Skip to content

Commit 4f2c4e6

Browse files
committed
feat(daffio): consolidate docs list rendering (#2989)
1 parent b2f33c5 commit 4f2c4e6

32 files changed

+251
-389
lines changed

apps/daffio/src/app/app.module.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { StoreModule } from '@ngrx/store';
1515
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
1616

1717
import { DAFF_THEME_INITIALIZER } from '@daffodil/design';
18+
import { provideDaffRouterActivatedRoute } from '@daffodil/router';
1819

1920
import { AppRoutingModule } from './app-routing.module';
2021
import { DaffioAppComponent } from './app.component';
@@ -35,7 +36,7 @@ import { environment } from '../environments/environment';
3536
BrowserAnimationsModule,
3637

3738
StoreModule.forRoot({}),
38-
EffectsModule.forRoot([]),
39+
EffectsModule.forRoot(),
3940
HttpClientModule,
4041

4142
AppRoutingModule,
@@ -75,6 +76,7 @@ import { environment } from '../environments/environment';
7576
provide: APP_ID,
7677
useValue: 'serverApp',
7778
},
79+
provideDaffRouterActivatedRoute(),
7880
],
7981
})
8082
export class AppModule {}

apps/daffio/src/app/docs/api/api-routing.module.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,41 @@
1-
import { NgModule } from '@angular/core';
1+
import {
2+
inject,
3+
NgModule,
4+
} from '@angular/core';
25
import {
36
Routes,
47
RouterModule,
58
} from '@angular/router';
69

7-
import { DaffRouteWithNamedViews } from '@daffodil/router';
10+
import { DaffDocKind } from '@daffodil/docs-utils';
811

912
import { DaffioApiListPageComponent } from './pages/api-list-page/api-list-page.component';
1013
import { DaffioApiPageComponent } from './pages/api-page/api-page.component';
11-
import { DaffioApiListResolver } from './resolvers/api-list-resolver.service';
1214
import { DaffioSimpleFooterComponent } from '../../core/footer/simple-footer/simple-footer.component';
15+
import { DaffioRoute } from '../../core/router/route.type';
1316
import { DaffioDocsSidebarContentComponent } from '../../core/sidebar/components/docs-sidebar-content/docs-sidebar-content.component';
1417
import { DaffioRouterNamedViewsEnum } from '../../named-views/models/named-views.enum';
18+
import { DaffioDocsListContainer } from '../containers/docs-list/docs-list.component';
1519
import { DocsResolver } from '../resolvers/docs-resolver.service';
20+
import { DaffioDocsIndexService } from '../services/index.service';
1621

1722
export const apiRoutes: Routes = [
18-
<DaffRouteWithNamedViews>{
23+
<DaffioRoute>{
1924
path: '',
2025
data: {
2126
daffNamedViews: {
2227
[DaffioRouterNamedViewsEnum.SIDEBARCONTENT]: DaffioDocsSidebarContentComponent,
28+
[DaffioRouterNamedViewsEnum.DOCS_SIDEBAR]: DaffioDocsListContainer,
2329
[DaffioRouterNamedViewsEnum.FOOTER]: DaffioSimpleFooterComponent,
2430
},
31+
docKind: DaffDocKind.API,
2532
},
2633
children: [
2734
{
2835
path: '',
2936
component: DaffioApiListPageComponent,
3037
resolve: {
31-
reference: DaffioApiListResolver,
38+
reference: () => inject(DaffioDocsIndexService).getList(DaffDocKind.API),
3239
},
3340
},
3441
{

apps/daffio/src/app/docs/api/components/api-list/api-list.component.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<div *ngFor="let doc of apiList" class="daffio-api-list__package">
1+
<div *ngFor="let doc of apiList.children" class="daffio-api-list__package">
22
<h2 class="daffio-api-list__package-name">
33
<a [routerLink]="doc.path">{{ doc.title }}</a>
44
</h2>
55
<div class="daffio-api-list__list">
6-
<a *ngFor="let childDoc of doc.items" [routerLink]="childDoc.path" class="daffio-api-list__item" >
6+
<a *ngFor="let childDoc of doc.children" [routerLink]="childDoc.path" class="daffio-api-list__item" >
77
<div class="daffio-api-list__item-name">{{ childDoc.title }}</div>
88
<label class="daffio-api-list__item-label {{ childDoc.docType }}">{{ childDoc.docType }}</label>
99
</a>

apps/daffio/src/app/docs/api/components/api-list/api-list.component.spec.ts

+26-20
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,30 @@ import { DaffioApiReference } from '../../models/api-reference';
1414

1515
@Component({ template: '<daffio-api-list [apiList]="apiListValue"></daffio-api-list>' })
1616
class WrapperComponent {
17-
apiListValue: DaffioApiReference[] = [
18-
{
19-
id: 'name1',
20-
title: 'title1',
21-
path: 'path1',
22-
docType: 'docType1',
23-
docTypeShorthand: 'doc',
24-
children: [],
25-
},
26-
{
27-
id: 'name2',
28-
title: 'title2',
29-
path: 'path2',
30-
docType: 'docType2',
31-
docTypeShorthand: 'doc',
32-
children: [],
33-
},
34-
];
17+
apiListValue: DaffioApiReference = {
18+
id: 'id',
19+
title: 'title',
20+
docType: '',
21+
docTypeShorthand: '',
22+
children: [
23+
{
24+
id: 'name1Component',
25+
title: 'title1Component',
26+
path: 'path1',
27+
docType: 'docType1',
28+
docTypeShorthand: 'dt',
29+
children: [],
30+
},
31+
{
32+
id: 'name2Module',
33+
title: 'title2Module',
34+
path: 'path2',
35+
docType: 'docType2',
36+
docTypeShorthand: 'dt',
37+
children: [],
38+
},
39+
],
40+
};
3541
}
3642

3743
describe('DaffioApiListComponent', () => {
@@ -73,13 +79,13 @@ describe('DaffioApiListComponent', () => {
7379

7480
it('should render a link for every doc in apiList', () => {
7581

76-
expect(links.length).toEqual(component.apiList.length);
82+
expect(links.length).toEqual(component.apiList.children.length);
7783
});
7884

7985
describe('on link', () => {
8086

8187
it('should set routerLink', () => {
82-
expect(links[0].attributes['ng-reflect-router-link']).toEqual(component.apiList[0].path);
88+
expect(links[0].attributes['ng-reflect-router-link']).toEqual(component.apiList.children[0].path);
8389
});
8490
});
8591
});

apps/daffio/src/app/docs/api/components/api-list/api-list.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ export class DaffioApiListComponent {
1919
/**
2020
* A list of references for API documents.
2121
*/
22-
@Input() apiList: DaffioApiReference[] = [];
22+
@Input() apiList: DaffioApiReference;
2323
}

apps/daffio/src/app/docs/api/pages/api-list-page/api-list-page.component.spec.ts

+24-18
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,30 @@ describe('DaffioApiListPageComponent', () => {
3636
let fixture: ComponentFixture<DaffioApiListPageComponent>;
3737
let activatedRoute: ActivatedRouteStub;
3838

39-
const stubDocsList = [
40-
{
41-
id: 'name1Component',
42-
title: 'title1Component',
43-
path: 'path1',
44-
docType: 'docType1',
45-
docTypeShorthand: 'dt',
46-
children: [],
47-
},
48-
{
49-
id: 'name2Module',
50-
title: 'title2Module',
51-
path: 'path2',
52-
docType: 'docType2',
53-
docTypeShorthand: 'dt',
54-
children: [],
55-
},
56-
];
39+
const stubDocsList: DaffioApiReference = {
40+
id: 'id',
41+
title: 'title',
42+
docType: '',
43+
docTypeShorthand: '',
44+
children: [
45+
{
46+
id: 'name1Component',
47+
title: 'title1Component',
48+
path: 'path1',
49+
docType: 'docType1',
50+
docTypeShorthand: 'dt',
51+
children: [],
52+
},
53+
{
54+
id: 'name2Module',
55+
title: 'title2Module',
56+
path: 'path2',
57+
docType: 'docType2',
58+
docTypeShorthand: 'dt',
59+
children: [],
60+
},
61+
],
62+
};
5763

5864
beforeEach(waitForAsync(() => {
5965
TestBed.configureTestingModule({

apps/daffio/src/app/docs/api/pages/api-list-page/api-list-page.component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ export class DaffioApiListPageComponent implements OnInit {
1919
/**
2020
* A list of references for API documents.
2121
*/
22-
apiList$: Observable<DaffioApiReference[]>;
22+
apiList$: Observable<DaffioApiReference>;
2323

2424
constructor(private route: ActivatedRoute) { }
2525

2626
ngOnInit() {
2727
this.apiList$ = this.route.data.pipe(
28-
map((data: { reference: DaffioApiReference[] }) => data.reference),
28+
map((data: { reference: DaffioApiReference }) => data.reference),
2929
);
3030
}
3131
}

apps/daffio/src/app/docs/api/resolvers/api-list-resolver.service.spec.ts

-66
This file was deleted.

apps/daffio/src/app/docs/api/resolvers/api-list-resolver.service.ts

-33
This file was deleted.

apps/daffio/src/app/docs/api/services/api-service.interface.ts

-7
This file was deleted.

apps/daffio/src/app/docs/api/services/api.service.spec.ts

-45
This file was deleted.

0 commit comments

Comments
 (0)