From dec3ef2f3da0ef9262292cdb30bb2d48f43204f4 Mon Sep 17 00:00:00 2001 From: scottybollinger Date: Fri, 29 Mar 2024 12:31:19 -0500 Subject: [PATCH] Add Try Console selector to Console widget --- .../web/docs_js/components/console_widget.jsx | 128 +++++++++++++++--- resources/web/style/console_widget.pcss | 13 ++ 2 files changed, 121 insertions(+), 20 deletions(-) diff --git a/resources/web/docs_js/components/console_widget.jsx b/resources/web/docs_js/components/console_widget.jsx index 01c7e5fdee2b5..2dc169aeda1c5 100644 --- a/resources/web/docs_js/components/console_widget.jsx +++ b/resources/web/docs_js/components/console_widget.jsx @@ -62,6 +62,50 @@ export class _ConsoleForm extends Component { } } +export class _TryConsoleSelector extends Component { + componentWillMount() { + const defaultVals = omit(['langStrings', 'saveSettings', 'url_label', 'setting'], this.props); + this.setState(defaultVals); + } + + + render(props) { + const handleConfigureClick = (e) => { + e.preventDefault(); + props.settingsModalAction(); + } + + return ( +
+

Try in Console

+

We were unable to detect a running console server.

+

+ + Sign up for Elastic Cloud trial + +

+

+ + Install Elasticsearch and Kibana locally + +

+

+ + Configure the example widget + +

+
+ ) + } +} + export const ConsoleForm = connect((state, props) => pick(["langStrings", `${props.setting}_url`, @@ -70,30 +114,74 @@ export const ConsoleForm = connect((state, props) => `${props.setting}_curl_password`], state.settings) , {saveSettings})(_ConsoleForm); +export const TryConsoleSelector = connect((state, props) => + pick(["langStrings", + `${props.setting}_url`, + `${props.setting}_curl_host`, + `${props.setting}_curl_user`, + `${props.setting}_curl_password`], state.settings) +, {saveSettings})(_TryConsoleSelector); + // ConsoleWidget isn't quite the right name for this any more.... export const ConsoleWidget = props => { - const modalAction = () => props.openModal(ConsoleForm, {setting: props.setting, url_label: props.url_label}); - return
- + const settingsModalAction = () => props.openModal(ConsoleForm, {setting: props.setting, url_label: props.url_label}); + const openConsoleModal = () => + props.openModal(TryConsoleSelector, { settingsModalAction }) + const consoleModalAction = (e) => { + e.preventDefault(); + const target = e.target; + + utils.checkServerStatus(target.href) + .then((isUp) => { + if (isUp) { + window.open(target.href) + } else { + openConsoleModal(); + } + }) + .catch((_) => { + openConsoleModal(); + }); + }; + + return (
- props.copyAsCurl({ - isKibana: props.isKibana, - consoleText: props.consoleText, - setting: props.setting, - addPretty: props.addPretty - })}> - {props.langStrings('Copy as curl')} - - {props.view_in_text && - {props.langStrings(props.view_in_text)} - } -   + +
-
+ ) } export default connect( diff --git a/resources/web/style/console_widget.pcss b/resources/web/style/console_widget.pcss index 5b8a5fdf532b5..54fe4b0a815cf 100644 --- a/resources/web/style/console_widget.pcss +++ b/resources/web/style/console_widget.pcss @@ -61,3 +61,16 @@ background-image: inline("img/check.svg"); } } + +.try_console_selector { + text-align: center; + + h4 { + font-size: 30px; + } + + a.button { + margin: 10px auto; + cursor: pointer; + } +}