forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request elastic#4 from Samiul-TheSoccerFan/empty-state-for…
…-ai-playground
- Loading branch information
Showing
18 changed files
with
298 additions
and
136 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...ic/applications/enterprise_search_content/components/ai_playground/ai_playground.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { setMockValues } from '../../../__mocks__/kea_logic'; | ||
|
||
import React from 'react'; | ||
|
||
import { shallow } from 'enzyme'; | ||
|
||
import { AIPlayground } from './ai_playground'; | ||
import { Chat } from './components/chat'; | ||
import { EmptyIndex } from './components/empty_index'; | ||
|
||
describe('AI Playground', () => { | ||
describe('Empty state', () => { | ||
it('renders when Indices are empty', () => { | ||
setMockValues({ | ||
hasNoIndices: true, | ||
}); | ||
|
||
const wrapper = shallow(<AIPlayground />); | ||
|
||
expect(wrapper.find(EmptyIndex)).toHaveLength(1); | ||
}); | ||
}); | ||
|
||
it('renders when indices are available', () => { | ||
setMockValues({ | ||
hasNoIndices: false, | ||
}); | ||
|
||
const wrapper = shallow(<AIPlayground />); | ||
|
||
expect(wrapper.find(EmptyIndex)).toHaveLength(0); | ||
expect(wrapper.find(Chat)).toHaveLength(1); | ||
}); | ||
}); |
68 changes: 68 additions & 0 deletions
68
.../public/applications/enterprise_search_content/components/ai_playground/ai_playground.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { useEffect } from 'react'; | ||
|
||
import { useValues, useActions } from 'kea'; | ||
|
||
import { EuiPageTemplate } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { EnterpriseSearchContentPageTemplate } from '../layout/page_template'; | ||
|
||
import { IndicesLogic } from '../search_indices/indices_logic'; | ||
|
||
import { Chat } from './components/chat'; | ||
import { EmptyIndex } from './components/empty_index'; | ||
|
||
export const AIPlayground: React.FC = () => { | ||
const { fetchIndices } = useActions(IndicesLogic); | ||
const { hasNoIndices, isLoading } = useValues(IndicesLogic); | ||
|
||
useEffect(() => { | ||
fetchIndices({ | ||
from: 0, | ||
onlyShowSearchOptimizedIndices: false, | ||
returnHiddenIndices: false, | ||
size: 20, | ||
}); | ||
}, []); | ||
|
||
return ( | ||
<EnterpriseSearchContentPageTemplate | ||
pageChrome={[ | ||
i18n.translate('xpack.enterpriseSearch.content.aiPlayground.breadcrumb', { | ||
defaultMessage: 'AI Playground', | ||
}), | ||
]} | ||
pageHeader={{ | ||
pageTitle: i18n.translate('xpack.enterpriseSearch.content.aiPlayground.headerTitle', { | ||
defaultMessage: 'AI Playground', | ||
}), | ||
rightSideItems: [], | ||
}} | ||
pageViewTelemetry="AI Playground" | ||
isLoading={isLoading} | ||
customPageSections | ||
bottomBorder="extended" | ||
> | ||
{hasNoIndices ? ( | ||
<EmptyIndex /> | ||
) : ( | ||
<EuiPageTemplate.Section | ||
alignment="top" | ||
restrictWidth={false} | ||
grow | ||
contentProps={{ css: { display: 'flex', flexGrow: 1 } }} | ||
paddingSize="none" | ||
> | ||
<Chat /> | ||
</EuiPageTemplate.Section> | ||
)} | ||
</EnterpriseSearchContentPageTemplate> | ||
); | ||
}; |
48 changes: 0 additions & 48 deletions
48
...lications/enterprise_search_content/components/ai_playground/components/ai_playground.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 6 additions & 7 deletions
13
...plications/enterprise_search_content/components/ai_playground/components/chat_sidebar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...ations/enterprise_search_content/components/ai_playground/components/empty_index.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { mockKibanaValues } from '../../../../__mocks__/kea_logic'; | ||
|
||
import React from 'react'; | ||
|
||
import { mount } from 'enzyme'; | ||
|
||
import { EuiButton, EuiEmptyPrompt } from '@elastic/eui'; | ||
|
||
import { NEW_INDEX_PATH } from '../../../routes'; | ||
|
||
import { EmptyIndex } from './empty_index'; | ||
|
||
describe('Empty state', () => { | ||
it('renders the empty state component', () => { | ||
const wrapper = mount(<EmptyIndex />); | ||
|
||
expect(wrapper.find(EuiEmptyPrompt)).toHaveLength(1); | ||
expect(wrapper.find(EuiButton)).toHaveLength(1); | ||
}); | ||
|
||
it('clicking in navigates to new index page', () => { | ||
const { navigateToUrl } = mockKibanaValues; | ||
|
||
const wrapper = mount(<EmptyIndex />); | ||
// @ts-ignore | ||
wrapper.find(EuiButton).props().onClick(); | ||
|
||
expect(navigateToUrl).toHaveBeenCalledTimes(1); | ||
expect(navigateToUrl).toHaveBeenCalledWith(NEW_INDEX_PATH); | ||
}); | ||
}); |
66 changes: 66 additions & 0 deletions
66
...pplications/enterprise_search_content/components/ai_playground/components/empty_index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { EuiButton, EuiEmptyPrompt, EuiFlexGroup, EuiFlexItem, EuiPanel } from '@elastic/eui'; | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { KibanaLogic } from '../../../../shared/kibana'; | ||
import { NEW_INDEX_PATH } from '../../../routes'; | ||
|
||
export const EmptyIndex: React.FC = () => { | ||
return ( | ||
<EuiFlexGroup gutterSize="l"> | ||
<EuiFlexItem> | ||
<EuiPanel> | ||
<EuiEmptyPrompt | ||
title={ | ||
<h2> | ||
{i18n.translate( | ||
'xpack.enterpriseSearch.content.aiPlayground.emptyIndex.h2.addData', | ||
{ | ||
defaultMessage: 'Add data', | ||
} | ||
)} | ||
</h2> | ||
} | ||
iconType="plusInCircle" | ||
titleSize="m" | ||
body={ | ||
<p> | ||
{i18n.translate( | ||
'xpack.enterpriseSearch.content.aiPlayground.emptyIndex.p.addDataAndIndexLabel', | ||
{ | ||
defaultMessage: 'To use the AI Playground, create an index and add some data.', | ||
} | ||
)} | ||
</p> | ||
} | ||
actions={ | ||
<EuiButton | ||
color="primary" | ||
disabled={false} | ||
fill | ||
iconType="plusInCircle" | ||
onClick={() => KibanaLogic.values.navigateToUrl(NEW_INDEX_PATH)} | ||
> | ||
{i18n.translate( | ||
'xpack.enterpriseSearch.content.aiPlayground.emptyIndex.newIndexButtonLabel', | ||
{ | ||
defaultMessage: 'Create an index', | ||
} | ||
)} | ||
</EuiButton> | ||
} | ||
/> | ||
</EuiPanel> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
}; |
11 changes: 5 additions & 6 deletions
11
...ions/enterprise_search_content/components/ai_playground/components/instructions_field.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 10 additions & 8 deletions
18
...ise_search_content/components/ai_playground/components/message_list/assistant_message.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 5 additions & 6 deletions
11
...se_search_content/components/ai_playground/components/message_list/copy_action_button.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.