Skip to content

Commit da8c718

Browse files
committed
fix tsunamiconfig, expose data in tabletest
1 parent 0e5f6b1 commit da8c718

5 files changed

Lines changed: 149 additions & 51 deletions

File tree

tsunami/demo/tabletest/app.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ type Person struct {
1919
// Create the table component for Person data
2020
var PersonTable = ui.MakeTableComponent[Person]("PersonTable")
2121

22-
// Sample data
23-
var sampleData = []Person{
22+
// Sample data exposed as DataAtom for external system access
23+
var sampleData = app.DataAtom("sampleData", []Person{
2424
{Name: "Alice Johnson", Age: 28, Email: "alice@example.com", City: "New York"},
2525
{Name: "Bob Smith", Age: 34, Email: "bob@example.com", City: "Los Angeles"},
2626
{Name: "Carol Davis", Age: 22, Email: "carol@example.com", City: "Chicago"},
@@ -31,7 +31,7 @@ var sampleData = []Person{
3131
{Name: "Henry Taylor", Age: 33, Email: "henry@example.com", City: "San Diego"},
3232
{Name: "Ivy Chen", Age: 26, Email: "ivy@example.com", City: "Dallas"},
3333
{Name: "Jack Anderson", Age: 31, Email: "jack@example.com", City: "San Jose"},
34-
}
34+
})
3535

3636
// The App component is the required entry point for every Tsunami application
3737
var App = app.DefineComponent("App", func(_ struct{}) any {
@@ -93,7 +93,7 @@ var App = app.DefineComponent("App", func(_ struct{}) any {
9393
"className": "bg-gray-800 p-4 rounded-lg",
9494
},
9595
PersonTable(ui.TableProps[Person]{
96-
Data: sampleData,
96+
Data: sampleData.Get(),
9797
Columns: columns,
9898
OnRowClick: handleRowClick,
9999
OnSort: handleSort,

tsunami/demo/tabletest/static/tw.css

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
--color-blue-600: oklch(54.6% 0.245 262.881);
1111
--color-blue-700: oklch(48.8% 0.243 264.376);
1212
--color-blue-900: oklch(37.9% 0.146 265.522);
13+
--color-gray-200: oklch(92.8% 0.006 264.531);
1314
--color-gray-300: oklch(87.2% 0.01 258.338);
1415
--color-gray-400: oklch(70.7% 0.022 261.325);
1516
--color-gray-500: oklch(55.1% 0.027 264.364);
@@ -404,9 +405,6 @@
404405
.transform {
405406
transform: var(--tw-rotate-x,) var(--tw-rotate-y,) var(--tw-rotate-z,) var(--tw-skew-x,) var(--tw-skew-y,);
406407
}
407-
.cursor-not-allowed {
408-
cursor: not-allowed;
409-
}
410408
.cursor-pointer {
411409
cursor: pointer;
412410
}
@@ -735,6 +733,9 @@
735733
.text-blue-400 {
736734
color: var(--color-blue-400);
737735
}
736+
.text-gray-200 {
737+
color: var(--color-gray-200);
738+
}
738739
.text-gray-300 {
739740
color: var(--color-gray-300);
740741
}

tsunami/demo/tsunamiconfig/app.go

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"context"
54
"encoding/json"
65
"fmt"
76
"io"
@@ -137,7 +136,7 @@ func postConfig(baseURL, jsonContent string) error {
137136
}
138137

139138
var URLInput = app.DefineComponent("URLInput",
140-
func(ctx context.Context, props URLInputProps) any {
139+
func(props URLInputProps) any {
141140
keyHandler := &vdom.VDomFunc{
142141
Type: "func",
143142
Fn: func(event vdom.VDomEvent) {
@@ -179,7 +178,7 @@ var URLInput = app.DefineComponent("URLInput",
179178
)
180179

181180
var JSONEditor = app.DefineComponent("JSONEditor",
182-
func(ctx context.Context, props JSONEditorProps) any {
181+
func(props JSONEditorProps) any {
183182
if props.Value == "" && props.Placeholder == "" {
184183
return vdom.H("div", map[string]any{
185184
"className": "text-slate-400 text-center py-8",
@@ -216,7 +215,7 @@ var JSONEditor = app.DefineComponent("JSONEditor",
216215
)
217216

218217
var ErrorDisplay = app.DefineComponent("ErrorDisplay",
219-
func(ctx context.Context, props ErrorDisplayProps) any {
218+
func(props ErrorDisplayProps) any {
220219
if props.Message == "" {
221220
return nil
222221
}
@@ -235,7 +234,7 @@ var ErrorDisplay = app.DefineComponent("ErrorDisplay",
235234
)
236235

237236
var SuccessDisplay = app.DefineComponent("SuccessDisplay",
238-
func(ctx context.Context, props SuccessDisplayProps) any {
237+
func(props SuccessDisplayProps) any {
239238
if props.Message == "" {
240239
return nil
241240
}
@@ -254,75 +253,75 @@ var SuccessDisplay = app.DefineComponent("SuccessDisplay",
254253
)
255254

256255
var App = app.DefineComponent("App",
257-
func(ctx context.Context, _ any) any {
256+
func(_ struct{}) any {
258257
app.UseSetAppTitle("Tsunami Config Manager")
259258

260259
// Get atom value once at the top
261260
urlInput := serverURLAtom.Get()
262-
jsonContent, setJSONContent, _ := app.UseState("")
263-
errorMessage, setErrorMessage, _ := app.UseState("")
264-
successMessage, setSuccessMessage, _ := app.UseState("")
265-
isLoading, setIsLoading, _ := app.UseState(false)
266-
lastFetch, setLastFetch, _ := app.UseState("")
267-
currentBaseURL, setCurrentBaseURL, _ := app.UseState("")
261+
jsonContent := app.UseLocal("")
262+
errorMessage := app.UseLocal("")
263+
successMessage := app.UseLocal("")
264+
isLoading := app.UseLocal(false)
265+
lastFetch := app.UseLocal("")
266+
currentBaseURL := app.UseLocal("")
268267

269268
clearMessages := func() {
270-
setErrorMessage("")
271-
setSuccessMessage("")
269+
errorMessage.Set("")
270+
successMessage.Set("")
272271
}
273272

274273
fetchConfigData := func() {
275274
clearMessages()
276275

277-
baseURL, err := parseURL(urlInput)
276+
baseURL, err := parseURL(serverURLAtom.Get())
278277
if err != nil {
279-
setErrorMessage(err.Error())
278+
errorMessage.Set(err.Error())
280279
return
281280
}
282281

283-
setIsLoading(true)
284-
setCurrentBaseURL(baseURL)
282+
isLoading.Set(true)
283+
currentBaseURL.Set(baseURL)
285284

286285
go func() {
287286
defer func() {
288-
setIsLoading(false)
287+
isLoading.Set(false)
289288
app.SendAsyncInitiation()
290289
}()
291290

292291
content, err := fetchConfig(baseURL)
293292
if err != nil {
294-
setErrorMessage(err.Error())
293+
errorMessage.Set(err.Error())
295294
return
296295
}
297296

298-
setJSONContent(content)
299-
setLastFetch(time.Now().Format("2006-01-02 15:04:05"))
300-
setSuccessMessage(fmt.Sprintf("Successfully fetched config from %s", baseURL))
297+
jsonContent.Set(content)
298+
lastFetch.Set(time.Now().Format("2006-01-02 15:04:05"))
299+
successMessage.Set(fmt.Sprintf("Successfully fetched config from %s", baseURL))
301300
}()
302301
}
303302

304303
submitConfigData := func() {
305-
if currentBaseURL == "" {
306-
setErrorMessage("No base URL available. Please fetch config first.")
304+
if currentBaseURL.Get() == "" {
305+
errorMessage.Set("No base URL available. Please fetch config first.")
307306
return
308307
}
309308

310309
clearMessages()
311-
setIsLoading(true)
310+
isLoading.Set(true)
312311

313312
go func() {
314313
defer func() {
315-
setIsLoading(false)
314+
isLoading.Set(false)
316315
app.SendAsyncInitiation()
317316
}()
318317

319-
err := postConfig(currentBaseURL, jsonContent)
318+
err := postConfig(currentBaseURL.Get(), jsonContent.Get())
320319
if err != nil {
321-
setErrorMessage(fmt.Sprintf("Failed to submit config: %v", err))
320+
errorMessage.Set(fmt.Sprintf("Failed to submit config: %v", err))
322321
return
323322
}
324323

325-
setSuccessMessage(fmt.Sprintf("Successfully submitted config to %s", currentBaseURL))
324+
successMessage.Set(fmt.Sprintf("Successfully submitted config to %s", currentBaseURL.Get()))
326325
}()
327326
}
328327

@@ -344,28 +343,28 @@ var App = app.DefineComponent("App",
344343
Value: urlInput,
345344
OnChange: serverURLAtom.Set,
346345
OnSubmit: fetchConfigData,
347-
IsLoading: isLoading,
346+
IsLoading: isLoading.Get(),
348347
}),
349348

350349
ErrorDisplay(ErrorDisplayProps{
351-
Message: errorMessage,
350+
Message: errorMessage.Get(),
352351
}),
353352

354353
SuccessDisplay(SuccessDisplayProps{
355-
Message: successMessage,
354+
Message: successMessage.Get(),
356355
}),
357356

358-
vdom.If(lastFetch != "",
357+
vdom.If(lastFetch.Get() != "",
359358
vdom.H("div", map[string]any{
360359
"className": "text-sm text-slate-400 mb-4",
361-
}, fmt.Sprintf("Last fetched: %s from %s", lastFetch, currentBaseURL)),
360+
}, fmt.Sprintf("Last fetched: %s from %s", lastFetch.Get(), currentBaseURL.Get())),
362361
),
363362

364363
JSONEditor(JSONEditorProps{
365-
Value: jsonContent,
366-
OnChange: setJSONContent,
364+
Value: jsonContent.Get(),
365+
OnChange: jsonContent.Set,
367366
OnSubmit: submitConfigData,
368-
IsLoading: isLoading,
367+
IsLoading: isLoading.Get(),
369368
Placeholder: "JSON configuration will appear here after fetching...",
370369
}),
371370
)

0 commit comments

Comments
 (0)