Skip to content

Commit aff847b

Browse files
authored
fix: database model Collapse state (#34126)
1 parent b24aca0 commit aff847b

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

superset-frontend/src/features/databases/DatabaseModal/ExtraOptions.test.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,32 @@ describe('ExtraOptions Component', () => {
191191
fireEvent.change(input, { target: { value: '1000' } });
192192
expect(onExtraInputChange).toHaveBeenCalled();
193193
});
194+
195+
it('renders the collaps tab correctly and resets to default tab after closing', () => {
196+
const { rerender } = renderComponent();
197+
const sqlLabTab = screen.getByRole('tab', {
198+
name: /SQL Lab./i,
199+
});
200+
201+
expect(sqlLabTab).toHaveAttribute('aria-expanded', 'false');
202+
fireEvent.click(sqlLabTab);
203+
expect(sqlLabTab).toHaveAttribute('aria-expanded', 'true');
204+
const customDb = {
205+
...defaultDb,
206+
expose_in_sqllab: false,
207+
};
208+
209+
rerender(
210+
<ExtraOptions
211+
db={customDb as unknown as DatabaseObject}
212+
onInputChange={onInputChange}
213+
onTextChange={onTextChange}
214+
onEditorChange={onEditorChange}
215+
onExtraInputChange={onExtraInputChange}
216+
onExtraEditorChange={onExtraEditorChange}
217+
extraExtension={undefined}
218+
/>,
219+
);
220+
expect(sqlLabTab).toHaveAttribute('aria-expanded', 'false');
221+
});
194222
});

superset-frontend/src/features/databases/DatabaseModal/ExtraOptions.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
import { ChangeEvent, EventHandler } from 'react';
19+
import { ChangeEvent, EventHandler, useState, useEffect } from 'react';
2020
import cx from 'classnames';
2121
import {
2222
t,
@@ -88,12 +88,21 @@ const ExtraOptions = ({
8888
const isAllowRunAsyncDisabled = isFeatureEnabled(
8989
FeatureFlag.ForceSqlLabRunAsync,
9090
);
91+
const [activeKey, setActiveKey] = useState<string[] | undefined>();
92+
93+
useEffect(() => {
94+
if (!expandableModalIsOpen && activeKey !== undefined) {
95+
setActiveKey(undefined);
96+
}
97+
}, [expandableModalIsOpen, activeKey]);
9198

9299
return (
93100
<Collapse
94101
expandIconPosition="end"
95102
accordion
96103
modalMode
104+
activeKey={activeKey}
105+
onChange={key => setActiveKey(key)}
97106
items={[
98107
{
99108
key: 'sql-lab',

0 commit comments

Comments
 (0)