@@ -40,6 +40,10 @@ export interface PodLogsProps {
40
40
containerGroups ?: any [ ] ;
41
41
onClickContainer ?: ( group : any , i : number , tab : string ) => void ;
42
42
fullscreen ?: boolean ;
43
+ viewPodNames ?: boolean ;
44
+ viewTimestamps ?: boolean ;
45
+ follow ?: boolean ;
46
+ showPreviousLogs ?: boolean ;
43
47
}
44
48
45
49
// ansi colors, see https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
@@ -86,11 +90,29 @@ export const PodsLogsViewer = (props: PodLogsProps) => {
86
90
const [ logs , setLogs ] = useState < LogEntry [ ] > ( [ ] ) ;
87
91
const logsContainerRef = useRef ( null ) ;
88
92
89
- useEffect ( ( ) => {
90
- if ( viewPodNames ) {
91
- setViewTimestamps ( false ) ;
93
+ const setWithQueryParams = < T extends ( val : any ) => void > ( key : string , cb : T ) => {
94
+ history . replaceState ( null , '' , `${ location . pathname } ?${ queryParams } ` ) ;
95
+
96
+ return ( val => {
97
+ cb ( val ) ;
98
+ queryParams . set ( key , val . toString ( ) ) ;
99
+ history . replaceState ( null , '' , `${ location . pathname } ?${ queryParams } ` ) ;
100
+ } ) as T ;
101
+ } ;
102
+
103
+ const setViewPodNamesWithQueryParams = setWithQueryParams ( 'viewPodNames' , setViewPodNames ) ;
104
+ const setViewTimestampsWithQueryParams = setWithQueryParams ( 'viewTimestamps' , setViewTimestamps ) ;
105
+ const setFollowWithQueryParams = setWithQueryParams ( 'follow' , setFollow ) ;
106
+ const setPreviousLogsWithQueryParams = setWithQueryParams ( 'showPreviousLogs' , setPreviousLogs ) ;
107
+ const setTailWithQueryParams = setWithQueryParams ( 'tail' , setTail ) ;
108
+ const setFilterWithQueryParams = setWithQueryParams ( 'filterText' , setFilter ) ;
109
+
110
+ const onToggleViewPodNames = ( val : boolean ) => {
111
+ setViewPodNamesWithQueryParams ( val ) ;
112
+ if ( val ) {
113
+ setViewTimestampsWithQueryParams ( false ) ;
92
114
}
93
- } , [ viewPodNames ] ) ;
115
+ } ;
94
116
95
117
useEffect ( ( ) => {
96
118
// https://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
@@ -165,32 +187,32 @@ export const PodsLogsViewer = (props: PodLogsProps) => {
165
187
< React . Fragment >
166
188
< div className = 'pod-logs-viewer__settings' >
167
189
< span >
168
- < FollowToggleButton follow = { follow } setFollow = { setFollow } />
190
+ < FollowToggleButton follow = { follow } setFollow = { setFollowWithQueryParams } />
169
191
{ follow && < AutoScrollButton scrollToBottom = { scrollToBottom } setScrollToBottom = { setScrollToBottom } /> }
170
- < ShowPreviousLogsToggleButton setPreviousLogs = { setPreviousLogs } showPreviousLogs = { previous } />
192
+ < ShowPreviousLogsToggleButton setPreviousLogs = { setPreviousLogsWithQueryParams } showPreviousLogs = { previous } />
171
193
< Spacer />
172
194
< ContainerSelector containerGroups = { containerGroups } containerName = { containerName } onClickContainer = { onClickContainer } />
173
195
< Spacer />
174
196
{ ! follow && (
175
197
< >
176
198
< SinceSecondsSelector sinceSeconds = { sinceSeconds } setSinceSeconds = { n => setSinceSeconds ( n ) } />
177
- < TailSelector tail = { tail } setTail = { setTail } />
199
+ < TailSelector tail = { tail } setTail = { setTailWithQueryParams } />
178
200
</ >
179
201
) }
180
- < LogMessageFilter filterText = { filter } setFilterText = { setFilter } />
202
+ < LogMessageFilter filterText = { filter } setFilterText = { setFilterWithQueryParams } />
181
203
</ span >
182
204
< Spacer />
183
205
< span >
184
206
< WrapLinesButton prefs = { prefs } />
185
- < PodNamesToggleButton viewPodNames = { viewPodNames } setViewPodNames = { setViewPodNames } />
186
- < TimestampsToggleButton setViewTimestamps = { setViewTimestamps } viewTimestamps = { viewTimestamps } timestamp = { timestamp } />
207
+ < PodNamesToggleButton viewPodNames = { viewPodNames } setViewPodNames = { onToggleViewPodNames } />
208
+ < TimestampsToggleButton setViewTimestamps = { setViewTimestampsWithQueryParams } viewTimestamps = { viewTimestamps } timestamp = { timestamp } />
187
209
< DarkModeToggleButton prefs = { prefs } />
188
210
</ span >
189
211
< Spacer />
190
212
< span >
191
213
< CopyLogsButton logs = { logs } />
192
214
< DownloadLogsButton { ...props } />
193
- < FullscreenButton { ...props } />
215
+ < FullscreenButton { ...props } viewPodNames = { viewPodNames } viewTimestamps = { viewTimestamps } follow = { follow } showPreviousLogs = { previous } />
194
216
</ span >
195
217
</ div >
196
218
< div className = { classNames ( 'pod-logs-viewer' , { 'pod-logs-viewer--inverted' : prefs . appDetails . darkMode } ) } onWheel = { handleScroll } >
0 commit comments