Skip to content

Commit 7498e14

Browse files
committed
fix: styles and types
1 parent af849dd commit 7498e14

File tree

9 files changed

+54
-71
lines changed

9 files changed

+54
-71
lines changed

packages/compass-indexes/src/components/regular-indexes-table/in-progress-index-actions.tsx

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,13 @@ import {
44
ItemActionGroup,
55
SpinLoader,
66
Body,
7-
css,
8-
spacing,
97
} from '@mongodb-js/compass-components';
108
import type { InProgressIndex } from '../../modules/regular-indexes';
119

12-
const buildingTextStyles = css({
13-
display: 'flex',
14-
alignItems: 'center',
15-
gap: spacing[1],
16-
marginRight: spacing[2],
17-
});
18-
1910
type Index = {
2011
name: string;
2112
status: InProgressIndex['status'];
22-
buildProgress?: number;
13+
buildProgress: number;
2314
};
2415

2516
type IndexActionsProps = {
@@ -57,19 +48,27 @@ const IndexActions: React.FunctionComponent<IndexActionsProps> = ({
5748
[onDeleteFailedIndexClick, index]
5849
);
5950

60-
const progress = (index.buildProgress ?? 0) * 100;
51+
const progress = index.buildProgress * 100;
6152
const isBuilding = progress > 0 && progress < 100;
6253

6354
return (
64-
<div style={{ display: 'flex', alignItems: 'center' }}>
55+
<div
56+
style={{
57+
display: 'flex',
58+
alignItems: 'center',
59+
justifyContent: 'flex-end',
60+
gap: '8px',
61+
}}
62+
>
6563
{isBuilding && (
66-
<div
67-
className={buildingTextStyles}
68-
data-testid="index-building-spinner"
69-
>
70-
<SpinLoader size={16} title="Index build in progress" />
64+
<>
7165
<Body>Building... {progress | 0}%</Body>
72-
</div>
66+
<SpinLoader
67+
size={16}
68+
title="Index build in progress"
69+
data-testid="index-building-spinner"
70+
/>
71+
</>
7372
)}
7473
<ItemActionGroup<IndexAction>
7574
data-testid="index-actions"

packages/compass-indexes/src/components/regular-indexes-table/regular-index-actions.tsx

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
css,
66
ItemActionGroup,
77
SpinLoader,
8-
spacing,
98
Body,
109
} from '@mongodb-js/compass-components';
1110
import type { RegularIndex } from '../../modules/regular-indexes';
@@ -15,26 +14,8 @@ const styles = css({
1514
justifyContent: 'flex-end',
1615
});
1716

18-
const combinedContainerStyles = css({
19-
display: 'flex',
20-
alignItems: 'center',
21-
gap: spacing[200],
22-
minWidth: spacing[800],
23-
justifyContent: 'flex-end',
24-
});
25-
26-
const progressTextStyles = css({
27-
fontSize: '12px',
28-
fontWeight: 'normal',
29-
});
30-
31-
// Extended type to include buildProgress which might not be in the base RegularIndex type
32-
type IndexWithProgress = RegularIndex & {
33-
buildProgress?: number;
34-
};
35-
3617
type IndexActionsProps = {
37-
index: IndexWithProgress;
18+
index: RegularIndex;
3819
serverVersion: string;
3920
onDeleteIndexClick: (name: string) => void;
4021
onHideIndexClick: (name: string) => void;
@@ -62,7 +43,7 @@ const IndexActions: React.FunctionComponent<IndexActionsProps> = ({
6243
}) => {
6344
const indexActions: GroupedItemAction<IndexAction>[] = useMemo(() => {
6445
const actions: GroupedItemAction<IndexAction>[] = [];
65-
const buildProgress = index.buildProgress ?? 0;
46+
const buildProgress = index.buildProgress;
6647
const isBuilding = buildProgress > 0 && buildProgress < 1;
6748

6849
if (isBuilding) {
@@ -116,16 +97,19 @@ const IndexActions: React.FunctionComponent<IndexActionsProps> = ({
11697
[onDeleteIndexClick, onHideIndexClick, onUnhideIndexClick, index]
11798
);
11899

119-
const buildProgress = index.buildProgress ?? 0;
100+
const buildProgress = index.buildProgress;
120101
if (buildProgress > 0 && buildProgress < 1) {
121102
return (
122103
<div
123-
className={combinedContainerStyles}
104+
style={{
105+
display: 'flex',
106+
alignItems: 'center',
107+
justifyContent: 'flex-end',
108+
gap: '8px',
109+
}}
124110
data-testid="index-building-spinner"
125111
>
126-
<Body className={progressTextStyles}>
127-
Building... {(buildProgress * 100) | 0}%
128-
</Body>
112+
<Body>Building... {(buildProgress * 100) | 0}%</Body>
129113
<SpinLoader size={16} title="Index build in progress" />
130114
<ItemActionGroup<IndexAction>
131115
data-testid="index-actions"

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,9 @@ function mergeIndexes(
252252
inProgressIndexes.map(({ name }) => name)
253253
);
254254

255-
// Create a map of regular indexes by name to look up buildProgress
256-
const regularIndexesByName = new Map<string, RegularIndex>();
257-
indexes.forEach((index) => {
258-
regularIndexesByName.set(index.name, index);
259-
});
255+
const regularIndexesByName = new Map<string, RegularIndex>(
256+
indexes.map((index) => [index.name, index])
257+
);
260258

261259
const mappedIndexes: MappedRegularIndex[] = indexes
262260
// exclude partially-built indexes so that we don't include indexes that
@@ -271,12 +269,9 @@ function mergeIndexes(
271269
// For in-progress indexes, merge in buildProgress from regular indexes if available
272270
const mappedInProgressIndexes: MappedInProgressIndex[] =
273271
inProgressIndexes.map((index) => {
274-
const regularIndex = regularIndexesByName.get(index.name);
275-
const buildProgress = regularIndex?.buildProgress;
276-
277272
return {
278273
...index,
279-
buildProgress,
274+
buildProgress: regularIndexesByName.get(index.name)?.buildProgress ?? 0,
280275
compassIndexType: 'in-progress-index',
281276
};
282277
});

packages/compass-indexes/src/modules/regular-indexes.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,14 @@ export type RegularIndex = Partial<IndexDefinition> &
3636
| 'size'
3737
| 'relativeSize'
3838
| 'usageCount'
39-
> & {
40-
// Explicitly include buildProgress to ensure it's available
41-
buildProgress?: number;
42-
};
39+
| 'buildProgress'
40+
>;
4341

4442
export type InProgressIndex = Pick<IndexDefinition, 'name' | 'fields'> & {
4543
id: string;
4644
status: 'inprogress' | 'failed';
4745
error?: string;
48-
buildProgress?: number;
46+
buildProgress: number;
4947
};
5048

5149
export type RollingIndex = Partial<AtlasIndexStats> &
@@ -87,6 +85,7 @@ export const prepareInProgressIndex = (
8785
status: 'inprogress',
8886
fields: inProgressIndexFields,
8987
name: inProgressIndexName,
88+
buildProgress: 0,
9089
// TODO(COMPASS-8335): we never mapped properties and the table does have
9190
// room to display them
9291
};

packages/compass-indexes/src/stores/store.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ export type IndexesDataServiceProps =
4949
| 'collectionStats'
5050
| 'collectionInfo'
5151
| 'listCollections'
52-
| 'isListSearchIndexesSupported'
53-
// Required for tracking index build progress
54-
| 'currentOp';
52+
| 'isListSearchIndexesSupported';
5553
export type IndexesDataService = Pick<DataService, IndexesDataServiceProps>;
5654

5755
export type IndexesPluginServices = {

packages/compass-indexes/test/fixtures/regular-indexes.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const indexesList: IndexDefinition[] = [
1919
ns: 'foo',
2020
fields: [],
2121
relativeSize: 1,
22+
buildProgress: 0,
2223
},
2324
{
2425
name: 'CCCC',
@@ -37,6 +38,7 @@ export const indexesList: IndexDefinition[] = [
3738
ns: 'foo',
3839
fields: [],
3940
relativeSize: 1,
41+
buildProgress: 0,
4042
},
4143
{
4244
name: 'AAAA',
@@ -55,6 +57,7 @@ export const indexesList: IndexDefinition[] = [
5557
ns: 'foo',
5658
fields: [],
5759
relativeSize: 1,
60+
buildProgress: 0,
5861
},
5962
{
6063
name: 'BBBB',
@@ -73,6 +76,7 @@ export const indexesList: IndexDefinition[] = [
7376
ns: 'foo',
7477
fields: [],
7578
relativeSize: 1,
79+
buildProgress: 0,
7680
},
7781
];
7882

@@ -96,6 +100,7 @@ export const defaultSortedIndexes: IndexDefinition[] = [
96100

97101
fields: [],
98102
relativeSize: 1,
103+
buildProgress: 0,
99104
},
100105
{
101106
ns: 'citibike.trips',
@@ -126,6 +131,7 @@ export const defaultSortedIndexes: IndexDefinition[] = [
126131

127132
fields: [],
128133
relativeSize: 1,
134+
buildProgress: 0,
129135
},
130136
{
131137
ns: 'citibike.trips',
@@ -143,6 +149,7 @@ export const defaultSortedIndexes: IndexDefinition[] = [
143149

144150
fields: [],
145151
relativeSize: 1,
152+
buildProgress: 0,
146153
},
147154
];
148155

@@ -167,6 +174,7 @@ export const usageSortedIndexes: IndexDefinition[] = [
167174

168175
fields: [],
169176
relativeSize: 1,
177+
buildProgress: 0,
170178
},
171179
{
172180
name: 'CCCC',
@@ -185,6 +193,7 @@ export const usageSortedIndexes: IndexDefinition[] = [
185193

186194
fields: [],
187195
relativeSize: 1,
196+
buildProgress: 0,
188197
},
189198
{
190199
name: '_id_',
@@ -203,6 +212,7 @@ export const usageSortedIndexes: IndexDefinition[] = [
203212

204213
fields: [],
205214
relativeSize: 1,
215+
buildProgress: 0,
206216
},
207217
{
208218
name: 'BBBB',
@@ -234,6 +244,7 @@ export const usageSortedIndexes: IndexDefinition[] = [
234244

235245
fields: [],
236246
relativeSize: 1,
247+
buildProgress: 0,
237248
},
238249
];
239250

@@ -244,6 +255,7 @@ export const inProgressIndexes: InProgressIndex[] = [
244255
//version: 2,
245256
fields: [],
246257
status: 'inprogress',
258+
buildProgress: 0,
247259
},
248260
{
249261
id: 'in-progress-2',
@@ -255,5 +267,6 @@ export const inProgressIndexes: InProgressIndex[] = [
255267
},
256268
],
257269
status: 'inprogress',
270+
buildProgress: 0,
258271
},
259272
];

packages/compass-indexes/test/helpers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export function mockRegularIndex(info: Partial<RegularIndex>): RegularIndex {
1212
relativeSize: 0,
1313
cardinality: 'single',
1414
properties: [],
15+
buildProgress: 0,
16+
usageCount: 0,
1517
...info,
1618
extra: {
1719
...info.extra,

packages/compass-indexes/test/setup-store.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ const NOOP_DATA_PROVIDER: IndexesDataService = {
9090
sample(namespace: string) {
9191
return Promise.resolve([]);
9292
},
93-
currentOp() {
94-
return Promise.resolve({ inprog: [] });
95-
},
9693
};
9794

9895
class FakeInstance extends EventEmitter {

packages/data-service/src/index-detail-helper.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ export type IndexStats = {
1616

1717
type IndexSize = number;
1818

19-
type IndexProgress = {
20-
buildProgress?: number;
21-
};
22-
2319
export type IndexDefinition = {
2420
ns: string;
2521
name: string;
@@ -39,8 +35,8 @@ export type IndexDefinition = {
3935
extra: Record<string, string | number | boolean | Record<string, any>>;
4036
size: IndexSize;
4137
relativeSize: number;
42-
} & IndexStats &
43-
IndexProgress;
38+
buildProgress: number;
39+
} & IndexStats;
4440

4541
export function getIndexCardinality(
4642
index: Pick<IndexDefinition, 'key' | 'fields' | 'extra'>
@@ -155,6 +151,6 @@ export function createIndexDefinition(
155151
properties: getIndexProperties(index),
156152
size: indexSize,
157153
relativeSize: (indexSize / maxSize) * 100,
158-
buildProgress,
154+
buildProgress: buildProgress ?? 0,
159155
};
160156
}

0 commit comments

Comments
 (0)