Skip to content

Commit 5df6c54

Browse files
authored
BG-655: Fix shop selector (#490)
1 parent 6ede450 commit 5df6c54

File tree

12 files changed

+251
-29
lines changed

12 files changed

+251
-29
lines changed

src/app/parties/party/wallet-webhooks/create-wallet-webhook-dialog/create-wallet-webhook-dialog.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<v-dialog [progress]="progress()" title="Create wallet webhook">
22
<cc-fistful-thrift-form
3+
[extensions]="extensions$ | async"
34
[formControl]="control"
45
namespace="webhooker"
56
type="WebhookParams"

src/app/parties/party/wallet-webhooks/create-wallet-webhook-dialog/create-wallet-webhook-dialog.component.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
1+
import { distinctUntilChanged, map, of } from 'rxjs';
2+
3+
import { CommonModule } from '@angular/common';
14
import { Component, inject, signal } from '@angular/core';
25
import { FormControl, ReactiveFormsModule } from '@angular/forms';
36
import { MatButtonModule } from '@angular/material/button';
47

58
import { WebhookParams } from '@vality/fistful-proto/webhooker';
6-
import { DialogModule, DialogSuperclass, NotifyLogService, progressTo } from '@vality/matez';
9+
import {
10+
DialogModule,
11+
DialogSuperclass,
12+
NotifyLogService,
13+
getValueChanges,
14+
progressTo,
15+
} from '@vality/matez';
16+
import { isTypeWithAliases } from '@vality/ng-thrift';
717

818
import { ThriftWalletWebhooksManagementService } from '~/api/services';
919
import { FistfulThriftFormComponent } from '~/components/fistful-thrift-form';
20+
import { DomainMetadataFormExtensionsService } from '~/components/thrift-api-crud';
1021

1122
@Component({
1223
selector: 'cc-create-wallet-webhook-dialog',
13-
imports: [DialogModule, FistfulThriftFormComponent, ReactiveFormsModule, MatButtonModule],
24+
imports: [
25+
CommonModule,
26+
DialogModule,
27+
FistfulThriftFormComponent,
28+
ReactiveFormsModule,
29+
MatButtonModule,
30+
],
1431
templateUrl: './create-wallet-webhook-dialog.component.html',
1532
})
1633
export class CreateWalletWebhookDialogComponent extends DialogSuperclass<
@@ -19,12 +36,23 @@ export class CreateWalletWebhookDialogComponent extends DialogSuperclass<
1936
> {
2037
private walletWebhooksManagementService = inject(ThriftWalletWebhooksManagementService);
2138
private log = inject(NotifyLogService);
39+
private domainMetadataFormExtensionsService = inject(DomainMetadataFormExtensionsService);
2240

2341
control = new FormControl<Partial<WebhookParams>>(
2442
{ party_id: this.dialogData.partyId },
2543
{ nonNullable: true },
2644
);
2745
progress = signal(0);
46+
extensions$ = this.domainMetadataFormExtensionsService.createFullDomainObjectsOptionsByType(
47+
'WalletConfigObject',
48+
'wallet_config',
49+
getValueChanges(this.control).pipe(
50+
map((value) => value?.party_id ?? this.dialogData.partyId),
51+
distinctUntilChanged(),
52+
map((partyId) => (obj) => obj.object.wallet_config.data.party_ref.id === partyId),
53+
),
54+
(data) => of(isTypeWithAliases(data, 'WalletID', 'webhooker')),
55+
);
2856

2957
create() {
3058
this.walletWebhooksManagementService

src/app/parties/party/webhooks/create-webhook-dialog/create-webhook-dialog.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<v-dialog [progress]="progress()" title="Create shop webhook">
22
<cc-domain-thrift-editor
3+
[extensions]="extensions$ | async"
34
[formControl]="control"
45
namespace="webhooker"
56
type="WebhookParams"

src/app/parties/party/webhooks/create-webhook-dialog/create-webhook-dialog.component.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
1+
import { distinctUntilChanged, map } from 'rxjs';
2+
3+
import { CommonModule } from '@angular/common';
14
import { Component, inject, signal } from '@angular/core';
25
import { FormControl, ReactiveFormsModule } from '@angular/forms';
36
import { MatButtonModule } from '@angular/material/button';
47

58
import { WebhookParams } from '@vality/domain-proto/webhooker';
6-
import { DialogModule, DialogSuperclass, NotifyLogService, progressTo } from '@vality/matez';
9+
import {
10+
DialogModule,
11+
DialogSuperclass,
12+
NotifyLogService,
13+
getValueChanges,
14+
progressTo,
15+
} from '@vality/matez';
716

817
import { ThriftShopWebhooksManagementService } from '~/api/services';
9-
import { DomainThriftFormComponent } from '~/components/thrift-api-crud';
18+
import {
19+
DomainMetadataFormExtensionsService,
20+
DomainThriftFormComponent,
21+
} from '~/components/thrift-api-crud';
1022

1123
@Component({
1224
selector: 'cc-create-webhook-dialog',
13-
imports: [DialogModule, DomainThriftFormComponent, ReactiveFormsModule, MatButtonModule],
25+
imports: [
26+
CommonModule,
27+
DialogModule,
28+
DomainThriftFormComponent,
29+
ReactiveFormsModule,
30+
MatButtonModule,
31+
],
1432
templateUrl: './create-webhook-dialog.component.html',
1533
})
1634
export class CreateWebhookDialogComponent extends DialogSuperclass<
@@ -19,12 +37,22 @@ export class CreateWebhookDialogComponent extends DialogSuperclass<
1937
> {
2038
private webhooksManagementService = inject(ThriftShopWebhooksManagementService);
2139
private log = inject(NotifyLogService);
40+
private domainMetadataFormExtensionsService = inject(DomainMetadataFormExtensionsService);
2241

2342
control = new FormControl<Partial<WebhookParams>>(
2443
{ party_ref: { id: this.dialogData.partyId } },
2544
{ nonNullable: true },
2645
);
2746
progress = signal(0);
47+
extensions$ = this.domainMetadataFormExtensionsService.createFullDomainObjectsOptionsByType(
48+
'ShopConfigObject',
49+
'shop_config',
50+
getValueChanges(this.control).pipe(
51+
map((value) => value?.party_ref?.id ?? this.dialogData.partyId),
52+
distinctUntilChanged(),
53+
map((partyId) => (obj) => obj.object.shop_config.data.party_ref.id === partyId),
54+
),
55+
);
2856

2957
create() {
3058
this.webhooksManagementService

src/components/create-invoice-template-dialog/create-invoice-template-dialog.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
</div>
2121
} @else {
2222
<cc-domain-thrift-editor
23+
[extensions]="extensions$ | async"
2324
[formControl]="control"
2425
namespace="api_extensions"
2526
noToolbar

src/components/create-invoice-template-dialog/create-invoice-template-dialog.component.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
catchError,
44
combineLatest,
55
debounceTime,
6+
distinctUntilChanged,
67
map,
78
of,
89
shareReplay,
@@ -31,10 +32,11 @@ import {
3132
progressTo,
3233
} from '@vality/matez';
3334

35+
import { DomainObjectsStoreService } from '~/api/domain-config';
3436
import { ThriftInvoiceTemplatingService } from '~/api/services';
3537
import { ConfigService } from '~/services';
3638

37-
import { DomainThriftFormComponent } from '../thrift-api-crud';
39+
import { DomainMetadataFormExtensionsService, DomainThriftFormComponent } from '../thrift-api-crud';
3840

3941
@Component({
4042
templateUrl: './create-invoice-template-dialog.component.html',
@@ -59,6 +61,8 @@ export class CreateInvoiceTemplateDialogComponent extends DialogSuperclass<Creat
5961
private configService = inject(ConfigService);
6062
private clipboard = inject(Clipboard);
6163
private fb = inject(FormBuilder);
64+
private domainMetadataFormExtensionsService = inject(DomainMetadataFormExtensionsService);
65+
private domainStoreService = inject(DomainObjectsStoreService);
6266

6367
linkForm = this.fb.group({
6468
name: null,
@@ -111,6 +115,46 @@ export class CreateInvoiceTemplateDialogComponent extends DialogSuperclass<Creat
111115
}),
112116
shareReplay({ refCount: true, bufferSize: 1 }),
113117
);
118+
extensions$ = combineLatest([
119+
this.domainMetadataFormExtensionsService.createFullDomainObjectsOptionsByType(
120+
'ShopConfigObject',
121+
'shop_config',
122+
getValueChanges(this.control).pipe(
123+
map((value) => value?.party_id?.id),
124+
distinctUntilChanged(),
125+
map((partyId) =>
126+
partyId
127+
? (obj) => obj.object.shop_config.data.party_ref.id === partyId
128+
: () => true,
129+
),
130+
),
131+
),
132+
this.domainMetadataFormExtensionsService.createFullDomainObjectsOptionsByType(
133+
'CurrencyObject',
134+
'currency',
135+
getValueChanges(this.control).pipe(
136+
map((value) => value?.shop_id?.id),
137+
distinctUntilChanged(),
138+
switchMap((shopId) =>
139+
shopId
140+
? this.domainStoreService.getObject({
141+
shop_config: { id: shopId },
142+
}).value$
143+
: of(null),
144+
),
145+
map((shop) =>
146+
shop
147+
? (obj) =>
148+
obj.object.currency.data.symbolic_code ===
149+
shop.object.shop_config.data.account.currency.symbolic_code
150+
: () => true,
151+
),
152+
),
153+
),
154+
]).pipe(
155+
map((extensionGroups) => extensionGroups.flat()),
156+
shareReplay({ refCount: true, bufferSize: 1 }),
157+
);
114158

115159
create() {
116160
this.createTemplate$.next(null);

src/components/shops-table/shops-table.component.ts

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export class ShopsTableComponent {
5757
private partyManagementService = inject(ThriftPartyManagementService);
5858

5959
shops = input<ShopWithInfo[]>([]);
60+
isHistoryView = input(false, { transform: booleanAttribute });
6061
@Input() progress: number | boolean = false;
6162
@Input() hasMore: boolean = false;
6263
@Output() update = new EventEmitter<UpdateOptions>();
@@ -120,12 +121,24 @@ export class ShopsTableComponent {
120121
)[getUnionKey(d.data.suspension)],
121122
}),
122123
},
124+
{
125+
field: 'Settlement/Guarantee Accounts',
126+
header: { value: 'Accounts', description: 'Settlement/Guarantee' },
127+
cell: (d) => ({
128+
value: d.data.account.settlement,
129+
description: d.data.account.guarantee,
130+
}),
131+
},
123132
createCurrencyColumn(
124133
(d) =>
125134
this.getSettlementAccountState(d).pipe(
126135
map((b) => ({ amount: b.own_amount, code: b.currency.symbolic_code })),
127136
),
128-
{ header: 'Own', isLazyCell: true },
137+
{
138+
header: 'Own',
139+
isLazyCell: true,
140+
hidden: toObservable(this.isHistoryView, { injector: this.injector }),
141+
},
129142
),
130143
createCurrencyColumn(
131144
(d) =>
@@ -135,21 +148,33 @@ export class ShopsTableComponent {
135148
code: b.currency.symbolic_code,
136149
})),
137150
),
138-
{ header: 'Hold', isLazyCell: true },
151+
{
152+
header: 'Hold',
153+
isLazyCell: true,
154+
hidden: toObservable(this.isHistoryView, { injector: this.injector }),
155+
},
139156
),
140157
createCurrencyColumn(
141158
(d) =>
142159
this.getSettlementAccountState(d).pipe(
143160
map((b) => ({ amount: b.available_amount, code: b.currency.symbolic_code })),
144161
),
145-
{ header: 'Available', isLazyCell: true },
162+
{
163+
header: 'Available',
164+
isLazyCell: true,
165+
hidden: toObservable(this.isHistoryView, { injector: this.injector }),
166+
},
146167
),
147168
createCurrencyColumn(
148169
(d) =>
149170
this.getGuaranteeAccountState(d).pipe(
150171
map((b) => ({ amount: b.own_amount, code: b.currency.symbolic_code })),
151172
),
152-
{ header: 'Guarantee Own', isLazyCell: true },
173+
{
174+
header: 'Guarantee Own',
175+
isLazyCell: true,
176+
hidden: toObservable(this.isHistoryView, { injector: this.injector }),
177+
},
153178
),
154179
createCurrencyColumn(
155180
(d) =>
@@ -159,14 +184,22 @@ export class ShopsTableComponent {
159184
code: b.currency.symbolic_code,
160185
})),
161186
),
162-
{ header: 'Guarantee Hold', isLazyCell: true },
187+
{
188+
header: 'Guarantee Hold',
189+
isLazyCell: true,
190+
hidden: toObservable(this.isHistoryView, { injector: this.injector }),
191+
},
163192
),
164193
createCurrencyColumn(
165194
(d) =>
166195
this.getGuaranteeAccountState(d).pipe(
167196
map((b) => ({ amount: b.available_amount, code: b.currency.symbolic_code })),
168197
),
169-
{ header: 'Guarantee Available', isLazyCell: true },
198+
{
199+
header: 'Guarantee Available',
200+
isLazyCell: true,
201+
hidden: toObservable(this.isHistoryView, { injector: this.injector }),
202+
},
170203
),
171204
{ field: 'version', cell: (d) => ({ value: d.info.version }) },
172205
{ field: 'changed_at', cell: (d) => ({ value: d.info.changed_at, type: 'datetime' }) },

src/components/thrift-api-crud/domain/domain-object-history-card/domain-object-history-card.component.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@
1010
[extendMenu]="menuColumn"
1111
[hasMore]="resource.hasMore()"
1212
[shops]="shopsResource.value()"
13+
isHistoryView
1314
(more)="resource.more()"
1415
(update)="resource.reload()"
1516
/>
1617
}
1718
@case ('wallet_config') {
18-
<cc-wallets-table [extendMenu]="menuColumn" [resource]="fullObjectsResource" />
19+
<cc-wallets-table
20+
[extendMenu]="menuColumn"
21+
[resource]="fullObjectsResource"
22+
isHistoryView
23+
/>
1924
}
2025
@default {
2126
<cc-domain-objects-table [menu]="menuColumn" [resource]="resource" />

src/components/thrift-api-crud/domain/services/domain-metadata-form-extensions/domain-metadata-form-extensions.service.ts

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
import { Observable, of } from 'rxjs';
1+
import { Observable, combineLatest, of } from 'rxjs';
22
import { map, shareReplay } from 'rxjs/operators';
33
import short from 'short-uuid';
44

55
import { Injectable, inject } from '@angular/core';
66

77
import { ThriftAstMetadata, metadata$ } from '@vality/domain-proto';
88
import { DomainObject } from '@vality/domain-proto/domain';
9-
import { getNoTimeZoneIsoString } from '@vality/matez';
9+
import { VersionedObject } from '@vality/domain-proto/domain_config_v2';
10+
import { PossiblyAsync, getNoTimeZoneIsoString, getPossiblyAsyncObservable } from '@vality/matez';
1011
import { ThriftData, ThriftFormExtension, isTypeWithAliases } from '@vality/ng-thrift';
1112

1213
import { DomainObjectsStoreService, DomainService } from '~/api/domain-config';
1314
import { AuthorStoreService } from '~/api/domain-config/stores/author-store.service';
1415

1516
import { createDomainObjectExtensions } from './utils/create-domain-object-extension';
16-
import { getDomainObjectOption } from './utils/get-domain-object-option';
17+
import { getDomainObjectOption, getFullDomainObjectOption } from './utils/get-domain-object-option';
1718

1819
@Injectable({
1920
providedIn: 'root',
@@ -101,6 +102,39 @@ export class DomainMetadataFormExtensionsService {
101102
shareReplay({ refCount: true, bufferSize: 1 }),
102103
);
103104

105+
createFullDomainObjectsOptionsByType(
106+
objectType: string,
107+
objectKey: keyof DomainObject,
108+
filterFn$: PossiblyAsync<Parameters<VersionedObject[]['filter']>[0]>,
109+
determinant?: ThriftFormExtension['determinant'],
110+
): Observable<ThriftFormExtension[]> {
111+
return metadata$.pipe(
112+
map((metadata) => {
113+
const objectFields = new ThriftData<string, 'struct'>(
114+
metadata,
115+
'domain',
116+
objectType,
117+
).ast;
118+
const refType = objectFields.find((n) => n.name === 'ref').type as string;
119+
return createDomainObjectExtensions(
120+
refType,
121+
() =>
122+
combineLatest([
123+
this.domainStoreService.getObjects(objectKey).value$,
124+
getPossiblyAsyncObservable(filterFn$),
125+
]).pipe(
126+
map(([objects, filterFn]) =>
127+
objects
128+
.filter(filterFn)
129+
.map((obj) => getFullDomainObjectOption(obj)),
130+
),
131+
),
132+
determinant,
133+
);
134+
}),
135+
);
136+
}
137+
104138
private createDomainObjectsOptions(metadata: ThriftAstMetadata[]): ThriftFormExtension[] {
105139
const domainFields = new ThriftData<string, 'struct'>(metadata, 'domain', 'DomainObject')
106140
.ast;

0 commit comments

Comments
 (0)