-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IMP-231: Add shops tariffs page (only dev) (#359)
- Loading branch information
Showing
18 changed files
with
408 additions
and
52 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/app/sections/tariffs/components/shops-tariffs/shops-tariffs.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<cc-page-layout title="Shops tariffs"> | ||
<cc-page-layout-actions> | ||
<v-more-filters-button [filters]="filters"></v-more-filters-button> | ||
</cc-page-layout-actions> | ||
<v-filters #filters [active]="active$ | async" (clear)="filtersForm.reset()"> | ||
<ng-template [formGroup]="filtersForm"> | ||
<cc-merchant-field formControlName="party_id"></cc-merchant-field> | ||
<cc-shop-field | ||
[partyId]="filtersForm.value.party_id" | ||
formControlName="shop_ids" | ||
multiple | ||
></cc-shop-field> | ||
<v-list-field formControlName="currencies" label="Currencies"></v-list-field> | ||
<v-list-field formControlName="term_sets_names" label="Term sets names"></v-list-field> | ||
<v-list-field formControlName="term_sets_ids" label="Term sets IDs"></v-list-field> | ||
</ng-template> | ||
</v-filters> | ||
|
||
<v-table | ||
[columns]="columns" | ||
[data]="tariffs$ | async" | ||
[hasMore]="hasMore$ | async" | ||
[progress]="isLoading$ | async" | ||
(more)="more()" | ||
(update)="update($event)" | ||
></v-table> | ||
</cc-page-layout> |
143 changes: 143 additions & 0 deletions
143
src/app/sections/tariffs/components/shops-tariffs/shops-tariffs.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { Component, DestroyRef, Inject, OnInit } from '@angular/core'; | ||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; | ||
import { NonNullableFormBuilder, ReactiveFormsModule } from '@angular/forms'; | ||
import { TermSetHierarchyRef } from '@vality/domain-proto/internal/domain'; | ||
import { | ||
CommonSearchQueryParams, | ||
ShopSearchQuery, | ||
ShopTermSet, | ||
} from '@vality/dominator-proto/internal/dominator'; | ||
import { | ||
clean, | ||
Column, | ||
countChanged, | ||
createControls, | ||
debounceTimeWithFirst, | ||
FiltersModule, | ||
getValueChanges, | ||
InputFieldModule, | ||
ListFieldModule, | ||
LoadOptions, | ||
QueryParamsService, | ||
TableModule, | ||
UpdateOptions, | ||
} from '@vality/ng-core'; | ||
import { map, shareReplay } from 'rxjs/operators'; | ||
import { Overwrite } from 'utility-types'; | ||
|
||
import { | ||
createContractColumn, | ||
createPartyColumn, | ||
createShopColumn, | ||
PageLayoutModule, | ||
ShopFieldModule, | ||
} from '@cc/app/shared'; | ||
import { CurrencyFieldComponent } from '@cc/app/shared/components/currency-field'; | ||
import { MerchantFieldModule } from '@cc/app/shared/components/merchant-field'; | ||
import { DEBOUNCE_TIME_MS } from '@cc/app/tokens'; | ||
|
||
import { ShopsTariffsService } from './shops-tariffs.service'; | ||
|
||
type Params = Pick<CommonSearchQueryParams, 'currencies'> & | ||
Overwrite< | ||
Omit<ShopSearchQuery, 'common_search_query_params'>, | ||
{ term_sets_ids?: TermSetHierarchyRef['id'][] } | ||
>; | ||
|
||
@Component({ | ||
selector: 'cc-shops-tariffs', | ||
standalone: true, | ||
imports: [ | ||
CommonModule, | ||
PageLayoutModule, | ||
TableModule, | ||
InputFieldModule, | ||
FiltersModule, | ||
ReactiveFormsModule, | ||
MerchantFieldModule, | ||
ShopFieldModule, | ||
ListFieldModule, | ||
CurrencyFieldComponent, | ||
], | ||
templateUrl: './shops-tariffs.component.html', | ||
}) | ||
export class ShopsTariffsComponent implements OnInit { | ||
filtersForm = this.fb.group( | ||
createControls<Params>({ | ||
currencies: null, | ||
party_id: null, | ||
shop_ids: null, | ||
term_sets_names: null, | ||
term_sets_ids: null, | ||
}), | ||
); | ||
tariffs$ = this.shopsTariffsService.result$; | ||
hasMore$ = this.shopsTariffsService.hasMore$; | ||
isLoading$ = this.shopsTariffsService.isLoading$; | ||
columns: Column<ShopTermSet>[] = [ | ||
createShopColumn<ShopTermSet>('shop_id', (d) => d.owner_id), | ||
createPartyColumn<ShopTermSet>('owner_id'), | ||
createContractColumn<ShopTermSet>( | ||
(d) => d.contract_id, | ||
(d) => d.owner_id, | ||
(d) => d.shop_id, | ||
), | ||
{ field: 'currency' }, | ||
{ | ||
field: 'current_term_set', | ||
formatter: (d) => d.current_term_set?.data?.name, | ||
description: (d) => d.current_term_set?.data?.description, | ||
tooltip: (d) => d.current_term_set, | ||
}, | ||
{ | ||
field: 'term_set_history', | ||
formatter: (d) => d.term_set_history?.length, | ||
tooltip: (d) => d.term_set_history, | ||
}, | ||
]; | ||
active$ = getValueChanges(this.filtersForm).pipe( | ||
map((filters) => countChanged(this.initFiltersValue, filters)), | ||
shareReplay({ refCount: true, bufferSize: 1 }), | ||
); | ||
|
||
private initFiltersValue = this.filtersForm.value; | ||
|
||
constructor( | ||
private shopsTariffsService: ShopsTariffsService, | ||
private fb: NonNullableFormBuilder, | ||
private qp: QueryParamsService<Params>, | ||
@Inject(DEBOUNCE_TIME_MS) private debounceTimeMs: number, | ||
private dr: DestroyRef, | ||
) {} | ||
|
||
ngOnInit() { | ||
this.filtersForm.patchValue(this.qp.params); | ||
getValueChanges(this.filtersForm) | ||
.pipe(debounceTimeWithFirst(this.debounceTimeMs), takeUntilDestroyed(this.dr)) | ||
.subscribe((filters) => { | ||
void this.qp.set(filters); | ||
this.load(filters); | ||
}); | ||
} | ||
|
||
load(params: Params, options?: LoadOptions) { | ||
const { currencies, term_sets_ids, ...otherParams } = params; | ||
this.shopsTariffsService.load( | ||
clean({ | ||
common_search_query_params: { currencies }, | ||
term_sets_ids: term_sets_ids?.map((id) => ({ id })), | ||
...otherParams, | ||
}), | ||
options, | ||
); | ||
} | ||
|
||
update(options?: UpdateOptions) { | ||
this.shopsTariffsService.reload(options); | ||
} | ||
|
||
more() { | ||
this.shopsTariffsService.more(); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/app/sections/tariffs/components/shops-tariffs/shops-tariffs.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { ShopSearchQuery, ShopTermSet } from '@vality/dominator-proto/internal/dominator'; | ||
import { | ||
FetchOptions, | ||
FetchSuperclass, | ||
handleError, | ||
NotifyLogService, | ||
clean, | ||
} from '@vality/ng-core'; | ||
import { map } from 'rxjs/operators'; | ||
|
||
import { DominatorService } from '@cc/app/api/dominator'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class ShopsTariffsService extends FetchSuperclass<ShopTermSet, ShopSearchQuery> { | ||
constructor( | ||
private dominatorService: DominatorService, | ||
private log: NotifyLogService, | ||
) { | ||
super(); | ||
} | ||
|
||
protected fetch(params: ShopSearchQuery, options: FetchOptions<string>) { | ||
return this.dominatorService | ||
.SearchShopTermSets({ | ||
...params, | ||
common_search_query_params: clean({ | ||
continuation_token: options.continuationToken, | ||
limit: options.size, | ||
currencies: params?.common_search_query_params?.currencies, | ||
}), | ||
}) | ||
.pipe( | ||
map(({ terms, continuation_token }) => ({ | ||
result: terms, | ||
continuationToken: continuation_token, | ||
})), | ||
handleError(this.log.error), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './tariffs.module'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Services, RoutingConfig } from '@cc/app/shared/services'; | ||
|
||
export const ROUTING_CONFIG: RoutingConfig = { | ||
services: [Services.Dominator], | ||
}; |
Oops, something went wrong.