Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
InfoSprinkle,
Tooltip,
} from '@mongodb-js/compass-components';
import React, { useState } from 'react';
import React, { useState, useCallback } from 'react';
import type { Field } from '../../modules/create-index';
import MDBCodeViewer from './mdb-code-viewer';

Expand Down Expand Up @@ -173,25 +173,30 @@ const IndexFlowSection = ({
{}
);

const coveredQueriesArr = fields.map((field, index) => {
return { [field.name]: index + 1 };
const [coveredQueriesObj, setCoveredQueriesObj] = useState<{
Copy link
Member

@Anemy Anemy Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the user changes the fields should we reset this so that they have to re-click the show covered queries button? That way we don't show them something out of date. Fine as is also, I'm mostly thinking if it's a nicer experience for the user one way.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://jira.mongodb.org/browse/CLOUDP-311787 i have this ticket for polishing up all the UX for further disabled states, error states etc for everything across the modal

coveredQueries: JSX.Element;
optimalQueries: string | JSX.Element;
showCoveredQueries: boolean;
}>({
coveredQueries: <></>,
optimalQueries: '',
showCoveredQueries: false,
});

const [coveredQueriesExamples, setCoveredQueriesExamples] =
useState<JSX.Element>(<></>);
const [optimalQueriesExamples, setOptimalQueriesExamples] = useState<
string | JSX.Element
>('');
const [showCoveredQueries, setShowCoveredQueries] = useState(false);
const onCoveredQueriesButtonClick = useCallback(() => {
const coveredQueriesArr = fields.map((field, index) => {
return { [field.name]: index + 1 };
});

const onCoveredQueriesButtonClick = () => {
generateCoveredQueries(coveredQueriesArr);
generateOptimalQueries(coveredQueriesArr);
setCoveredQueriesObj({
coveredQueries: generateCoveredQueries(coveredQueriesArr),
optimalQueries: generateOptimalQueries(coveredQueriesArr),
showCoveredQueries: true,
});
}, [fields]);

setCoveredQueriesExamples(generateCoveredQueries(coveredQueriesArr));
setOptimalQueriesExamples(generateOptimalQueries(coveredQueriesArr));
setShowCoveredQueries(true);
};
const { coveredQueries, optimalQueries, showCoveredQueries } =
coveredQueriesObj;

return (
<div>
Expand Down Expand Up @@ -280,10 +285,10 @@ const IndexFlowSection = ({
className={codeStyles}
data-testid="index-flow-section-covered-queries-examples"
>
{coveredQueriesExamples}
{coveredQueries}
</Body>

{!!optimalQueriesExamples && (
{!!optimalQueries && (
<>
<p>
<span className={underlineStyles}>
Expand All @@ -295,7 +300,7 @@ const IndexFlowSection = ({
className={codeStyles}
data-testid="index-flow-section-optimal-queries-examples"
>
{optimalQueriesExamples}
{optimalQueries}
</Body>
</p>
<Link href="https://www.mongodb.com/docs/manual/core/query-optimization/">
Expand Down
Loading