MCPcopy
hub / github.com/wavetermdev/waveterm / genTableRenderFunc

Function genTableRenderFunc

tsunami/ui/table.go:208–459  ·  view source on GitHub ↗
(props TableProps[T])

Source from the content-addressed store, hash-verified

206}
207
208func genTableRenderFunc[T any](props TableProps[T]) any {
209 // State for sorting
210 sortColumnAtom := app.UseLocal(props.DefaultSort)
211 sortDirectionAtom := app.UseLocal("asc")
212
213 // State for pagination - initialize with prop values
214 initialPage := 0
215 initialPageSize := 25
216 if props.Pagination != nil {
217 initialPage = props.Pagination.CurrentPage
218 initialPageSize = props.Pagination.PageSize
219 }
220 currentPageAtom := app.UseLocal(initialPage)
221 pageSizeAtom := app.UseLocal(initialPageSize)
222
223 // State for selection - initialize with empty slice if nil
224 initialSelection := props.SelectedRows
225 if initialSelection == nil {
226 initialSelection = []int{}
227 }
228 selectedRowsAtom := app.UseLocal(initialSelection)
229
230
231 // Handle sorting
232 handleSort := func(column string) {
233 currentSort := sortColumnAtom.Get()
234 currentDir := sortDirectionAtom.Get()
235
236 if currentSort == column {
237 // Toggle direction
238 newDir := vdom.IfElse(currentDir == "asc", "desc", "asc").(string)
239 sortDirectionAtom.Set(newDir)
240 if props.OnSort != nil {
241 props.OnSort(column, newDir)
242 }
243 } else {
244 // New column
245 sortColumnAtom.Set(column)
246 sortDirectionAtom.Set("asc")
247 if props.OnSort != nil {
248 props.OnSort(column, "asc")
249 }
250 }
251 }
252
253 // Handle row selection
254 handleRowSelect := func(rowIdx int) {
255 if !props.Selectable {
256 return
257 }
258
259 selectedRowsAtom.SetFn(func(current []int) []int {
260 // Toggle selection
261 for i, idx := range current {
262 if idx == rowIdx {
263 // Remove
264 return append(current[:i], current[i+1:]...)
265 }

Callers

nothing calls this directly

Calls 15

UseLocalFunction · 0.92
IfElseFunction · 0.92
HFunction · 0.92
IfFunction · 0.92
ForEachFunction · 0.92
ClassesFunction · 0.92
findColumnByKeyFunction · 0.85
sortDataFunction · 0.85
paginateDataFunction · 0.85
defaultHeaderRendererFunction · 0.85
makeRowClassNameFunction · 0.85
getFieldValueFunction · 0.85

Tested by

no test coverage detected