Skip to content

Commit

Permalink
fix(LogsPanelScene): respect collapsed status of logs volume
Browse files Browse the repository at this point in the history
  • Loading branch information
matyax committed Feb 18, 2025
1 parent b7f0e45 commit c03150d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
23 changes: 16 additions & 7 deletions src/Components/ServiceScene/LogsPanelScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
VizPanel,
} from '@grafana/scenes';
import { DataFrame, getValueFormat, LoadingState, LogRowModel, PanelData } from '@grafana/data';
import { getLogOption, setDisplayedFields } from '../../services/store';
import { getLogOption, getLogsVolumeOption, setDisplayedFields } from '../../services/store';
import React, { MouseEvent } from 'react';
import { LogsListScene } from './LogsListScene';
import { LoadingPlaceholder, useStyles2 } from '@grafana/ui';
Expand Down Expand Up @@ -43,6 +43,7 @@ import { clearVariables } from 'services/variableHelpers';
interface LogsPanelSceneState extends SceneObjectState {
body?: VizPanel<Options>;
error?: string;
logsVolumeCollapsedByError?: boolean;
sortOrder?: LogsSortOrder;
wrapLogMessage?: boolean;
}
Expand Down Expand Up @@ -150,16 +151,24 @@ export class LogsPanelScene extends SceneObjectBase<LogsPanelSceneState> {
}

handleLogsError(data: PanelData) {
const logsVolumeCollapsedByError = this.state.logsVolumeCollapsedByError ?? !getLogsVolumeOption('collapsed');

const error = data.errors?.length ? data.errors[0].message : data.error?.message;
this.setState({ error });
const logsVolume = sceneGraph.findByKeyAndType(this, logsVolumePanelKey, LogsVolumePanel);
logsVolume.state.panel?.setState({ collapsed: true });
this.setState({ error, logsVolumeCollapsedByError });

if (logsVolumeCollapsedByError) {
const logsVolume = sceneGraph.findByKeyAndType(this, logsVolumePanelKey, LogsVolumePanel);
logsVolume.state.panel?.setState({ collapsed: true });
}
}

clearLogsError() {
this.setState({ error: undefined });
const logsVolume = sceneGraph.findByKeyAndType(this, logsVolumePanelKey, LogsVolumePanel);
logsVolume.state.panel?.setState({ collapsed: false });
if (this.state.logsVolumeCollapsedByError) {
const logsVolume = sceneGraph.findByKeyAndType(this, logsVolumePanelKey, LogsVolumePanel);
logsVolume.state.panel?.setState({ collapsed: false });
}

this.setState({ error: undefined, logsVolumeCollapsedByError: undefined });
}

onClickShowField = (field: string) => {
Expand Down
2 changes: 1 addition & 1 deletion src/Components/ServiceScene/LogsVolumePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class LogsVolumePanel extends SceneObjectBase<LogsVolumePanelState> {
.setUnit('short')
.setMenu(new PanelMenu({ investigationOptions: { labelName: 'level' } }))
.setCollapsible(true)
.setCollapsed(Boolean(getLogsVolumeOption('collapsed')))
.setCollapsed(getLogsVolumeOption('collapsed'))
.setHeaderActions(new LogsVolumeActions({}))
// 11.5
// .setShowMenuAlways(true)
Expand Down
2 changes: 1 addition & 1 deletion src/services/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export function setLogsVolumeOption(option: 'collapsed', value: string | undefin
}

export function getLogsVolumeOption(option: 'collapsed') {
return localStorage.getItem(`${LOGS_VOLUME_LOCALSTORAGE_KEY}.${option}`);
return Boolean(localStorage.getItem(`${LOGS_VOLUME_LOCALSTORAGE_KEY}.${option}`));
}

// Log visualization options
Expand Down

0 comments on commit c03150d

Please sign in to comment.