Skip to content

Commit

Permalink
[8.x] [ES|QL] Enhances the inline documentation experience (#192156) (#…
Browse files Browse the repository at this point in the history
…193444)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[ES|QL] Enhances the inline documentation experience
(#192156)](#192156)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Stratoula
Kalafateli","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-09-19T15:10:39Z","message":"[ES|QL]
Enhances the inline documentation experience (#192156)\n\n##
Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/166907\r\n\r\nThis
PR:\r\n\r\n1. Changes the inline docs implementation to a flyout for
Discover\r\n\r\n<img width=\"1256\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/3665c73a-82d5-49b9-88c3-e129eda63885\">\r\n\r\n2.
Adds the flyout to open from the help menu and removes it from
the\r\neditor footer\r\n\r\n3. For the inline editing changes the docs
to be rendered as a component\r\ninside the editor (exactly as the
history component)\r\n\r\nNote: The documentation in the inline editing
has limited space (same\r\nproblem has the history component). I need to
sync with Ryan to see what\r\nwe can do, I am exploring some ideas in
follow up PRs\r\n\r\n<img width=\"647\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/2fa9fcc3-2a07-4bea-b675-5ae6578696d3\">\r\n\r\n4.
Moves the esql docs to the language package and the script
associated\r\nto this\r\n\r\n### Follow up\r\n- The language package
should be renamed as the `popover` makes sense\r\nonly for the formula
implementation now. I will do it after this PR gets\r\nmerged\r\n- See
how we can give more space to the docs / history container when
in\r\ninline mode\r\n\r\n### Note\r\nThe async bundle got increased as
we want the ES|QL docs in unified\r\nsearch too. It wont be a problem as
is loaded asynchronously.\r\n\r\n### Checklist\r\n\r\n- [ ] Any text
added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] Any UI
touched in this PR is usable by keyboard only (learn more\r\nabout
[keyboard accessibility](https://webaim.org/techniques/keyboard/))\r\n-
[ ] Any UI touched in this PR does not create any new axe
failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>\r\nCo-authored-by:
Ryan Keairns <[email protected]>\r\nCo-authored-by: Drew Tate
<[email protected]>\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"dfbd7de3f53cae4b81d8643283f106cbf16e3415","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement","v9.0.0","backport:prev-minor","Feature:ES|QL","Team:ESQL","v8.16.0"],"title":"[ES|QL]
Enhances the inline documentation
experience","number":192156,"url":"https://github.com/elastic/kibana/pull/192156","mergeCommit":{"message":"[ES|QL]
Enhances the inline documentation experience (#192156)\n\n##
Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/166907\r\n\r\nThis
PR:\r\n\r\n1. Changes the inline docs implementation to a flyout for
Discover\r\n\r\n<img width=\"1256\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/3665c73a-82d5-49b9-88c3-e129eda63885\">\r\n\r\n2.
Adds the flyout to open from the help menu and removes it from
the\r\neditor footer\r\n\r\n3. For the inline editing changes the docs
to be rendered as a component\r\ninside the editor (exactly as the
history component)\r\n\r\nNote: The documentation in the inline editing
has limited space (same\r\nproblem has the history component). I need to
sync with Ryan to see what\r\nwe can do, I am exploring some ideas in
follow up PRs\r\n\r\n<img width=\"647\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/2fa9fcc3-2a07-4bea-b675-5ae6578696d3\">\r\n\r\n4.
Moves the esql docs to the language package and the script
associated\r\nto this\r\n\r\n### Follow up\r\n- The language package
should be renamed as the `popover` makes sense\r\nonly for the formula
implementation now. I will do it after this PR gets\r\nmerged\r\n- See
how we can give more space to the docs / history container when
in\r\ninline mode\r\n\r\n### Note\r\nThe async bundle got increased as
we want the ES|QL docs in unified\r\nsearch too. It wont be a problem as
is loaded asynchronously.\r\n\r\n### Checklist\r\n\r\n- [ ] Any text
added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] Any UI
touched in this PR is usable by keyboard only (learn more\r\nabout
[keyboard accessibility](https://webaim.org/techniques/keyboard/))\r\n-
[ ] Any UI touched in this PR does not create any new axe
failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>\r\nCo-authored-by:
Ryan Keairns <[email protected]>\r\nCo-authored-by: Drew Tate
<[email protected]>\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"dfbd7de3f53cae4b81d8643283f106cbf16e3415"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/192156","number":192156,"mergeCommit":{"message":"[ES|QL]
Enhances the inline documentation experience (#192156)\n\n##
Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/166907\r\n\r\nThis
PR:\r\n\r\n1. Changes the inline docs implementation to a flyout for
Discover\r\n\r\n<img width=\"1256\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/3665c73a-82d5-49b9-88c3-e129eda63885\">\r\n\r\n2.
Adds the flyout to open from the help menu and removes it from
the\r\neditor footer\r\n\r\n3. For the inline editing changes the docs
to be rendered as a component\r\ninside the editor (exactly as the
history component)\r\n\r\nNote: The documentation in the inline editing
has limited space (same\r\nproblem has the history component). I need to
sync with Ryan to see what\r\nwe can do, I am exploring some ideas in
follow up PRs\r\n\r\n<img width=\"647\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/2fa9fcc3-2a07-4bea-b675-5ae6578696d3\">\r\n\r\n4.
Moves the esql docs to the language package and the script
associated\r\nto this\r\n\r\n### Follow up\r\n- The language package
should be renamed as the `popover` makes sense\r\nonly for the formula
implementation now. I will do it after this PR gets\r\nmerged\r\n- See
how we can give more space to the docs / history container when
in\r\ninline mode\r\n\r\n### Note\r\nThe async bundle got increased as
we want the ES|QL docs in unified\r\nsearch too. It wont be a problem as
is loaded asynchronously.\r\n\r\n### Checklist\r\n\r\n- [ ] Any text
added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] Any UI
touched in this PR is usable by keyboard only (learn more\r\nabout
[keyboard accessibility](https://webaim.org/techniques/keyboard/))\r\n-
[ ] Any UI touched in this PR does not create any new axe
failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>\r\nCo-authored-by:
Ryan Keairns <[email protected]>\r\nCo-authored-by: Drew Tate
<[email protected]>\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"dfbd7de3f53cae4b81d8643283f106cbf16e3415"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Stratoula Kalafateli <[email protected]>
  • Loading branch information
kibanamachine and stratoula authored Sep 19, 2024
1 parent b2e6263 commit c5ff79a
Show file tree
Hide file tree
Showing 41 changed files with 2,199 additions and 1,850 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -euo pipefail

VALIDATION_PACKAGE_DIR="packages/kbn-esql-validation-autocomplete"
EDITOR_PACKAGE_DIR="packages/kbn-text-based-editor"
EDITOR_PACKAGE_DIR="packages/kbn-language-documentation-popover"
GIT_SCOPE="$VALIDATION_PACKAGE_DIR/**/* $EDITOR_PACKAGE_DIR/**/*"

report_main_step () {
Expand Down
9 changes: 5 additions & 4 deletions packages/kbn-language-documentation-popover/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export { LanguageDocumentationPopover } from './src/components/documentation_popover';
export { LanguageDocumentationPopoverContent } from './src/components/documentation_content';
export type { LanguageDocumentationSections } from './src/components/documentation_content';
export { LanguageDocumentationPopover } from './src/components/as_popover';
export { LanguageDocumentationPopoverContent } from './src/components/as_popover/popover_content';
export { LanguageDocumentationFlyout } from './src/components/as_flyout';
export { LanguageDocumentationInline } from './src/components/as_inline';
export type { LanguageDocumentationSections } from './src/types';
9 changes: 7 additions & 2 deletions packages/kbn-language-documentation-popover/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
"private": true,
"sideEffects": [
"*.scss"
]
}
],
"scripts": {
"make:docs": "ts-node --transpileOnly scripts/generate_esql_docs.ts",
"postmake:docs": "yarn run lint:fix",
"lint:fix": "cd ../.. && node ./scripts/eslint --fix ./packages/kbn-language-documentation-popover/src/sections/generated"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import * as recast from 'recast';
const n = recast.types.namedTypes;
import fs from 'fs';
import path from 'path';
import { functions } from '../src/inline_documentation/generated/scalar_functions';
import { functions } from '../src/sections/generated/scalar_functions';

(function () {
const pathToElasticsearch = process.argv[2];
const { scalarFunctions, aggregationFunctions } = loadFunctionDocs(pathToElasticsearch);
writeFunctionDocs(
scalarFunctions,
path.join(__dirname, '../src/inline_documentation/generated/scalar_functions.tsx')
path.join(__dirname, '../src/sections/generated/scalar_functions.tsx')
);
writeFunctionDocs(
aggregationFunctions,
path.join(__dirname, '../src/inline_documentation/generated/aggregation_functions.tsx')
path.join(__dirname, '../src/sections/generated/aggregation_functions.tsx')
);
})();

Expand Down Expand Up @@ -86,7 +86,7 @@ function writeFunctionDocs(functionDocs: Map<string, string>, pathToDocsFile: st
// Do not edit manually... automatically generated by scripts/generate_esql_docs.ts
{
label: i18n.translate(
'textBasedEditor.query.textBasedLanguagesEditor.documentationESQL.${name}',
'languageDocumentationPopover.documentationESQL.${name}',
{
defaultMessage: '${name.toUpperCase()}',
}
Expand All @@ -97,7 +97,7 @@ function writeFunctionDocs(functionDocs: Map<string, string>, pathToDocsFile: st
readOnly
enableSoftLineBreaks
markdownContent={i18n.translate(
'textBasedEditor.query.textBasedLanguagesEditor.documentationESQL.${name}.markdown',
'languageDocumentationPopover.documentationESQL.${name}.markdown',
{
defaultMessage: \`${docWithoutLinks.replaceAll('`', '\\`')}\`,
description:
Expand Down
11 changes: 11 additions & 0 deletions packages/kbn-language-documentation-popover/setup_tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

// eslint-disable-next-line import/no-extraneous-dependencies
import '@testing-library/jest-dom';
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import React from 'react';
import { storiesOf } from '@storybook/react';
import { LanguageDocumentationPopover } from '../components/documentation_popover';
import { LanguageDocumentationPopover } from '../components/as_popover';

const sections = {
groups: [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import React from 'react';
import { screen, render, fireEvent, waitFor } from '@testing-library/react';
import { LanguageDocumentationFlyout } from '.';

jest.mock('../../sections', () => {
const module = jest.requireActual('../../sections');
return {
...module,
getESQLDocsSections: () => ({
groups: [
{
label: 'Section one',
description: 'Section 1 description',
items: [],
},
{
label: 'Section two',
items: [
{
label: 'Section two item 1',
description: 'Section two item 1 description',
},
{
label: 'Section two item 2',
description: 'Section two item 2 description',
},
],
},
{
label: 'Section three',
items: [
{
label: 'Section three item 1',
description: 'Section three item 1 description',
},
{
label: 'Section three item 2',
description: 'Section three item 2 description',
},
],
},
],
initialSection: <span>Here is the initial section</span>,
}),
};
});

describe('###Documentation flyout component', () => {
const renderFlyout = (linkToDocumentation?: string) => {
return render(
<LanguageDocumentationFlyout
isHelpMenuOpen={true}
onHelpMenuVisibilityChange={jest.fn()}
linkToDocumentation={linkToDocumentation}
/>
);
};
it('has a header element for navigation through the sections', () => {
renderFlyout();
expect(screen.getByTestId('language-documentation-navigation-search')).toBeInTheDocument();
expect(screen.getByTestId('language-documentation-navigation-dropdown')).toBeInTheDocument();
expect(screen.queryByTestId('language-documentation-navigation-link')).not.toBeInTheDocument();
});

it('has a link if linkToDocumentation prop is given', () => {
renderFlyout('meow');
expect(screen.getByTestId('language-documentation-navigation-link')).toBeInTheDocument();
});

it('contains the two last sections', async () => {
renderFlyout();
await waitFor(() => {
expect(screen.getByText('Section two')).toBeInTheDocument();
expect(screen.getByText('Section three')).toBeInTheDocument();
});
});

it('contains the correct section if user updates the search input', async () => {
renderFlyout();
const input = screen.getByTestId('language-documentation-navigation-search');
fireEvent.change(input, { target: { value: 'two' } });
await waitFor(() => {
expect(screen.getByText('Section two')).toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import React, { useCallback, useEffect, useState, useRef, useMemo } from 'react';
import {
EuiFlyout,
useEuiTheme,
EuiFlyoutBody,
EuiFlyoutHeader,
EuiTitle,
EuiSpacer,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { getFilteredGroups } from '../../utils/get_filtered_groups';
import { DocumentationMainContent, DocumentationNavigation } from '../shared';
import { getESQLDocsSections } from '../../sections';
import type { LanguageDocumentationSections } from '../../types';

interface DocumentationFlyoutProps {
isHelpMenuOpen: boolean;
onHelpMenuVisibilityChange: (status: boolean) => void;
searchInDescription?: boolean;
linkToDocumentation?: string;
}

function DocumentationFlyout({
searchInDescription,
linkToDocumentation,
isHelpMenuOpen,
onHelpMenuVisibilityChange,
}: DocumentationFlyoutProps) {
const [documentationSections, setDocumentationSections] =
useState<LanguageDocumentationSections>();

const { euiTheme } = useEuiTheme();
const DEFAULT_WIDTH = euiTheme.base * 34;

const [selectedSection, setSelectedSection] = useState<string | undefined>();
const [searchText, setSearchText] = useState('');

const scrollTargets = useRef<Record<string, HTMLElement>>({});

const onNavigationChange = useCallback((selectedOptions) => {
setSelectedSection(selectedOptions.length ? selectedOptions[0].label : undefined);
if (selectedOptions.length) {
const scrollToElement = scrollTargets.current[selectedOptions[0].label];
scrollToElement.scrollIntoView();
}
}, []);

useEffect(() => {
onHelpMenuVisibilityChange(isHelpMenuOpen ?? false);
}, [isHelpMenuOpen, onHelpMenuVisibilityChange]);

useEffect(() => {
async function getDocumentation() {
const sections = await getESQLDocsSections();
setDocumentationSections(sections);
}
if (!documentationSections) {
getDocumentation();
}
}, [documentationSections]);

const filteredGroups = useMemo(() => {
return getFilteredGroups(searchText, searchInDescription, documentationSections, 1);
}, [documentationSections, searchText, searchInDescription]);

return (
<>
{isHelpMenuOpen && (
<EuiFlyout
ownFocus
onClose={() => onHelpMenuVisibilityChange(false)}
aria-labelledby="esqlInlineDocumentationFlyout"
type="push"
size={DEFAULT_WIDTH}
paddingSize="m"
>
<EuiFlyoutHeader hasBorder>
<EuiTitle size="s">
<h3>
{i18n.translate('languageDocumentationPopover.documentationFlyoutTitle', {
defaultMessage: 'ES|QL quick reference',
})}
</h3>
</EuiTitle>
<EuiSpacer size="m" />
<DocumentationNavigation
searchText={searchText}
setSearchText={setSearchText}
onNavigationChange={onNavigationChange}
filteredGroups={filteredGroups}
linkToDocumentation={linkToDocumentation}
selectedSection={selectedSection}
/>
</EuiFlyoutHeader>
<EuiFlyoutBody>
<DocumentationMainContent
searchText={searchText}
scrollTargets={scrollTargets}
filteredGroups={filteredGroups}
sections={documentationSections}
/>
</EuiFlyoutBody>
</EuiFlyout>
)}
</>
);
}

export const LanguageDocumentationFlyout = React.memo(DocumentationFlyout);
Loading

0 comments on commit c5ff79a

Please sign in to comment.