forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Insight component #7
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7e2525d
Update AskAssistantButton to include Sparkles from Eui
CoenWarmer a9c59b6
Added Insight component
CoenWarmer e3a67c8
Merge branch 'obs-ai-assistant' into storybook
CoenWarmer d391008
Update i18n translation base key
CoenWarmer cc0f643
Merge branch 'storybook' of github.com:CoenWarmer/kibana into storybook
CoenWarmer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
62 changes: 62 additions & 0 deletions
62
x-pack/plugins/observability_ai_assistant/public/components/feedback_buttons.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,62 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
import { EuiButtonEmpty, EuiFlexGroup, EuiFlexItem, EuiText } from '@elastic/eui'; | ||
|
||
export type Feedback = 'positive' | 'negative'; | ||
|
||
interface FeedbackButtonsProps { | ||
onClickFeedback: (feedback: Feedback) => void; | ||
} | ||
|
||
export function FeedbackButtons({ onClickFeedback }: FeedbackButtonsProps) { | ||
return ( | ||
<EuiFlexGroup responsive={false} direction="row" alignItems="center" gutterSize="s"> | ||
<EuiFlexItem grow={false}> | ||
<EuiText color="subdued" size="s"> | ||
<em> | ||
{i18n.translate('xpack.obsAiAssistant.insight.feedbackButtons.title', { | ||
defaultMessage: 'Was this helpful?', | ||
})} | ||
</em> | ||
</EuiText> | ||
</EuiFlexItem> | ||
|
||
<EuiFlexItem grow={false}> | ||
<EuiFlexGroup responsive={false} direction="row" alignItems="center" gutterSize="xs"> | ||
<EuiFlexItem grow={false}> | ||
<EuiButtonEmpty | ||
color="success" | ||
iconType="faceHappy" | ||
size="s" | ||
onClick={() => onClickFeedback('positive')} | ||
> | ||
{i18n.translate('xpack.obsAiAssistant.insight.feedbackButtons.positive', { | ||
defaultMessage: 'Yes', | ||
})} | ||
</EuiButtonEmpty> | ||
</EuiFlexItem> | ||
|
||
<EuiFlexItem grow={false}> | ||
<EuiButtonEmpty | ||
color="danger" | ||
iconType="faceSad" | ||
size="s" | ||
onClick={() => onClickFeedback('negative')} | ||
> | ||
{i18n.translate('xpack.obsAiAssistant.insight.feedbackButtons.negative', { | ||
defaultMessage: 'No', | ||
})} | ||
</EuiButtonEmpty> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
} |
42 changes: 42 additions & 0 deletions
42
x-pack/plugins/observability_ai_assistant/public/components/insight/insight.stories.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,42 @@ | ||
/* | ||
* 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 { ComponentStory } from '@storybook/react'; | ||
|
||
import { Insight as Component, InsightProps } from './insight'; | ||
import { KibanaReactStorybookDecorator } from '../../utils/storybook_decorator'; | ||
|
||
export default { | ||
component: Component, | ||
title: 'app/Molecules/Insight', | ||
argTypes: { | ||
debug: { | ||
control: { | ||
type: 'boolean', | ||
}, | ||
}, | ||
}, | ||
decorators: [KibanaReactStorybookDecorator], | ||
}; | ||
|
||
const Template: ComponentStory<typeof Component> = (props: InsightProps) => ( | ||
<Component {...props} /> | ||
); | ||
|
||
const defaultProps = { | ||
title: 'Elastic Assistant', | ||
actions: [ | ||
{ id: 'foo', label: 'Put hands in pockets', handler: () => {} }, | ||
{ id: 'bar', label: 'Drop kick', handler: () => {} }, | ||
], | ||
description: 'What is the root cause of performance degradation in my service?', | ||
debug: true, | ||
}; | ||
|
||
export const Insight = Template.bind({}); | ||
Insight.args = defaultProps; |
171 changes: 171 additions & 0 deletions
171
x-pack/plugins/observability_ai_assistant/public/components/insight/insight.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,171 @@ | ||
/* | ||
* 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, { useState } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { | ||
EuiAccordion, | ||
EuiButtonIcon, | ||
EuiContextMenuItem, | ||
EuiContextMenuPanel, | ||
EuiFilterButton, | ||
EuiFilterGroup, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiPanel, | ||
EuiPopover, | ||
EuiSpacer, | ||
EuiText, | ||
useEuiTheme, | ||
} from '@elastic/eui'; | ||
import moment from 'moment'; | ||
import { useKibana } from '@kbn/kibana-react-plugin/public'; | ||
import { AssistantAvatar } from '../assistant_avatar'; | ||
import { InsightMissingCredentials } from './insight_missing_credentials'; | ||
import { InsightError } from './insight_error'; | ||
import { InsightGeneratedResponse } from './insight_generated_response'; | ||
import { Feedback } from '../feedback_buttons'; | ||
|
||
export interface InsightProps { | ||
title: string; | ||
description?: string; | ||
date?: Date; | ||
debug?: boolean; | ||
actions: Array<{ id: string; label: string; icon?: string; handler: () => void }>; | ||
} | ||
|
||
export function Insight({ | ||
title, | ||
description, | ||
date = new Date(), | ||
debug, | ||
actions = [], | ||
}: InsightProps) { | ||
const { euiTheme } = useEuiTheme(); | ||
const { uiSettings } = useKibana().services; | ||
|
||
const dateFormat = uiSettings?.get('dateFormat'); | ||
|
||
const [isActionsPopoverOpen, setIsActionsPopover] = useState(false); | ||
|
||
const [state, setState] = useState<'missing' | 'error' | 'insightGenerated'>('insightGenerated'); | ||
|
||
const handleClickActions = () => { | ||
setIsActionsPopover(!isActionsPopoverOpen); | ||
}; | ||
|
||
const handleFeedback = (feedback: Feedback) => {}; | ||
|
||
const handleRegenerate = () => {}; | ||
|
||
const handleStartChat = () => {}; | ||
|
||
return ( | ||
<EuiPanel hasBorder hasShadow={false}> | ||
<EuiAccordion | ||
id="obsAiAssistantInsight" | ||
arrowProps={{ css: { alignSelf: 'flex-start' } }} | ||
buttonContent={ | ||
<EuiFlexGroup wrap responsive={false} gutterSize="m"> | ||
<EuiFlexItem grow={false}> | ||
<EuiSpacer size="xs" /> | ||
<AssistantAvatar size="xs" /> | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
<EuiText css={{ marginTop: 2, marginBottom: 1 }}> | ||
<h5>{title}</h5> | ||
</EuiText> | ||
|
||
<EuiText size="s" css={{ color: euiTheme.colors.subduedText }}> | ||
<span>{description}</span> | ||
</EuiText> | ||
|
||
<EuiSpacer size="xs" /> | ||
|
||
<EuiText size="xs" css={{ color: euiTheme.colors.subduedText }}> | ||
<strong> | ||
{i18n.translate('xpack.obsAiAssistant.insight.generatedAt', { | ||
defaultMessage: 'Generated at', | ||
})}{' '} | ||
{moment(date).format(dateFormat)} | ||
</strong> | ||
</EuiText> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
} | ||
extraAction={ | ||
<EuiPopover | ||
anchorPosition="downLeft" | ||
button={ | ||
<EuiButtonIcon | ||
aria-label={i18n.translate('xpack.obsAiAssistant.insight.actions', { | ||
defaultMessage: 'Actions', | ||
})} | ||
color="text" | ||
css={{ alignSelf: 'flex-start' }} | ||
disabled={actions.length === 0} | ||
display="empty" | ||
iconType="boxesHorizontal" | ||
size="s" | ||
onClick={handleClickActions} | ||
/> | ||
} | ||
panelPaddingSize="s" | ||
closePopover={handleClickActions} | ||
isOpen={isActionsPopoverOpen} | ||
> | ||
<EuiContextMenuPanel | ||
size="s" | ||
items={actions.map(({ id, icon, label, handler }) => ( | ||
<EuiContextMenuItem key={id} icon={icon} onClick={handler}> | ||
{label} | ||
</EuiContextMenuItem> | ||
))} | ||
/> | ||
</EuiPopover> | ||
} | ||
> | ||
<EuiSpacer size="m" /> | ||
|
||
{/* Debug controls. */} | ||
{debug ? ( | ||
<EuiFilterGroup style={{ position: 'absolute', bottom: 20, left: 20 }}> | ||
<EuiFilterButton | ||
hasActiveFilters={state === 'insightGenerated'} | ||
onClick={() => setState('insightGenerated')} | ||
> | ||
Normal | ||
</EuiFilterButton> | ||
<EuiFilterButton | ||
withNext | ||
hasActiveFilters={state === 'missing'} | ||
onClick={() => setState('missing')} | ||
> | ||
Missing credentials | ||
</EuiFilterButton> | ||
<EuiFilterButton hasActiveFilters={state === 'error'} onClick={() => setState('error')}> | ||
Error | ||
</EuiFilterButton> | ||
</EuiFilterGroup> | ||
) : null} | ||
|
||
{state === 'insightGenerated' ? ( | ||
<InsightGeneratedResponse | ||
answer={''} | ||
onClickFeedback={handleFeedback} | ||
onClickRegenerate={handleRegenerate} | ||
onClickStartChat={handleStartChat} | ||
/> | ||
) : null} | ||
|
||
{state === 'error' ? <InsightError /> : null} | ||
|
||
{state === 'missing' ? <InsightMissingCredentials /> : null} | ||
</EuiAccordion> | ||
</EuiPanel> | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be
xpack.observabilityAiAssistant
(as configured in x-pack/.i18nrc.json)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated