Skip to content

Commit

Permalink
Display unsupported formats as disabled options, minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vafeini committed Oct 29, 2024
1 parent 7b73c87 commit ea60081
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 21 deletions.
8 changes: 3 additions & 5 deletions src/app/core/constants/attestations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ export const SUPPORTED_ATTESTATIONS: { [id: string]: Attestation } = {
"age_over_18": AGE_OVER_18_ATTESTATION,
}

export const SUPPORTED_FORMATS: { [id: string]: AttestationFormat } = {
"mso_mdoc": AttestationFormat.MSO_MDOC,
"vc+sd-jwt": AttestationFormat.SD_JWT_VC,
"jwt_vc_json": AttestationFormat.JWT_VC_JSON,
}
export const SUPPORTED_FORMATS: AttestationFormat[] = [
AttestationFormat.MSO_MDOC
]

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<mat-label>-- format --</mat-label>
<mat-select matNativeControl [(value)]="selectedFormat" [formControl]="formatControl" (selectionChange)="emit()">
<ng-container *ngFor="let format of supportedFormats">
<mat-option [value]="format.key">{{ format.value }}</mat-option>
<mat-option [value]="format.key" disabled="{{format.disabled}}">{{ format.value }}</mat-option>
</ng-container>
</mat-select>
<mat-error *ngIf="formatControl.hasError('required')">Please choose an format</mat-error>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {SUPPORTED_ATTESTATIONS, SUPPORTED_FORMATS} from "@core/constants/attesta
import {MatExpansionModule} from "@angular/material/expansion";
import {AttestationFormat} from "@core/models/attestation/AttestationFormat";
import {AttestationSelection} from "@features/presentation-request-preparation/models/ScenarioSelection";
import {FormatSelectOption} from "@features/presentation-request-preparation/components/attestation/model/format-select-option";

@Component({
selector: 'vc-scenario-attestation',
Expand All @@ -33,7 +34,7 @@ export class AttestationComponent {
@Input() attestation!: ScenarioAttestation;
@Output() attestationSelectionEvent = new EventEmitter<AttestationSelection>();

protected readonly supportedFormats: KeyValue<string, string>[] = this.formats(SUPPORTED_FORMATS)
protected readonly supportedFormats: FormatSelectOption[] = this.formatOptions()

methodControl = new FormControl<AttributeSelectionMethod | null>(null, Validators.required);
formatControl = new FormControl<AttestationFormat | null>(null, Validators.required);
Expand All @@ -49,15 +50,21 @@ export class AttestationComponent {
}
}

formats(formats: { [p: string]: AttestationFormat }) {
let result: KeyValue<string, string>[] = [];
Object.keys(formats).forEach((item) => {
formatOptions(): FormatSelectOption[] {
function enumKeys<O extends object, K extends keyof O = keyof O>(obj: O): K[] {
return Object.keys(obj).filter(k => !Number.isNaN(k)) as K[]
}

let result: FormatSelectOption[] = [];
for (const enumKey of enumKeys(AttestationFormat)) {
const format = AttestationFormat[enumKey];
result.push({
key: item,
value: formats[item]
});
});
return result;
key: format,
value: format,
disabled: !SUPPORTED_FORMATS.includes(format)
})
}
return result
}

emit() {
Expand All @@ -72,4 +79,5 @@ export class AttestationComponent {
return SUPPORTED_ATTESTATIONS[attestation.attestationType as string].name
}

protected readonly frameElement = frameElement;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type FormatSelectOption = {
key: string,
value: string,
disabled: boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ <h3>Select attributes of the attestation to be included in the request</h3>
</mat-dialog-content>

<mat-dialog-actions align="end">
<button mat-button mat-dialog-close (click)="saveSelection()">Select</button>
<button mat-button mat-dialog-close (click)="saveSelection()" [disabled]="!isSomethingSelected()">Select</button>
<button mat-button mat-dialog-close>Close</button>
</mat-dialog-actions>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChangeDetectorRef, Component, inject, OnInit} from '@angular/core';
import {Component, inject, OnInit} from '@angular/core';
import {MsoMdocPresentationService} from "@app/core/services/mso-mdoc-presentation.service";
import {VerifierEndpointService} from "@core/services/verifier-endpoint.service";
import {FieldConstraint, Filter} from "@core/models/presentation/FieldConstraint";
Expand Down Expand Up @@ -45,7 +45,6 @@ export class SelectableAttestationAttributesComponent implements OnInit {

constructor(
private readonly msoMdocPresentationService: MsoMdocPresentationService,
private readonly changeDetectorRef: ChangeDetectorRef,
private dialogRef: MatDialogRef<InputDescriptor>
) {
}
Expand All @@ -59,11 +58,12 @@ export class SelectableAttestationAttributesComponent implements OnInit {
this.selectedFields = this.seed.constraints.fields
this.draftInputDescriptor = this.seed
} else {
this.initEmptyInputDecriptor();
this.initEmptyInputDescriptor();
}
this.inputDescriptorText = this.convertJSONtoString(this.draftInputDescriptor);
}

initEmptyInputDecriptor() {
initEmptyInputDescriptor() {
switch (this.attestationFormat) {
case AttestationFormat.MSO_MDOC:
let msomdoc = MSO_MDOC_BY_TYPE[this.attestationType as string];
Expand Down Expand Up @@ -91,7 +91,6 @@ export class SelectableAttestationAttributesComponent implements OnInit {
this.draftInputDescriptor.constraints.fields = this.selectedFields;
// refresh descriptor text from model
this.inputDescriptorText = this.convertJSONtoString(this.draftInputDescriptor);
this.changeDetectorRef.detectChanges();
}

convertJSONtoString(obj: object) {
Expand Down Expand Up @@ -142,6 +141,10 @@ export class SelectableAttestationAttributesComponent implements OnInit {
}).length > 0
}

isSomethingSelected(): boolean {
return this.selectedFields.length > 0;
}

areEqualConstraints(one: FieldConstraint, other: FieldConstraint): boolean {
function pathsAreEqual(a: string[], b: string[]): boolean {
if (a === b) return true;
Expand Down

0 comments on commit ea60081

Please sign in to comment.