Skip to content

Commit 650d8fd

Browse files
ottermataJenkins
authored andcommitted
graphing/designer: unset a constant whose value was cleared
Vue casts a number field through looseToNumber, which hands back the raw string when parseFloat cannot read it, so an emptied input stored '' in a field typed number | null and sent it to a backend that rejects it. JIRA-Ref: CMK-37206 Change-Id: Ia0b8ff7dd7200c995f87099f20df04ba12d4ed83
1 parent 1acd9c5 commit 650d8fd

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

packages/cmk-frontend-vue/src/graphing/designer/components/forms/ConstantLineForm.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ const { _t } = usei18n()
2121
2222
const valueInputId = useId()
2323
24-
function onValueChange(value: number | undefined): void {
25-
store.replace({ ...item, value: value ?? null })
24+
function onValueChange(value: unknown): void {
25+
const parsed = parseFloat(String(value))
26+
store.replace({ ...item, value: Number.isFinite(parsed) ? parsed : null })
2627
}
2728
</script>
2829

packages/cmk-frontend-vue/tests/graphing/designer/components/ConstantLineForm.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,13 @@ test('entering a value completes a constant', async () => {
2020

2121
expect(store.items.value[0]).toMatchObject({ type: 'constant', value: 42 })
2222
})
23+
24+
test('clearing the value leaves the constant unset rather than blank', async () => {
25+
const draft = { ...newConstantDraft('A', '#28a2f3'), value: 42 }
26+
const store = useGraphItems(PALETTE, [draft])
27+
render(ConstantLineForm, { props: { item: draft, store } })
28+
29+
await fireEvent.update(screen.getByRole('spinbutton', { name: 'Constant at' }), '')
30+
31+
expect(store.items.value[0]).toMatchObject({ type: 'constant', value: null })
32+
})

0 commit comments

Comments
 (0)