Skip to content

Commit fbc0169

Browse files
committed
fix field types
1 parent 94909c5 commit fbc0169

File tree

11 files changed

+231
-75
lines changed

11 files changed

+231
-75
lines changed

web-app/admin/src/app/admin/admin-event/admin-event-form/fields-list/fields-list.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ <h4 class="field-title">{{ field.title || 'No title set' }}</h4>
1111
<div class="field-details">
1212
<div class="field-row">
1313
<span class="field-label">Type:</span>
14-
<span class="field-value">{{ getFieldTypeLabel(field.type) }}</span>
14+
<span class="field-value">{{ getFieldTypeLabel(field.type, field) }}</span>
1515
<span class="field-label" *ngIf="field.required" style="margin-left: 1rem;">Required:</span>
1616
<span class="field-value" *ngIf="field.required">Yes</span>
1717
</div>
@@ -81,7 +81,7 @@ <h4 class="field-title">{{ field.title || 'No title set' }}</h4>
8181
<div class="field-content-compact">
8282
<div class="field-info">
8383
<div class="field-title">{{ field.title }}</div>
84-
<div class="field-type">{{ getFieldTypeLabel(field.type) }}
84+
<div class="field-type">{{ getFieldTypeLabel(field.type, field) }}
8585
<span *ngIf="field.required" class="required-badge">Required</span>
8686
</div>
8787
</div>

web-app/admin/src/app/admin/admin-event/admin-event-form/fields-list/fields-list.component.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class FieldsListComponent {
2424
@Input() fields: Field[] = [];
2525
@Input() fieldTypes: FieldType[] = [];
2626
@Input() attachmentAllowedTypes: AttachmentType[] = [];
27+
@Input() userFields: string[] = [];
2728
@Input() showDetailedView: boolean = false;
2829
@Output() fieldsChange = new EventEmitter<Field[]>();
2930

@@ -124,9 +125,18 @@ export class FieldsListComponent {
124125
this.fieldsChange.emit(this.fields);
125126
}
126127

127-
getFieldTypeLabel(type: string): string {
128-
const fieldType = this.fieldTypes.find(ft => ft.name === type);
129-
return fieldType?.title || type;
128+
getFieldTypeLabel(type: string, field?: Field): string {
129+
if (field && this.isMemberField(field)) {
130+
const userType = this.fieldTypes.find(ft => ft.name === 'userDropdown');
131+
return userType?.title || 'User Select';
132+
}
133+
134+
const lookupType = type === 'multiselectdropdown' ? 'dropdown' : type;
135+
const fieldType = this.fieldTypes.find(ft => ft.name === lookupType);
136+
if (fieldType) {
137+
return fieldType.title;
138+
}
139+
return type === 'multiselectdropdown' ? 'Select' : type;
130140
}
131141

132142
getActiveFields(): Field[] {
@@ -150,7 +160,8 @@ export class FieldsListComponent {
150160
}
151161

152162
isMemberField(field: Field): boolean {
153-
return field.type === 'userDropdown' || field.type === 'multiSelectUserDropdown';
163+
const isExplicitUserType = field.type === 'userDropdown' || field.type === 'multiSelectUserDropdown';
164+
return isExplicitUserType || this.userFields.includes(field.name || '');
154165
}
155166

156167
private getNextFieldId(): number {

web-app/admin/src/app/admin/admin-event/admin-event-form/form-details/field-dialog/field-dialog.component.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,16 @@ export class FieldDialogComponent {
4040

4141
if (this.isEditMode && data.existingField) {
4242
this.field = JSON.parse(JSON.stringify(data.existingField));
43-
if (this.field.type === 'multiselectdropdown') {
43+
const originalType = this.field.type;
44+
45+
if (data.isMemberField) {
46+
const wasMultiselect = originalType === 'multiselectdropdown' || !!this.field.multiselect;
47+
this.field.type = 'userDropdown';
48+
this.field.multiselect = wasMultiselect;
49+
} else if (originalType === 'multiselectdropdown') {
4450
this.field.type = 'dropdown';
4551
this.field.multiselect = true;
46-
} else if (this.field.type === 'multiSelectUserDropdown') {
52+
} else if (originalType === 'multiSelectUserDropdown') {
4753
this.field.type = 'userDropdown';
4854
this.field.multiselect = true;
4955
}
@@ -64,11 +70,6 @@ export class FieldDialogComponent {
6470

6571
onSave(): void {
6672
if (this.field.title) {
67-
if (this.field.type === 'dropdown' && this.field.multiselect) {
68-
this.field.type = 'multiselectdropdown';
69-
} else if (this.field.type === 'userDropdown' && this.field.multiselect) {
70-
this.field.type = 'multiSelectUserDropdown';
71-
}
7273
this.dialogRef.close(this.field);
7374
}
7475
}

web-app/admin/src/app/admin/admin-event/admin-event-form/form-details/form-details.component.html

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ <h3 class="section-title">Fields</h3>
164164

165165
<!-- Use the fields-list component -->
166166
<mage-fields-list [fields]="form.fields || []" [fieldTypes]="fieldTypes"
167-
[attachmentAllowedTypes]="attachmentAllowedTypes" [showDetailedView]="true"
167+
[attachmentAllowedTypes]="attachmentAllowedTypes"
168+
[userFields]="form.userFields || []" [showDetailedView]="true"
168169
(fieldsChange)="onFieldsChange($event)">
169170
</mage-fields-list>
170171
</div>
@@ -255,10 +256,10 @@ <h4 class="subsection-title">Configured Symbology</h4>
255256
</div>
256257

257258
<!-- Field Selection Controls -->
258-
<div style="flex: 1; display: flex; flex-direction: column; gap: 1.5rem;">
259-
<!-- Primary Field Selection -->
259+
<div style="flex: 1; display: flex; flex-direction: column; gap: 1rem;">
260+
<!-- Field Selection -->
260261
<div class="config-section">
261-
<h4 class="subsection-title">Primary Field</h4>
262+
<h4 class="subsection-title">Configure Fields</h4>
262263

263264
<div class="config-inline-item">
264265
<div class="config-inline-label">
@@ -278,14 +279,9 @@ <h4 class="subsection-title">Primary Field</h4>
278279
</select>
279280
</div>
280281
</div>
281-
</div>
282-
283-
<!-- Variant Field Selection -->
284-
<div class="config-section"
285-
*ngIf="form.primaryField && getDropdownFields(form.primaryField).length > 0">
286-
<h4 class="subsection-title">Variant Field</h4>
287282

288-
<div class="config-inline-item">
283+
<div class="config-inline-item"
284+
*ngIf="form.primaryField && getDropdownFields(form.primaryField).length > 0">
289285
<div class="config-inline-label">
290286
<strong>Variant Field</strong>
291287
<p class="field-hint">Select a second dropdown field for
@@ -414,7 +410,7 @@ <h4 class="subsection-title">Variant Field</h4>
414410
<div class="section-icon-wrapper feed-color">
415411
<i class="fa fa-list-ul"></i>
416412
</div>
417-
<h3 class="section-title">Feed Configuration</h3>
413+
<h3 class="section-title">Observation Feed Configuration</h3>
418414
</div>
419415
<button class="icon-button-subtle" type="button">
420416
<i class="fa"

web-app/admin/src/app/admin/admin-event/admin-event-form/form-details/form-details.component.scss

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@
349349
}
350350

351351
.config-section {
352-
margin-bottom: 1.5rem;
352+
margin-bottom: 1rem;
353353

354354
&:last-child {
355355
margin-bottom: 0;
@@ -366,29 +366,20 @@
366366
.feed-config-inline {
367367
display: flex;
368368
flex-direction: column;
369-
gap: 1.5rem;
369+
gap: 1rem;
370370
margin-bottom: 2rem;
371371
}
372372

373373
.config-inline-item {
374374
display: grid;
375375
grid-template-columns: 1fr 2fr;
376-
gap: 2rem;
377-
padding: 1.5rem;
378-
background: white;
379-
border: 1px solid #e5e7eb;
380-
border-radius: 12px;
376+
gap: 1.25rem;
381377
align-items: start;
382-
transition: all 0.2s ease;
383-
384-
&:hover {
385-
border-color: #d1d5db;
386-
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
387-
}
378+
margin-bottom: 1.5rem;
388379

389380
@media (max-width: 768px) {
390381
grid-template-columns: 1fr;
391-
gap: 1rem;
382+
gap: 0.75rem;
392383
}
393384
}
394385

@@ -407,9 +398,9 @@
407398
.config-inline-control {
408399
.form-input {
409400
flex: 1;
410-
height: 44px;
411-
padding: 0.625rem 2.5rem 0.625rem 1rem;
412-
font-size: 0.9375rem;
401+
height: 36px;
402+
padding: 0.5rem 2.5rem 0.5rem 0.875rem;
403+
font-size: 0.875rem;
413404
font-weight: 500;
414405
color: #1f2937;
415406
background-color: #ffffff;
@@ -418,7 +409,7 @@
418409
background-repeat: no-repeat;
419410
background-size: 1.25rem 1.25rem;
420411
border: 2px solid #e5e7eb;
421-
border-radius: 8px;
412+
border-radius: 6px;
422413
cursor: pointer;
423414
transition: all 0.2s ease;
424415
appearance: none;

web-app/admin/src/app/admin/admin-event/admin-event-form/form-details/form-details.component.spec.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,19 @@ describe('FormDetailsComponent', () => {
214214
component.saveForm();
215215

216216
expect(component.saving).toBe(false);
217-
expect(mockEventsService.updateForm).toHaveBeenCalledWith('1', '1', component.form);
218-
expect(component.form).toEqual(savedForm);
217+
expect(mockEventsService.updateForm).toHaveBeenCalled();
218+
const [eventId, formId, payload] = mockEventsService.updateForm.calls.mostRecent().args;
219+
expect(eventId).toBe('1');
220+
expect(formId).toBe('1');
221+
expect(payload).toEqual(jasmine.objectContaining({
222+
name: 'Test Form',
223+
color: '#ff0000'
224+
}));
225+
expect(payload.fields).toEqual([]);
226+
expect(payload.userFields).toEqual([]);
227+
expect(component.form).toEqual(jasmine.objectContaining(savedForm));
228+
expect(component.form.fields).toEqual([]);
229+
expect(component.form.userFields).toEqual([]);
219230
expect(component.formDirty).toBe(false);
220231
expect(component.generalFormSubmitted).toBe(false);
221232
expect(mockSnackBar.open).toHaveBeenCalledWith('Form saved successfully', 'Close', { duration: 3000 });
@@ -268,7 +279,11 @@ describe('FormDetailsComponent', () => {
268279
component.archiveForm();
269280

270281
expect(component.form.archived).toBe(true);
271-
expect(mockEventsService.updateForm).toHaveBeenCalledWith('1', '1', component.form);
282+
expect(mockEventsService.updateForm).toHaveBeenCalledWith(
283+
'1',
284+
'1',
285+
jasmine.objectContaining({ archived: true })
286+
);
272287
expect(mockSnackBar.open).toHaveBeenCalledWith('Form archived successfully', 'Close', { duration: 3000 });
273288
});
274289

@@ -304,7 +319,11 @@ describe('FormDetailsComponent', () => {
304319
component.restoreForm();
305320

306321
expect(component.form.archived).toBe(false);
307-
expect(mockEventsService.updateForm).toHaveBeenCalledWith('1', '1', component.form);
322+
expect(mockEventsService.updateForm).toHaveBeenCalledWith(
323+
'1',
324+
'1',
325+
jasmine.objectContaining({ archived: false })
326+
);
308327
expect(mockSnackBar.open).toHaveBeenCalledWith('Form restored successfully', 'Close', { duration: 3000 });
309328
});
310329

0 commit comments

Comments
 (0)