Skip to content

Commit d4e8ccb

Browse files
authored
chore(typescript): replace enums with const records COMPASS-10124 (#7621)
chore(typescript): replace enums with const records
1 parent 91e7220 commit d4e8ccb

File tree

92 files changed

+1497
-1349
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+1497
-1349
lines changed

packages/compass-aggregations/src/components/pipeline-toolbar/index.spec.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { renderWithStore } from '../../../test/configure-store';
1111
import { PipelineToolbar } from './index';
1212
import { createElectronPipelineStorage } from '@mongodb-js/my-queries-storage/electron';
1313
import { CompassExperimentationProvider } from '@mongodb-js/compass-telemetry';
14-
import { ExperimentTestGroup } from '@mongodb-js/compass-telemetry/provider';
14+
import { ExperimentTestGroups } from '@mongodb-js/compass-telemetry/provider';
1515
import type { PreferencesAccess } from 'compass-preferences-model';
1616
import { createSandboxFromDefaultPreferences } from 'compass-preferences-model';
1717

@@ -164,7 +164,7 @@ describe('PipelineToolbar', function () {
164164
mockUseAssignment.returns({
165165
assignment: {
166166
assignmentData: {
167-
variant: ExperimentTestGroup.atlasSkillsVariant,
167+
variant: ExperimentTestGroups.atlasSkillsVariant,
168168
},
169169
},
170170
...commonAsyncStatus,
@@ -173,7 +173,7 @@ describe('PipelineToolbar', function () {
173173
mockUseAssignment.returns({
174174
assignment: {
175175
assignmentData: {
176-
variant: ExperimentTestGroup.atlasSkillsControl,
176+
variant: ExperimentTestGroups.atlasSkillsControl,
177177
},
178178
},
179179
...commonAsyncStatus,

packages/compass-aggregations/src/modules/aggregation.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,15 @@ export const WriteOperation = {
4141
Overwrite: 'overwriting',
4242
} as const;
4343

44-
// @ts-expect-error TODO(COMPASS-10124): replace enums with const kv objects
45-
export enum ActionTypes {
46-
RunAggregation = 'compass-aggeregations/runAggregation',
47-
AggregationStarted = 'compass-aggregations/aggregationStarted',
48-
AggregationFinished = 'compass-aggregations/aggregationFinished',
49-
AggregationFailed = 'compass-aggregations/aggregationFailed',
50-
AggregationCancelledByUser = 'compass-aggregations/aggregationCancelledByUser',
51-
LastPageReached = 'compass-aggregations/lastPageReached',
52-
ResultViewTypeChanged = 'compass-aggregations/resultViewTypeChanged',
53-
}
44+
export const ActionTypes = {
45+
RunAggregation: 'compass-aggeregations/runAggregation',
46+
AggregationStarted: 'compass-aggregations/aggregationStarted',
47+
AggregationFinished: 'compass-aggregations/aggregationFinished',
48+
AggregationFailed: 'compass-aggregations/aggregationFailed',
49+
AggregationCancelledByUser: 'compass-aggregations/aggregationCancelledByUser',
50+
LastPageReached: 'compass-aggregations/lastPageReached',
51+
ResultViewTypeChanged: 'compass-aggregations/resultViewTypeChanged',
52+
} as const;
5453

5554
type PreviousPageData = {
5655
page: number;
@@ -59,17 +58,17 @@ type PreviousPageData = {
5958
};
6059

6160
export type RunAggregation = {
62-
type: ActionTypes.RunAggregation;
61+
type: typeof ActionTypes.RunAggregation;
6362
pipeline: Document[];
6463
};
6564

6665
export type AggregationStartedAction = {
67-
type: ActionTypes.AggregationStarted;
66+
type: typeof ActionTypes.AggregationStarted;
6867
abortController: AbortController;
6968
};
7069

7170
export type AggregationFinishedAction = {
72-
type: ActionTypes.AggregationFinished;
71+
type: typeof ActionTypes.AggregationFinished;
7372
documents: HadronDocument[];
7473
page: number;
7574
isLast: boolean;
@@ -81,22 +80,22 @@ export type AggregationError = {
8180
};
8281

8382
export type AggregationFailedAction = {
84-
type: ActionTypes.AggregationFailed;
83+
type: typeof ActionTypes.AggregationFailed;
8584
error: AggregationError;
8685
page: number;
8786
};
8887

8988
export type AggregationCancelledAction = {
90-
type: ActionTypes.AggregationCancelledByUser;
89+
type: typeof ActionTypes.AggregationCancelledByUser;
9190
};
9291

9392
export type LastPageReachedAction = {
94-
type: ActionTypes.LastPageReached;
93+
type: typeof ActionTypes.LastPageReached;
9594
page: number;
9695
};
9796

9897
export type ResultViewTypeChangedAction = {
99-
type: ActionTypes.ResultViewTypeChanged;
98+
type: typeof ActionTypes.ResultViewTypeChanged;
10099
viewType: 'document' | 'json';
101100
};
102101

packages/compass-aggregations/src/modules/auto-preview.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ import type { RestorePipelineAction } from './saved-pipeline';
77
import { RESTORE_PIPELINE } from './saved-pipeline';
88
import { isAction } from '../utils/is-action';
99

10-
// @ts-expect-error TODO(COMPASS-10124): replace enums with const kv objects
11-
export enum ActionTypes {
12-
AutoPreviewToggled = 'compass-aggregations/autoPreviewToggled',
13-
}
10+
export const ActionTypes = {
11+
AutoPreviewToggled: 'compass-aggregations/autoPreviewToggled',
12+
} as const;
1413

1514
export type AutoPreviewToggledAction = {
16-
type: ActionTypes.AutoPreviewToggled;
15+
type: typeof ActionTypes.AutoPreviewToggled;
1716
value: boolean;
1817
};
1918
export type AutoPreviewAction = AutoPreviewToggledAction;

packages/compass-aggregations/src/modules/collection-stats.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ export function pickCollectionStats(collection: Collection): CollectionStats {
2020
};
2121
}
2222

23-
// @ts-expect-error TODO(COMPASS-10124): replace enums with const kv objects
24-
enum CollectionStatsActions {
25-
CollectionStatsFetched = 'compass-aggregations/collection-stats/CollectionStatsFetched',
26-
}
23+
const CollectionStatsActions = {
24+
CollectionStatsFetched:
25+
'compass-aggregations/collection-stats/CollectionStatsFetched',
26+
} as const;
2727

2828
interface CollectionStatsFetchedAction {
29-
type: CollectionStatsActions.CollectionStatsFetched;
29+
type: typeof CollectionStatsActions.CollectionStatsFetched;
3030
collection: Collection;
3131
}
3232

packages/compass-aggregations/src/modules/collections-fields.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,26 @@ export type CollectionInfo = Pick<Collection, 'name' | 'type'>;
1212

1313
type CollectionType = CollectionInfo['type'];
1414

15-
// @ts-expect-error TODO(COMPASS-10124): replace enums with const kv objects
16-
export enum ActionTypes {
17-
CollectionsFetch = 'compass-aggregations/collectionsFetched',
18-
CollectionFieldsFetched = 'compass-aggregations/collectionFieldsFetched',
19-
CollectionDataUpdated = 'compass-aggregations/collectionDataUpdated',
20-
}
15+
export const ActionTypes = {
16+
CollectionsFetch: 'compass-aggregations/collectionsFetched',
17+
CollectionFieldsFetched: 'compass-aggregations/collectionFieldsFetched',
18+
CollectionDataUpdated: 'compass-aggregations/collectionDataUpdated',
19+
} as const;
2120

2221
type CollectionsFetchedAction = {
23-
type: ActionTypes.CollectionsFetch;
22+
type: typeof ActionTypes.CollectionsFetch;
2423
data: State;
2524
};
2625

2726
type CollectionFieldsFetchedAction = {
28-
type: ActionTypes.CollectionFieldsFetched;
27+
type: typeof ActionTypes.CollectionFieldsFetched;
2928
collection: string;
3029
fields: string[];
3130
collectionType: CollectionType;
3231
};
3332

3433
type CollectionDataUpdatedAction = {
35-
type: ActionTypes.CollectionDataUpdated;
34+
type: typeof ActionTypes.CollectionDataUpdated;
3635
collection: string;
3736
data: CollectionData;
3837
};

packages/compass-aggregations/src/modules/count-documents.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,24 @@ import { ActionTypes as ConfirmNewPipelineActions } from './is-new-pipeline-conf
1010
import { getPipelineFromBuilderState } from './pipeline-builder/builder-helpers';
1111
import { isAction } from '../utils/is-action';
1212

13-
// @ts-expect-error TODO(COMPASS-10124): replace enums with const kv objects
14-
export enum ActionTypes {
15-
CountStarted = 'compass-aggregations/countStarted',
16-
CountFinished = 'compass-aggregations/countFinished',
17-
CountFailed = 'compass-aggregations/countFailed',
18-
}
13+
export const ActionTypes = {
14+
CountStarted: 'compass-aggregations/countStarted',
15+
CountFinished: 'compass-aggregations/countFinished',
16+
CountFailed: 'compass-aggregations/countFailed',
17+
} as const;
1918

2019
type CountStartedAction = {
21-
type: ActionTypes.CountStarted;
20+
type: typeof ActionTypes.CountStarted;
2221
abortController: AbortController;
2322
};
2423

2524
type CountFinishedAction = {
26-
type: ActionTypes.CountFinished;
25+
type: typeof ActionTypes.CountFinished;
2726
count: number;
2827
};
2928

3029
type CountFailedAction = {
31-
type: ActionTypes.CountFailed;
30+
type: typeof ActionTypes.CountFailed;
3231
};
3332

3433
export type Actions =

packages/compass-aggregations/src/modules/create-view/index.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,50 +26,49 @@ export const INITIAL_STATE: CreateViewState = {
2626
pipeline: [],
2727
};
2828

29-
// @ts-expect-error TODO(COMPASS-10124): replace enums with const kv objects
30-
enum CreateViewActionTypes {
31-
Open = 'aggregations/create-view/Open',
32-
Close = 'aggregations/create-view/Close',
33-
ToggleIsRunning = 'aggregations/create-view/is-running/ToggleIsRunning',
34-
HandleError = 'aggregations/create-view/error/HandleError',
35-
ClearError = 'aggregations/create-view/error/ClearError',
36-
ChangeViewName = 'aggregations/create-view/name/ChangeName',
37-
Reset = 'aggregations/create-view/reset',
38-
}
29+
const CreateViewActionTypes = {
30+
Open: 'aggregations/create-view/Open',
31+
Close: 'aggregations/create-view/Close',
32+
ToggleIsRunning: 'aggregations/create-view/is-running/ToggleIsRunning',
33+
HandleError: 'aggregations/create-view/error/HandleError',
34+
ClearError: 'aggregations/create-view/error/ClearError',
35+
ChangeViewName: 'aggregations/create-view/name/ChangeName',
36+
Reset: 'aggregations/create-view/reset',
37+
} as const;
3938

4039
export type OpenAction = {
41-
type: CreateViewActionTypes.Open;
40+
type: typeof CreateViewActionTypes.Open;
4241
connectionId: string;
4342
source: string;
4443
pipeline: unknown[];
4544
duplicate: boolean;
4645
};
4746

4847
export type CloseAction = {
49-
type: CreateViewActionTypes.Close;
48+
type: typeof CreateViewActionTypes.Close;
5049
};
5150

5251
export type ToggleIsRunningAction = {
53-
type: CreateViewActionTypes.ToggleIsRunning;
52+
type: typeof CreateViewActionTypes.ToggleIsRunning;
5453
isRunning: boolean;
5554
};
5655

5756
export type HandleErrorAction = {
58-
type: CreateViewActionTypes.HandleError;
57+
type: typeof CreateViewActionTypes.HandleError;
5958
error: Error;
6059
};
6160

6261
export type ClearErrorAction = {
63-
type: CreateViewActionTypes.ClearError;
62+
type: typeof CreateViewActionTypes.ClearError;
6463
};
6564

6665
export type ChangeViewNameAction = {
67-
type: CreateViewActionTypes.ChangeViewName;
66+
type: typeof CreateViewActionTypes.ChangeViewName;
6867
name: string;
6968
};
7069

7170
export type ResetAction = {
72-
type: CreateViewActionTypes.Reset;
71+
type: typeof CreateViewActionTypes.Reset;
7372
};
7473

7574
export type CreateViewAction =

packages/compass-aggregations/src/modules/focus-mode.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,23 @@ import type { PipelineBuilderThunkAction } from '.';
33
import { isAction } from '../utils/is-action';
44
import { addStage, pipelineFromStore } from './pipeline-builder/stage-editor';
55

6-
// @ts-expect-error TODO(COMPASS-10124): replace enums with const kv objects
7-
enum ActionTypes {
8-
FocusModeEnabled = 'compass-aggregations/focusModeEnabled',
9-
FocusModeDisabled = 'compass-aggregations/focusModeDisabled',
10-
SelectFocusModeStage = 'compass-aggregations/selectFocusModeStage',
11-
}
6+
const ActionTypes = {
7+
FocusModeEnabled: 'compass-aggregations/focusModeEnabled',
8+
FocusModeDisabled: 'compass-aggregations/focusModeDisabled',
9+
SelectFocusModeStage: 'compass-aggregations/selectFocusModeStage',
10+
} as const;
1211

1312
type FocusModeEnabledAction = {
14-
type: ActionTypes.FocusModeEnabled;
13+
type: typeof ActionTypes.FocusModeEnabled;
1514
stageIndex: number;
1615
};
1716

1817
type FocusModeDisabledAction = {
19-
type: ActionTypes.FocusModeDisabled;
18+
type: typeof ActionTypes.FocusModeDisabled;
2019
};
2120

2221
type SelectFocusModeStageAction = {
23-
type: ActionTypes.SelectFocusModeStage;
22+
type: typeof ActionTypes.SelectFocusModeStage;
2423
index: number;
2524
};
2625

packages/compass-aggregations/src/modules/input-documents.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,22 @@ import type { AnyAction } from 'redux';
55
import { isAction } from '../utils/is-action';
66
import { DEFAULT_MAX_TIME_MS } from '../constants';
77

8-
// @ts-expect-error TODO(COMPASS-10124): replace enums with const kv objects
9-
export enum ActionTypes {
10-
CollapseToggled = 'aggregations/input-documents/CollapseToggled',
11-
DocumentsFetchStarted = 'aggregations/input-documents/DocumentsFetchStarted',
12-
DocumentsFetchFinished = 'aggregations/input-documents/DocumentsFetchFinished',
13-
}
8+
export const ActionTypes = {
9+
CollapseToggled: 'aggregations/input-documents/CollapseToggled',
10+
DocumentsFetchStarted: 'aggregations/input-documents/DocumentsFetchStarted',
11+
DocumentsFetchFinished: 'aggregations/input-documents/DocumentsFetchFinished',
12+
} as const;
1413

1514
type CollapseToggledAction = {
16-
type: ActionTypes.CollapseToggled;
15+
type: typeof ActionTypes.CollapseToggled;
1716
};
1817

1918
type DocumentsFetchStartedAction = {
20-
type: ActionTypes.DocumentsFetchStarted;
19+
type: typeof ActionTypes.DocumentsFetchStarted;
2120
};
2221

2322
type DocumentsFetchFinishedAction = {
24-
type: ActionTypes.DocumentsFetchFinished;
23+
type: typeof ActionTypes.DocumentsFetchFinished;
2524
documents: HadronDocument[];
2625
error: Error | null;
2726
};

packages/compass-aggregations/src/modules/is-new-pipeline-confirm.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import type Stage from './pipeline-builder/stage';
55
import type { Document } from 'bson';
66
import type { PipelineParserError } from './pipeline-builder/pipeline-parser/utils';
77

8-
// @ts-expect-error TODO(COMPASS-10124): replace enums with const kv objects
9-
export enum ActionTypes {
10-
NewPipelineConfirmed = 'compass-aggregations/is-new-pipeline-confirm/newPipelineConfirmed',
11-
}
8+
export const ActionTypes = {
9+
NewPipelineConfirmed:
10+
'compass-aggregations/is-new-pipeline-confirm/newPipelineConfirmed',
11+
} as const;
1212

1313
export type NewPipelineConfirmedAction = {
14-
type: ActionTypes.NewPipelineConfirmed;
14+
type: typeof ActionTypes.NewPipelineConfirmed;
1515
stages: Stage[];
1616
pipelineText: string;
1717
pipeline: Document[] | null;

0 commit comments

Comments
 (0)