Skip to content
Snippets Groups Projects
Unverified Commit c240510e authored by Anton Kulyk's avatar Anton Kulyk Committed by GitHub
Browse files

Fix ace editor popover in action editor (#28525)

* Move `ace` element ID to constants

* Close ace popover before opening the save modal

* Change name

* Workaround type warning
parent 67980297
No related branches found
No related tags found
No related merge requests found
...@@ -29,6 +29,7 @@ import type Metadata from "metabase-lib/metadata/Metadata"; ...@@ -29,6 +29,7 @@ import type Metadata from "metabase-lib/metadata/Metadata";
import { isSavedAction } from "../../utils"; import { isSavedAction } from "../../utils";
import ActionContext, { useActionContext } from "./ActionContext"; import ActionContext, { useActionContext } from "./ActionContext";
import ActionCreatorView from "./ActionCreatorView"; import ActionCreatorView from "./ActionCreatorView";
import { ACE_ELEMENT_ID } from "./QueryActionEditor";
import CreateActionForm, { import CreateActionForm, {
FormValues as CreateActionFormValues, FormValues as CreateActionFormValues,
} from "./CreateActionForm"; } from "./CreateActionForm";
...@@ -95,7 +96,7 @@ function ActionCreator({ ...@@ -95,7 +96,7 @@ function ActionCreator({
renderEditorBody, renderEditorBody,
} = useActionContext(); } = useActionContext();
const [showSaveModal, setShowSaveModal] = useState(false); const [isSaveModalShown, setShowSaveModal] = useState(false);
const isEditable = isNew || model.canWriteActions(); const isEditable = isNew || model.canWriteActions();
...@@ -131,9 +132,14 @@ function ActionCreator({ ...@@ -131,9 +132,14 @@ function ActionCreator({
} }
}; };
const showSaveModal = () => {
ensureAceEditorClosed();
setShowSaveModal(true);
};
const handleClickSave = () => { const handleClickSave = () => {
if (isNew) { if (isNew) {
setShowSaveModal(true); showSaveModal();
} else { } else {
handleUpdate(); handleUpdate();
onClose?.(); onClose?.();
...@@ -158,7 +164,7 @@ function ActionCreator({ ...@@ -158,7 +164,7 @@ function ActionCreator({
> >
{renderEditorBody({ isEditable })} {renderEditorBody({ isEditable })}
</ActionCreatorView> </ActionCreatorView>
{showSaveModal && ( {isSaveModalShown && (
<Modal title={t`New Action`} onClose={handleCloseNewActionModal}> <Modal title={t`New Action`} onClose={handleCloseNewActionModal}>
<CreateActionForm <CreateActionForm
initialValues={{ initialValues={{
...@@ -175,6 +181,14 @@ function ActionCreator({ ...@@ -175,6 +181,14 @@ function ActionCreator({
); );
} }
function ensureAceEditorClosed() {
// @ts-expect-error — `ace` isn't typed yet
const editor = window.ace?.edit(ACE_ELEMENT_ID);
if (editor) {
editor.completer.popup.hide();
}
}
function ActionCreatorWithContext({ function ActionCreatorWithContext({
initialAction, initialAction,
metadata, metadata,
......
import React from "react"; import React from "react";
import NativeQueryEditor from "metabase/query_builder/components/NativeQueryEditor"; import NativeQueryEditor from "metabase/query_builder/components/NativeQueryEditor";
import { ACE_ELEMENT_ID } from "metabase/query_builder/components/NativeQueryEditor/constants";
import type NativeQuery from "metabase-lib/queries/NativeQuery"; import type NativeQuery from "metabase-lib/queries/NativeQuery";
...@@ -31,4 +32,6 @@ function QueryActionEditor({ ...@@ -31,4 +32,6 @@ function QueryActionEditor({
); );
} }
export { ACE_ELEMENT_ID };
export default QueryActionEditor; export default QueryActionEditor;
...@@ -39,7 +39,11 @@ import NativeQueryEditorSidebar from "./NativeQueryEditor/NativeQueryEditorSideb ...@@ -39,7 +39,11 @@ import NativeQueryEditorSidebar from "./NativeQueryEditor/NativeQueryEditorSideb
import VisibilityToggler from "./NativeQueryEditor/VisibilityToggler"; import VisibilityToggler from "./NativeQueryEditor/VisibilityToggler";
import RightClickPopover from "./NativeQueryEditor/RightClickPopover"; import RightClickPopover from "./NativeQueryEditor/RightClickPopover";
import DataSourceSelectors from "./NativeQueryEditor/DataSourceSelectors"; import DataSourceSelectors from "./NativeQueryEditor/DataSourceSelectors";
import { SCROLL_MARGIN, MIN_HEIGHT_LINES } from "./NativeQueryEditor/constants"; import {
ACE_ELEMENT_ID,
SCROLL_MARGIN,
MIN_HEIGHT_LINES,
} from "./NativeQueryEditor/constants";
import { import {
calcInitialEditorHeight, calcInitialEditorHeight,
getEditorLineHeight, getEditorLineHeight,
...@@ -578,7 +582,7 @@ class NativeQueryEditor extends Component { ...@@ -578,7 +582,7 @@ class NativeQueryEditor extends Component {
this._editor.resize(); this._editor.resize();
}} }}
> >
<div className="flex-full" id="id_sql" ref={this.editor} /> <div className="flex-full" id={ACE_ELEMENT_ID} ref={this.editor} />
<RightClickPopover <RightClickPopover
isOpen={this.state.isSelectedTextPopoverOpen} isOpen={this.state.isSelectedTextPopoverOpen}
......
export const SCROLL_MARGIN = 8; export const SCROLL_MARGIN = 8;
export const MIN_HEIGHT_LINES = 15; export const MIN_HEIGHT_LINES = 15;
export const ACE_ELEMENT_ID = "id_sql";
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment