forked from opensearch-project/dashboards-assistant
-
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.
Support creating alert in the chat window
Signed-off-by: Heng Qian <[email protected]>
- Loading branch information
1 parent
2421ad3
commit 302123a
Showing
12 changed files
with
275 additions
and
43 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
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
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
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 OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { EuiButtonEmpty, EuiButtonIcon, EuiFlexGroup, EuiFlexItem, EuiIcon } from '@elastic/eui'; | ||
import React, { useCallback } from 'react'; | ||
import { IChatContext, useChatContext } from '../contexts/chat_context'; | ||
import { TAB_ID } from '../utils/constants'; | ||
import { SidecarIconMenu } from '../components/sidecar_icon_menu'; | ||
|
||
export const ChatOverrideHeader = React.memo(() => { | ||
const chatContext = useChatContext() as IChatContext; | ||
const { setSelectedTabId, setFlyoutComponent, setOverrideName } = chatContext; | ||
|
||
const handleBack = useCallback(() => { | ||
setSelectedTabId(TAB_ID.CHAT); | ||
setFlyoutComponent(null); | ||
setOverrideName(undefined); | ||
}, [setSelectedTabId]); | ||
|
||
return ( | ||
<> | ||
<EuiFlexGroup | ||
gutterSize="s" | ||
justifyContent="spaceAround" | ||
alignItems="center" | ||
responsive={false} | ||
> | ||
<EuiFlexItem> | ||
<EuiFlexGroup gutterSize="none" alignItems="center" responsive={false}> | ||
<EuiButtonEmpty flush="left" size="xs" onClick={handleBack} iconType="arrowLeft"> | ||
{chatContext?.overrideName || 'Back'} | ||
</EuiButtonEmpty> | ||
</EuiFlexGroup> | ||
</EuiFlexItem> | ||
<SidecarIconMenu /> | ||
<EuiFlexItem grow={false}> | ||
<EuiButtonIcon | ||
aria-label="close" | ||
size="xs" | ||
color="text" | ||
iconType="cross" | ||
onClick={() => { | ||
chatContext.setFlyoutVisible(false); | ||
}} | ||
/> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false} /> | ||
</EuiFlexGroup> | ||
</> | ||
); | ||
}); |
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
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,46 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import Qs from 'querystring'; | ||
import { | ||
IAdditionalAction, | ||
IMessage, | ||
Interaction, | ||
} from '../../common/types/chat_saved_object_attributes'; | ||
|
||
export const CreateMonitorParserHelper = (interaction: Interaction): IAdditionalAction[] => { | ||
const monitorParameters = | ||
(interaction.additional_info?.['CreateAlertTool.output'] as string[] | null)?.flatMap( | ||
(item: string): {} => { | ||
// @typescript-eslint/no-explicit-any | ||
let parameters: { [key: string]: string } = {}; | ||
try { | ||
const parsedItem = JSON.parse(item); | ||
parameters.name = parsedItem.name; | ||
parameters.index = parsedItem.search.indices; | ||
parameters.timeField = parsedItem.search.timeField; | ||
parameters.bucketValue = parsedItem.search.bucketValue; | ||
parameters.bucketUnitOfTime = parsedItem.search.bucketUnitOfTime; | ||
parameters.filters = JSON.stringify(parsedItem.search.filters); | ||
parameters.aggregations = JSON.stringify(parsedItem.search.aggregations); | ||
parameters.triggers = JSON.stringify(parsedItem.triggers); | ||
} catch (e) { | ||
parameters = {}; | ||
} | ||
|
||
return parameters; | ||
} | ||
) || []; | ||
|
||
if (!monitorParameters.length) return []; | ||
|
||
return [...new Set(monitorParameters)] | ||
.filter((parameters) => parameters) | ||
.map((parameters) => ({ | ||
actionType: 'create_monitor_grid', | ||
message: 'Create Alert', | ||
content: Qs.stringify(parameters), | ||
})); | ||
}; |
Oops, something went wrong.