-
Notifications
You must be signed in to change notification settings - Fork 228
feat(compass-indexes): Add view support to indexes tab COMPASS-9667 #7182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 11 commits
0b4ab54
0c96520
6bc7021
8cc8504
aaf0f70
cdbbfc8
481bbd4
b9be029
6d9d8b8
8f2ec15
5b976d3
fbbb21f
50cee9a
aa59476
26e428b
73b536b
6961789
f6cee34
cd9de5b
6c47264
4dccafe
dad9efd
815f210
f88bf80
f7983f1
7bc8bb7
e060334
3d29b2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,23 @@ | ||
import React, { useCallback } from 'react'; | ||
import React, { useCallback, useEffect } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { | ||
withPreferences, | ||
usePreference, | ||
withPreferences, | ||
} from 'compass-preferences-model/provider'; | ||
import { | ||
Button, | ||
ErrorSummary, | ||
Tooltip, | ||
WarningSummary, | ||
Link, | ||
css, | ||
spacing, | ||
DropdownMenuButton, | ||
ErrorSummary, | ||
Icon, | ||
SpinLoader, | ||
SignalPopover, | ||
Link, | ||
PerformanceSignals, | ||
DropdownMenuButton, | ||
SegmentedControl, | ||
SegmentedControlOption, | ||
SignalPopover, | ||
spacing, | ||
SpinLoader, | ||
Tooltip, | ||
} from '@mongodb-js/compass-components'; | ||
import { useConnectionInfo } from '@mongodb-js/compass-connections/provider'; | ||
import semver from 'semver'; | ||
|
@@ -107,9 +106,15 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({ | |
readOnly, // preferences readOnly. | ||
}) => { | ||
const isSearchManagementActive = usePreference('enableAtlasSearchIndexes'); | ||
const mongoDBMajorVersion = parseFloat( | ||
serverVersion.split('.').slice(0, 2).join('.') | ||
); | ||
const { atlasMetadata } = useConnectionInfo(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use semver package for handling mongodb version comparison, you can't really rely fully on the version here being fully parseable as a number (because it's not). There are some examples in the code here that already use semver for similar checks (see There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me know if the way I changed this works! The majority of cases check 8.1+ but i had a few cases that differed so created a function that defaulted to 8.1+ but let me override which operator and comparison version. |
||
const showInsights = usePreference('showInsights') && !errorMessage; | ||
const showCreateIndexButton = !isReadonlyView && !readOnly && !errorMessage; | ||
const showCreateIndexButton = | ||
(!isReadonlyView || mongoDBMajorVersion > 8.0) && | ||
!readOnly && | ||
!errorMessage; | ||
const refreshButtonIcon = isRefreshing ? ( | ||
<div className={spinnerStyles}> | ||
<SpinLoader title="Refreshing Indexes" /> | ||
|
@@ -118,12 +123,19 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({ | |
<Icon glyph="Refresh" title="Refresh Indexes" /> | ||
); | ||
|
||
useEffect(() => { | ||
// If the view is readonly, set the default tab to 'search-indexes' | ||
if (isReadonlyView) { | ||
onIndexViewChanged('search-indexes'); // Update redux state | ||
} | ||
}, [isReadonlyView, onIndexViewChanged]); | ||
|
||
DarshanaVenkatesh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return ( | ||
<div | ||
className={indexesToolbarContainerStyles} | ||
data-testid="indexes-toolbar-container" | ||
> | ||
{!isReadonlyView && ( | ||
{(!isReadonlyView || mongoDBMajorVersion > 8.0) && ( | ||
<div data-testid="indexes-toolbar"> | ||
<div className={toolbarButtonsContainer}> | ||
{showCreateIndexButton && ( | ||
|
@@ -139,7 +151,9 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({ | |
isWritable={isWritable} | ||
onCreateRegularIndexClick={onCreateRegularIndexClick} | ||
onCreateSearchIndexClick={onCreateSearchIndexClick} | ||
></CreateIndexButton> | ||
isReadonlyView={isReadonlyView} | ||
indexView={indexView} | ||
/> | ||
</div> | ||
} | ||
> | ||
|
@@ -173,6 +187,7 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({ | |
signals={PerformanceSignals.get('too-many-indexes')} | ||
/> | ||
)} | ||
|
||
{isSearchManagementActive && ( | ||
<SegmentedControl | ||
size="xsmall" | ||
|
@@ -182,13 +197,34 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({ | |
value={indexView} | ||
data-testid="indexes-segment-controls" | ||
> | ||
<SegmentedControlOption | ||
data-testid="regular-indexes-tab" | ||
value="regular-indexes" | ||
> | ||
Indexes | ||
</SegmentedControlOption> | ||
{!isSearchIndexesSupported && ( | ||
{isReadonlyView && ( | ||
<Tooltip | ||
align="top" | ||
justify="end" | ||
enabled={true} | ||
renderMode="portal" | ||
trigger={ | ||
<SegmentedControlOption | ||
data-testid="regular-indexes-tab" | ||
value="regular-indexes" | ||
disabled={isReadonlyView} | ||
> | ||
Indexes | ||
</SegmentedControlOption> | ||
} | ||
> | ||
Readonly views may not contain standard indexes. | ||
</Tooltip> | ||
)} | ||
{!isReadonlyView && ( | ||
<SegmentedControlOption | ||
data-testid="regular-indexes-tab" | ||
value="regular-indexes" | ||
> | ||
Indexes | ||
</SegmentedControlOption> | ||
)} | ||
{!isSearchIndexesSupported && !isReadonlyView && ( | ||
<Tooltip | ||
align="top" | ||
justify="end" | ||
|
@@ -227,7 +263,7 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({ | |
)} | ||
</Tooltip> | ||
)} | ||
{isSearchIndexesSupported && ( | ||
{(isSearchIndexesSupported || isReadonlyView) && ( | ||
<SegmentedControlOption | ||
data-testid="search-indexes-tab" | ||
value="search-indexes" | ||
|
@@ -240,14 +276,8 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({ | |
</div> | ||
</div> | ||
)} | ||
{isReadonlyView ? ( | ||
<WarningSummary | ||
warnings={['Readonly views may not contain indexes.']} | ||
/> | ||
) : ( | ||
!!errorMessage && ( | ||
<ErrorSummary data-testid="indexes-error" errors={[errorMessage]} /> | ||
) | ||
{!!errorMessage && ( | ||
<ErrorSummary data-testid="indexes-error" errors={[errorMessage]} /> | ||
)} | ||
</div> | ||
); | ||
|
@@ -259,6 +289,8 @@ type CreateIndexButtonProps = { | |
isWritable: boolean; | ||
onCreateRegularIndexClick: () => void; | ||
onCreateSearchIndexClick: () => void; | ||
isReadonlyView: boolean; | ||
indexView: IndexView; | ||
}; | ||
|
||
type CreateIndexActions = 'createRegularIndex' | 'createSearchIndex'; | ||
|
@@ -271,6 +303,8 @@ export const CreateIndexButton: React.FunctionComponent< | |
isWritable, | ||
onCreateRegularIndexClick, | ||
onCreateSearchIndexClick, | ||
isReadonlyView, | ||
indexView, | ||
}) => { | ||
const onActionDispatch = useCallback( | ||
(action: CreateIndexActions) => { | ||
|
@@ -284,7 +318,23 @@ export const CreateIndexButton: React.FunctionComponent< | |
[onCreateRegularIndexClick, onCreateSearchIndexClick] | ||
); | ||
|
||
if (isSearchIndexesSupported && isSearchManagementActive) { | ||
if (isReadonlyView && isSearchManagementActive) { | ||
if (indexView === 'search-indexes') { | ||
return ( | ||
<Button | ||
disabled={!isWritable} | ||
onClick={onCreateSearchIndexClick} | ||
variant="primary" | ||
size="small" | ||
> | ||
Create Search Index | ||
</Button> | ||
); | ||
} | ||
|
||
return null; | ||
} | ||
if (!isReadonlyView && isSearchIndexesSupported && isSearchManagementActive) { | ||
return ( | ||
<DropdownMenuButton | ||
data-testid="multiple-index-types-creation-dropdown" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a small note for the future, I'm not sure what's doing the re-ordering of the imports here, we don't have this style requirement in compass, but it makes reviewing this code way harder because it's not clear what exactly changed in the imports. If it's possible at all not to do, that would be very helpful 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, will keep this in mind. I think it's probably an intelllij setting I have set up that I can disable.