Skip to content

Commit e42f945

Browse files
committed
feat(showcase): add tanstack usage for server state
feat: regenerate sdk with revivers feat: core model for Pet feat(ngrx): store
1 parent ee36ba1 commit e42f945

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2532
-420
lines changed

apps/showcase/db/contacts.json

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
{
2+
"contacts": [
3+
{
4+
"id": "1",
5+
"firstName": "Winnie",
6+
"lastName": "The Pooh"
7+
},
8+
{
9+
"id": "2",
10+
"firstName": "Christopher",
11+
"lastName": "Robin"
12+
},
13+
{
14+
"id": "3",
15+
"firstName": "Eyeore",
16+
"lastName": "The Donkey"
17+
},
18+
{
19+
"id": "5",
20+
"firstName": "Scrooge",
21+
"lastName": "McDuck"
22+
},
23+
{
24+
"id": "6",
25+
"firstName": "Tinker",
26+
"lastName": "Bell"
27+
},
28+
{
29+
"id": "7",
30+
"firstName": "Peter",
31+
"lastName": "Pan"
32+
},
33+
{
34+
"id": "8",
35+
"firstName": "Capitan",
36+
"lastName": "Hook"
37+
},
38+
{
39+
"id": "9",
40+
"firstName": "Snow",
41+
"lastName": "White"
42+
},
43+
{
44+
"id": "10",
45+
"firstName": "Prince",
46+
"lastName": "Charming"
47+
},
48+
{
49+
"id": "11",
50+
"firstName": "Fairy",
51+
"lastName": "Godmother"
52+
},
53+
{
54+
"id": "12",
55+
"firstName": "Simba",
56+
"lastName": "The Lion"
57+
},
58+
{
59+
"id": "13",
60+
"firstName": "Mufasa",
61+
"lastName": "The Lion King"
62+
},
63+
{
64+
"id": "14",
65+
"firstName": "Mike",
66+
"lastName": "Wazowski"
67+
},
68+
{
69+
"id": "15",
70+
"firstName": "James",
71+
"lastName": "P. Sullivan"
72+
},
73+
{
74+
"id": "16",
75+
"firstName": "Randall",
76+
"lastName": "Boggs"
77+
},
78+
{
79+
"id": "17",
80+
"firstName": "Buzz",
81+
"lastName": "Lightyear"
82+
},
83+
{
84+
"id": "18",
85+
"firstName": "Launchpad",
86+
"lastName": "McQuack"
87+
},
88+
{
89+
"id": "19",
90+
"firstName": "Minnie",
91+
"lastName": "Mouse"
92+
},
93+
{
94+
"id": "20",
95+
"firstName": "Mickey",
96+
"lastName": "Mouse"
97+
},
98+
{
99+
"id": "21",
100+
"firstName": "Donald",
101+
"lastName": "Duck"
102+
},
103+
{
104+
"id": "22",
105+
"firstName": "Daisy",
106+
"lastName": "Duck"
107+
}
108+
]
109+
}

apps/showcase/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"nx": "nx",
1010
"start": "ng run showcase:run",
1111
"build": "yarn run generate:translations && ng build",
12+
"db": "json-server --watch db/contacts.json",
1213
"watch": "ng compile --watch --configuration development",
1314
"test": "ng test",
1415
"start:no-translation": "ng serve",
@@ -61,6 +62,8 @@
6162
"@o3r/styling": "workspace:^",
6263
"@o3r/testing": "workspace:^",
6364
"@popperjs/core": "^2.11.5",
65+
"@tanstack/angular-query-devtools-experimental": "^5.28.8",
66+
"@tanstack/angular-query-experimental": "^5.28.8",
6467
"ag-grid-angular": "~31.1.0",
6568
"ag-grid-community": "~31.1.0",
6669
"bootstrap": "5.3.3",
@@ -112,6 +115,7 @@
112115
"jest-environment-jsdom": "~29.7.0",
113116
"jest-junit": "~16.0.0",
114117
"jest-preset-angular": "~14.0.3",
118+
"json-server": "^1.0.0-alpha.23",
115119
"jsonc-eslint-parser": "~2.4.0",
116120
"lighthouse": "9.6.8",
117121
"playwright-lighthouse": "2.2.2",

apps/showcase/project.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,18 @@
135135
"^build"
136136
]
137137
},
138+
"serve-db": {
139+
"executor": "nx:run-commands",
140+
"options": {
141+
"commands": ["yarn db", "yarn ng serve showcase"],
142+
"parallel": true
143+
}
144+
},
138145
"serve-app": {
139146
"executor": "@angular-devkit/build-angular:dev-server",
147+
"options": {
148+
"proxyConfig": "./proxy.config.js"
149+
},
140150
"configurations": {
141151
"production": {
142152
"buildTarget": "showcase:compile:production"

apps/showcase/src/app/app-routing.module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const appRoutes: Routes = [
1313
{path: 'run-app-locally', loadComponent: () => import('./run-app-locally/index').then((m) => m.RunAppLocallyComponent), title: 'Otter Showcase - Run App Locally'},
1414
{path: 'sdk', loadComponent: () => import('./sdk/index').then((m) => m.SdkComponent), title: 'Otter Showcase - SDK'},
1515
{path: 'placeholder', loadComponent: () => import('./placeholder/index').then((m) => m.PlaceholderComponent), title: 'Otter Showcase - Placeholder'},
16+
{path: 'tanstack', loadComponent: () => import('./tanstack/index').then((m) => m.TanstackComponent)},
1617
{path: '**', redirectTo: '/home', pathMatch: 'full'}
1718
];
1819

apps/showcase/src/app/app.component.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ export class AppComponent implements OnDestroy {
3939
links: [
4040
{ url: '/sdk', label: 'Generator' }
4141
]
42+
},
43+
{
44+
label: 'Server side storage',
45+
links: [
46+
{ url: '/tanstack', label: 'Tanstack' }
47+
]
4248
}
4349
];
4450

apps/showcase/src/app/app.module.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ import { AppRoutingModule } from './app-routing.module';
3333
import { AppComponent } from './app.component';
3434

3535

36+
// Tanstack
37+
import {
38+
provideAngularQuery,
39+
QueryClient
40+
} from '@tanstack/angular-query-experimental';
41+
import { HttpClientModule } from '@angular/common/http';
42+
3643
const runtimeChecks: Partial<RuntimeChecks> = {
3744
strictActionImmutability: false,
3845
strictActionSerializability: false,
@@ -87,6 +94,7 @@ export function registerCustomComponents(): Map<string, any> {
8794
],
8895
imports: [
8996
BrowserModule,
97+
HttpClientModule,
9098
BrowserAnimationsModule.withConfig({disableAnimations: prefersReducedMotion()}),
9199
EffectsModule.forRoot([]),
92100
StoreModule.forRoot({}, { runtimeChecks }),
@@ -133,7 +141,8 @@ export function registerCustomComponents(): Map<string, any> {
133141
{provide: OTTER_RULES_ENGINE_DEVTOOLS_OPTIONS, useValue: {isActivatedOnBootstrap: true}},
134142
{provide: OTTER_COMPONENTS_DEVTOOLS_OPTIONS, useValue: {isActivatedOnBootstrap: true}},
135143
{provide: OTTER_APPLICATION_DEVTOOLS_OPTIONS, useValue: {isActivatedOnBootstrap: true}},
136-
{provide: OTTER_STYLING_DEVTOOLS_OPTIONS, useValue: {isActivatedOnBootstrap: true}}
144+
{provide: OTTER_STYLING_DEVTOOLS_OPTIONS, useValue: {isActivatedOnBootstrap: true}},
145+
provideAngularQuery(new QueryClient())
137146
],
138147
bootstrap: [AppComponent]
139148
})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Tanstack usage
2+
3+
the Tanstack query page
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './tanstack.component';
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { AsyncPipe } from '@angular/common';
2+
import { AfterViewInit, ChangeDetectionStrategy, Component, QueryList, ViewChildren, ViewEncapsulation } from '@angular/core';
3+
import { RouterLink } from '@angular/router';
4+
import { O3rComponent } from '@o3r/core';
5+
import {
6+
CopyTextPresComponent,
7+
IN_PAGE_NAV_PRES_DIRECTIVES,
8+
InPageNavLink,
9+
InPageNavLinkDirective,
10+
InPageNavPresService,
11+
TanstackPresComponent
12+
} from '../../components';
13+
14+
@O3rComponent({ componentType: 'Page' })
15+
@Component({
16+
selector: 'o3r-tanstack',
17+
standalone: true,
18+
imports: [
19+
CopyTextPresComponent,
20+
RouterLink,
21+
TanstackPresComponent,
22+
IN_PAGE_NAV_PRES_DIRECTIVES,
23+
AsyncPipe
24+
],
25+
templateUrl: './tanstack.template.html',
26+
styleUrls: ['./tanstack.style.scss'],
27+
encapsulation: ViewEncapsulation.None,
28+
changeDetection: ChangeDetectionStrategy.OnPush
29+
})
30+
export class TanstackComponent implements AfterViewInit {
31+
@ViewChildren(InPageNavLinkDirective)
32+
private readonly inPageNavLinkDirectives!: QueryList<InPageNavLink>;
33+
public links$ = this.inPageNavPresService.links$;
34+
35+
constructor(private readonly inPageNavPresService: InPageNavPresService) {}
36+
37+
public ngAfterViewInit() {
38+
this.inPageNavPresService.initialize(this.inPageNavLinkDirectives);
39+
}
40+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { PetApi } from '@ama-sdk/showcase-sdk';
2+
import { PetApiFixture } from '@ama-sdk/showcase-sdk/fixtures';
3+
import { AsyncPipe } from '@angular/common';
4+
import { ComponentFixture, TestBed } from '@angular/core/testing';
5+
import { RouterModule } from '@angular/router';
6+
7+
import { TanstackComponent } from './tanstack.component';
8+
import '@angular/localize/init';
9+
10+
describe('TanstackComponent', () => {
11+
let component: TanstackComponent;
12+
let fixture: ComponentFixture<TanstackComponent>;
13+
const petApiFixture = new PetApiFixture();
14+
petApiFixture.findPetsByStatus = petApiFixture.findPetsByStatus.mockResolvedValue([]);
15+
16+
beforeEach(() => {
17+
TestBed.configureTestingModule({
18+
imports: [
19+
TanstackComponent,
20+
RouterModule.forRoot([]),
21+
AsyncPipe
22+
],
23+
providers: [
24+
{provide: PetApi, useValue: petApiFixture}
25+
]
26+
});
27+
fixture = TestBed.createComponent(TanstackComponent);
28+
component = fixture.componentInstance;
29+
fixture.detectChanges();
30+
});
31+
32+
it('should create', () => {
33+
expect(component).toBeTruthy();
34+
});
35+
});

0 commit comments

Comments
 (0)