Skip to content

Commit b6bb19f

Browse files
committed
chore: fix test, combine preference to hook
1 parent 0e82ba8 commit b6bb19f

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

packages/compass-assistant/src/compass-assistant-provider.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ export const AssistantContext = createContext<AssistantContextType | null>(
2525
);
2626

2727
type AssistantActionsContextType = {
28-
interpretExplainPlan: (explainPlan: string) => void;
28+
interpretExplainPlan: ({
29+
namespace,
30+
explainPlan,
31+
}: {
32+
namespace: string;
33+
explainPlan: string;
34+
}) => void;
2935
};
3036
export const AssistantActionsContext =
3137
createContext<AssistantActionsContextType>({
@@ -49,9 +55,12 @@ export const AssistantProvider: React.FunctionComponent<
4955
}>
5056
> = ({ chat, children }) => {
5157
const assistantActionsContext = useRef<AssistantActionsContextType>({
52-
interpretExplainPlan: (explainPlan: string) => {
58+
interpretExplainPlan: ({ namespace, explainPlan }) => {
5359
openDrawer(ASSISTANT_DRAWER_ID);
54-
const { prompt, displayText } = buildExplainPlanPrompt(explainPlan);
60+
const { prompt, displayText } = buildExplainPlanPrompt({
61+
namespace,
62+
explainPlan,
63+
});
5564
void chat.sendMessage(
5665
{
5766
text: prompt,
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
export const buildExplainPlanPrompt = (explainPlan: string) => {
1+
export const buildExplainPlanPrompt = ({
2+
namespace,
3+
explainPlan,
4+
}: {
5+
namespace: string;
6+
explainPlan: string;
7+
}) => {
28
return {
39
prompt: `Given the MongoDB explain plan output below, provide a concise human readable explanation that explains the query execution plan and highlights aspects of the plan that might impact query performance. Respond with as much concision and clarity as possible.
410
If a clear optimization should be made, please suggest the optimization and describe how it can be accomplished in MongoDB Compass. Do not advise users to create indexes without weighing the pros and cons.
511
Explain output:
612
${explainPlan}`,
7-
displayText:
8-
'Given this MongoDB explain plan, provide a concise human readable explanation that explains the query execution plan and highlights aspects of the plan that might impact query performance.',
13+
displayText: `Given this MongoDB explain plan for ${namespace}, provide a concise human readable explanation that explains the query execution plan and highlights aspects of the plan that might impact query performance.`,
914
};
1015
};

packages/compass-explain-plan/src/components/explain-plan-modal.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export const ExplainPlanModal: React.FunctionComponent<
132132
}
133133
/>
134134
</div>
135-
{isAssistantEnabled && (
135+
{isAssistantEnabled && explainPlan && (
136136
<div className={headerButtonSectionStyles}>
137137
<Button
138138
size="small"
@@ -144,7 +144,10 @@ export const ExplainPlanModal: React.FunctionComponent<
144144
data-testid="interpret-for-me-button"
145145
onClick={() => {
146146
onModalClose();
147-
interpretExplainPlan(JSON.stringify(explainPlan));
147+
interpretExplainPlan({
148+
namespace: explainPlan.namespace,
149+
explainPlan: JSON.stringify(explainPlan),
150+
});
148151
}}
149152
disabled={status !== 'ready'}
150153
>

0 commit comments

Comments
 (0)