Skip to content

Commit

Permalink
[Search][Playground] Update UI (#187608)
Browse files Browse the repository at this point in the history
## Summary

Summarize your PR. If it involves visual changes include a screenshot or
gif.


### Checklist

Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)


### Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to
identify risks that should be tested prior to the change/feature
release.

When forming the risk matrix, consider some of the following examples
and how they may potentially impact the change:

| Risk | Probability | Severity | Mitigation/Notes |

|---------------------------|-------------|----------|-------------------------|
| Multiple Spaces—unexpected behavior in non-default Kibana Space.
| Low | High | Integration tests will verify that all features are still
supported in non-default Kibana Space and when user switches between
spaces. |
| Multiple nodes—Elasticsearch polling might have race conditions
when multiple Kibana nodes are polling for the same tasks. | High | Low
| Tasks are idempotent, so executing them multiple times will not result
in logical error, but will degrade performance. To test for this case we
add plenty of unit tests around this logic and document manual testing
procedure. |
| Code should gracefully handle cases when feature X or plugin Y are
disabled. | Medium | High | Unit tests will verify that any feature flag
or plugin combination still results in our service operational. |
| [See more potential risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) |


### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: Joseph McElroy <[email protected]>
  • Loading branch information
yansavitski and joemcelroy authored Jul 10, 2024
1 parent 6f168b5 commit 77267b2
Show file tree
Hide file tree
Showing 59 changed files with 1,490 additions and 1,879 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ import React from 'react';

import { useValues } from 'kea';

import { EuiBetaBadge, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import { FormattedMessage } from '@kbn/i18n-react';

import { KibanaLogic } from '../../../shared/kibana';
import { EnterpriseSearchApplicationsPageTemplate } from '../layout/page_template';

Expand All @@ -31,32 +28,9 @@ export const Playground: React.FC = () => {
defaultMessage: 'Playground',
}),
]}
pageHeader={{
pageTitle: (
<EuiFlexGroup>
<EuiFlexItem grow={false}>
<FormattedMessage
id="xpack.enterpriseSearch.content.playground.headerTitle"
defaultMessage="Playground"
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiBetaBadge
label={i18n.translate(
'xpack.enterpriseSearch.content.playground.headerTitle.techPreview',
{
defaultMessage: 'TECH PREVIEW',
}
)}
color="hollow"
/>
</EuiFlexItem>
</EuiFlexGroup>
),
rightSideItems: [<searchPlayground.PlaygroundToolbar />],
}}
pageViewTelemetry="Playground"
restrictWidth={false}
panelled={false}
customPageSections
bottomBorder="extended"
docLink="playground"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export type Start = jest.Mocked<SearchPlaygroundPluginStart>;
const createStartMock = (): Start => {
const startContract: Start = {
PlaygroundProvider: jest.fn(),
PlaygroundToolbar: jest.fn(),
Playground: jest.fn(),
PlaygroundHeaderDocs: jest.fn(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,21 @@ export enum AnalyticsEvents {
chatRegenerateMessages = 'chat_regenerate_messages',
citationDetailsExpanded = 'citation_details_expanded',
citationDetailsCollapsed = 'citation_details_collapsed',
editContextFlyoutOpened = 'edit_context_flyout_opened',
editContextFieldToggled = 'edit_context_field_toggled',
editContextDocSizeChanged = 'edit_context_doc_size_changed',
editContextSaved = 'edit_context_saved',
genAiConnectorAdded = 'gen_ai_connector_added',
genAiConnectorCreated = 'gen_ai_connector_created',
genAiConnectorExists = 'gen_ai_connector_exists',
genAiConnectorSetup = 'gen_ai_connector_setup',
includeCitations = 'include_citations',
instructionsFieldChanged = 'instructions_field_changed',
queryFieldsUpdated = 'view_query_fields_updated',
queryModeLoaded = 'query_mode_loaded',
modelSelected = 'model_selected',
retrievalDocsFlyoutOpened = 'retrieval_docs_flyout_opened',
sourceFieldsLoaded = 'source_fields_loaded',
sourceIndexUpdated = 'source_index_updated',
startNewChatPageLoaded = 'start_new_chat_page_loaded',
viewQueryFlyoutOpened = 'view_query_flyout_opened',
viewQueryFieldsUpdated = 'view_query_fields_updated',
viewQuerySaved = 'view_query_saved',
setupChatPageLoaded = 'start_new_chat_page_loaded',
viewCodeFlyoutOpened = 'view_code_flyout_opened',
viewCodeLanguageChange = 'view_code_language_change',
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
* 2.0.
*/

import { i18n } from '@kbn/i18n';
import React, { useMemo } from 'react';
import { EuiBetaBadge, EuiFlexGroup, EuiFlexItem, EuiPageTemplate, EuiTitle } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { EuiPageTemplate } from '@elastic/eui';
import { QueryClientProvider } from '@tanstack/react-query';
import { queryClient } from './utils/query_client';
import { PlaygroundProvider } from './providers/playground_provider';

import { App } from './components/app';
import { PlaygroundToolbar } from './embeddable';
import { PlaygroundHeaderDocs } from './components/playground_header_docs';
import { useKibana } from './hooks/use_kibana';

export const ChatPlaygroundOverview: React.FC = () => {
Expand All @@ -27,46 +25,19 @@ export const ChatPlaygroundOverview: React.FC = () => {
);

return (
<PlaygroundProvider>
<EuiPageTemplate
offset={0}
restrictWidth={false}
data-test-subj="svlPlaygroundPage"
grow={false}
>
<EuiPageTemplate.Header
css={{ '.euiPageHeaderContent > .euiFlexGroup': { flexWrap: 'wrap' } }}
pageTitle={
<EuiFlexGroup>
<EuiFlexItem grow={false}>
<EuiTitle
css={{ whiteSpace: 'nowrap' }}
data-test-subj="chat-playground-home-page-title"
>
<h2>
<FormattedMessage
id="xpack.searchPlayground.pageTitle"
defaultMessage="Playground"
/>
</h2>
</EuiTitle>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiBetaBadge
label={i18n.translate('xpack.searchPlayground.pageTitle.techPreview', {
defaultMessage: 'TECH PREVIEW',
})}
color="hollow"
/>
</EuiFlexItem>
</EuiFlexGroup>
}
data-test-subj="chat-playground-home-page"
rightSideItems={[<PlaygroundHeaderDocs />, <PlaygroundToolbar />]}
/>
<App />
{embeddableConsole}
</EuiPageTemplate>
</PlaygroundProvider>
<QueryClientProvider client={queryClient}>
<PlaygroundProvider>
<EuiPageTemplate
offset={0}
restrictWidth={false}
data-test-subj="svlPlaygroundPage"
grow={false}
panelled={false}
>
<App showDocs />
{embeddableConsole}
</EuiPageTemplate>
</PlaygroundProvider>
</QueryClientProvider>
);
};
67 changes: 50 additions & 17 deletions x-pack/plugins/search_playground/public/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,61 @@
* 2.0.
*/

import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import { KibanaPageTemplate } from '@kbn/shared-ux-page-kibana-template';

import { StartNewChat } from './start_new_chat';
import { useFormContext } from 'react-hook-form';
import { QueryMode } from './query_mode/query_mode';
import { SetupPage } from './setup_page/setup_page';
import { Header } from './header';
import { useLoadConnectors } from '../hooks/use_load_connectors';
import { ChatForm, ChatFormFields } from '../types';
import { Chat } from './chat';

export const App: React.FC = () => {
const [showStartPage, setShowStartPage] = useState(true);
export interface AppProps {
showDocs?: boolean;
}

export enum ViewMode {
chat = 'chat',
query = 'query',
}

export const App: React.FC<AppProps> = ({ showDocs = false }) => {
const [showSetupPage, setShowSetupPage] = useState(true);
const [selectedMode, setSelectedMode] = useState<ViewMode>(ViewMode.chat);
const { watch } = useFormContext<ChatForm>();
const { data: connectors } = useLoadConnectors();
const hasSelectedIndices = watch(ChatFormFields.indices).length;
const handleModeChange = (id: string) => setSelectedMode(id as ViewMode);

useEffect(() => {
if (showSetupPage && connectors?.length && hasSelectedIndices) {
setShowSetupPage(false);
}
}, [connectors, hasSelectedIndices, showSetupPage]);

return (
<KibanaPageTemplate.Section
alignment="top"
restrictWidth={false}
grow
css={{
position: 'relative',
}}
contentProps={{ css: { display: 'flex', flexGrow: 1, position: 'absolute', inset: 0 } }}
paddingSize="none"
className="eui-fullHeight"
>
{showStartPage ? <StartNewChat onStartClick={() => setShowStartPage(false)} /> : <Chat />}
</KibanaPageTemplate.Section>
<>
<Header
showDocs={showDocs}
onModeChange={handleModeChange}
selectedMode={selectedMode}
isActionsDisabled={showSetupPage}
/>
<KibanaPageTemplate.Section
alignment="top"
restrictWidth={false}
grow
css={{
position: 'relative',
}}
contentProps={{ css: { display: 'flex', flexGrow: 1, position: 'absolute', inset: 0 } }}
paddingSize="none"
className="eui-fullHeight"
>
{showSetupPage ? <SetupPage /> : selectedMode === ViewMode.chat ? <Chat /> : <QueryMode />}
</KibanaPageTemplate.Section>
</>
);
};
20 changes: 11 additions & 9 deletions x-pack/plugins/search_playground/public/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
EuiFlexGroup,
EuiFlexItem,
EuiForm,
EuiHideFor,
EuiHorizontalRule,
EuiSpacer,
useEuiTheme,
Expand Down Expand Up @@ -50,14 +51,12 @@ export const Chat = () => {
const { euiTheme } = useEuiTheme();
const {
control,
watch,
formState: { isValid, isSubmitting },
resetField,
handleSubmit,
getValues,
} = useFormContext<ChatForm>();
const { messages, append, stop: stopRequest, setMessages, reload, error } = useChat();
const selectedIndicesCount = watch(ChatFormFields.indices, []).length;
const messagesRef = useAutoBottomScroll();
const [isRegenerating, setIsRegenerating] = useState<boolean>(false);
const usageTracker = useUsageTracker();
Expand Down Expand Up @@ -123,7 +122,6 @@ export const Chat = () => {
<EuiFlexItem
grow={2}
css={{
borderRight: euiTheme.border.thin,
paddingTop: euiTheme.size.l,
paddingBottom: euiTheme.size.l,
// don't allow the chat to shrink below 66.6% of the screen
Expand All @@ -149,14 +147,15 @@ export const Chat = () => {
>
<EuiHorizontalRule margin="none" />

<EuiSpacer size="m" />
<EuiSpacer size="s" />

<EuiFlexGroup>
<EuiFlexGroup responsive={false}>
<EuiFlexItem grow={false}>
<EuiButtonEmpty
iconType="sparkles"
disabled={isToolBarActionsDisabled}
onClick={regenerateMessages}
size="xs"
data-test-subj="regenerateActionButton"
>
<FormattedMessage
Expand All @@ -170,6 +169,7 @@ export const Chat = () => {
iconType="refresh"
disabled={isToolBarActionsDisabled}
onClick={handleClearChat}
size="xs"
data-test-subj="clearChatActionButton"
>
<FormattedMessage
Expand All @@ -180,7 +180,7 @@ export const Chat = () => {
</EuiFlexItem>
</EuiFlexGroup>

<EuiSpacer size="m" />
<EuiSpacer size="s" />

<Controller
name={ChatFormFields.question}
Expand Down Expand Up @@ -234,9 +234,11 @@ export const Chat = () => {
</EuiFlexGroup>
</EuiFlexItem>

<EuiFlexItem grow={1} css={{ flexBasis: 0, minWidth: '33.3%' }}>
<ChatSidebar selectedIndicesCount={selectedIndicesCount} />
</EuiFlexItem>
<EuiHideFor sizes={['xs', 's']}>
<EuiFlexItem grow={1} css={{ flexBasis: 0, minWidth: '33.3%' }}>
<ChatSidebar />
</EuiFlexItem>
</EuiHideFor>
</EuiFlexGroup>
</EuiForm>
);
Expand Down
Loading

0 comments on commit 77267b2

Please sign in to comment.