@@ -56,55 +56,76 @@ func (s StateFilteredModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
5656
5757 s .Application .Update (msg )
5858
59- switch typedMsg := msg .(type ) {
60- case * StateFilteredModel :
61- entries , err := s .Application .Entries .Filter (s .filterText )
62- if err != nil {
63- return s , events .ShowError (err )
64- }
65- s .logEntries = entries
66- s .table = newLogsTableModel (s .Application , entries )
67- msg = events .LogEntriesUpdateMsg (entries )
68- case events.LogEntriesUpdateMsg :
69- entries , err := s .Application .Entries .Filter (s .filterText )
70- if err != nil {
71- return s , events .ShowError (err )
72- }
73- s .logEntries = entries
74- msg = events .LogEntriesUpdateMsg (entries )
59+ if _ , ok := msg .(* StateFilteredModel ); ok {
60+ s , msg = s .handleStateFilteredModel ()
61+ }
62+
63+ if _ , ok := msg .(* events.LogEntriesUpdateMsg ); ok {
64+ s , msg = s .handleLogEntriesUpdateMsg ()
65+ }
7566
67+ switch typedMsg := msg .(type ) {
7668 case events.ErrorOccuredMsg :
7769 return s .handleErrorOccuredMsg (typedMsg )
7870 case events.OpenJSONRowRequestedMsg :
7971 return s .handleOpenJSONRowRequestedMsg (typedMsg , s )
8072 case tea.KeyMsg :
81- switch {
82- case key .Matches (typedMsg , s .keys .Back ):
83- return s .previousState .refresh ()
84- case key .Matches (typedMsg , s .keys .Filter ):
85- return s .handleFilterKeyClickedMsg ()
86- case key .Matches (typedMsg , s .keys .ToggleViewArrow ), key .Matches (typedMsg , s .keys .Open ):
87- return s .handleRequestOpenJSON ()
88- }
89- if cmd := s .handleKeyMsg (typedMsg ); cmd != nil {
90- return s , cmd
73+ if mdl , cmd := s .handleKeyMsg (typedMsg ); mdl != nil {
74+ return mdl , cmd
9175 }
9276 default :
9377 s .table , cmdBatch = batched (s .table .Update (typedMsg ))(cmdBatch )
9478 }
9579
9680 s .table , cmdBatch = batched (s .table .Update (msg ))(cmdBatch )
81+
9782 return s , tea .Batch (cmdBatch ... )
9883}
9984
85+ func (s StateFilteredModel ) handleKeyMsg (msg tea.KeyMsg ) (tea.Model , tea.Cmd ) {
86+ switch {
87+ case key .Matches (msg , s .keys .Back ):
88+ return s .previousState .refresh ()
89+ case key .Matches (msg , s .keys .Filter ):
90+ return s .handleFilterKeyClickedMsg ()
91+ case key .Matches (msg , s .keys .ToggleViewArrow ), key .Matches (msg , s .keys .Open ):
92+ return s .handleRequestOpenJSON ()
93+ default :
94+ return nil , nil
95+ }
96+ }
97+
98+ func (s StateFilteredModel ) handleLogEntriesUpdateMsg () (StateFilteredModel , tea.Msg ) {
99+ entries , err := s .Application .Entries .Filter (s .filterText )
100+ if err != nil {
101+ return s , events .ShowError (err )()
102+ }
103+
104+ s .logEntries = entries
105+
106+ return s , events .LogEntriesUpdateMsg (entries )
107+ }
108+
109+ func (s StateFilteredModel ) handleStateFilteredModel () (StateFilteredModel , tea.Msg ) {
110+ entries , err := s .Application .Entries .Filter (s .filterText )
111+ if err != nil {
112+ return s , events .ShowError (err )()
113+ }
114+
115+ s .logEntries = entries
116+ s .table = newLogsTableModel (s .Application , entries )
117+
118+ return s , events .LogEntriesUpdateMsg (entries )
119+ }
120+
100121func (s StateFilteredModel ) handleFilterKeyClickedMsg () (tea.Model , tea.Cmd ) {
101122 state := newStateFiltering (s .previousState )
102123 return initializeModel (state )
103124}
104125
105126func (s StateFilteredModel ) handleRequestOpenJSON () (tea.Model , tea.Cmd ) {
106127 if s .logEntries .Len () == 0 {
107- return s , events .BackKeyClicked
128+ return s , events .EscKeyClicked
108129 }
109130
110131 return s , events .OpenJSONRowRequested (s .logEntries , s .table .Cursor ())
@@ -114,9 +135,9 @@ func (s StateFilteredModel) getApplication() *Application {
114135 return s .Application
115136}
116137
117- func (s StateFilteredModel ) refresh () (stateModel , tea.Cmd ) {
118- var cmd tea.Cmd
138+ func (s StateFilteredModel ) refresh () (_ stateModel , cmd tea.Cmd ) {
119139 s .table , cmd = s .table .Update (s .Application .LastWindowSize )
140+
120141 return s , cmd
121142}
122143
0 commit comments