This is an automated email from the ASF dual-hosted git repository.
lizhimins pushed a commit to branch rocketmq-studio
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/rocketmq-studio by this push:
new ae47e2192 fix(metrics): keep the current query when a failed load
recovers (#5797)
ae47e2192 is described below
commit ae47e2192bd6b9aa384598bfba8990588a08040e
Author: coder999o <[email protected]>
AuthorDate: Sat Oct 10 12:04:45 2026 +0800
fix(metrics): keep the current query when a failed load recovers (#5797)
A failed metrics load cleared the current query on recovery, so the
explorer came back empty instead of retrying what the user had asked for.
Three-line move; the defect reproduces every time.
1 suite, 36 tests green.
Note for the next change to `MetricsExplorer.tsx`: #5728 touches the same
file for an unrelated defect and will need a rebase.
---
web/src/components/MetricsExplorer.tsx | 7 ++---
.../components/__tests__/MetricsExplorer.test.tsx | 30 ++++++++++++++++++++++
2 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/web/src/components/MetricsExplorer.tsx
b/web/src/components/MetricsExplorer.tsx
index a40cc41f8..6c3d90b32 100644
--- a/web/src/components/MetricsExplorer.tsx
+++ b/web/src/components/MetricsExplorer.tsx
@@ -1146,10 +1146,9 @@ const MetricsExplorer = ({ instanceId }:
MetricsExplorerProps) => {
customPromql,
storedProfileId: localStorage.getItem(PROFILE_STORAGE_KEY),
};
- setRangeId(nextRange.value);
- setHistoryOpen(false);
-
if (entry.profileId === CUSTOM_HISTORY_PROFILE_ID) {
+ setRangeId(nextRange.value);
+ setHistoryOpen(false);
setCustomPromql(entry.promql);
if (nextDataSource && getDataSourceAuthMode(nextDataSource.auth) !==
'none') {
restoreProtectedDataSource(
@@ -1171,6 +1170,8 @@ const MetricsExplorer = ({ instanceId }:
MetricsExplorerProps) => {
return;
}
+ setRangeId(nextRange.value);
+ setHistoryOpen(false);
localStorage.setItem(PROFILE_STORAGE_KEY, nextProfile.id);
setProfileId(nextProfile.id);
if (nextDataSource && getDataSourceAuthMode(nextDataSource.auth) !==
'none') {
diff --git a/web/src/components/__tests__/MetricsExplorer.test.tsx
b/web/src/components/__tests__/MetricsExplorer.test.tsx
index 70660aeb3..3ea7711e1 100644
--- a/web/src/components/__tests__/MetricsExplorer.test.tsx
+++ b/web/src/components/__tests__/MetricsExplorer.test.tsx
@@ -1135,6 +1135,36 @@ describe('MetricsExplorer', () => {
expect(screen.getByText('Consumer Lag Messages')).toBeInTheDocument();
});
+ it('keeps the active query unchanged when history references a removed
profile', async () => {
+ const user = userEvent.setup();
+ localStorage.setItem(
+ METRICS_QUERY_HISTORY_STORAGE_KEY,
+ JSON.stringify([
+ createHistoryEntry({
+ profileId: 'removed-profile',
+ profileName: 'Removed Profile',
+ metricName: 'Removed Metric',
+ }),
+ ]),
+ );
+ renderWithProviders(<MetricsExplorer />);
+
+ await screen.findByRole('img', { name: 'Message In TPS time series' });
+ const queryCount = vi.mocked(queryMetrics).mock.calls.length;
+ await user.click(screen.getByRole('button', { name: '查询历史' }));
+ const historyDialog = await screen.findByRole('dialog', { name: '指标查询历史'
});
+ const historyItem = within(historyDialog).getByText('Removed
Metric').closest('.ant-list-item');
+ expect(historyItem).not.toBeNull();
+ await user.click(within(historyItem as HTMLElement).getByRole('button', {
name: '恢复' }));
+
+ expect(screen.getByRole('dialog', { name: '指标查询历史' })).toBeInTheDocument();
+ expect(
+
screen.getByLabelText('时间范围').querySelector('.ant-segmented-item-selected')?.textContent,
+ ).toBe('1h');
+ expect(screen.getByRole('img', { name: 'Message In TPS time series'
})).toBeInTheDocument();
+ expect(vi.mocked(queryMetrics)).toHaveBeenCalledTimes(queryCount);
+ });
+
it('keeps the current data source when cancelling a protected history
restore', async () => {
const user = userEvent.setup();
vi.mocked(listDataSources).mockResolvedValue([