-
Notifications
You must be signed in to change notification settings - Fork 229
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
Changes from all 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
0de5a0e
2833412
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,32 @@ | ||
import React, { useCallback } 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, | ||
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. 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 commentThe 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. |
||
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'; | ||
|
||
import type { RootState } from '../../modules'; | ||
import { createSearchIndexOpened } from '../../modules/search-indexes'; | ||
import { | ||
isVersionSearchCompatibleForViews, | ||
createSearchIndexOpened, | ||
} from '../../modules/search-indexes'; | ||
import { getAtlasSearchIndexesLink } from '../../utils/atlas-search-indexes-link'; | ||
import { createIndexOpened } from '../../modules/create-index'; | ||
import type { IndexView } from '../../modules/index-view'; | ||
|
@@ -109,7 +111,10 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({ | |
const isSearchManagementActive = usePreference('enableAtlasSearchIndexes'); | ||
const { atlasMetadata } = useConnectionInfo(); | ||
const showInsights = usePreference('showInsights') && !errorMessage; | ||
const showCreateIndexButton = !isReadonlyView && !readOnly && !errorMessage; | ||
const showCreateIndexButton = | ||
(!isReadonlyView || isVersionSearchCompatibleForViews(serverVersion)) && | ||
!readOnly && | ||
!errorMessage; | ||
const refreshButtonIcon = isRefreshing ? ( | ||
<div className={spinnerStyles}> | ||
<SpinLoader title="Refreshing Indexes" /> | ||
|
@@ -123,7 +128,9 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({ | |
className={indexesToolbarContainerStyles} | ||
data-testid="indexes-toolbar-container" | ||
> | ||
{!isReadonlyView && ( | ||
{(!isReadonlyView || | ||
(isVersionSearchCompatibleForViews(serverVersion) && | ||
isSearchManagementActive)) && ( | ||
<div data-testid="indexes-toolbar"> | ||
<div className={toolbarButtonsContainer}> | ||
{showCreateIndexButton && ( | ||
|
@@ -139,7 +146,9 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({ | |
isWritable={isWritable} | ||
onCreateRegularIndexClick={onCreateRegularIndexClick} | ||
onCreateSearchIndexClick={onCreateSearchIndexClick} | ||
></CreateIndexButton> | ||
isReadonlyView={isReadonlyView} | ||
indexView={indexView} | ||
/> | ||
</div> | ||
} | ||
> | ||
|
@@ -173,6 +182,7 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({ | |
signals={PerformanceSignals.get('too-many-indexes')} | ||
/> | ||
)} | ||
|
||
{isSearchManagementActive && ( | ||
<SegmentedControl | ||
size="xsmall" | ||
|
@@ -182,13 +192,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 +258,7 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({ | |
)} | ||
</Tooltip> | ||
)} | ||
{isSearchIndexesSupported && ( | ||
{(isSearchIndexesSupported || isReadonlyView) && ( | ||
<SegmentedControlOption | ||
data-testid="search-indexes-tab" | ||
value="search-indexes" | ||
|
@@ -240,14 +271,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 && isSearchManagementActive && ( | ||
<ErrorSummary data-testid="indexes-error" errors={[errorMessage]} /> | ||
)} | ||
</div> | ||
); | ||
|
@@ -259,6 +284,8 @@ type CreateIndexButtonProps = { | |
isWritable: boolean; | ||
onCreateRegularIndexClick: () => void; | ||
onCreateSearchIndexClick: () => void; | ||
isReadonlyView: boolean; | ||
indexView: IndexView; | ||
}; | ||
|
||
type CreateIndexActions = 'createRegularIndex' | 'createSearchIndex'; | ||
|
@@ -271,6 +298,8 @@ export const CreateIndexButton: React.FunctionComponent< | |
isWritable, | ||
onCreateRegularIndexClick, | ||
onCreateSearchIndexClick, | ||
isReadonlyView, | ||
indexView, | ||
}) => { | ||
const onActionDispatch = useCallback( | ||
(action: CreateIndexActions) => { | ||
|
@@ -284,7 +313,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.
There usually should be a corresponding package-lock update. If you added this one manually, you can run
npm install
on your machine to update the lockfileThere 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.
ran npm install and pushed!