Skip to content

Commit

Permalink
Revert the docs button from the footer
Browse files Browse the repository at this point in the history
  • Loading branch information
stratoula committed Sep 16, 2024
1 parent a056700 commit 4d099f2
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
40 changes: 38 additions & 2 deletions packages/kbn-text-based-editor/src/editor_footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,27 @@
import React, { memo, useState, useCallback, useMemo } from 'react';

import { i18n } from '@kbn/i18n';
import { EuiText, EuiFlexGroup, EuiFlexItem, EuiCode, EuiButtonIcon } from '@elastic/eui';
import {
EuiText,
EuiFlexGroup,
EuiFlexItem,
EuiCode,
EuiButtonIcon,
EuiButtonEmpty,
} from '@elastic/eui';
import { Interpolation, Theme, css } from '@emotion/react';
import { LanguageDocumentationInline } from '@kbn/language-documentation-popover';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import {
LanguageDocumentationInline,
LanguageDocumentationFlyout,
} from '@kbn/language-documentation-popover';
import { getLimitFromESQLQuery } from '@kbn/esql-utils';
import { type MonacoMessage } from '../helpers';
import { ErrorsWarningsFooterPopover } from './errors_warnings_popover';
import { QueryHistoryAction, QueryHistory } from './query_history';
import { SubmitFeedbackComponent } from './feedback_component';
import { QueryWrapComponent } from './query_wrap_component';
import type { TextBasedEditorDeps } from '../types';

const isMac = navigator.platform.toLowerCase().indexOf('mac') >= 0;
const COMMAND_KEY = isMac ? '⌘' : '^';
Expand All @@ -45,6 +57,7 @@ interface EditorFooterProps {
hideTimeFilterInfo?: boolean;
hideQueryHistory?: boolean;
isInCompactMode?: boolean;
displayDocumentationAsFlyout?: boolean;
}

export const EditorFooter = memo(function EditorFooter({
Expand All @@ -64,9 +77,12 @@ export const EditorFooter = memo(function EditorFooter({
setIsHistoryOpen,
hideQueryHistory,
isInCompactMode,
displayDocumentationAsFlyout,
measuredContainerWidth,
code,
}: EditorFooterProps) {
const kibana = useKibana<TextBasedEditorDeps>();
const { docLinks } = kibana.services;
const [isErrorPopoverOpen, setIsErrorPopoverOpen] = useState(false);
const [isLanguageComponentOpen, setIsLanguageComponentOpen] = useState(false);
const [isWarningPopoverOpen, setIsWarningPopoverOpen] = useState(false);
Expand Down Expand Up @@ -273,6 +289,26 @@ export const EditorFooter = memo(function EditorFooter({
</EuiFlexGroup>
</EuiFlexItem>
)}
{displayDocumentationAsFlyout && !Boolean(editorIsInline) && (
<>
<EuiButtonEmpty
iconType="documentation"
color="text"
data-test-subj="TextBasedLangEditor-documentation"
size="m"
onClick={() => toggleLanguageComponent()}
css={css`
cursor: pointer;
`}
/>
<LanguageDocumentationFlyout
searchInDescription
linkToDocumentation={docLinks?.links?.query?.queryESQL ?? ''}
isHelpMenuOpen={isLanguageComponentOpen}
onHelpMenuVisibilityChange={setIsLanguageComponentOpen}
/>
</>
)}
</EuiFlexGroup>
</EuiFlexItem>
{Boolean(editorIsInline) && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ describe('TextBasedLanguagesEditor', () => {
expect(component.find('[data-test-subj="TextBasedLangEditor-run-query"]').length).not.toBe(0);
});

it('should render the doc icon if the displayDocumentationAsFlyout is true', async () => {
const newProps = {
...props,
displayDocumentationAsFlyout: true,
editorIsInline: false,
};
const component = mount(renderTextBasedLanguagesEditorComponent({ ...newProps }));
expect(component.find('[data-test-subj="TextBasedLangEditor-documentation"]').length).not.toBe(
0
);
});

it('should not render the run query text if the hideRunQueryText prop is set to true', async () => {
const newProps = {
...props,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const TextBasedLanguagesEditor = memo(function TextBasedLanguagesEditor({
hideTimeFilterInfo,
hideQueryHistory,
hasOutline,
displayDocumentationAsFlyout,
}: TextBasedLanguagesEditorProps) {
const popoverRef = useRef<HTMLDivElement>(null);
const datePickerOpenStatusRef = useRef<boolean>(false);
Expand Down Expand Up @@ -734,6 +735,7 @@ export const TextBasedLanguagesEditor = memo(function TextBasedLanguagesEditor({
setIsHistoryOpen={toggleHistory}
measuredContainerWidth={measuredEditorWidth}
hideQueryHistory={hideHistoryComponent}
displayDocumentationAsFlyout={displayDocumentationAsFlyout}
/>
<ResizableButton
onMouseDownResizeHandler={onMouseDownResizeHandler}
Expand Down
3 changes: 3 additions & 0 deletions packages/kbn-text-based-editor/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ export interface TextBasedLanguagesEditorProps {

/** adds border in the editor **/
hasOutline?: boolean;

/** adds a documentation icon in the footer which opens the inline docs as a flyout **/
displayDocumentationAsFlyout?: boolean;
}

export interface TextBasedEditorDeps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ export const IndexDataVisualizerESQL: FC<IndexDataVisualizerESQLProps> = (dataVi
detectedTimestamp={currentDataView?.timeFieldName}
hideRunQueryText={false}
isLoading={queryHistoryStatus ?? false}
displayDocumentationAsFlyout
/>

<EuiFlexGroup gutterSize="m" direction={isWithinLargeBreakpoint ? 'column' : 'row'}>
Expand Down

0 comments on commit 4d099f2

Please sign in to comment.