From b1cf5b651938b35556f23024c7e7decf44cd28bf Mon Sep 17 00:00:00 2001 From: Joseph McElroy Date: Fri, 23 Feb 2024 13:58:52 +0000 Subject: [PATCH] changes for fields redesign --- .../kbn-ai-playground/components/index.ts | 1 + .../components/view_code/view_code_action.tsx | 95 ++++++++++++ .../view_query/view_query_action.tsx | 140 ++++++++++++------ .../ai_playground/ai_playground.tsx | 13 +- 4 files changed, 202 insertions(+), 47 deletions(-) create mode 100644 packages/kbn-ai-playground/components/view_code/view_code_action.tsx diff --git a/packages/kbn-ai-playground/components/index.ts b/packages/kbn-ai-playground/components/index.ts index 491553ffd7093..a72022959034a 100644 --- a/packages/kbn-ai-playground/components/index.ts +++ b/packages/kbn-ai-playground/components/index.ts @@ -10,3 +10,4 @@ export * from './chat'; export * from './empty_index'; export * from './view_query/view_query_action'; +export * from './view_code/view_code_action'; diff --git a/packages/kbn-ai-playground/components/view_code/view_code_action.tsx b/packages/kbn-ai-playground/components/view_code/view_code_action.tsx new file mode 100644 index 0000000000000..9c1ddd753b90e --- /dev/null +++ b/packages/kbn-ai-playground/components/view_code/view_code_action.tsx @@ -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 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 or the Server + * Side Public License, v 1. + */ + +import React, { useState } from 'react'; +import { + EuiFlyout, + EuiFlyoutHeader, + EuiFlyoutBody, + EuiTitle, + EuiCodeBlock, + EuiButton, + EuiText, + EuiSpacer, + EuiSteps, + EuiCode, +} from '@elastic/eui'; +import { useFormContext } from 'react-hook-form'; +import { ChatForm } from '../../types'; + +interface ViewCodeActionProps {} + +export const ViewCodeAction: React.FC = () => { + const { getValues } = useFormContext(); + const [showFlyout, setShowFlyout] = useState(false); + const selectedIndices: string[] = getValues('indices'); + + let flyout; + + const steps = [ + { + title: 'Generate and copy an API key', + children: ( + <> + +

Run this code snippet to install things.

+
+ + npm install + + ), + }, + { + title: 'Create application', + children: ( + +

+ Now that you've completed step 2, go find the thing. +

+

+ Go to Overview >> Endpoints note Elasticsearch{' '} + as <thing>. +

+
+ ), + }, + ]; + + if (showFlyout) { + flyout = ( + setShowFlyout(false)}> + + +

Download Code

+
+ + +

Download the code to use in your application.

+
+
+ + + +
+ ); + } + + return ( + <> + {flyout} + setShowFlyout(true)} + disabled={!selectedIndices || selectedIndices?.length === 0} + > + Download Code + + + ); +}; diff --git a/packages/kbn-ai-playground/components/view_query/view_query_action.tsx b/packages/kbn-ai-playground/components/view_query/view_query_action.tsx index 62fde840b9390..e9755ef63280a 100644 --- a/packages/kbn-ai-playground/components/view_query/view_query_action.tsx +++ b/packages/kbn-ai-playground/components/view_query/view_query_action.tsx @@ -16,8 +16,14 @@ import { EuiFlexItem, EuiFlexGroup, EuiButtonEmpty, - EuiLink, EuiButton, + EuiFlyoutFooter, + EuiSpacer, + EuiText, + EuiPanel, + EuiAccordion, + EuiBasicTable, + EuiSwitch, } from '@elastic/eui'; import { useController, useFormContext } from 'react-hook-form'; import { ChatForm, ChatFormFields } from '../../types'; @@ -70,66 +76,110 @@ export const ViewQueryAction: React.FC = () => { setShowFlyout(false); }; + const closeFlyout = () => setShowFlyout(false); + let flyout; if (showFlyout) { flyout = ( - setShowFlyout(false)}> + setShowFlyout(false)} size="l"> -

View Query

+

Customise your Elasticsearch Query

+ + +

+ The query that will be used to search your data. You can customise it by choosing + which fields to search on. +

+
- - + + {JSON.stringify(createQuery(queryFields, fields), null, 2)} - - {Object.keys(fields).map((index: string) => { - const group = fields[index]; - return ( - <> -

{index}

-
- {[...group.elser_query_fields, ...group.dense_vector_query_fields].map( - (field) => { - return ( - toggleQueryField(index, field.field)} - color={isQueryFieldSelected(index, field.field) ? 'primary' : 'text'} - > - {field.field} ({field.model_id}) - - ); - } - )} - {group.bm25_query_fields.map((field) => { - return ( - toggleQueryField(index, field)} - color={isQueryFieldSelected(index, field) ? 'primary' : 'text'} + + + +
Selected Fields
+
+ {Object.keys(fields).map((index: string) => { + const group = fields[index]; + return ( + + + +
{index}
+ + } > - {field} -
- ); - })} - - ); - })} + + ({ + field: typeof field === 'string' ? field : field.field, + }))} + columns={[ + { + field: 'field', + name: 'Field', + truncateText: false, + render: (field) => field, + }, + { + actions: [ + { + name: 'toggle', + description: 'Toggle field', + isPrimary: true, + render: ({ field }: { field: string }) => ( + toggleQueryField(index, field)} + compressed + /> + ), + }, + ], + }, + ]} + hasActions + /> + + +
+ ); + })} +
- - - setShowFlyout(false)}>Close +
+ + + + + Close + - - Save + + + Save changes + - +
); } @@ -137,9 +187,9 @@ export const ViewQueryAction: React.FC = () => { return ( <> {flyout} - {selectedIndices?.length > 0 && ( - setShowFlyout(true)}>View Query - )} + setShowFlyout(true)} disabled={selectedIndices?.length === 0}> + View Query + ); }; diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/ai_playground/ai_playground.tsx b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/ai_playground/ai_playground.tsx index 40b26e2bff5ac..0dc0eeee55d04 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/ai_playground/ai_playground.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/ai_playground/ai_playground.tsx @@ -10,7 +10,13 @@ import React, { useCallback, useEffect } from 'react'; import { useValues, useActions } from 'kea'; import { EuiPageTemplate } from '@elastic/eui'; -import { Chat, EmptyIndex, AIPlaygroundProvider, ViewQueryAction } from '@kbn/ai-playground'; +import { + Chat, + EmptyIndex, + AIPlaygroundProvider, + ViewQueryAction, + ViewCodeAction, +} from '@kbn/ai-playground'; import { i18n } from '@kbn/i18n'; import { KibanaLogic } from '../../../shared/kibana'; @@ -46,7 +52,10 @@ export const AIPlayground: React.FC = () => { pageTitle: i18n.translate('xpack.enterpriseSearch.content.aiPlayground.headerTitle', { defaultMessage: 'AI Playground', }), - rightSideItems: [], + rightSideItems: [ + , + , + ], }} pageViewTelemetry="AI Playground" restrictWidth={false}