diff --git a/packages/kbn-language-documentation/scripts/generate_esql_docs.ts b/packages/kbn-language-documentation/scripts/generate_esql_docs.ts index 072d53a02753a..da42dc7a44480 100644 --- a/packages/kbn-language-documentation/scripts/generate_esql_docs.ts +++ b/packages/kbn-language-documentation/scripts/generate_esql_docs.ts @@ -13,6 +13,11 @@ import fs from 'fs'; import path from 'path'; import { functions } from '../src/sections/generated/scalar_functions'; +interface DocsSectionContent { + description: string; + preview?: boolean; +} + (function () { const pathToElasticsearch = process.argv[2]; const { scalarFunctions, aggregationFunctions } = loadFunctionDocs(pathToElasticsearch); @@ -41,8 +46,8 @@ function loadFunctionDocs(pathToElasticsearch: string) { .readdirSync(definitionsPath) .map((file) => JSON.parse(fs.readFileSync(`${definitionsPath}/${file}`, 'utf-8'))); - const scalarFunctions = new Map(); - const aggregationFunctions = new Map(); + const scalarFunctions = new Map(); + const aggregationFunctions = new Map(); // Iterate over each file in the directory for (const file of docsFiles) { @@ -64,10 +69,16 @@ function loadFunctionDocs(pathToElasticsearch: string) { // Add the function name and content to the map if (functionDefinition.type === 'eval') { - scalarFunctions.set(functionName, content); + scalarFunctions.set(functionName, { + description: content, + preview: functionDefinition.preview, + }); } if (functionDefinition.type === 'agg') { - aggregationFunctions.set(functionName, content); + aggregationFunctions.set(functionName, { + description: content, + preview: functionDefinition.preview, + }); } } } @@ -75,10 +86,10 @@ function loadFunctionDocs(pathToElasticsearch: string) { return { scalarFunctions, aggregationFunctions }; } -function writeFunctionDocs(functionDocs: Map, pathToDocsFile: string) { +function writeFunctionDocs(functionDocs: Map, pathToDocsFile: string) { const codeStrings = Array.from(functionDocs.entries()).map(([name, doc]) => { const docWithoutLinks = removeAsciiDocInternalCrossReferences( - doc, + doc.description, Array.from(functionDocs.keys()) ); return ` @@ -91,6 +102,7 @@ function writeFunctionDocs(functionDocs: Map, pathToDocsFile: st defaultMessage: '${name.toUpperCase()}', } ), + preview: ${doc.preview || false}, description: ( ; + options: Array<{ label: string; description?: JSX.Element | undefined; preview?: boolean }>; }>; sections?: LanguageDocumentationSections; } @@ -76,6 +77,23 @@ function DocumentationContent({ } }} > + {helpItem.preview && ( + + )} {helpItem.description} ); diff --git a/packages/kbn-language-documentation/src/sections/generated/aggregation_functions.tsx b/packages/kbn-language-documentation/src/sections/generated/aggregation_functions.tsx index 14a824c3183ee..6fe761e489c04 100644 --- a/packages/kbn-language-documentation/src/sections/generated/aggregation_functions.tsx +++ b/packages/kbn-language-documentation/src/sections/generated/aggregation_functions.tsx @@ -29,6 +29,7 @@ export const functions = { label: i18n.translate('languageDocumentation.documentationESQL.avg', { defaultMessage: 'AVG', }), + preview: false, description: (