IMP-111, IMP-137: Show terminals global allow, show shops terms (#313)

This commit is contained in:
Rinat Arsaev 2024-01-17 17:59:41 +07:00 committed by GitHub
parent dba5a4b114
commit 425a4cb234
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 116 additions and 40 deletions

8
package-lock.json generated
View File

@ -26,7 +26,7 @@
"@vality/fistful-proto": "2.0.1-3b9a0a7.0",
"@vality/machinegun-proto": "1.0.0",
"@vality/magista-proto": "2.0.2-4383410.0",
"@vality/ng-core": "^17.1.1-pr-57-9275cb3.0",
"@vality/ng-core": "^17.1.1-pr-57-1a4e713.0",
"@vality/payout-manager-proto": "2.0.1-eb4091a.0",
"@vality/repairer-proto": "2.0.2-07b73e9.0",
"@vality/thrift-ts": "2.4.1-8ad5123.0",
@ -6523,9 +6523,9 @@
"integrity": "sha512-kAiKSTvof+jFuNkQKyAsc2s+Br2NXPWAyKuD0f7mQIk9HrP8uHsKJya5KxdOdng97JYe0MSUlx7seQxWmCgYfA=="
},
"node_modules/@vality/ng-core": {
"version": "17.1.1-pr-57-9275cb3.0",
"resolved": "https://registry.npmjs.org/@vality/ng-core/-/ng-core-17.1.1-pr-57-9275cb3.0.tgz",
"integrity": "sha512-vmazXnrnQDrSio3pFk6Bvp6ou0KgzqdnuJE+JufJxuxZHGbAf2wig8qTlauIY/tG0yNWNiPoSaYlvooZm6PxOw==",
"version": "17.1.1-pr-57-1a4e713.0",
"resolved": "https://registry.npmjs.org/@vality/ng-core/-/ng-core-17.1.1-pr-57-1a4e713.0.tgz",
"integrity": "sha512-Jar5VUIp5OISoCc0rhmcsk9EkVjzItlT2N/sMCFIKIKD51XDxn6NvYXOOwOiNAyu1LAd71mGPT8GvdWazR12cA==",
"dependencies": {
"@angular/material-date-fns-adapter": "^17.0.0",
"@ng-matero/extensions": "^17.0.0",

View File

@ -34,7 +34,7 @@
"@vality/fistful-proto": "2.0.1-3b9a0a7.0",
"@vality/machinegun-proto": "1.0.0",
"@vality/magista-proto": "2.0.2-4383410.0",
"@vality/ng-core": "^17.1.1-pr-57-9275cb3.0",
"@vality/ng-core": "^17.1.1-pr-57-1a4e713.0",
"@vality/payout-manager-proto": "2.0.1-eb4091a.0",
"@vality/repairer-proto": "2.0.2-07b73e9.0",
"@vality/thrift-ts": "2.4.1-8ad5123.0",

View File

@ -1,7 +1,7 @@
import { Component, DestroyRef } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { ActivatedRoute } from '@angular/router';
import { RoutingCandidate, Predicate } from '@vality/domain-proto/domain';
import { RoutingCandidate } from '@vality/domain-proto/domain';
import {
DialogResponseStatus,
DialogService,
@ -22,7 +22,8 @@ import {
DomainObjectCardComponent,
} from '@cc/app/shared/components/thrift-api-crud';
import { objectToJSON, getUnionKey } from '../../../../utils';
import { objectToJSON } from '../../../../utils';
import { createPredicateColumn } from '../../../shared';
import { CandidateCardComponent } from '../../../shared/components/candidate-card/candidate-card.component';
import { SidenavInfoService } from '../../../shared/components/sidenav-info';
import { RoutingRulesService } from '../services/routing-rules';
@ -80,24 +81,20 @@ export class RoutingRulesetComponent {
});
},
},
{
field: 'global_allow',
formatter: (d) =>
combineLatest([
this.domainStoreService.getObjects('terminal'),
this.routingRulesType$,
]).pipe(
map(([terminals, type]) => {
const terms = terminals.find((t) => t.ref.id === d.terminal.id).data?.terms;
const globalAllow =
type === RoutingRulesType.Payment
? terms?.payments?.global_allow
: terms?.wallet?.withdrawals?.global_allow;
return this.formatPredicate(globalAllow);
}),
),
},
{ field: 'allowed', formatter: (d) => this.formatPredicate(d.allowed) },
createPredicateColumn('global_allow', (d) =>
combineLatest([
this.domainStoreService.getObjects('terminal'),
this.routingRulesType$,
]).pipe(
map(([terminals, type]) => {
const terms = terminals.find((t) => t.ref.id === d.terminal.id).data?.terms;
return type === RoutingRulesType.Payment
? terms?.payments?.global_allow
: terms?.wallet?.withdrawals?.global_allow;
}),
),
),
createPredicateColumn('allowed', (d) => d.allowed),
{ field: 'weight', sortable: true },
{
field: 'pin',
@ -306,14 +303,4 @@ export class RoutingRulesetComponent {
},
});
}
private formatPredicate(predicate: Predicate) {
if (!predicate) {
return '';
}
if (getUnionKey(predicate) === 'constant') {
return JSON.stringify(predicate.constant);
}
return getUnionKey(predicate);
}
}

View File

@ -8,6 +8,7 @@ import { of } from 'rxjs';
import { map, take } from 'rxjs/operators';
import { DomainStoreService } from '../../api/domain-config';
import { createPredicateColumn } from '../../shared';
import { SidenavInfoService } from '../../shared/components/sidenav-info';
import { TerminalDelegatesCardComponent } from '../../shared/components/terminal-delegates-card/terminal-delegates-card.component';
import { DomainObjectCardComponent } from '../../shared/components/thrift-api-crud';
@ -50,6 +51,11 @@ export class TerminalsComponent {
});
},
},
createPredicateColumn('payments global allow', (d) => d.data.terms?.payments?.global_allow),
createPredicateColumn(
'withdrawals global allow',
(d) => d.data.terms?.wallet?.withdrawals?.global_allow,
),
{
field: 'delegates',
formatter: (d) =>

View File

@ -17,7 +17,7 @@ import {
import isNil from 'lodash-es/isNil';
import { of } from 'rxjs';
import { map, shareReplay, catchError, debounceTime } from 'rxjs/operators';
import { Memoize } from 'typescript-memoize';
import { MemoizeExpiring } from 'typescript-memoize';
import { WalletParams } from '@cc/app/api/fistful-stat/query-dsl/types/wallet';
import { ManagementService } from '@cc/app/api/wallet';
@ -153,7 +153,7 @@ export class WalletsComponent implements OnInit {
this.fetchWalletsTextService.reload();
}
@Memoize()
@MemoizeExpiring(5 * 60_000)
getBalance(walletId: string) {
return this.walletManagementService.GetAccountBalance(walletId).pipe(
catchError((err) => {

View File

@ -3,7 +3,7 @@ import { Component, Output, EventEmitter, Input, booleanAttribute, OnChanges } f
import { MatCardModule } from '@angular/material/card';
import { Sort } from '@angular/material/sort';
import { Router } from '@angular/router';
import { Shop, Party } from '@vality/domain-proto/domain';
import { Shop, Party, Reference } from '@vality/domain-proto/domain';
import {
InputFieldModule,
TableModule,
@ -17,7 +17,8 @@ import {
} from '@vality/ng-core';
import startCase from 'lodash-es/startCase';
import { map, switchMap, Subject, defer, combineLatest } from 'rxjs';
import { filter, shareReplay, startWith, take } from 'rxjs/operators';
import { filter, shareReplay, startWith, take, first } from 'rxjs/operators';
import { MemoizeExpiring } from 'typescript-memoize';
import { getUnionKey } from '../../../../utils';
import { DomainStoreService } from '../../../api/domain-config';
@ -27,7 +28,11 @@ import { RoutingRulesType } from '../../../sections/routing-rules/types/routing-
import { ShopCardComponent } from '../shop-card/shop-card.component';
import { ShopContractCardComponent } from '../shop-contract-card/shop-contract-card.component';
import { SidenavInfoService } from '../sidenav-info';
import { DomainThriftViewerComponent } from '../thrift-api-crud';
import {
DomainThriftViewerComponent,
DomainObjectCardComponent,
getDomainObjectDetails,
} from '../thrift-api-crud';
export interface ShopParty {
shop: Shop;
@ -102,6 +107,25 @@ export class ShopsTableComponent implements OnChanges {
});
},
},
{
field: 'terms',
formatter: (d) =>
this.getTerms(d.party.id, d.shop.id).pipe(
map((terms) => getDomainObjectDetails(terms).label),
),
description: (d) =>
this.getTerms(d.party.id, d.shop.id).pipe(
map((terms) => getDomainObjectDetails(terms).id),
),
lazy: true,
click: (d) => {
this.getTerms(d.party.id, d.shop.id).subscribe((terms) => {
this.sidenavInfoService.toggle(DomainObjectCardComponent, {
ref: { term_set_hierarchy: terms.term_set_hierarchy.ref },
});
});
},
},
{
field: 'shop.location.url',
},
@ -278,4 +302,13 @@ export class ShopsTableComponent implements OnChanges {
},
});
}
@MemoizeExpiring(5 * 60_000, (...args) => JSON.stringify(args))
getTerms(partyId: string, shopId: string) {
return this.partyManagementService.GetShopContract(partyId, shopId).pipe(
map((c): Reference => ({ term_set_hierarchy: { id: c.contract.terms.id } })),
switchMap((ref) => this.domainStoreService.getObject(ref).pipe(first())),
shareReplay({ refCount: true, bufferSize: 1 }),
);
}
}

View File

@ -0,0 +1,35 @@
import { Predicate } from '@vality/domain-proto/domain';
import {
ColumnObject,
TagColumn,
PossiblyAsync,
getPossiblyAsyncObservable,
} from '@vality/ng-core';
import { map } from 'rxjs/operators';
import { formatPredicate } from './format-predicate';
export function createPredicateColumn<T extends object>(
field: ColumnObject<T>['field'],
select: (d: T) => PossiblyAsync<Predicate>,
params: Partial<ColumnObject<T>> = {},
): TagColumn<T> {
const formatter = (d: T) =>
getPossiblyAsyncObservable(select(d)).pipe(map((predicate) => formatPredicate(predicate)));
return {
field,
formatter,
type: 'tag',
sortable: true,
typeParameters: {
label: formatter,
tags: {
/* eslint-disable @typescript-eslint/naming-convention */
True: { color: 'success' },
False: { color: 'warn' },
/* eslint-enable @typescript-eslint/naming-convention */
},
},
...params,
} as TagColumn<T>;
}

View File

@ -0,0 +1,14 @@
import { Predicate } from '@vality/domain-proto/domain';
import startCase from 'lodash-es/startCase';
import { getUnionKey } from '../../../../utils';
export function formatPredicate(predicate: Predicate) {
if (!predicate) {
return '';
}
if (getUnionKey(predicate) === 'constant') {
return startCase(String(predicate.constant));
}
return startCase(getUnionKey(predicate));
}

View File

@ -1,3 +1,4 @@
export * from './create-currency-column';
export * from './create-party-column';
export * from './create-shop-column';
export * from './create-predicate-column';