Skip to content

Commit 9cf5d83

Browse files
committed
binary & fk widgets: don't emit on mount
BinaryEditComponent.ngOnInit re-emitted the stored value after a parseBinaryValue → bytesToHex → toBufferJson round-trip. When the server returned the column as a string (or any non-Buffer-JSON shape) the emit silently differed from what was in tableRowValues, tainting the row-edit touched-fields set and causing the column to be rewritten on every save. ForeignKeyEditComponent.ngOnInit had the same pattern with currentFieldValue. Widgets now emit only on actual user input.
1 parent 7e39bb6 commit 9cf5d83

3 files changed

Lines changed: 6 additions & 14 deletions

File tree

frontend/src/app/components/ui-components/record-edit-fields/binary/binary.component.spec.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,29 @@ describe('BinaryEditComponent', () => {
2121
expect(component).toBeTruthy();
2222
});
2323

24-
it('parses a server string as char-code-per-byte and emits Buffer-JSON on init', () => {
24+
it('parses a server string as char-code-per-byte on init and does not emit', () => {
2525
vi.spyOn(component.onFieldChange, 'emit');
2626
fixture.componentRef.setInput('value', 'Hello');
2727
component.ngOnInit();
2828
// 'Hello' -> bytes 48 65 6c 6c 6f -> hex '48656c6c6f'
2929
expect(component.hexData).toBe('48656c6c6f');
30-
expect(component.onFieldChange.emit).toHaveBeenCalledWith({
31-
type: 'Buffer',
32-
data: [0x48, 0x65, 0x6c, 0x6c, 0x6f],
33-
});
30+
expect(component.onFieldChange.emit).not.toHaveBeenCalled();
3431
});
3532

36-
it('re-emits an incoming Buffer-JSON value as Buffer-JSON on init', () => {
33+
it('parses an incoming Buffer-JSON value into hex on init without emitting', () => {
3734
vi.spyOn(component.onFieldChange, 'emit');
3835
fixture.componentRef.setInput('value', { type: 'Buffer', data: [0x48, 0x65, 0x6c] });
3936
component.ngOnInit();
4037
expect(component.hexData).toBe('48656c');
41-
expect(component.onFieldChange.emit).toHaveBeenCalledWith({
42-
type: 'Buffer',
43-
data: [0x48, 0x65, 0x6c],
44-
});
38+
expect(component.onFieldChange.emit).not.toHaveBeenCalled();
4539
});
4640

47-
it('emits null and shows empty hex when incoming value is null', () => {
41+
it('shows empty hex when incoming value is null and does not emit on init', () => {
4842
vi.spyOn(component.onFieldChange, 'emit');
4943
fixture.componentRef.setInput('value', null);
5044
component.ngOnInit();
5145
expect(component.hexData).toBe('');
52-
expect(component.onFieldChange.emit).toHaveBeenCalledWith(null);
46+
expect(component.onFieldChange.emit).not.toHaveBeenCalled();
5347
});
5448

5549
it('emits Buffer-JSON when the user types valid hex', () => {

frontend/src/app/components/ui-components/record-edit-fields/binary/binary.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export class BinaryEditComponent extends BaseEditFieldComponent implements OnIni
2424
ngOnInit(): void {
2525
super.ngOnInit();
2626
this.hexData = bytesToHex(parseBinaryValue(this.value()));
27-
this.emitCurrentValue();
2827
}
2928

3029
onHexChange(): void {

frontend/src/app/components/ui-components/record-edit-fields/foreign-key/foreign-key.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ export class ForeignKeyEditComponent extends BaseEditFieldComponent {
117117
[primaeyKey.column_name]: res.rows[0][primaeyKey.column_name],
118118
})),
119119
);
120-
this.onFieldChange.emit(this.currentFieldValue);
121120
}
122121
}
123122

0 commit comments

Comments
 (0)