Skip to content

Commit 6b7b23e

Browse files
fix(timeseries): restore ECharts tooltip after closing drill menu (#37284)
1 parent 5ac5480 commit 6b7b23e

File tree

2 files changed

+155
-0
lines changed

2 files changed

+155
-0
lines changed
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
import { useRef, useState } from 'react';
20+
import { FeatureFlag, VizType } from '@superset-ui/core';
21+
import { render, screen, waitFor } from 'spec/helpers/testing-library';
22+
import userEvent from '@testing-library/user-event';
23+
import mockState from 'spec/fixtures/mockState';
24+
import { sliceId } from 'spec/fixtures/mockChartQueries';
25+
import { cachedSupersetGet } from 'src/utils/cachedSupersetGet';
26+
import ChartContextMenu, {
27+
ChartContextMenuRef,
28+
ContextMenuItem,
29+
} from './ChartContextMenu';
30+
31+
jest.mock('src/utils/cachedSupersetGet');
32+
33+
const mockCachedSupersetGet = cachedSupersetGet as jest.MockedFunction<
34+
typeof cachedSupersetGet
35+
>;
36+
37+
const defaultFormData = {
38+
datasource: '1__table',
39+
viz_type: VizType.Pie,
40+
};
41+
42+
const TestWrapper = () => {
43+
const contextMenuRef = useRef<ChartContextMenuRef>(null);
44+
const [isTooltipVisible, setIsTooltipVisible] = useState(true);
45+
46+
const handleClose = () => {
47+
setIsTooltipVisible(true);
48+
};
49+
50+
return (
51+
<>
52+
<button
53+
onClick={() => contextMenuRef.current?.open(100, 100, {})}
54+
data-test="open-context-menu"
55+
>
56+
Open Context Menu
57+
</button>
58+
{isTooltipVisible && (
59+
<div data-test="tooltip-visible">Tooltip is visible</div>
60+
)}
61+
<ChartContextMenu
62+
ref={contextMenuRef}
63+
id={sliceId}
64+
formData={defaultFormData}
65+
onSelection={jest.fn()}
66+
onClose={handleClose}
67+
displayedItems={ContextMenuItem.All}
68+
/>
69+
</>
70+
);
71+
};
72+
73+
const setup = () => {
74+
return render(<TestWrapper />, {
75+
useRedux: true,
76+
initialState: {
77+
...mockState,
78+
user: {
79+
...mockState.user,
80+
roles: {
81+
Admin: [
82+
['can_explore', 'Superset'],
83+
['can_samples', 'Datasource'],
84+
['can_write', 'ExploreFormDataRestApi'],
85+
['can_get_drill_info', 'Dataset'],
86+
],
87+
},
88+
},
89+
},
90+
});
91+
};
92+
93+
beforeEach(() => {
94+
// @ts-ignore
95+
global.featureFlags = {
96+
[FeatureFlag.DrillToDetail]: true,
97+
[FeatureFlag.DrillBy]: true,
98+
};
99+
100+
mockCachedSupersetGet.mockClear();
101+
mockCachedSupersetGet.mockResolvedValue({
102+
response: {} as Response,
103+
json: {
104+
result: {
105+
columns: [],
106+
metrics: [],
107+
},
108+
},
109+
});
110+
});
111+
112+
afterEach(() => {
113+
// @ts-ignore
114+
delete global.featureFlags;
115+
});
116+
117+
test('tooltip is restored when user clicks outside to close context menu', async () => {
118+
setup();
119+
120+
const openButton = screen.getByTestId('open-context-menu');
121+
userEvent.click(openButton);
122+
123+
await waitFor(() => {
124+
expect(screen.getByTestId('chart-context-menu')).toBeInTheDocument();
125+
});
126+
127+
expect(screen.getByTestId('tooltip-visible')).toBeInTheDocument();
128+
129+
userEvent.click(document.body);
130+
131+
await waitFor(() => {
132+
expect(screen.getByTestId('tooltip-visible')).toBeInTheDocument();
133+
});
134+
});
135+
136+
test('tooltip is restored when user selects a menu item', async () => {
137+
setup();
138+
139+
const openButton = screen.getByTestId('open-context-menu');
140+
userEvent.click(openButton);
141+
142+
await waitFor(() => {
143+
expect(screen.getByTestId('chart-context-menu')).toBeInTheDocument();
144+
});
145+
146+
const menuItem = screen.getByText('Drill to detail');
147+
userEvent.click(menuItem);
148+
149+
await waitFor(() => {
150+
expect(screen.getByTestId('tooltip-visible')).toBeInTheDocument();
151+
});
152+
});

superset-frontend/src/components/Chart/ChartContextMenu/ChartContextMenu.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,9 @@ const ChartContextMenu = (
423423
trigger={['click']}
424424
onOpenChange={value => {
425425
setVisible(value);
426+
if (!value) {
427+
onClose();
428+
}
426429
}}
427430
open={visible}
428431
>

0 commit comments

Comments
 (0)