-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend search query input with option to view search query history (#…
…18067) * Add search query input completer for query history. * Add button to view query history. * Improve token helper naming. * Replace completer with solution where we manually set completions when triggering action to show history. * Set fixed width and position for editor dropdown. * Fix background color of focused autocompletion. * Fixing tests * Fix order of query history. * Cleanup code. * Add changelog. * Extend query history limit. * Fix changelog. * Show query history when showing suggestions in empty input. * Remove `Ctrl-Space` and `Ctrl-Shift-Space` keybindings for query input. * Display further query input keyboard shortcuts in keyboard shortcuts modal. * Do not select query input value, when inserting history suggestion. * Update changelog. * Cleanup code. * Do not show empty dropdown when triggering action to show query history while there is no history.
- Loading branch information
Showing
25 changed files
with
348 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
type = "a" | ||
message = "Extend search query input with option to view search query history." | ||
|
||
issues = ["Graylog2/graylog-plugin-enterprise#4012"] | ||
pulls = ["18067"] | ||
|
||
details.user = """ | ||
The history is scoped by user and sorted chronologically. The history contains all queries executed on the search page, dashboards and dashboard widgets. | ||
It can be opened by clicking on the history icon or by pressing the keyboard shortcut alt+shift+h. | ||
While it is open, it can be filtered using the query input. When a previous query has been selected, it will replace the current value of the query input. | ||
With this change we are also removing the keyboard shortcuts ctrl+space and ctrl+shift+space to manually display the suggestions. | ||
It is still possible to display the suggestions by pressing alt+space. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
graylog2-web-interface/src/views/components/searchbar/QueryHistoryButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
import * as React from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
import { SearchSuggestions } from '@graylog/server-api'; | ||
import IconButton from 'components/common/IconButton'; | ||
import type { Editor } from 'views/components/searchbar/queryinput/ace-types'; | ||
import { startAutocomplete } from 'views/components/searchbar/queryinput/commands'; | ||
|
||
const QUERY_HISTORY_LIMIT = 100; | ||
|
||
const ButtonContainer = styled.div` | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
margin-left: 6px; | ||
`; | ||
|
||
const fetchQueryHistoryCompletions = () => SearchSuggestions.suggestQueryStrings(QUERY_HISTORY_LIMIT).then((response) => ( | ||
response.sort(( | ||
{ last_used: lastUsedA }, { last_used: lastUsedB }) => new Date(lastUsedB).getTime() - new Date(lastUsedA).getTime(), | ||
).map((entry, index) => ({ | ||
value: entry.query, | ||
meta: 'history', | ||
score: index, | ||
completer: { | ||
insertMatch: ( | ||
editor: { setValue: (value: string, cursorPosition?: number) => void }, | ||
data: { value: string }, | ||
) => { | ||
editor.setValue(data.value, 1); | ||
}, | ||
}, | ||
})))); | ||
|
||
export const displayHistoryCompletions = async (editor: Editor) => { | ||
const historyCompletions = await fetchQueryHistoryCompletions(); | ||
|
||
if (historyCompletions?.length) { | ||
startAutocomplete(editor, { matches: historyCompletions }); | ||
} | ||
}; | ||
|
||
type Props = { | ||
editorRef: React.MutableRefObject<Editor> | ||
} | ||
|
||
const QueryHistoryButton = ({ editorRef }: Props) => { | ||
const showQueryHistory = async () => { | ||
if (editorRef.current) { | ||
editorRef.current.focus(); | ||
|
||
displayHistoryCompletions(editorRef.current); | ||
} | ||
}; | ||
|
||
return ( | ||
<ButtonContainer> | ||
<IconButton name="clock-rotate-left" onClick={showQueryHistory} /> | ||
</ButtonContainer> | ||
); | ||
}; | ||
|
||
export default QueryHistoryButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.