Skip to content

Commit

Permalink
feat(daffio): add pakcages list sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
xelaint committed Jan 16, 2024
1 parent 74eafff commit a202eae
Show file tree
Hide file tree
Showing 23 changed files with 366 additions and 130 deletions.
4 changes: 2 additions & 2 deletions apps/daffio/src/app/api/api.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { DaffioApiListModule } from './components/api-list/api-list.module';
import { DaffioApiListPageComponent } from './pages/api-list-page/api-list-page.component';
import { DaffioApiPageComponent } from './pages/api-page/api-page.component';
import { DaffioDocViewerModule } from '../docs/components/doc-viewer/doc-viewer.module';
import { DaffioDocsSidebarModule } from '../docs/containers/sidebar/sidebar.module';
import { DaffioDocsPackagesSidebarComponentModule } from '../guides/components/packages-sidebar/packages-sidebar.module';

@NgModule({
imports: [
Expand All @@ -18,7 +18,7 @@ import { DaffioDocsSidebarModule } from '../docs/containers/sidebar/sidebar.modu
DaffioDocsApiRoutingModule,
DaffioApiListModule,
DaffioDocViewerModule,
DaffioDocsSidebarModule,
DaffioDocsPackagesSidebarComponentModule,

DaffContainerModule,
],
Expand Down
3 changes: 2 additions & 1 deletion apps/daffio/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { DaffioMarketingSidebarContentComponent } from './core/sidebar/component
import { DaffioMarketingSidebarFooterComponent } from './core/sidebar/components/marketing-sidebar/marketing-sidebar-footer/marketing-sidebar-footer.component';
import { DaffioMarketingSidebarHeaderComponent } from './core/sidebar/components/marketing-sidebar/marketing-sidebar-header/marketing-sidebar-header.component';
import { TemplateComponent } from './core/template/template.component';
import { DaffioDocsPackagesSidebarComponent } from './guides/components/packages-sidebar/packages-sidebar.component';
import { DaffioRouterNamedViewsEnum } from './named-views/models/named-views.enum';

export const appRoutes: Routes = [
Expand Down Expand Up @@ -57,7 +58,7 @@ export const appRoutes: Routes = [
data: {
daffNamedViews: {
[DaffioRouterNamedViewsEnum.NAV]: DaffioDocsHeaderContainer,
[DaffioRouterNamedViewsEnum.SIDEBAR]: DaffioDocsSidebarComponent,
[DaffioRouterNamedViewsEnum.SIDEBARCONTENT]: DaffioDocsPackagesSidebarComponent,
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions apps/daffio/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { DaffioMarketingHeaderContainerModule } from './core/header/containers/m
import { DaffioDocsSidebarComponentModule } from './core/sidebar/components/docs-sidebar/docs-sidebar.module';
import { DaffioMarketingSidebarComponentModule } from './core/sidebar/components/marketing-sidebar/marketing-sidebar.module';
import { TemplateModule } from './core/template/template.module';
import { DaffioDocsPackagesSidebarComponentModule } from './guides/components/packages-sidebar/packages-sidebar.module';
import { environment } from '../environments/environment';

@NgModule({
Expand All @@ -36,6 +37,7 @@ import { environment } from '../environments/environment';
DaffioDocsHeaderContainerModule,
DaffioMarketingSidebarComponentModule,
DaffioDocsSidebarComponentModule,
DaffioDocsPackagesSidebarComponentModule,

//Make sure this loads after Router and Store
StoreRouterConnectingModule.forRoot({ serializer: FullRouterStateSerializer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class DaffioSidebarRoutingModeEffects {

changeModeWhenVisitingConfiguredRoute$ = createEffect(() => (): Observable<Action> => combineLatest(
this.actions$.pipe<RouterNavigatedAction>(ofType(ROUTER_NAVIGATED)),
this.breakpointsObserver.observe(DaffBreakpoints.TABLET),
this.breakpointsObserver.observe(DaffBreakpoints.BIG_TABLET),
).pipe(
map(([action, state]) => {
const mode = computeDeepestSidebarMode(action.payload.routerState.root);
Expand Down
4 changes: 2 additions & 2 deletions apps/daffio/src/app/core/sidebar/sidebar.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { DaffRouterNamedViewOutletModule } from '@daffodil/router';

import { DaffioSidebarViewportContainer } from './containers/sidebar-viewport/sidebar-viewport.component';
import { DaffioSidebarStateModule } from './sidebar.state.module';
import { DaffioGuidesNavModule } from '../../guides/components/guides-nav/guides-nav.module';
import { DaffioDocsPackagesListContainerModule } from '../../guides/containers/packages-list/packages-list.module';

@NgModule({
imports: [
Expand All @@ -21,7 +21,7 @@ import { DaffioGuidesNavModule } from '../../guides/components/guides-nav/guides
DaffButtonModule,

DaffioSidebarStateModule,
DaffioGuidesNavModule,
DaffioDocsPackagesListContainerModule,
DaffRouterNamedViewOutletModule,
],
declarations: [
Expand Down

This file was deleted.

Empty file.

This file was deleted.

27 changes: 0 additions & 27 deletions apps/daffio/src/app/docs/containers/sidebar/sidebar.component.ts

This file was deleted.

24 changes: 0 additions & 24 deletions apps/daffio/src/app/docs/containers/sidebar/sidebar.module.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<ul daff-tree [tree]="_tree" *ngIf="_tree">
<ng-template #daffTreeItemWithChildrenTpl let-node>
<button daffTreeItem [node]="node">{{ node.title }} </button>
</ng-template>

<ng-template #daffTreeItemTpl let-node>
<a daffTreeItem [node]="node" [routerLink]="node.url">{{ node.title }}</a>
</ng-template>
</ul>
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import {
waitForAsync,
ComponentFixture,
TestBed,
} from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { RouterTestingModule } from '@angular/router/testing';

import { DaffTreeModule } from '@daffodil/design/tree';

import { DaffioGuidesNavComponent } from './guides-nav.component';

describe('DaffioGuidesNavComponent', () => {
let component: DaffioGuidesNavComponent;
let fixture: ComponentFixture<DaffioGuidesNavComponent>;

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [
DaffioGuidesNavComponent,
],
imports: [
RouterTestingModule,
NoopAnimationsModule,
DaffTreeModule,
],
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(DaffioGuidesNavComponent);
component = fixture.componentInstance;
const guideWithoutChildren = {
id: 'id2',
title: 'title2',
children: [],
};
const guideWithChildren = {
id: 'id3',
title: 'title3',
children: [
{
id: 'id4',
title: 'title4',
children: [],
},
],
};

component.guideList = {
id: 'root',
title: 'root',
children: [
guideWithoutChildren,
guideWithChildren,
],
};
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});

it('should render an anchor tag when the guide child has no children', () => {
const anchorTags = fixture.debugElement.queryAll(By.css('a'));
expect(anchorTags.length).toEqual(1);
const buttons = fixture.debugElement.queryAll(By.css('button'));
expect(buttons.length).toEqual(1);
console.log(fixture.debugElement.nativeElement.innerHTML);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {
ChangeDetectionStrategy,
Component,
Input,
} from '@angular/core';
import { RouterLinkActive } from '@angular/router';

import {
DaffTreeData,
daffTransformTreeInPlace,
} from '@daffodil/design/tree';

import { DaffioGuideList } from '../../../docs/models/guide-list';

const visit = (guide: DaffioGuideList): DaffTreeData<unknown> => ({
id: guide.id,
title: guide.title,
url: guide.path,
items: [],
data: {},
});

@Component({
selector: 'daffio-docs-packages-list',
templateUrl: './packages-list.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class DaffioDocsPackagesListComponent {

_guideList: DaffioGuideList;
/**
* The guide list to render
*/
@Input()
get guideList(): DaffioGuideList {
return this._guideList;
};
set guideList(val: DaffioGuideList) {
if(this._guideList !== val) {
this._tree = daffTransformTreeInPlace(val, visit, 'children');
}
this._guideList = val;
}

_tree: DaffTreeData<unknown>;

activeRouterLinkConfiguration: RouterLinkActive['routerLinkActiveOptions'] = {
exact: true,
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';

import { DaffTreeModule } from '@daffodil/design/tree';

import { DaffioDocsPackagesListComponent } from './packages-list.component';

@NgModule({
declarations: [
DaffioDocsPackagesListComponent,
],
exports: [
DaffioDocsPackagesListComponent,
],
imports: [
CommonModule,
RouterModule,
DaffTreeModule,
],
})
export class DaffioDocsPackagesListComponentModule { }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<daffio-docs-packages-list-container></daffio-docs-packages-list-container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:host {
display: block;
padding: 24px 0;
}
Loading

0 comments on commit a202eae

Please sign in to comment.