Skip to content

Commit d13fbdd

Browse files
committed
Fix duplicate shortcut registration for focus_query_bar
Renamed the shortcut ID to be unique per instance in the data plugin and distinctive in the explore plugin to prevent crashes when multiple query bars are rendered. Signed-off-by: Mumukshu D.C <phoenixrising656@gmail.com>
1 parent 5546456 commit d13fbdd

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/plugins/data/public/ui/query_string_input/query_string_input.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ describe('QueryStringInput', () => {
335335
);
336336

337337
expect(mockRegister).toHaveBeenCalledWith({
338-
id: 'focus_query_bar',
338+
id: expect.stringMatching(/^focus_query_bar_/),
339339
pluginId: 'data',
340340
name: expect.any(String),
341341
category: expect.any(String),
@@ -357,7 +357,7 @@ describe('QueryStringInput', () => {
357357
component.unmount();
358358

359359
expect(mockUnregister).toHaveBeenCalledWith({
360-
id: 'focus_query_bar',
360+
id: expect.stringMatching(/^focus_query_bar_/),
361361
pluginId: 'data',
362362
});
363363
});

src/plugins/data/public/ui/query_string_input/query_string_input.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ export default class QueryStringInputUI extends Component<Props, State> {
534534
const { keyboardShortcut } = this.services;
535535
if (keyboardShortcut) {
536536
keyboardShortcut.register({
537-
id: 'focus_query_bar',
537+
id: `focus_query_bar_${this.textareaId || ''}`,
538538
pluginId: 'data',
539539
name: i18n.translate('data.query.queryStringInput.focusQueryBarShortcut', {
540540
defaultMessage: 'Focus query bar',
@@ -596,7 +596,7 @@ export default class QueryStringInputUI extends Component<Props, State> {
596596
const { keyboardShortcut } = this.services;
597597
if (keyboardShortcut) {
598598
keyboardShortcut.unregister({
599-
id: 'focus_query_bar',
599+
id: `focus_query_bar_${this.textareaId || ''}`,
600600
pluginId: 'data',
601601
});
602602
}

src/plugins/explore/public/components/query_panel/query_panel_editor/use_query_panel_editor/use_query_panel_editor.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export const useQueryPanelEditor = (): UseQueryPanelEditorReturnType => {
123123
}, [queryLanguage]);
124124

125125
keyboardShortcut?.useKeyboardShortcut({
126-
id: 'focus_query_bar',
126+
id: 'focus_explore_query_bar',
127127
pluginId: 'explore',
128128
name: i18n.translate('explore.queryPanelEditor.focusQueryBarShortcut', {
129129
defaultMessage: 'Focus query bar',
@@ -230,9 +230,9 @@ export const useQueryPanelEditor = (): UseQueryPanelEditorReturnType => {
230230
sortText: s.sortText,
231231
documentation: s.documentation
232232
? {
233-
value: s.documentation,
234-
isTrusted: true,
235-
}
233+
value: s.documentation,
234+
isTrusted: true,
235+
}
236236
: '',
237237
command: {
238238
id: 'editor.action.triggerSuggest',

0 commit comments

Comments
 (0)