Skip to content

Commit f3af524

Browse files
committed
frontend/title-bar: only open one AI Assistant dialog -- fixes #8559
1 parent 978125e commit f3af524

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

src/packages/frontend/frame-editors/frame-tree/title-bar.tsx

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,10 @@ export function FrameTitleBar(props: FrameTitleBarProps) {
205205
const [close_and_halt_confirm, set_close_and_halt_confirm] =
206206
useState<boolean>(false);
207207

208-
const [showAI, setShowAI] = useState<boolean>(false);
208+
const [showAIDialogs, setShowAIDialogs] = useState<{
209+
main: boolean;
210+
popover: boolean;
211+
}>({ main: false, popover: false });
209212
const [showNewAI, setShowNewAI] = useState<boolean>(false);
210213

211214
const [helpSearch, setHelpSearch] = useState<string>("");
@@ -235,7 +238,8 @@ export function FrameTitleBar(props: FrameTitleBarProps) {
235238
new ManageCommands({
236239
props,
237240
studentProjectFunctionality: student_project_functionality,
238-
setShowAI,
241+
setShowAI: (val: boolean) =>
242+
setShowAIDialogs((prev) => ({ ...prev, main: val })),
239243
setShowNewAI,
240244
helpSearch,
241245
setHelpSearch,
@@ -248,7 +252,7 @@ export function FrameTitleBar(props: FrameTitleBarProps) {
248252
student_project_functionality,
249253
helpSearch,
250254
setHelpSearch,
251-
setShowAI,
255+
setShowAIDialogs,
252256
setShowNewAI,
253257
read_only,
254258
editorSettings,
@@ -579,7 +583,7 @@ export function FrameTitleBar(props: FrameTitleBarProps) {
579583
);
580584
}
581585

582-
function renderAssistant(noLabel): Rendered {
586+
function renderAssistant(noLabel, where: "main" | "popover"): Rendered {
583587
if (
584588
!manageCommands.isVisible("chatgpt") ||
585589
!redux.getStore("projects").hasLanguageModelEnabled(props.project_id)
@@ -590,11 +594,13 @@ export function FrameTitleBar(props: FrameTitleBarProps) {
590594
<LanguageModelTitleBarButton
591595
path={props.path}
592596
type={props.type}
593-
showDialog={showAI}
594-
setShowDialog={setShowAI}
597+
showDialog={showAIDialogs[where]}
598+
setShowDialog={(value: boolean) => {
599+
setShowAIDialogs((prev) => ({ ...prev, [where]: value }));
600+
}}
595601
project_id={props.project_id}
596602
buttonRef={getTourRef("chatgpt")}
597-
key={"ai-button"}
603+
key={`ai-button-${where}`}
598604
id={props.id}
599605
actions={props.actions}
600606
buttonSize={button_size()}
@@ -641,7 +647,7 @@ export function FrameTitleBar(props: FrameTitleBarProps) {
641647
);
642648
}
643649

644-
function renderSaveTimetravelGroup(): Rendered {
650+
function renderSaveTimetravelGroup(where: "main" | "popover"): Rendered {
645651
if (props.type == "chat") {
646652
// these buttons don't make much sense for side chat.
647653
return;
@@ -651,7 +657,7 @@ export function FrameTitleBar(props: FrameTitleBarProps) {
651657
let x;
652658
if ((x = renderSaveButton(noLabel))) v.push(x);
653659
if ((x = renderTimeTravel(noLabel))) v.push(x);
654-
if ((x = renderAssistant(noLabel))) v.push(x);
660+
if ((x = renderAssistant(noLabel, where))) v.push(x);
655661
if ((x = renderComputeServer(noLabel))) v.push(x);
656662
if (v.length == 1) return v[0];
657663
if (v.length > 0) {
@@ -754,7 +760,11 @@ export function FrameTitleBar(props: FrameTitleBarProps) {
754760
// seems too horrible right now since it is a selector.
755761
}
756762

757-
function renderButtons(style?: CSS, noRefs?): Rendered {
763+
function renderButtons(
764+
style?: CSS,
765+
noRefs?,
766+
where: "main" | "popover" = "main",
767+
): Rendered {
758768
if (!is_active) {
759769
return (
760770
<div style={{ display: "flex", width: "100%" }}>
@@ -784,7 +794,7 @@ export function FrameTitleBar(props: FrameTitleBarProps) {
784794
}
785795

786796
const v: (React.JSX.Element | undefined | null)[] = [];
787-
v.push(renderSaveTimetravelGroup());
797+
v.push(renderSaveTimetravelGroup(where));
788798
if (props.title != null) {
789799
v.push(renderTitle());
790800
}
@@ -841,7 +851,7 @@ export function FrameTitleBar(props: FrameTitleBarProps) {
841851
}
842852
return (
843853
<Popover
844-
overlayStyle={{ zIndex: 990 }}
854+
styles={{ root: { zIndex: 990 } }}
845855
open={
846856
props.tab_is_visible && props.is_visible && showMainButtonsPopover
847857
}
@@ -860,7 +870,11 @@ export function FrameTitleBar(props: FrameTitleBarProps) {
860870
marginRight: "3px",
861871
}}
862872
>
863-
{renderButtons({ maxHeight: "50vh", display: "block" }, true)}
873+
{renderButtons(
874+
{ maxHeight: "50vh", display: "block" },
875+
true,
876+
"popover",
877+
)}
864878
</div>
865879
<div>
866880
{renderFrameControls()}

0 commit comments

Comments
 (0)