From 8003a8fee968b80483de5f0e89594a5a5192d044 Mon Sep 17 00:00:00 2001 From: vato007 Date: Wed, 14 May 2025 20:38:14 +0930 Subject: [PATCH] Use accordions for nested field types --- .../list-field/list-field.component.scss | 5 +- .../editor/list-field/list-field.component.ts | 42 +++++++++------ .../editor/map-field/map-field.component.scss | 7 +-- .../editor/map-field/map-field.component.ts | 52 +++++++++++-------- .../object-field/object-field.component.scss | 4 ++ .../object-field/object-field.component.ts | 40 +++++++++----- 6 files changed, 90 insertions(+), 60 deletions(-) diff --git a/src/app/editor/list-field/list-field.component.scss b/src/app/editor/list-field/list-field.component.scss index a101913..5639c01 100644 --- a/src/app/editor/list-field/list-field.component.scss +++ b/src/app/editor/list-field/list-field.component.scss @@ -1,6 +1,7 @@ :host { display: flex; flex-direction: column; + margin: 0.5rem 0; } .row-wrapper { @@ -11,7 +12,3 @@ app-proto-field { flex: 1; } - -.add-button { - align-self: flex-end; -} diff --git a/src/app/editor/list-field/list-field.component.ts b/src/app/editor/list-field/list-field.component.ts index e20b948..0188930 100644 --- a/src/app/editor/list-field/list-field.component.ts +++ b/src/app/editor/list-field/list-field.component.ts @@ -11,30 +11,40 @@ import { MatButtonModule } from '@angular/material/button'; import { MatIconModule } from '@angular/material/icon'; import { ListMessage } from '../../model/proto-message.model'; import { ProtoFieldComponent } from '../proto-field/proto-field.component'; +import { MatExpansionModule } from '@angular/material/expansion'; @Component({ selector: 'app-list-field', imports: [ MatButtonModule, + MatExpansionModule, MatIconModule, forwardRef(() => ProtoFieldComponent), ], - template: `

{{ label() }}

- @if(values()) { @for(value of values(); track $index) { -
- - -
- } } - `, + template: ` + + + + {{ label() }} + + @if(values()) { @for(value of values(); track $index) { +
+ + +
+ } } + +
+
+ `, styleUrl: './list-field.component.scss', changeDetection: ChangeDetectionStrategy.OnPush, }) diff --git a/src/app/editor/map-field/map-field.component.scss b/src/app/editor/map-field/map-field.component.scss index 5605be6..99d9e37 100644 --- a/src/app/editor/map-field/map-field.component.scss +++ b/src/app/editor/map-field/map-field.component.scss @@ -1,6 +1,7 @@ :host { display: flex; flex-direction: column; + margin: 0.5rem 0; } .row-wrapper { @@ -12,10 +13,6 @@ app-proto-field { flex: 1; &:first-child { - margin-right: 10px; + margin-right: 0.5rem; } } - -.add-button { - align-self: flex-end; -} diff --git a/src/app/editor/map-field/map-field.component.ts b/src/app/editor/map-field/map-field.component.ts index 31d761e..69f6ca6 100644 --- a/src/app/editor/map-field/map-field.component.ts +++ b/src/app/editor/map-field/map-field.component.ts @@ -11,6 +11,7 @@ import { MatButtonModule } from '@angular/material/button'; import { MatIconModule } from '@angular/material/icon'; import { MapMessage } from '../../model/proto-message.model'; import { ProtoFieldComponent } from '../proto-field/proto-field.component'; +import { MatExpansionModule } from '@angular/material/expansion'; const keyIsEmpty = (key: string | number) => key == null || key === ''; @@ -18,30 +19,39 @@ const keyIsEmpty = (key: string | number) => key == null || key === ''; selector: 'app-map-field', imports: [ forwardRef(() => ProtoFieldComponent), + MatExpansionModule, MatIconModule, MatButtonModule, ], - template: `

{{ label() }}

- @if(valuePairs()) { @for(value of valuePairs(); track $index) { -
- - - -
- } } - `, + template: ` + + + + {{ label() }} + + @if(valuePairs()) { @for(value of valuePairs(); track $index) { +
+ + + +
+ } } + +
+
+ `, styleUrl: './map-field.component.scss', changeDetection: ChangeDetectionStrategy.OnPush, }) diff --git a/src/app/editor/object-field/object-field.component.scss b/src/app/editor/object-field/object-field.component.scss index e69de29..7088c3b 100644 --- a/src/app/editor/object-field/object-field.component.scss +++ b/src/app/editor/object-field/object-field.component.scss @@ -0,0 +1,4 @@ +:host { + display: block; + margin: 0.5rem 0; +} diff --git a/src/app/editor/object-field/object-field.component.ts b/src/app/editor/object-field/object-field.component.ts index 4c8a670..caed7ff 100644 --- a/src/app/editor/object-field/object-field.component.ts +++ b/src/app/editor/object-field/object-field.component.ts @@ -8,23 +8,35 @@ import { } from '@angular/core'; import { ObjectMessage } from '../../model/proto-message.model'; import { ProtoFieldComponent } from '../proto-field/proto-field.component'; +import { MatExpansionModule } from '@angular/material/expansion'; @Component({ selector: 'app-object-field', - imports: [forwardRef(() => ProtoFieldComponent)], - template: `

- {{ label() }} ({{ configuration().messageDefinition.name }}) -

-
- @for (item of configuration().messageDefinition.values; track $index) { - - } -
`, + imports: [MatExpansionModule, forwardRef(() => ProtoFieldComponent)], + template: ` + + + + + {{ label() ?? configuration().messageDefinition.name }} + + @if(label()) { + + {{ configuration().messageDefinition.name }} + + } + + @for (item of configuration().messageDefinition.values; track $index) { + + } + + + `, styleUrl: './object-field.component.scss', changeDetection: ChangeDetectionStrategy.OnPush, })