Skip to content

Commit

Permalink
Typed NaturalAbstractDetail.data #9819
Browse files Browse the repository at this point in the history
`NaturalAbstractDetail.data` is implicitly typed with the result of
`service.resolve()`. If needed that type can be widened by specifying
a type for extra properties in the generic, like so:

```ts
class MyComponent extends NaturalAbstractDetail<MyService, {myProp: string}> {
}
```

`getConsolidatedForClient()` was dropped entirely without a replacement.
 It should never be used in our projects (and it was not).

`getDefaultForClient()` was renamed into `getFormExtraFieldDefaultValues()`
to better reflect its usage. It should never be called in projects, only
within Natural itself. Projects were updated to instead call
`getDefaultForServer()`.

The overall behavior of both `NaturalAbstractModelService` and
`NaturalAbstractDetail` is intact.
  • Loading branch information
PowerKiKi committed Aug 23, 2023
1 parent 96789fc commit 9906799
Show file tree
Hide file tree
Showing 54 changed files with 133 additions and 195 deletions.
5 changes: 0 additions & 5 deletions client/app/admin/comments/comment.ts

This file was deleted.

2 changes: 1 addition & 1 deletion client/app/admin/comments/comment/comment.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</div>
</div>

<natural-stamp [item]="data.model"></natural-stamp>
<natural-stamp *ngIf="isUpdatePage()" [item]="data.model"></natural-stamp>
</div>
</mat-tab>
</mat-tab-group>
Expand Down
7 changes: 3 additions & 4 deletions client/app/admin/comments/comment/comment.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import {ActivatedRoute} from '@angular/router';
import {
NaturalAbstractDetail,
NaturalDetailHeaderComponent,
NaturalFixedButtonDetailComponent,
NaturalLinkableTabDirective,
NaturalSelectComponent,
NaturalSeoResolveData,
NaturalStampComponent,
NaturalFixedButtonDetailComponent,
} from '@ecodev/natural';
import {NaturalSearchFacetsService} from '../../../shared/natural-search/natural-search-facets.service';
import {PermissionsService} from '../../../shared/services/permissions.service';
import {EventService} from '../../events/services/event.service';
import {NewsService} from '../../newses/services/news.service';
Expand Down Expand Up @@ -40,11 +40,10 @@ import {FormsModule, ReactiveFormsModule} from '@angular/forms';
NaturalFixedButtonDetailComponent,
],
})
export class CommentComponent extends NaturalAbstractDetail<CommentService> implements OnInit {
export class CommentComponent extends NaturalAbstractDetail<CommentService, NaturalSeoResolveData> implements OnInit {
public constructor(
route: ActivatedRoute,
commentService: CommentService,
naturalSearchFacetsService: NaturalSearchFacetsService,
public readonly newsService: NewsService,
public readonly eventService: EventService,
public readonly permissionsService: PermissionsService,
Expand Down
5 changes: 2 additions & 3 deletions client/app/admin/comments/services/comment.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import {inject} from '@angular/core';
import {ActivatedRouteSnapshot} from '@angular/router';
import {last, Observable} from 'rxjs';
import {last} from 'rxjs';
import {ErrorService} from '../../../shared/components/error/error.service';
import {CommentResolve} from '../comment';
import {CommentService} from './comment.service';

/**
* Resolve product data for router
*/
export function resolveComment(route: ActivatedRouteSnapshot): Observable<CommentResolve> {
export function resolveComment(route: ActivatedRouteSnapshot): ReturnType<CommentService['resolve']> {
const productService = inject(CommentService);
const errorService = inject(ErrorService);
const observable = productService.resolve(route.params.commentId).pipe(last());
Expand Down
2 changes: 1 addition & 1 deletion client/app/admin/comments/services/comment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class CommentService extends NaturalAbstractModelService<
);
}

protected override getDefaultForServer(): CommentInput {
public override getDefaultForServer(): CommentInput {
return {
description: '',
event: null,
Expand Down
5 changes: 0 additions & 5 deletions client/app/admin/events/event.ts

This file was deleted.

4 changes: 2 additions & 2 deletions client/app/admin/events/event/event.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
label="Événement"
[newLabel]="data.seo.title"
>
<a [routerLink]="['/agenda', data.model.id]" color="primary" mat-raised-button *ngIf="data.model.id">
<a [routerLink]="['/agenda', data.model.id]" color="primary" mat-raised-button *ngIf="isUpdatePage()">
<mat-icon naturalIcon="remove_red_eye"></mat-icon>
Voir la page
</a>
Expand Down Expand Up @@ -55,7 +55,7 @@
</div>
</div>

<natural-stamp [item]="data.model"></natural-stamp>
<natural-stamp *ngIf="isUpdatePage()" [item]="data.model"></natural-stamp>
</div>
</mat-tab>
</mat-tab-group>
Expand Down
10 changes: 4 additions & 6 deletions client/app/admin/events/event/event.component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {Component, OnInit} from '@angular/core';
import {ActivatedRoute, RouterLink} from '@angular/router';
import {RouterLink} from '@angular/router';
import {
NaturalAbstractDetail,
NaturalDetailHeaderComponent,
NaturalFixedButtonDetailComponent,
NaturalIconDirective,
NaturalLinkableTabDirective,
NaturalSeoResolveData,
NaturalStampComponent,
NaturalFixedButtonDetailComponent,
} from '@ecodev/natural';
import {NaturalSearchFacetsService} from '../../../shared/natural-search/natural-search-facets.service';
import {PermissionsService} from '../../../shared/services/permissions.service';
import {EventService} from '../services/event.service';
import {MatDatepickerModule} from '@angular/material/datepicker';
Expand Down Expand Up @@ -45,11 +45,9 @@ import {FormsModule, ReactiveFormsModule} from '@angular/forms';
NaturalFixedButtonDetailComponent,
],
})
export class EventComponent extends NaturalAbstractDetail<EventService> implements OnInit {
export class EventComponent extends NaturalAbstractDetail<EventService, NaturalSeoResolveData> implements OnInit {
public constructor(
route: ActivatedRoute,
eventService: EventService,
naturalSearchFacetsService: NaturalSearchFacetsService,
public readonly permissionsService: PermissionsService,
) {
super('event', eventService);
Expand Down
5 changes: 2 additions & 3 deletions client/app/admin/events/services/event.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import {inject} from '@angular/core';
import {ActivatedRouteSnapshot} from '@angular/router';
import {last, Observable} from 'rxjs';
import {last} from 'rxjs';
import {ErrorService} from '../../../shared/components/error/error.service';
import {EventResolve} from '../event';
import {EventService} from './event.service';

/**
* Resolve product data for router
*/
export function resolveEvent(route: ActivatedRouteSnapshot): Observable<EventResolve> {
export function resolveEvent(route: ActivatedRouteSnapshot): ReturnType<EventService['resolve']> {
const productService = inject(EventService);
const errorService = inject(ErrorService);
const observable = productService.resolve(route.params.eventId).pipe(last());
Expand Down
2 changes: 1 addition & 1 deletion client/app/admin/events/services/event.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class EventService extends NaturalAbstractModelService<
super(apollo, naturalDebounceService, 'event', eventQuery, eventsQuery, createEvent, updateEvent, deleteEvents);
}

protected override getDefaultForServer(): EventInput {
public override getDefaultForServer(): EventInput {
return {
name: '',
place: '',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {FacilitatorDocument} from '../../shared/generated-types';
import {FacilitatorDocument, FacilitatorDocumentInput} from '../../shared/generated-types';

export interface FacilitatorDocumentResolve {
model: FacilitatorDocument['facilitatorDocument'];
model: FacilitatorDocument['facilitatorDocument'] | FacilitatorDocumentInput;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
routerLink="/agir-avec-nous/conversation-carbone/facilitateurs-prive"
color="primary"
mat-raised-button
*ngIf="data.model.id"
*ngIf="isUpdatePage()"
>
<mat-icon naturalIcon="remove_red_eye"></mat-icon>
Voir la page
Expand Down Expand Up @@ -58,7 +58,7 @@ <h2 class="mat-h2">Document</h2>

<mat-divider></mat-divider>

<natural-stamp [item]="data.model"></natural-stamp>
<natural-stamp *ngIf="isUpdatePage()" [item]="data.model"></natural-stamp>
</div>
</mat-tab>
</mat-tab-group>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
NaturalFileComponent,
NaturalStampComponent,
NaturalFixedButtonDetailComponent,
NaturalSeoResolveData,
} from '@ecodev/natural';
import {FilesService} from '../../files/services/files.service';
import {FacilitatorDocumentsService} from '../services/facilitator-documents.service';
Expand Down Expand Up @@ -48,7 +49,10 @@ import {FormsModule, ReactiveFormsModule} from '@angular/forms';
NaturalFixedButtonDetailComponent,
],
})
export class FacilitatorDocumentComponent extends NaturalAbstractDetail<FacilitatorDocumentsService> {
export class FacilitatorDocumentComponent extends NaturalAbstractDetail<
FacilitatorDocumentsService,
NaturalSeoResolveData
> {
public constructor(
public readonly facilitatorDocumentService: FacilitatorDocumentsService,
private readonly fileService: FilesService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class FacilitatorDocumentsService extends NaturalAbstractModelService<
);
}

protected override getDefaultForServer(): FacilitatorDocumentInput {
public override getDefaultForServer(): FacilitatorDocumentInput {
return {
name: '',
file: null,
Expand Down
2 changes: 1 addition & 1 deletion client/app/admin/files/services/files.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class FilesService extends NaturalAbstractModelService<
super(apollo, naturalDebounceService, 'file', null, null, createFileMutation, null, deleteFileMutation);
}

protected override getDefaultForServer(): FileInput {
public override getDefaultForServer(): FileInput {
return {
file: null as unknown as File,
};
Expand Down
5 changes: 0 additions & 5 deletions client/app/admin/newses/news.ts

This file was deleted.

4 changes: 2 additions & 2 deletions client/app/admin/newses/news/news.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
label="Actualité"
[newLabel]="data.seo.title"
>
<a [routerLink]="['/actualite', data.model.id]" color="primary" mat-raised-button *ngIf="data.model.id">
<a [routerLink]="['/actualite', data.model.id]" color="primary" mat-raised-button *ngIf="isUpdatePage()">
<mat-icon naturalIcon="remove_red_eye"></mat-icon>
Voir la page
</a>
Expand Down Expand Up @@ -55,7 +55,7 @@
</div>
</div>

<natural-stamp [item]="data.model"></natural-stamp>
<natural-stamp *ngIf="isUpdatePage()" [item]="data.model"></natural-stamp>
</div>
</mat-tab>
</mat-tab-group>
Expand Down
10 changes: 4 additions & 6 deletions client/app/admin/newses/news/news.component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {Component, OnInit} from '@angular/core';
import {ActivatedRoute, RouterLink} from '@angular/router';
import {RouterLink} from '@angular/router';
import {
NaturalAbstractDetail,
NaturalDetailHeaderComponent,
NaturalFixedButtonDetailComponent,
NaturalIconDirective,
NaturalLinkableTabDirective,
NaturalSeoResolveData,
NaturalStampComponent,
NaturalFixedButtonDetailComponent,
} from '@ecodev/natural';
import {NaturalSearchFacetsService} from '../../../shared/natural-search/natural-search-facets.service';
import {PermissionsService} from '../../../shared/services/permissions.service';
import {NewsService} from '../services/news.service';
import {MatDatepickerModule} from '@angular/material/datepicker';
Expand Down Expand Up @@ -51,11 +51,9 @@ import {FormsModule, ReactiveFormsModule} from '@angular/forms';
NaturalFixedButtonDetailComponent,
],
})
export class NewsComponent extends NaturalAbstractDetail<NewsService> implements OnInit {
export class NewsComponent extends NaturalAbstractDetail<NewsService, NaturalSeoResolveData> implements OnInit {
public constructor(
route: ActivatedRoute,
newsService: NewsService,
naturalSearchFacetsService: NaturalSearchFacetsService,
public readonly permissionsService: PermissionsService,
) {
super('news', newsService);
Expand Down
5 changes: 2 additions & 3 deletions client/app/admin/newses/services/news.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import {inject} from '@angular/core';
import {ActivatedRouteSnapshot} from '@angular/router';
import {last, Observable} from 'rxjs';
import {last} from 'rxjs';
import {ErrorService} from '../../../shared/components/error/error.service';
import {NewsResolve} from '../news';
import {NewsService} from './news.service';

/**
* Resolve product data for router
*/
export function resolveNews(route: ActivatedRouteSnapshot): Observable<NewsResolve> {
export function resolveNews(route: ActivatedRouteSnapshot): ReturnType<NewsService['resolve']> {
const productService = inject(NewsService);
const errorService = inject(ErrorService);

Expand Down
2 changes: 1 addition & 1 deletion client/app/admin/newses/services/news.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class NewsService extends NaturalAbstractModelService<
return super.getInput(object);
}

protected override getDefaultForServer(): NewsInput {
public override getDefaultForServer(): NewsInput {
return {
isActive: false,
name: '',
Expand Down
5 changes: 0 additions & 5 deletions client/app/admin/order/order-line.ts

This file was deleted.

8 changes: 6 additions & 2 deletions client/app/admin/order/order-line/order-line.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
NaturalDialogTriggerProvidedData,
NaturalSelectComponent,
NaturalSelectEnumComponent,
NaturalSeoResolveData,
} from '@ecodev/natural';
import {merge, omit} from 'lodash-es';
import {ProductService} from '../../products/services/product.service';
Expand Down Expand Up @@ -37,7 +38,10 @@ import {FormsModule, ReactiveFormsModule} from '@angular/forms';
MatButtonModule,
],
})
export class OrderLineComponent extends NaturalAbstractDetail<OrderLineService> implements OnInit {
export class OrderLineComponent
extends NaturalAbstractDetail<OrderLineService, NaturalSeoResolveData>
implements OnInit
{
public constructor(
private readonly orderLineService: OrderLineService,
public readonly productService: ProductService,
Expand All @@ -53,7 +57,7 @@ export class OrderLineComponent extends NaturalAbstractDetail<OrderLineService>
public override ngOnInit(): void {
this.dialogData.activatedRoute.data.subscribe(data => {
const key = 'orderLine';
this.data = merge({model: this.service.getConsolidatedForClient()}, data[key]);
this.data = merge({model: this.service.getDefaultForServer()}, data[key]);
this.data = merge(this.data, omit(data, [key]));
this.initForm();
});
Expand Down
5 changes: 0 additions & 5 deletions client/app/admin/order/order.ts

This file was deleted.

5 changes: 2 additions & 3 deletions client/app/admin/order/services/order-line.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import {inject} from '@angular/core';
import {ActivatedRouteSnapshot} from '@angular/router';
import {last, Observable} from 'rxjs';
import {last} from 'rxjs';
import {ErrorService} from '../../../shared/components/error/error.service';
import {OrderLineResolve} from '../order-line';
import {OrderLineService} from './order-lines.service';

/**
* Resolve orderLine data for router
*/
export function resolveOrderLine(route: ActivatedRouteSnapshot): Observable<OrderLineResolve> {
export function resolveOrderLine(route: ActivatedRouteSnapshot): ReturnType<OrderLineService['resolve']> {
const orderLineService = inject(OrderLineService);
const errorService = inject(ErrorService);
const observable = orderLineService.resolve(route.params.orderLineId).pipe(last());
Expand Down
4 changes: 2 additions & 2 deletions client/app/admin/order/services/order-lines.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class OrderLineService extends NaturalAbstractModelService<
OrderLines['orderLines'],
OrderLinesVariables,
never,
never,
UpdateOrderLineVariables,
UpdateOrderLine['updateOrderLine'],
UpdateOrderLineVariables,
never,
Expand Down Expand Up @@ -53,7 +53,7 @@ export class OrderLineService extends NaturalAbstractModelService<
};
}

protected override getDefaultForServer(): OrderLineInput {
public override getDefaultForServer(): OrderLineInput {
return {
product: null,
subscription: null,
Expand Down
5 changes: 2 additions & 3 deletions client/app/admin/order/services/order.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import {inject} from '@angular/core';
import {ActivatedRouteSnapshot} from '@angular/router';
import {last, Observable} from 'rxjs';
import {last} from 'rxjs';
import {ErrorService} from '../../../shared/components/error/error.service';
import {OrderResolve} from '../order';
import {OrderService} from './order.service';

/**
* Resolve order data for router
*/
export function resolveOrder(route: ActivatedRouteSnapshot): Observable<OrderResolve> {
export function resolveOrder(route: ActivatedRouteSnapshot): ReturnType<OrderService['resolve']> {
const orderService = inject(OrderService);
const errorService = inject(ErrorService);

Expand Down
5 changes: 0 additions & 5 deletions client/app/admin/product-tags/productTag.ts

This file was deleted.

Loading

0 comments on commit 9906799

Please sign in to comment.