Skip to content

Commit 117aa6f

Browse files
committed
fix(SchemaTree): snippet not insert if user is not on Query tab
1 parent 27f9a9f commit 117aa6f

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/containers/Tenant/utils/schemaActions.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ const bindActions = (
6161

6262
const inputQuery = (tmpl: TemplateFn) => () => {
6363
const applyInsert = () => {
64-
//order is important here: firstly we should open query tab and initialize editor (it will be set to window.ydbEditor), after that it is possible to insert snippet
64+
//order is important here: firstly we should open query tab and initialize editor (it will be set to window.ydbEditor), after that it is possible to insert snippet. Also timeout is needed to wait for editor to be initialized
6565
dispatch(setTenantPage(TENANT_PAGES_IDS.query));
6666
dispatch(setQueryTab(TENANT_QUERY_TABS_ID.newQuery));
6767
setActivePath(params.path);
68-
insertSnippetToEditor(tmpl({...params, schemaData}));
68+
window.setTimeout(() => {
69+
insertSnippetToEditor(tmpl({...params, schemaData}));
70+
}, 100);
6971
};
7072
if (getConfirmation) {
7173
const confirmedPromise = getConfirmation();

src/utils/monaco/insertSnippet.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export function insertSnippetToEditor(input: string) {
22
if (!window.ydbEditor) {
33
console.error('Monaco editor not found');
4+
return;
45
}
5-
window.ydbEditor?.trigger(undefined, 'insertSnippetToEditor', input);
6+
window.ydbEditor.trigger(undefined, 'insertSnippetToEditor', input);
67
}

0 commit comments

Comments
 (0)