Skip to content

Commit 40c6077

Browse files
authoredSep 20, 2024··
fix(ui): carry over state when using full screen mode button (#20022)
1 parent 9ac1670 commit 40c6077

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed
 

‎ui/src/app/applications/components/pod-logs-viewer/fullscreen-button.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ export const FullscreenButton = ({
1212
kind,
1313
name,
1414
namespace,
15-
podName
15+
podName,
16+
viewPodNames,
17+
viewTimestamps,
18+
follow,
19+
showPreviousLogs
1620
}: PodLogsProps & {fullscreen?: boolean}) => {
1721
const fullscreenURL =
18-
`/applications/${applicationNamespace}/${applicationName}/${namespace}/${containerName}/logs?` + `podName=${podName}&group=${group}&kind=${kind}&name=${name}`;
22+
`/applications/${applicationNamespace}/${applicationName}/${namespace}/${containerName}/logs?` +
23+
`podName=${podName}&group=${group}&kind=${kind}&name=${name}&viewPodNames=${viewPodNames}&viewTimestamps=${viewTimestamps}&follow=${follow}&showPreviousLogs=${showPreviousLogs}`;
1924
return (
2025
!fullscreen && (
2126
<Link to={fullscreenURL} target='_blank' rel='noopener noreferrer'>

‎ui/src/app/applications/components/pod-logs-viewer/pod-logs-viewer.tsx

+33-11
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ export interface PodLogsProps {
4040
containerGroups?: any[];
4141
onClickContainer?: (group: any, i: number, tab: string) => void;
4242
fullscreen?: boolean;
43+
viewPodNames?: boolean;
44+
viewTimestamps?: boolean;
45+
follow?: boolean;
46+
showPreviousLogs?: boolean;
4347
}
4448

4549
// ansi colors, see https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
@@ -86,11 +90,29 @@ export const PodsLogsViewer = (props: PodLogsProps) => {
8690
const [logs, setLogs] = useState<LogEntry[]>([]);
8791
const logsContainerRef = useRef(null);
8892

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);
92114
}
93-
}, [viewPodNames]);
115+
};
94116

95117
useEffect(() => {
96118
// https://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
@@ -165,32 +187,32 @@ export const PodsLogsViewer = (props: PodLogsProps) => {
165187
<React.Fragment>
166188
<div className='pod-logs-viewer__settings'>
167189
<span>
168-
<FollowToggleButton follow={follow} setFollow={setFollow} />
190+
<FollowToggleButton follow={follow} setFollow={setFollowWithQueryParams} />
169191
{follow && <AutoScrollButton scrollToBottom={scrollToBottom} setScrollToBottom={setScrollToBottom} />}
170-
<ShowPreviousLogsToggleButton setPreviousLogs={setPreviousLogs} showPreviousLogs={previous} />
192+
<ShowPreviousLogsToggleButton setPreviousLogs={setPreviousLogsWithQueryParams} showPreviousLogs={previous} />
171193
<Spacer />
172194
<ContainerSelector containerGroups={containerGroups} containerName={containerName} onClickContainer={onClickContainer} />
173195
<Spacer />
174196
{!follow && (
175197
<>
176198
<SinceSecondsSelector sinceSeconds={sinceSeconds} setSinceSeconds={n => setSinceSeconds(n)} />
177-
<TailSelector tail={tail} setTail={setTail} />
199+
<TailSelector tail={tail} setTail={setTailWithQueryParams} />
178200
</>
179201
)}
180-
<LogMessageFilter filterText={filter} setFilterText={setFilter} />
202+
<LogMessageFilter filterText={filter} setFilterText={setFilterWithQueryParams} />
181203
</span>
182204
<Spacer />
183205
<span>
184206
<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} />
187209
<DarkModeToggleButton prefs={prefs} />
188210
</span>
189211
<Spacer />
190212
<span>
191213
<CopyLogsButton logs={logs} />
192214
<DownloadLogsButton {...props} />
193-
<FullscreenButton {...props} />
215+
<FullscreenButton {...props} viewPodNames={viewPodNames} viewTimestamps={viewTimestamps} follow={follow} showPreviousLogs={previous} />
194216
</span>
195217
</div>
196218
<div className={classNames('pod-logs-viewer', {'pod-logs-viewer--inverted': prefs.appDetails.darkMode})} onWheel={handleScroll}>

0 commit comments

Comments
 (0)
Please sign in to comment.