Skip to content

Commit

Permalink
Adding the close button to the generate interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jespino committed Jan 7, 2025
1 parent 67a7800 commit c3c49ae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
24 changes: 16 additions & 8 deletions webapp/src/components/modals/ai_modal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {WebSocketMessage} from '@mattermost/client';
import React, {useEffect, useState, useCallback, useRef} from 'react';

Check failure on line 2 in webapp/src/components/modals/ai_modal.tsx

View workflow job for this annotation

GitHub Actions / lint

Imports must be broken into multiple lines if there are more than 3 elements

Check failure on line 2 in webapp/src/components/modals/ai_modal.tsx

View workflow job for this annotation

GitHub Actions / lint

Member 'useCallback' of the import declaration should be sorted alphabetically
import ReactDOM from 'react-dom';

Check failure on line 3 in webapp/src/components/modals/ai_modal.tsx

View workflow job for this annotation

GitHub Actions / lint

'ReactDOM' is defined but never used

Check failure on line 3 in webapp/src/components/modals/ai_modal.tsx

View workflow job for this annotation

GitHub Actions / lint

'ReactDOM' is defined but never used
import styled from 'styled-components';
import {createGlobalStyle} from "styled-components";

Check failure on line 5 in webapp/src/components/modals/ai_modal.tsx

View workflow job for this annotation

GitHub Actions / lint

'styled-components' import is duplicated
import {FormattedMessage, useIntl} from 'react-intl';
import IconAI from 'src/components/assets/icons/ai';
import {Textbox} from 'src/webapp_globals';
Expand All @@ -20,28 +22,29 @@ type Props = {
playbookRunId: string
onAccept: (text: string) => void
onClose: () => void
isOpen: boolean
}

const AIModal = ({playbookRunId, onAccept, onClose}: Props) => {
const AIModal = ({playbookRunId, onAccept, onClose, isOpen}: Props) => {
const intl = useIntl();
const [copied, setCopied] = useState(false);
const [instruction, setInstruction] = useState('');
const suggestionBox = useRef<HTMLDivElement>()
const aiAvailableBots = useAIAvailableBots();
const BotSelector = useBotSelector() as any;
const [currentBot, setCurrentBot] = useState<any>(aiAvailableBots.length > 0 ? aiAvailableBots[0] : null);
const [currentVersion, setCurrentVersion] = useState<number>(1);
const [currentVersion, setCurrentVersion] = useState<number>(0);
const [versions, setVersions] = useState<Version[]>([]);
const [generating, setGenerating] = useState<any>(null);

useEffect(() => {
if (currentBot?.id) {
if (currentBot?.id && isOpen) {
setCurrentVersion(versions.length + 1)
setVersions([...versions, {instruction: '', value: '', prevValue: ''}])
setGenerating(true);
generateStatusUpdate(playbookRunId, currentBot.id, [], []);
}
}, []);
}, [isOpen]);

useEffect(() => {
if (generating) {
Expand Down Expand Up @@ -104,6 +107,10 @@ const AIModal = ({playbookRunId, onAccept, onClose}: Props) => {
return null
}

if (!isOpen) {
return null;
}

return (
<AIModalContainer>
<TopBar>
Expand All @@ -122,6 +129,10 @@ const AIModal = ({playbookRunId, onAccept, onClose}: Props) => {
activeBot={currentBot}
setActiveBot={onBotChange}
/>
<button type="button" className="close" aria-label="Close" onClick={onClose}>
<span aria-hidden="true">×</span>
<span className="sr-only">Close</span>
</button>
</TopBar>
<AssistantMessageBox ref={suggestionBox}>
<Textbox value={versions[currentVersion-1]?.value || ''} preview={true}/>
Expand All @@ -141,9 +152,6 @@ const AIModal = ({playbookRunId, onAccept, onClose}: Props) => {
<IconButton onClick={regenerate}>
<i className="icon icon-refresh"/>
</IconButton>
<IconButton onClick={onClose}>
<i className="icon icon-trash-can-outline"/>
</IconButton>
<InsertButton onClick={() => onAccept(versions[currentVersion-1].value)}>
<i className="icon icon-10 icon-check"/>
<FormattedMessage defaultMessage="Accept"/>
Expand Down Expand Up @@ -237,7 +245,6 @@ const AIModalContainer = styled.div`
right: -2px;
top: -10px;
position: absolute;
z-index: 1000;
background: var(--center-channel-bg);
border: 1px solid var(--center-channel-color-16);
border-radius: 4px;
Expand Down Expand Up @@ -356,6 +363,7 @@ const Versions = styled.div`
font-size: 12px;
gap: 4px;
font-weight: 600;
flex-grow: 1;
&.disabled {
color: var(--center-channel-color-64);
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/components/modals/update_run_status_modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,13 @@ const UpdateRunStatusModal = ({
))
}
</LastChangeSince>
{ aiAvailable && aiModalOpen &&
{ aiAvailable &&
<AiModalContainer>
<AIModal
playbookRunId={playbookRunId}
onAccept={(text) => { setMessage(text); setAIModalOpen(false); }}
onClose={() => setAIModalOpen(false)}
isOpen={aiModalOpen}
/>
</AiModalContainer>
}
Expand Down

0 comments on commit c3c49ae

Please sign in to comment.