Skip to content

Commit 2d7ceb5

Browse files
[8.x] [Drilldowns] Fix drilldown add variable adding additional brackets (#196539) (#196655)
# Backport This will backport the following commits from `main` to `8.x`: - [[Drilldowns] Fix drilldown add variable adding additional brackets (#196539)](#196539) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Krzysztof Kowalczyk","email":"krzysztof.kowalczyk@elastic.co"},"sourceCommit":{"committedDate":"2024-10-17T09:46:53Z","message":"[Drilldowns] Fix drilldown add variable adding additional brackets (#196539)\n\n## Summary\r\n\r\nThis PR adds a check to create/edit drilldown template editor for\r\nwhether the cursor (where variable would be inserted) is already between\r\ndouble brackets.\r\n\r\nFixes: #121421","sha":"3c3b7c8ecb97961d98f7760cb90f25e2937c623d","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Feature:Drilldowns","v9.0.0","Team:SharedUX","backport:prev-minor"],"title":"[Drilldowns] Fix drilldown add variable adding additional brackets","number":196539,"url":"https://github.com/elastic/kibana/pull/196539","mergeCommit":{"message":"[Drilldowns] Fix drilldown add variable adding additional brackets (#196539)\n\n## Summary\r\n\r\nThis PR adds a check to create/edit drilldown template editor for\r\nwhether the cursor (where variable would be inserted) is already between\r\ndouble brackets.\r\n\r\nFixes: #121421","sha":"3c3b7c8ecb97961d98f7760cb90f25e2937c623d"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/196539","number":196539,"mergeCommit":{"message":"[Drilldowns] Fix drilldown add variable adding additional brackets (#196539)\n\n## Summary\r\n\r\nThis PR adds a check to create/edit drilldown template editor for\r\nwhether the cursor (where variable would be inserted) is already between\r\ndouble brackets.\r\n\r\nFixes: #121421","sha":"3c3b7c8ecb97961d98f7760cb90f25e2937c623d"}}]}] BACKPORT--> Co-authored-by: Krzysztof Kowalczyk <krzysztof.kowalczyk@elastic.co>
1 parent 6bf25ab commit 2d7ceb5

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/plugins/ui_actions_enhanced/public/drilldowns/url_drilldown/components/url_drilldown_collect_config/url_drilldown_collect_config.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ export interface UrlDrilldownCollectConfigProps {
3131
variablesHelpDocsLink?: string;
3232
}
3333

34+
const isCursorBetweenDoubleCurlyBrackets = (editor: monaco.editor.IStandaloneCodeEditor) => {
35+
const model = editor.getModel();
36+
const position = editor.getPosition();
37+
if (!model || !position) return false;
38+
39+
const offset = model.getOffsetAt(position);
40+
const text = model.getValue();
41+
const twoCharactersBeforeOffset = text.slice(offset - 2, offset);
42+
const twoCharactersAfterOffset = text.slice(offset, offset + 2);
43+
44+
return twoCharactersBeforeOffset === '{{' && twoCharactersAfterOffset === '}}';
45+
};
46+
3447
export const UrlDrilldownCollectConfig: React.FC<UrlDrilldownCollectConfigProps> = ({
3548
config,
3649
variables,
@@ -64,9 +77,10 @@ export const UrlDrilldownCollectConfig: React.FC<UrlDrilldownCollectConfigProps>
6477
onSelect={(variable: string) => {
6578
const editor = editorRef.current;
6679
if (!editor) return;
80+
const text = isCursorBetweenDoubleCurlyBrackets(editor) ? variable : `{{${variable}}}`;
6781

6882
editor.trigger('keyboard', 'type', {
69-
text: '{{' + variable + '}}',
83+
text,
7084
});
7185
}}
7286
/>

0 commit comments

Comments
 (0)