From 44b64a9ff9d83a93c8ae8580dfdf32b37c502431 Mon Sep 17 00:00:00 2001 From: Sergey Petushkov Date: Wed, 26 Nov 2025 12:09:29 +0100 Subject: [PATCH] fix(eslint): resolve no-unsafe-enum-comparison issues --- configs/eslint-config-compass/index.js | 1 - .../src/modules/search-indexes.ts | 4 ++-- .../src/components/index.spec.tsx | 13 ++++++++++--- .../compass-global-writes/src/components/index.tsx | 8 ++++---- .../src/components/indexes/indexes.spec.tsx | 11 ++++++----- .../src/components/indexes/indexes.tsx | 3 +-- .../search-indexes-table.spec.tsx | 2 +- .../search-indexes-table/search-indexes-table.tsx | 5 ++--- .../compass-indexes/src/modules/regular-indexes.ts | 14 ++++++-------- .../compass-indexes/src/modules/search-indexes.ts | 10 ++++------ 10 files changed, 36 insertions(+), 35 deletions(-) diff --git a/configs/eslint-config-compass/index.js b/configs/eslint-config-compass/index.js index 46c92fcf22e..52341b154f9 100644 --- a/configs/eslint-config-compass/index.js +++ b/configs/eslint-config-compass/index.js @@ -16,7 +16,6 @@ const tempNewEslintRulesDisabled = { 'react-hooks/purity': 'off', '@typescript-eslint/no-redundant-type-constituents': 'off', '@typescript-eslint/await-thenable': 'off', - '@typescript-eslint/no-unsafe-enum-comparison': 'off', }; const extraTsRules = { diff --git a/packages/compass-aggregations/src/modules/search-indexes.ts b/packages/compass-aggregations/src/modules/search-indexes.ts index 3347ce41593..e47224664ff 100644 --- a/packages/compass-aggregations/src/modules/search-indexes.ts +++ b/packages/compass-aggregations/src/modules/search-indexes.ts @@ -3,7 +3,7 @@ import type { PipelineBuilderThunkAction } from '.'; import type { SearchIndex } from 'mongodb-data-service'; import { isAction } from '../utils/is-action'; -enum SearchIndexesStatuses { +export enum SearchIndexesStatuses { INITIAL = 'INITIAL', LOADING = 'LOADING', READY = 'READY', @@ -39,7 +39,7 @@ export type SearchIndexesAction = type State = { isSearchIndexesSupported: boolean; indexes: SearchIndex[]; - status: SearchIndexesStatus; + status: SearchIndexesStatuses; }; export const INITIAL_STATE: State = { diff --git a/packages/compass-global-writes/src/components/index.spec.tsx b/packages/compass-global-writes/src/components/index.spec.tsx index c5ab3f89791..4e5c6f94418 100644 --- a/packages/compass-global-writes/src/components/index.spec.tsx +++ b/packages/compass-global-writes/src/components/index.spec.tsx @@ -3,20 +3,27 @@ import { expect } from 'chai'; import { screen } from '@mongodb-js/testing-library-compass'; import { GlobalWrites } from './index'; import { renderWithStore } from './../../tests/create-store'; +import { ShardingStatuses } from '../store/reducer'; describe('Compass GlobalWrites Plugin', function () { it('renders plugin in NOT_READY state', async function () { - await renderWithStore(); + await renderWithStore( + + ); expect(screen.getByText(/loading/i)).to.exist; }); it('renders plugin in UNSHARDED state', async function () { - await renderWithStore(); + await renderWithStore( + + ); expect(screen.getByTestId('shard-collection-button')).to.exist; }); it('renders plugin in SHARDING state', async function () { - await renderWithStore(); + await renderWithStore( + + ); expect(screen.getByText(/sharding your collection/i)).to.exist; }); }); diff --git a/packages/compass-global-writes/src/components/index.tsx b/packages/compass-global-writes/src/components/index.tsx index 4a62e749417..73bb4a85cdc 100644 --- a/packages/compass-global-writes/src/components/index.tsx +++ b/packages/compass-global-writes/src/components/index.tsx @@ -7,7 +7,7 @@ import { SpinLoaderWithLabel, ConfirmationModalArea, } from '@mongodb-js/compass-components'; -import type { RootState, ShardingStatus } from '../store/reducer'; +import type { RootState } from '../store/reducer'; import { ShardingStatuses } from '../store/reducer'; import UnshardedState from './states/unsharded'; import ShardingState from './states/sharding'; @@ -36,13 +36,13 @@ const loaderStyles = css({ }); type GlobalWritesProps = { - shardingStatus: ShardingStatus; + shardingStatus: ShardingStatuses; }; function ShardingStateView({ shardingStatus, }: { - shardingStatus: Exclude; + shardingStatus: Exclude; }) { if (shardingStatus === ShardingStatuses.UNSHARDED) { return ; @@ -72,7 +72,7 @@ function ShardingStateView({ return ; } - if (shardingStatus === String(ShardingStatuses.LOADING_ERROR)) { + if (shardingStatus === ShardingStatuses.LOADING_ERROR) { return ; } diff --git a/packages/compass-indexes/src/components/indexes/indexes.spec.tsx b/packages/compass-indexes/src/components/indexes/indexes.spec.tsx index 050c346e09a..1310fdd4851 100644 --- a/packages/compass-indexes/src/components/indexes/indexes.spec.tsx +++ b/packages/compass-indexes/src/components/indexes/indexes.spec.tsx @@ -23,6 +23,7 @@ import type { RootState } from '../../modules'; import type { Document } from 'mongodb'; import { CompassExperimentationProvider } from '@mongodb-js/compass-telemetry'; import { ExperimentTestGroup } from '@mongodb-js/compass-telemetry/provider'; +import { FetchStatuses } from '../../utils/fetch-status'; const renderIndexes = async ( options: Partial = {}, @@ -82,7 +83,7 @@ describe('Indexes Component', function () { regularIndexes: { indexes: [], error: 'Some random error', - status: 'ERROR', + status: FetchStatuses.ERROR, inProgressIndexes: [], }, }); @@ -124,7 +125,7 @@ describe('Indexes Component', function () { await renderIndexes(undefined, undefined, { indexView: 'regular-indexes', regularIndexes: { - status: 'NOT_READY', + status: FetchStatuses.NOT_READY, inProgressIndexes: [], indexes: [], }, @@ -161,7 +162,7 @@ describe('Indexes Component', function () { }, ] as RegularIndex[], error: undefined, - status: 'READY', + status: FetchStatuses.READY, inProgressIndexes: [], }, }); @@ -211,7 +212,7 @@ describe('Indexes Component', function () { }, ], error: undefined, - status: 'READY', + status: FetchStatuses.READY, }, }); @@ -269,7 +270,7 @@ describe('Indexes Component', function () { }, ], error: undefined, - status: 'READY', + status: FetchStatuses.READY, }, }); diff --git a/packages/compass-indexes/src/components/indexes/indexes.tsx b/packages/compass-indexes/src/components/indexes/indexes.tsx index 987d9859003..68adce4be02 100644 --- a/packages/compass-indexes/src/components/indexes/indexes.tsx +++ b/packages/compass-indexes/src/components/indexes/indexes.tsx @@ -25,7 +25,6 @@ import { VIEW_PIPELINE_UTILS } from '@mongodb-js/mongodb-constants'; import type { State as RegularIndexesState } from '../../modules/regular-indexes'; import type { State as SearchIndexesState } from '../../modules/search-indexes'; import { FetchStatuses } from '../../utils/fetch-status'; -import type { FetchStatus } from '../../utils/fetch-status'; import type { RootState } from '../../modules'; import { CreateSearchIndexModal, @@ -174,7 +173,7 @@ type IndexesProps = { collectionStats: CollectionStats; }; -function isRefreshingStatus(status: FetchStatus) { +function isRefreshingStatus(status: FetchStatuses) { return ( status === FetchStatuses.FETCHING || status === FetchStatuses.REFRESHING ); diff --git a/packages/compass-indexes/src/components/search-indexes-table/search-indexes-table.spec.tsx b/packages/compass-indexes/src/components/search-indexes-table/search-indexes-table.spec.tsx index d5954e7b8c5..f8e70aff1bb 100644 --- a/packages/compass-indexes/src/components/search-indexes-table/search-indexes-table.spec.tsx +++ b/packages/compass-indexes/src/components/search-indexes-table/search-indexes-table.spec.tsx @@ -26,7 +26,7 @@ const renderIndexList = ( void; onEditIndexClick: (name: string) => void; onOpenCreateModalClick: () => void; @@ -56,7 +55,7 @@ type SearchIndexesTableProps = { onSearchIndexesClosed: (tabId: string) => void; }; -function isReadyStatus(status: FetchStatus) { +function isReadyStatus(status: FetchStatuses) { return ( status === FetchStatuses.READY || status === FetchStatuses.REFRESHING || diff --git a/packages/compass-indexes/src/modules/regular-indexes.ts b/packages/compass-indexes/src/modules/regular-indexes.ts index 661ea04d5c4..a989125da3f 100644 --- a/packages/compass-indexes/src/modules/regular-indexes.ts +++ b/packages/compass-indexes/src/modules/regular-indexes.ts @@ -7,9 +7,7 @@ import { } from '@mongodb-js/compass-components'; import { FetchStatuses, NOT_FETCHABLE_STATUSES } from '../utils/fetch-status'; -import type { FetchStatus } from '../utils/fetch-status'; import { FetchReasons } from '../utils/fetch-reason'; -import type { FetchReason } from '../utils/fetch-reason'; import { isAction } from '../utils/is-action'; import type { CreateIndexSpec } from './create-index'; import type { IndexesThunkAction, RootState } from '.'; @@ -130,7 +128,7 @@ type IndexesClosedAction = { type FetchIndexesStartedAction = { type: ActionTypes.FetchIndexesStarted; - reason: FetchReason; + reason: FetchReasons; }; type FetchIndexesSucceededAction = { @@ -171,7 +169,7 @@ type RollingIndexTimeoutCheckAction = { }; export type State = { - status: FetchStatus; + status: FetchStatuses; indexes: RegularIndex[]; inProgressIndexes: InProgressIndex[]; rollingIndexes?: RollingIndex[]; @@ -346,7 +344,7 @@ export default function reducer( } const fetchIndexesStarted = ( - reason: FetchReason + reason: FetchReasons ): FetchIndexesStartedAction => ({ type: ActionTypes.FetchIndexesStarted, reason, @@ -380,7 +378,7 @@ function pickCollectionStatFields(state: RootState) { } const fetchIndexes = ( - reason: FetchReason + reason: FetchReasons ): IndexesThunkAction, FetchIndexesActions> => { return async ( dispatch, @@ -425,8 +423,8 @@ const fetchIndexes = ( dataService.indexes(namespace), shouldFetchRollingIndexes ? rollingIndexesService.listRollingIndexes(namespace) - : undefined, - ] as [Promise, Promise | undefined]; + : Promise.resolve(undefined), + ] as [Promise, Promise]; const [indexes, rollingIndexes] = await Promise.all(promises); const indexesBefore = pickCollectionStatFields(getState()); dispatch(fetchIndexesSucceeded(indexes, rollingIndexes)); diff --git a/packages/compass-indexes/src/modules/search-indexes.ts b/packages/compass-indexes/src/modules/search-indexes.ts index 0261ef62711..0ba16f42773 100644 --- a/packages/compass-indexes/src/modules/search-indexes.ts +++ b/packages/compass-indexes/src/modules/search-indexes.ts @@ -9,10 +9,8 @@ import type { SearchIndex } from 'mongodb-data-service'; import { isAction } from '../utils/is-action'; import { FetchStatuses, NOT_FETCHABLE_STATUSES } from '../utils/fetch-status'; -import type { FetchStatus } from '../utils/fetch-status'; import { FetchReasons } from '../utils/fetch-reason'; -import type { FetchReason } from '../utils/fetch-reason'; import type { IndexesThunkAction } from '.'; import { switchToSearchIndexes } from './index-view'; @@ -48,7 +46,7 @@ export enum ActionTypes { type FetchSearchIndexesStartedAction = { type: ActionTypes.FetchSearchIndexesStarted; - reason: FetchReason; + reason: FetchReasons; }; type FetchSearchIndexesSucceededAction = { @@ -118,7 +116,7 @@ type UpdateSearchIndexState = { }; export type State = { - status: FetchStatus; + status: FetchStatuses; createIndex: CreateSearchIndexState; updateIndex: UpdateSearchIndexState; error?: string; @@ -376,7 +374,7 @@ export const updateSearchIndexClosed = (): UpdateSearchIndexClosedAction => ({ }); const fetchSearchIndexesStarted = ( - reason: FetchReason + reason: FetchReasons ): FetchSearchIndexesStartedAction => ({ type: ActionTypes.FetchSearchIndexesStarted, reason, @@ -596,7 +594,7 @@ type FetchSearchIndexesActions = | FetchSearchIndexesFailedAction; const fetchIndexes = ( - reason: FetchReason + reason: FetchReasons ): IndexesThunkAction, FetchSearchIndexesActions> => { return async (dispatch, getState, { dataService }) => { const {