fix(front-end): quantity changes and normalization
Some checks failed
Build, Test, Deploy and Analysis / qodana (push) Failing after 12s
Build, Test, Deploy and Analysis / test-backend (push) Successful in 37s
Build, Test, Deploy and Analysis / build-and-push (push) Successful in 25s
Build, Test, Deploy and Analysis / deploy (push) Successful in 10s
Some checks failed
Build, Test, Deploy and Analysis / qodana (push) Failing after 12s
Build, Test, Deploy and Analysis / test-backend (push) Successful in 37s
Build, Test, Deploy and Analysis / build-and-push (push) Successful in 25s
Build, Test, Deploy and Analysis / deploy (push) Successful in 10s
This commit is contained in:
@@ -226,9 +226,10 @@ export class CalculatorPageComponent implements OnInit {
|
||||
this.step.set('quote');
|
||||
}
|
||||
|
||||
onItemChange(event: {id?: string, fileName: string, quantity: number}) {
|
||||
onItemChange(event: {id?: string, index: number, fileName: string, quantity: number}) {
|
||||
// 1. Update local form for consistency (UI feedback)
|
||||
if (this.uploadForm) {
|
||||
this.uploadForm.updateItemQuantityByIndex(event.index, event.quantity);
|
||||
this.uploadForm.updateItemQuantityByName(event.fileName, event.quantity);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ export class QuoteResultComponent implements OnDestroy {
|
||||
result = input.required<QuoteResult>();
|
||||
consult = output<void>();
|
||||
proceed = output<void>();
|
||||
itemChange = output<{id?: string, fileName: string, quantity: number}>();
|
||||
itemChange = output<{id?: string, index: number, fileName: string, quantity: number}>();
|
||||
|
||||
// Local mutable state for items to handle quantity changes
|
||||
items = signal<QuoteItem[]>([]);
|
||||
@@ -83,6 +83,7 @@ export class QuoteResultComponent implements OnDestroy {
|
||||
|
||||
this.itemChange.emit({
|
||||
id: item.id,
|
||||
index,
|
||||
fileName: item.fileName,
|
||||
quantity: normalizedQty
|
||||
});
|
||||
|
||||
@@ -199,11 +199,28 @@ export class UploadFormComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
updateItemQuantityByName(fileName: string, quantity: number) {
|
||||
updateItemQuantityByIndex(index: number, quantity: number) {
|
||||
if (!Number.isInteger(index) || index < 0) return;
|
||||
const normalizedQty = this.normalizeQuantity(quantity);
|
||||
|
||||
this.items.update(current => {
|
||||
if (index >= current.length) return current;
|
||||
const updated = [...current];
|
||||
updated[index] = { ...updated[index], quantity: normalizedQty };
|
||||
return updated;
|
||||
});
|
||||
}
|
||||
|
||||
updateItemQuantityByName(fileName: string, quantity: number) {
|
||||
const targetName = this.normalizeFileName(fileName);
|
||||
const normalizedQty = this.normalizeQuantity(quantity);
|
||||
|
||||
this.items.update(current => {
|
||||
let matched = false;
|
||||
return current.map(item => {
|
||||
if (item.file.name === fileName) {
|
||||
return { ...item, quantity };
|
||||
if (!matched && this.normalizeFileName(item.file.name) === targetName) {
|
||||
matched = true;
|
||||
return { ...item, quantity: normalizedQty };
|
||||
}
|
||||
return item;
|
||||
});
|
||||
@@ -239,14 +256,9 @@ export class UploadFormComponent implements OnInit {
|
||||
|
||||
updateItemQuantity(index: number, event: Event) {
|
||||
const input = event.target as HTMLInputElement;
|
||||
let val = parseInt(input.value, 10);
|
||||
if (isNaN(val) || val < 1) val = 1;
|
||||
|
||||
this.items.update(current => {
|
||||
const updated = [...current];
|
||||
updated[index] = { ...updated[index], quantity: val };
|
||||
return updated;
|
||||
});
|
||||
const parsed = parseInt(input.value, 10);
|
||||
const quantity = Number.isFinite(parsed) ? parsed : 1;
|
||||
this.updateItemQuantityByIndex(index, quantity);
|
||||
}
|
||||
|
||||
updateItemColor(index: number, newSelection: string | { colorName: string; filamentVariantId?: number }) {
|
||||
@@ -387,4 +399,19 @@ export class UploadFormComponent implements OnInit {
|
||||
this.form.get('itemsTouched')?.setValue(true);
|
||||
}
|
||||
}
|
||||
|
||||
private normalizeQuantity(quantity: number): number {
|
||||
if (!Number.isFinite(quantity) || quantity < 1) {
|
||||
return 1;
|
||||
}
|
||||
return Math.floor(quantity);
|
||||
}
|
||||
|
||||
private normalizeFileName(fileName: string): string {
|
||||
return (fileName || '')
|
||||
.split(/[\\/]/)
|
||||
.pop()
|
||||
?.trim()
|
||||
.toLowerCase() ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user