mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
feat(web): support list editing for channel array fields (#2595)
Add reusable channel array list controls and parsing utilities for channel forms. Normalize channel string-array payloads in the backend, including pasted values, numeric IDs, hidden characters, duplicates, and empty clears. Also allow FlexibleStringSlice to unmarshal null values and cover the new behavior with backend and config tests.
This commit is contained in:
@@ -22,6 +22,11 @@ import (
|
||||
type FlexibleStringSlice []string
|
||||
|
||||
func (f *FlexibleStringSlice) UnmarshalJSON(data []byte) error {
|
||||
if string(data) == "null" {
|
||||
*f = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// Accept a single JSON string for convenience, e.g.:
|
||||
// "text": "Thinking..."
|
||||
var singleString string
|
||||
|
||||
@@ -1258,6 +1258,11 @@ func TestFlexibleStringSlice_UnmarshalJSON(t *testing.T) {
|
||||
input string
|
||||
expected []string
|
||||
}{
|
||||
{
|
||||
name: "null",
|
||||
input: `null`,
|
||||
expected: nil,
|
||||
},
|
||||
{
|
||||
name: "single string",
|
||||
input: `"Thinking..."`,
|
||||
@@ -1286,6 +1291,12 @@ func TestFlexibleStringSlice_UnmarshalJSON(t *testing.T) {
|
||||
if err := json.Unmarshal([]byte(tt.input), &f); err != nil {
|
||||
t.Fatalf("json.Unmarshal(%s) error = %v", tt.input, err)
|
||||
}
|
||||
if tt.expected == nil {
|
||||
if f != nil {
|
||||
t.Fatalf("json.Unmarshal(%s) = %#v, want nil slice", tt.input, f)
|
||||
}
|
||||
return
|
||||
}
|
||||
if len(f) != len(tt.expected) {
|
||||
t.Fatalf("json.Unmarshal(%s) len = %d, want %d", tt.input, len(f), len(tt.expected))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user