mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
[ES|QL] Navigate to create new policy page from the editor (#167012)
## Summary
When a user is writing am ES|QL query with the enrich command and
doesn't have a policy then we want to navigate them from the editor to
the index management page to create one.
In the future the same action can open a flyout in order for the users
to not change context but we don't have it atm.

---------
Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
This commit is contained in:
parent
2477e40c85
commit
32562aa53f
3 changed files with 19 additions and 3 deletions
|
@ -45,9 +45,15 @@ export const buildNoPoliciesAvailableDefinition = (): AutocompleteCommandDefinit
|
||||||
insertText: '',
|
insertText: '',
|
||||||
kind: 26,
|
kind: 26,
|
||||||
detail: i18n.translate('monaco.esql.autocomplete.noPoliciesLabelsFound', {
|
detail: i18n.translate('monaco.esql.autocomplete.noPoliciesLabelsFound', {
|
||||||
defaultMessage: 'No policies found',
|
defaultMessage: 'Click to create',
|
||||||
}),
|
}),
|
||||||
sortText: 'D',
|
sortText: 'D',
|
||||||
|
command: {
|
||||||
|
id: 'esql.policies.create',
|
||||||
|
title: i18n.translate('monaco.esql.autocomplete.createNewPolicy', {
|
||||||
|
defaultMessage: 'Click to create',
|
||||||
|
}),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -32,5 +32,5 @@ export interface UserDefinedVariables {
|
||||||
/** @internal **/
|
/** @internal **/
|
||||||
export type AutocompleteCommandDefinition = Pick<
|
export type AutocompleteCommandDefinition = Pick<
|
||||||
monaco.languages.CompletionItem,
|
monaco.languages.CompletionItem,
|
||||||
'label' | 'insertText' | 'kind' | 'detail' | 'documentation' | 'sortText'
|
'label' | 'insertText' | 'kind' | 'detail' | 'documentation' | 'sortText' | 'command'
|
||||||
>;
|
>;
|
||||||
|
|
|
@ -131,7 +131,7 @@ export const TextBasedLanguagesEditor = memo(function TextBasedLanguagesEditor({
|
||||||
const language = getAggregateQueryMode(query);
|
const language = getAggregateQueryMode(query);
|
||||||
const queryString: string = query[language] ?? '';
|
const queryString: string = query[language] ?? '';
|
||||||
const kibana = useKibana<TextBasedEditorDeps>();
|
const kibana = useKibana<TextBasedEditorDeps>();
|
||||||
const { dataViews, expressions, indexManagementApiService } = kibana.services;
|
const { dataViews, expressions, indexManagementApiService, application } = kibana.services;
|
||||||
const [code, setCode] = useState(queryString ?? '');
|
const [code, setCode] = useState(queryString ?? '');
|
||||||
const [codeOneLiner, setCodeOneLiner] = useState('');
|
const [codeOneLiner, setCodeOneLiner] = useState('');
|
||||||
const [editorHeight, setEditorHeight] = useState(
|
const [editorHeight, setEditorHeight] = useState(
|
||||||
|
@ -148,6 +148,16 @@ export const TextBasedLanguagesEditor = memo(function TextBasedLanguagesEditor({
|
||||||
useState<LanguageDocumentationSections>();
|
useState<LanguageDocumentationSections>();
|
||||||
|
|
||||||
const policiesRef = useRef<SerializedEnrichPolicy[]>([]);
|
const policiesRef = useRef<SerializedEnrichPolicy[]>([]);
|
||||||
|
|
||||||
|
// Registers a command to redirect users to the index management page
|
||||||
|
// to create a new policy. The command is called by the buildNoPoliciesAvailableDefinition
|
||||||
|
monaco.editor.registerCommand('esql.policies.create', (...args) => {
|
||||||
|
application?.navigateToApp('management', {
|
||||||
|
path: 'data/index_management/enrich_policies/create',
|
||||||
|
openInNewTab: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const styles = textBasedLanguagedEditorStyles(
|
const styles = textBasedLanguagedEditorStyles(
|
||||||
euiTheme,
|
euiTheme,
|
||||||
isCompactFocused,
|
isCompactFocused,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue