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#7 from Samiul-TheSoccerFan/open-ai-flyout
Open ai flyout
- Loading branch information
Showing
5 changed files
with
198 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* 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 { OpenAIKeyCallout } from "./open_ai_key_callout"; | ||
|
||
import { OpenAIKeyFlyOut } from "./open_ai_key_flyout"; | ||
|
||
interface OpenAIKeyProps { | ||
apiKey: string; | ||
onSave: () => void; | ||
} | ||
|
||
export const OpenAIKey: React.FC<OpenAIKeyProps> = ({ apiKey, onSave }) => { | ||
const [isOpenAIFlyOutOpen, setIsOpenAIFlyOutOpen] = useState<boolean>(false); | ||
|
||
const onCloseOpenAIFlyOut = () => { | ||
setIsOpenAIFlyOutOpen(!isOpenAIFlyOutOpen); | ||
}; | ||
|
||
return ( | ||
<> | ||
{isOpenAIFlyOutOpen && <OpenAIKeyFlyOut openAPIKey={apiKey} onSave={onSave} onClose={onCloseOpenAIFlyOut} />} | ||
<OpenAIKeyCallout setIsOpenAIFlyOutOpen={setIsOpenAIFlyOutOpen} /> | ||
</> | ||
); | ||
} |
53 changes: 53 additions & 0 deletions
53
packages/kbn-ai-playground/components/open_ai_key_callout.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,53 @@ | ||
/* | ||
* 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, EuiCallOut } from "@elastic/eui"; | ||
|
||
import { i18n } from "@kbn/i18n"; | ||
|
||
interface OpenAIKeyCalloutProps { | ||
setIsOpenAIFlyOutOpen: (flyOut: boolean) => void; | ||
} | ||
|
||
export const OpenAIKeyCallout: React.FC<OpenAIKeyCalloutProps> = ({ setIsOpenAIFlyOutOpen }) => { | ||
return ( | ||
<EuiCallOut | ||
title={i18n.translate( | ||
'aiPlayground.sidebar.openAICallout.headerText', | ||
{ | ||
defaultMessage: 'Add OpenAI API Key', | ||
} | ||
)} | ||
color="warning" | ||
iconType="warning" | ||
> | ||
<p> | ||
{i18n.translate( | ||
'aiPlayground.sidebar.openAICallout.description', | ||
{ | ||
defaultMessage: 'The AI Playground uses OpenAl models for summarization. Add your OpenAI API key to continue.', | ||
} | ||
)} | ||
</p> | ||
<EuiButton | ||
onClick={() => setIsOpenAIFlyOutOpen(true)} | ||
color="warning" | ||
fill | ||
data-test-subj="openaiflyout-open" | ||
> | ||
{i18n.translate( | ||
'aiPlayground.sidebar.openAICallout.buttonLabelText', | ||
{ | ||
defaultMessage: 'Add OpenAI API Key', | ||
} | ||
)} | ||
</EuiButton> | ||
</EuiCallOut> | ||
); | ||
}; |
102 changes: 102 additions & 0 deletions
102
packages/kbn-ai-playground/components/open_ai_key_flyout.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,102 @@ | ||
/* | ||
* 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 { EuiButton, EuiButtonEmpty, EuiFieldText, EuiFlexGroup, EuiFlexItem, EuiFlyout, EuiFlyoutBody, EuiFlyoutFooter, EuiFlyoutHeader, EuiFormRow, EuiLink, EuiSpacer, EuiText, EuiTitle } from "@elastic/eui"; | ||
import { i18n } from "@kbn/i18n"; | ||
import React, { useState } from "react"; | ||
|
||
export interface OpenAIKeyFlyOutProps { | ||
openAPIKey: string; | ||
onClose: () => void; | ||
onSave: (key: string) => void; | ||
} | ||
|
||
export const OpenAIKeyFlyOut: React.FC<OpenAIKeyFlyOutProps> = ({ openAPIKey, onClose, onSave }) => { | ||
const [apiKey, setApiKey] = useState<string>(openAPIKey); | ||
|
||
const handleSave = () => { | ||
onSave(apiKey); | ||
onClose(); | ||
} | ||
|
||
return ( | ||
<EuiFlyout onClose={onClose} size="m"> | ||
<EuiFlyoutHeader> | ||
<EuiTitle size="m"> | ||
<h3> | ||
{i18n.translate( | ||
'aiPlayground.sidebar.openAIFlyOut.headerTitle', | ||
{ | ||
defaultMessage: 'OpenAI API Key', | ||
} | ||
)} | ||
</h3> | ||
</EuiTitle> | ||
<EuiSpacer size="s" /> | ||
</EuiFlyoutHeader> | ||
<EuiFlyoutBody> | ||
<EuiFlexGroup direction="column" gutterSize="l"> | ||
<EuiFormRow | ||
fullWidth | ||
label={i18n.translate( | ||
'aiPlayground.sidebar.openAIFlyOut.labelTitle', | ||
{ defaultMessage: 'OpenAI API Key' } | ||
)} | ||
labelAppend={ | ||
<EuiText size="xs"> | ||
<EuiLink target="_blank" href="https://platform.openai.com/api-keys">OpenAI API Keys</EuiLink> | ||
</EuiText> | ||
}> | ||
<EuiFlexItem grow> | ||
<EuiFieldText | ||
fullWidth | ||
placeholder={i18n.translate( | ||
'aiPlayground.sidebar.openAIFlyOut.placeholder', | ||
{ defaultMessage: 'Enter API Key here' } | ||
)} | ||
value={apiKey} | ||
onChange={(e) => setApiKey(e.target.value)} | ||
/> | ||
</EuiFlexItem> | ||
</EuiFormRow> | ||
</EuiFlexGroup> | ||
</EuiFlyoutBody> | ||
<EuiFlyoutFooter> | ||
<EuiFlexGroup> | ||
<EuiFlexItem grow={false}> | ||
<EuiButtonEmpty | ||
data-telemetry-id="entSearchAIPlayground-addingOpenAIKey-cancel" | ||
onClick={onClose} | ||
> | ||
{i18n.translate('aiPlayground.sidebar.openAIFlyOut.cancelButtonLabel', | ||
{ | ||
defaultMessage: 'Cancel', | ||
}) | ||
} | ||
</EuiButtonEmpty> | ||
</EuiFlexItem> | ||
<EuiFlexItem /> | ||
<EuiFlexItem grow={false}> | ||
<EuiButton | ||
isDisabled={!apiKey.trim()} | ||
data-telemetry-id="entSearchAIPlayground-addingOpenAIKey-save" | ||
fill | ||
onClick={handleSave} | ||
> | ||
{i18n.translate( | ||
'aiPlayground.sidebar.openAIFlyOut.saveButtonLabel', | ||
{ | ||
defaultMessage: 'Save', | ||
} | ||
)} | ||
</EuiButton> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiFlyoutFooter> | ||
</EuiFlyout> | ||
); | ||
}; |
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