Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
with:
release: true
- name: Build
run: npm run build -- --define "SENTRY_DSN='${SENTRY_DSN}'"
run: npm run build -- --define "SENTRY_DSN='${SENTRY_DSN}'" --define "SENTRY_RELEASE='${GITHUB_SHA}'"
env:
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
- name: Sentry release
Expand All @@ -28,6 +28,8 @@ jobs:
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
with:
environment: production
release: ${{ github.sha }}
sourcemaps: ./dist/control-center/browser
set_commits: skip
- name: Remove source maps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { WrappedControlSuperclass } from '@s-libs/ng-core';

import { getErrorsTree } from './utils/get-errors-tree';

/**
* @deprecated Use FormControlValue
*/
@Directive()
export abstract class AbstractControlSuperclass<OuterType, InnerType = OuterType>
extends WrappedControlSuperclass<OuterType, InnerType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { hasControls } from '../has-controls';

import { FormGroupSuperclass } from './form-group-superclass.directive';

/**
* @deprecated Use FormControlValue
*/
@Directive()
export abstract class FormArraySuperclass<
OuterType extends unknown[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { AbstractControl, ValidationErrors, Validator } from '@angular/forms';
import { FormComponentSuperclass as BaseFormComponentSuperclass } from '@s-libs/ng-core';

/**
* @deprecated Use FormControlValue
*/
@Directive()
export abstract class FormComponentSuperclass<OuterType>
extends BaseFormComponentSuperclass<OuterType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { FormControl } from '@angular/forms';

import { AbstractControlSuperclass } from './abstract-control-superclass';

/**
* @deprecated Use FormControlValue
*/
@Directive()
export class FormControlSuperclass<
OuterType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { hasControls } from '../has-controls';

import { AbstractControlSuperclass } from './abstract-control-superclass';

/**
* @deprecated Use FormControlValue
*/
@Directive()
export abstract class FormGroupSuperclass<OuterType, InnerType = OuterType>
extends AbstractControlSuperclass<OuterType, InnerType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ export class ExtensionFieldComponent<T>
this.converter$
.pipe(first(), takeUntilDestroyed(this.destroyRef))
.subscribe((converter) => {
this.control.setValue(converter.outputToInternal(value) as never);
this.control.setValue(converter.outputToInternal(value) as never, {
emitEvent: false,
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<v-thrift-monaco
[value]="control.value"
(parseError)="setError($event)"
(valueChange)="control.setValue($event)"
(valueChange)="setEditorValue($event)"
></v-thrift-monaco>
}
@case ('form') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { filter, shareReplay } from 'rxjs/operators';
import {
ChangeDetectionStrategy,
Component,
Injector,
Input,
afterNextRender,
booleanAttribute,
inject,
model,
Expand All @@ -21,7 +23,9 @@ import {
} from '@vality/matez';
import { ValueType } from '@vality/thrift-ts';

import { ThriftData } from '../../models';
import { ThriftAstMetadata } from '../../types';
import { fromJson } from '../../utils/thrift-type/from-json';

import { ThriftFormExtension } from './types/thrift-form-extension';

Expand All @@ -40,6 +44,7 @@ export enum EditorKind {
})
export class ThriftEditorComponent<T> extends FormControlSuperclass<T> {
private dialogService = inject(DialogService);
private injector = inject(Injector);
readonly kind = model<UnionEnum<EditorKind>>(EditorKind.Form);

@Input() defaultValue?: T;
Expand Down Expand Up @@ -71,13 +76,29 @@ export class ThriftEditorComponent<T> extends FormControlSuperclass<T> {
this.control.updateValueAndValidity();
}

setEditorValue(value: unknown) {
this.control.setValue(
fromJson(value, new ThriftData(this.metadata, this.namespace, this.type)) as T,
);
}

toggleKind() {
this.editorError = null;
const kind = this.kind();
switch (kind) {
case EditorKind.Editor:
case EditorKind.Editor: {
const value = this.control.value;
this.kind.set(EditorKind.Form);
afterNextRender(
() => {
if (this.kind() === EditorKind.Form) {
this.control.setValue(value);
}
},
{ injector: this.injector },
);
break;
}
case EditorKind.Form:
this.kind.set(EditorKind.Editor);
break;
Expand Down
24 changes: 24 additions & 0 deletions projects/ng-thrift/src/lib/utils/thrift-type/from-json.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ThriftData } from '../../models';

import { fromJson } from './from-json';

describe('fromJson', () => {
it('restores maps and nested sets from their JSON representation', () => {
const data = new ThriftData([], 'test', {
name: 'map',
keyType: 'string',
valueType: { name: 'set', valueType: 'i64' },
});

expect(fromJson([['RUB', [1, 2]]], data)).toEqual(new Map([['RUB', new Set([1, 2])]]));
});

it('keeps thrift lists as arrays', () => {
const data = new ThriftData([], 'test', {
name: 'list',
valueType: 'i64',
});

expect(fromJson([1, 2], data)).toEqual([1, 2]);
});
});
62 changes: 62 additions & 0 deletions projects/ng-thrift/src/lib/utils/thrift-type/from-json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Field, ListType, MapType, SetType } from '@vality/thrift-ts';

import { ThriftData } from '../../models';

export function fromJson(value: unknown, data: ThriftData): unknown {
if (value == null) {
return value;
}

const trueData = data.trueTypeNode.data;
if (trueData.typeGroup === 'complex') {
switch ((trueData.type as ListType | MapType | SetType).name) {
case 'list':
return Array.from(value as unknown[]).map((item) =>
fromJson(
item,
trueData.create({ type: (trueData.type as ListType).valueType }),
),
);
case 'set':
return new Set(
Array.from(value as Set<unknown> | unknown[]).map((item) =>
fromJson(
item,
trueData.create({ type: (trueData.type as SetType).valueType }),
),
),
);
case 'map': {
const mapType = trueData.type as MapType;
const entries =
value instanceof Map
? Array.from(value.entries())
: (value as [unknown, unknown][]);
return new Map(
entries.map(([key, item]): [unknown, unknown] => [
fromJson(key, trueData.create({ type: mapType.keyType })),
fromJson(item, trueData.create({ type: mapType.valueType })),
]),
);
}
}
}

if (
(trueData.objectType === 'struct' ||
trueData.objectType === 'union' ||
trueData.objectType === 'exception') &&
typeof value === 'object' &&
!Array.isArray(value)
) {
const fields = (trueData.ast ?? []) as Field[];
return Object.fromEntries(
Object.entries(value).map(([name, item]) => {
const field = fields.find((candidate) => candidate.name === name);
return [name, field ? fromJson(item, trueData.create({ field })) : item];
}),
);
}

return value;
}
10 changes: 5 additions & 5 deletions src/components/account-field/account-field.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@let noCurrencyAccount = noCurrencyAccount$ | async;
@let inProgress = !!(progress$ | async);
@let generateDisabled = !noCurrencyAccount || inProgress || control.value?.length !== 3;
@let generateDisabled = !hasMissingAccounts() || inProgress || currency()?.length !== 3;

<div class="flex gap-1">
<v-autocomplete-field
Expand All @@ -9,18 +8,19 @@
[label]="label()"
[options]="options$ | async"
class="flex-1"
(focusout)="markAsTouched()"
></v-autocomplete-field>
<button
[disabled]="generateDisabled"
[disabled]="disabled() || generateDisabled"
[matTooltip]="
noCurrencyAccount
hasMissingAccounts()
? currencyAccounts().length === accountsNumber()
? 'Generate optional accounts'
: 'Generate missing accounts'
: 'All accounts are set'
"
mat-icon-button
(click)="noCurrencyAccount ? generate() : undefined"
(click)="hasMissingAccounts() ? generate() : undefined"
>
<mat-icon>{{ inProgress ? 'pending' : 'bolt' }}</mat-icon>
</button>
Expand Down
Loading
Loading