Skip to content

Commit 5fe7496

Browse files
feat: add search indexes table COMPASS-7163 [WIP] (#4831)
* initial search indexes table * move SortDirection * connect in the toolbar and tables * fixup * load indexes from the UI * turns out isReadonlyView !== readOnly * make typescript happier * simpler sort * some tests * test that search indexes errors show up * fix test * e2e selectors * leftover * indexes tests for search indexes * add tests for the actions * fixup * e2e selector fixes --------- Co-authored-by: svc-devtoolsbot <79531021+svc-devtoolsbot@users.noreply.github.com>
1 parent d50848a commit 5fe7496

File tree

22 files changed

+1210
-417
lines changed

22 files changed

+1210
-417
lines changed

packages/compass-e2e-tests/helpers/selectors.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -918,10 +918,10 @@ export const explainPlanSummaryStat = (
918918
// Indexes tab
919919
export const IndexList = '[data-testid="indexes-list"]';
920920
export const indexComponent = (name: string): string => {
921-
return `[data-testid="index-row-${name}"]`;
921+
return `[data-testid="indexes-row-${name}"]`;
922922
};
923-
export const IndexFieldName = '[data-testid="index-name-field"]';
924-
export const IndexFieldType = '[data-testid="index-type-field"]';
923+
export const IndexFieldName = '[data-testid="indexes-name-field"]';
924+
export const IndexFieldType = '[data-testid="indexes-type-field"]';
925925
export const IndexToggleOptions =
926926
'[data-testid="create-index-modal-toggle-options"]';
927927
export const indexToggleOption = (fieldName: string) => {

packages/compass-indexes/src/components/indexes-table/indexes-table.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
useDOMRect,
1313
} from '@mongodb-js/compass-components';
1414

15-
type SortDirection = 'asc' | 'desc';
15+
import type { SortDirection } from '../../modules';
1616

1717
// When row is hovered, we show the delete button
1818
const rowStyles = css({
@@ -142,7 +142,7 @@ export function IndexesTable<Column extends string>({
142142
const _columns = sortColumns.map((name) => {
143143
return (
144144
<TableHeader
145-
data-testid={`index-header-${name}`}
145+
data-testid={`${dataTestId}-header-${name}`}
146146
label={name}
147147
key={name}
148148
className={tableHeaderStyles}
@@ -177,14 +177,14 @@ export function IndexesTable<Column extends string>({
177177
return (
178178
<Row
179179
key={info.key}
180-
data-testid={info['data-testid']}
180+
data-testid={`${dataTestId}-${info['data-testid']}`}
181181
className={rowStyles}
182182
>
183183
{info.fields.map((field) => {
184184
return (
185185
<Cell
186186
key={field.key ?? `${info.key}-${index}`}
187-
data-testid={field['data-testid']}
187+
data-testid={`${dataTestId}-${field['data-testid']}`}
188188
className={cellStyles}
189189
>
190190
{field.children}
@@ -194,7 +194,7 @@ export function IndexesTable<Column extends string>({
194194
{/* Index actions column is conditional */}
195195
{canModifyIndex && (
196196
<Cell
197-
data-testid="index-actions-field"
197+
data-testid={`${dataTestId}-actions-field`}
198198
className={cellStyles}
199199
>
200200
{info.actions && (

packages/compass-indexes/src/components/indexes-toolbar/indexes-toolbar.tsx

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import React, { useCallback } from 'react';
2+
import { connect } from 'react-redux';
3+
import type AppRegistry from 'hadron-app-registry';
4+
import { withPreferences } from 'compass-preferences-model';
25
import {
36
Button,
47
ErrorSummary,
@@ -15,9 +18,11 @@ import {
1518
SegmentedControl,
1619
SegmentedControlOption,
1720
} from '@mongodb-js/compass-components';
18-
import type AppRegistry from 'hadron-app-registry';
1921
import { usePreference } from 'compass-preferences-model';
2022

23+
import type { RootState } from '../../modules';
24+
import { SearchIndexesStatuses } from '../../modules/search-indexes';
25+
2126
const containerStyles = css({
2227
margin: `${spacing[3]}px 0`,
2328
});
@@ -45,16 +50,21 @@ const createIndexButtonContainerStyles = css({
4550
export type IndexView = 'regular-indexes' | 'search-indexes';
4651

4752
type IndexesToolbarProps = {
53+
// passed props:
4854
errorMessage: string | null;
55+
hasTooManyIndexes: boolean;
56+
isRefreshing: boolean;
57+
onRefreshIndexes: () => void;
58+
onChangeIndexView: (newView: IndexView) => void;
59+
60+
// connected:
4961
isReadonlyView: boolean;
5062
isWritable: boolean;
51-
hasTooManyIndexes: boolean;
5263
localAppRegistry: AppRegistry;
53-
isRefreshing: boolean;
5464
writeStateDescription?: string;
5565
isAtlasSearchSupported: boolean;
56-
onRefreshIndexes: () => void;
57-
onChangeIndexView: (newView: IndexView) => void;
66+
67+
// via withPreferences:
5868
readOnly?: boolean;
5969
};
6070

@@ -101,7 +111,7 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
101111
);
102112

103113
return (
104-
<div className={containerStyles}>
114+
<div className={containerStyles} data-testid="indexes-toolbar-container">
105115
{!isReadonlyView && (
106116
<div data-testid="indexes-toolbar">
107117
<div className={toolbarButtonsContainer}>
@@ -266,3 +276,27 @@ export const CreateIndexButton: React.FunctionComponent<
266276
</Button>
267277
);
268278
};
279+
280+
const mapState = ({
281+
isWritable,
282+
isReadonlyView,
283+
description,
284+
serverVersion,
285+
appRegistry,
286+
searchIndexes,
287+
}: RootState) => ({
288+
isWritable,
289+
isReadonlyView,
290+
writeStateDescription: description,
291+
localAppRegistry: (appRegistry as any).localAppRegistry,
292+
serverVersion,
293+
isAtlasSearchSupported:
294+
searchIndexes.status !== SearchIndexesStatuses.NOT_AVAILABLE,
295+
});
296+
297+
const mapDispatch = {};
298+
299+
export default connect(
300+
mapState,
301+
mapDispatch
302+
)(withPreferences(IndexesToolbar, ['readOnly'], React));

0 commit comments

Comments
 (0)