MCPcopy Create free account
hub / github.com/OverloadBlitz/cloudcent-cli / handleHistoryEvent

Method handleHistoryEvent

internal/tui/app.go:319–370  ·  view source on GitHub ↗
(event views.HistoryEvent, idx int)

Source from the content-addressed store, hash-verified

317}
318
319func (a App) handleHistoryEvent(event views.HistoryEvent, idx int) (tea.Model, tea.Cmd) {
320 switch event {
321 case views.HistoryEventQuit:
322 return a, tea.Quit
323 case views.HistoryEventNextView:
324 a.switchViewNext()
325 case views.HistoryEventPrevView:
326 a.switchViewPrev()
327 case views.HistoryEventClearAll:
328 if a.db != nil {
329 a.db.ClearAll()
330 a.historyView.History, _ = a.db.GetHistory(100)
331 a.historyView.SelectedResults = nil
332 }
333 case views.HistoryEventOpenInPricing:
334 if idx < len(a.historyView.History) {
335 h := a.historyView.History[idx]
336 a.pricingView.CommandBuilder.ProductTags = splitNonEmpty(h.ProductFamilies, ",")
337 a.pricingView.CommandBuilder.RegionTags = splitNonEmpty(h.Regions, ",")
338 a.pricingView.CommandBuilder.AttributeTags = splitNonEmpty(h.Attributes, ",")
339 a.pricingView.CommandBuilder.PriceTags = splitNonEmpty(h.Prices, ",")
340 a.viewMode = ViewModePricing
341 a.pricingView.ActiveSection = views.PricingSectionCommand
342
343 // Try cache first
344 if a.db != nil {
345 if cached, _ := a.db.GetCache(h.CacheKey); cached != nil {
346 a.pricingView.Items = views.ConvertResponse(cached)
347 a.pricingView.FilteredItems = append([]views.PricingDisplayItem{}, a.pricingView.Items...)
348 a.pricingView.Selected = 0
349 a.pricingView.Loading = false
350 if len(a.pricingView.FilteredItems) > 0 {
351 a.pricingView.ActiveSection = views.PricingSectionResults
352 }
353 return a, nil
354 }
355 }
356 return a.submitPricingQuery()
357 }
358 case views.HistoryEventNone:
359 // Update preview for selected history item
360 if a.db != nil && idx < len(a.historyView.History) {
361 h := a.historyView.History[a.historyView.Selected]
362 if cached, _ := a.db.GetCache(h.CacheKey); cached != nil {
363 a.historyView.SelectedResults = views.ConvertResponse(cached)
364 } else {
365 a.historyView.SelectedResults = nil
366 }
367 }
368 }
369 return a, nil
370}
371
372func (a App) handleSettingsEvent(event views.SettingsEvent) (tea.Model, tea.Cmd) {
373 switch event {

Callers 1

handleKeyMethod · 0.95

Calls 8

switchViewNextMethod · 0.95
switchViewPrevMethod · 0.95
submitPricingQueryMethod · 0.95
ConvertResponseFunction · 0.92
splitNonEmptyFunction · 0.85
ClearAllMethod · 0.80
GetHistoryMethod · 0.80
GetCacheMethod · 0.80

Tested by

no test coverage detected