-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update choices showing logic rename stuff
- Loading branch information
Showing
6 changed files
with
283 additions
and
28 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
92 changes: 92 additions & 0 deletions
92
...ponents/PagePanelComponents/Home/Browse3/pages/ChatView/PlaygroundMessagePanelButtons.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,92 @@ | ||
import {Button} from '@wandb/weave/components/Button'; | ||
import classNames from 'classnames'; | ||
import React from 'react'; | ||
|
||
import {usePlaygroundContext} from '../PlaygroundPage/PlaygroundContext'; | ||
|
||
type PlaygroundMessagePanelButtonsProps = { | ||
index: number; | ||
isChoice: boolean; | ||
isTool: boolean; | ||
hasContent: boolean; | ||
isNested: boolean; | ||
contentRef: React.RefObject<HTMLDivElement>; | ||
setEditorHeight: (height: number | null) => void; | ||
responseIndexes?: number[]; | ||
}; | ||
|
||
export const PlaygroundMessagePanelButtons: React.FC< | ||
PlaygroundMessagePanelButtonsProps | ||
> = ({ | ||
index, | ||
isChoice, | ||
isTool, | ||
hasContent, | ||
isNested, | ||
contentRef, | ||
setEditorHeight, | ||
responseIndexes, | ||
}) => { | ||
const {deleteMessage, deleteChoice, retry} = usePlaygroundContext(); | ||
|
||
return ( | ||
<div | ||
className={classNames( | ||
'absolute right-0 flex w-full items-center justify-end pt-20', | ||
isNested ? 'bottom-0' : 'bottom-[-32px]' | ||
)}> | ||
<div className="z-10 flex gap-4 rounded-lg border border-moon-250 bg-white p-4"> | ||
<Button | ||
variant="quiet" | ||
size="small" | ||
startIcon="randomize-reset-reload" | ||
onClick={() => retry?.(index, isChoice)} | ||
tooltip={ | ||
!hasContent | ||
? 'We currently do not support retrying functions' | ||
: 'Retry' | ||
} | ||
disabled={!hasContent}> | ||
Retry | ||
</Button> | ||
<Button | ||
variant="quiet" | ||
size="small" | ||
startIcon="pencil-edit" | ||
onClick={() => { | ||
setEditorHeight( | ||
contentRef?.current?.clientHeight | ||
? // Accounts for padding and save buttons | ||
contentRef.current.clientHeight - 56 | ||
: null | ||
); | ||
}} | ||
tooltip={ | ||
!hasContent | ||
? 'We currently do not support editing functions' | ||
: 'Edit' | ||
} | ||
disabled={!hasContent}> | ||
Edit | ||
</Button> | ||
<Button | ||
variant="quiet" | ||
size="small" | ||
startIcon="delete" | ||
onClick={() => { | ||
if (isChoice) { | ||
deleteChoice?.(index); | ||
} else { | ||
deleteMessage?.(index, responseIndexes); | ||
} | ||
}} | ||
tooltip={ | ||
isTool ? 'Tool responses cannot be deleted' : 'Delete message' | ||
} | ||
disabled={isTool}> | ||
Delete | ||
</Button> | ||
</div> | ||
</div> | ||
); | ||
}; |
102 changes: 102 additions & 0 deletions
102
...mponents/PagePanelComponents/Home/Browse3/pages/ChatView/PlaygroundMessagePanelEditor.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 @@ | ||
import {Button} from '@wandb/weave/components/Button'; | ||
import classNames from 'classnames'; | ||
import _ from 'lodash'; | ||
import React, {useEffect, useMemo, useState} from 'react'; | ||
|
||
import {usePlaygroundContext} from '../PlaygroundPage/PlaygroundContext'; | ||
import {StyledTextArea} from '../PlaygroundPage/StyledTextarea'; | ||
import {Message} from './types'; | ||
|
||
type PlaygroundMessagePanelEditorProps = { | ||
editorHeight: number; | ||
isNested: boolean; | ||
pendingToolResponseId?: string; | ||
message: Message; | ||
index: number; | ||
isChoice: boolean; | ||
setEditorHeight: (height: number | null) => void; | ||
}; | ||
|
||
export const PlaygroundMessagePanelEditor: React.FC< | ||
PlaygroundMessagePanelEditorProps | ||
> = ({ | ||
index, | ||
isChoice, | ||
setEditorHeight, | ||
editorHeight, | ||
isNested, | ||
pendingToolResponseId, | ||
message, | ||
}) => { | ||
const {sendMessage, editMessage, editChoice} = usePlaygroundContext(); | ||
|
||
const initialContent = useMemo( | ||
() => | ||
_.isString(message.content) | ||
? message.content | ||
: message.content?.join('') ?? '', | ||
[message.content] | ||
); | ||
|
||
const [editedContent, setEditedContent] = useState(initialContent); | ||
|
||
useEffect(() => { | ||
setEditedContent(initialContent); | ||
}, [initialContent]); | ||
|
||
const handleSave = () => { | ||
if (isChoice) { | ||
editChoice?.(index, { | ||
content: editedContent, | ||
role: message.role, | ||
}); | ||
} else { | ||
editMessage?.(index, { | ||
...message, | ||
content: editedContent, | ||
}); | ||
} | ||
setEditorHeight(null); | ||
}; | ||
|
||
const handleCancel = () => { | ||
setEditedContent(initialContent); | ||
setEditorHeight(null); | ||
}; | ||
|
||
return ( | ||
<div | ||
className={classNames( | ||
'w-full pt-16 text-sm', | ||
isNested ? 'px-2' : 'px-16' | ||
)}> | ||
<StyledTextArea | ||
value={editedContent} | ||
onChange={e => setEditedContent(e.target.value)} | ||
style={{ | ||
minHeight: `${editorHeight}px`, | ||
}} | ||
/> | ||
<div className="z-100 mt-8 flex justify-end gap-8"> | ||
<Button variant="quiet" size="small" onClick={handleCancel}> | ||
Cancel | ||
</Button> | ||
<Button | ||
variant="primary" | ||
size="small" | ||
onClick={ | ||
pendingToolResponseId | ||
? () => | ||
sendMessage?.( | ||
'tool', | ||
editedContent ?? '', | ||
pendingToolResponseId | ||
) | ||
: handleSave | ||
}> | ||
Save | ||
</Button> | ||
</div> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.