Skip to content
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

refactor: move isAction to compass-utils #6268

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 1 addition & 8 deletions packages/atlas-service/src/store/atlas-signin-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@ import type { ThunkAction } from 'redux-thunk';
import { openToast } from '@mongodb-js/compass-components';
import type { AtlasUserInfo } from '../util';
import type { AtlasAuthService } from '../provider';
import { throwIfAborted } from '@mongodb-js/compass-utils';

export function isAction<A extends AnyAction>(
action: AnyAction,
type: A['type']
): action is A {
return action.type === type;
}
import { throwIfAborted, isAction } from '@mongodb-js/compass-utils';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good thing to do in general (we should also consider moving some type helpers for redux in the same place), but compass-utils has a dependency on electron and by moving this very generic dependency here you are adding electron to a dependency chain of all plugins that will use it, so we should either have it exported under a different named export to separate the code by imports (this might be good to do for this async helpers anyway), have electron and electron/remote as optional peer deps instead of direct deps and account for this in code, have a completely separate package for these redux helpers


export type AtlasSignInState = {
error: string | null;
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-aggregations/src/modules/aggregation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
isOutputStage,
} from '../utils/stage';
import { fetchExplainForPipeline } from './insights';
import { isAction } from '../utils/is-action';
import { isAction } from '@mongodb-js/compass-utils';
import {
showConfirmation,
ConfirmationModalVariant,
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-aggregations/src/modules/auto-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ActionTypes as ConfirmNewPipelineActions } from './is-new-pipeline-conf
import { updatePipelinePreview } from './pipeline-builder/builder-helpers';
import type { RestorePipelineAction } from './saved-pipeline';
import { RESTORE_PIPELINE } from './saved-pipeline';
import { isAction } from '../utils/is-action';
import { isAction } from '@mongodb-js/compass-utils';

export enum ActionTypes {
AutoPreviewToggled = 'compass-aggregations/autoPreviewToggled',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ActionTypes as ConfirmNewPipelineActions } from './is-new-pipeline-conf
import type { RestorePipelineAction } from './saved-pipeline';
import { RESTORE_PIPELINE } from './saved-pipeline';
import type { AnyAction } from 'redux';
import { isAction } from '../utils/is-action';
import { isAction } from '@mongodb-js/compass-utils';

/**
* Collation string changed action.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Action, Reducer } from 'redux';
import type Collection from 'mongodb-collection-model';
import { isAction } from '../utils/is-action';
import { isAction } from '@mongodb-js/compass-utils';

export type CollectionStats = {
document_count?: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isAction } from '../utils/is-action';
import { isAction } from '@mongodb-js/compass-utils';
import type { PipelineBuilderThunkAction } from '.';
import { getSchema } from '../utils/get-schema';
import toNS from 'mongodb-ns';
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-aggregations/src/modules/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { RestorePipelineAction } from './saved-pipeline';
import { RESTORE_PIPELINE } from './saved-pipeline';
import type { ApplySettingsAction } from './settings';
import { APPLY_SETTINGS } from './settings';
import { isAction } from '../utils/is-action';
import { isAction } from '@mongodb-js/compass-utils';

export type CommentsState = boolean;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ActionTypes as WorkspaceActionTypes } from './workspace';
import type { NewPipelineConfirmedAction } from './is-new-pipeline-confirm';
import { ActionTypes as ConfirmNewPipelineActions } from './is-new-pipeline-confirm';
import { getPipelineFromBuilderState } from './pipeline-builder/builder-helpers';
import { isAction } from '../utils/is-action';
import { isAction } from '@mongodb-js/compass-utils';

export enum ActionTypes {
CountStarted = 'compass-aggregations/countStarted',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Reducer } from 'redux';
import parseNs from 'mongodb-ns';
import type { Document } from 'bson';
import type { CreateViewThunkAction } from '../../stores/create-view';
import { isAction } from '../../utils/is-action';
import { isAction } from '@mongodb-js/compass-utils';

export type CreateViewState = {
connectionId: string;
Expand Down
3 changes: 2 additions & 1 deletion packages/compass-aggregations/src/modules/focus-mode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AnyAction } from 'redux';
import type { PipelineBuilderThunkAction } from '.';
import { isAction } from '../utils/is-action';
import { isAction } from '@mongodb-js/compass-utils';

import { addStage, pipelineFromStore } from './pipeline-builder/stage-editor';

enum ActionTypes {
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-aggregations/src/modules/id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
} from './pipeline-builder/pipeline-ai';
import { AIPipelineActionTypes } from './pipeline-builder/pipeline-ai';
import type { AnyAction } from 'redux';
import { isAction } from '../utils/is-action';
import { isAction } from '@mongodb-js/compass-utils';

/**
* Id create action.
Expand Down
3 changes: 2 additions & 1 deletion packages/compass-aggregations/src/modules/input-documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import HadronDocument from 'hadron-document';
import { capMaxTimeMSAtPreferenceLimit } from 'compass-preferences-model/provider';
import type { PipelineBuilderThunkAction } from '.';
import type { AnyAction } from 'redux';
import { isAction } from '../utils/is-action';
import { isAction } from '@mongodb-js/compass-utils';

import { DEFAULT_MAX_TIME_MS } from '../constants';

export enum ActionTypes {
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-aggregations/src/modules/insights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
} from './pipeline-builder/pipeline-ai';
import { AIPipelineActionTypes } from './pipeline-builder/pipeline-ai';
import { getStageOperator, isOutputStage } from '../utils/stage';
import { isAction } from '../utils/is-action';
import { isAction } from '@mongodb-js/compass-utils';

const FETCH_EXPLAIN_PLAN_SUCCESS =
'compass-aggregations/FETCH_EXPLAIN_PLAN_SUCCESS' as const;
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-aggregations/src/modules/is-modified.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type {
} from './pipeline-builder/pipeline-ai';
import { AIPipelineActionTypes } from './pipeline-builder/pipeline-ai';
import type { AnyAction } from 'redux';
import { isAction } from '../utils/is-action';
import { isAction } from '@mongodb-js/compass-utils';

/**
* Reducer function for handle state changes to isModified.
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-aggregations/src/modules/large-limit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { NewPipelineConfirmedAction } from './is-new-pipeline-confirm';
import { ActionTypes as ConfirmNewPipelineActions } from './is-new-pipeline-confirm';
import type { ApplySettingsAction } from './settings';
import { APPLY_SETTINGS } from './settings';
import { isAction } from '../utils/is-action';
import { isAction } from '@mongodb-js/compass-utils';

export type LargeLimitState = number;
export const INITIAL_STATE = DEFAULT_LARGE_LIMIT;
Expand Down
3 changes: 2 additions & 1 deletion packages/compass-aggregations/src/modules/limit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AnyAction } from 'redux';
import { DEFAULT_SAMPLE_SIZE } from '../constants';
import { isAction } from '../utils/is-action';
import { isAction } from '@mongodb-js/compass-utils';

import type { NewPipelineConfirmedAction } from './is-new-pipeline-confirm';
import { ActionTypes as ConfirmNewPipelineActions } from './is-new-pipeline-confirm';
import type { ApplySettingsAction } from './settings';
Expand Down
3 changes: 2 additions & 1 deletion packages/compass-aggregations/src/modules/max-time-ms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import type { Action, Reducer } from 'redux';
import type { NewPipelineConfirmedAction } from './is-new-pipeline-confirm';
import { ActionTypes as ConfirmNewPipelineActions } from './is-new-pipeline-confirm';
import { capMaxTimeMSAtPreferenceLimit } from 'compass-preferences-model/provider';
import { isAction } from '../utils/is-action';
import { isAction } from '@mongodb-js/compass-utils';

import type { PipelineBuilderThunkAction } from '.';

export const MAX_TIME_MS_CHANGED =
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-aggregations/src/modules/name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { RestorePipelineAction } from './saved-pipeline';
import { RESTORE_PIPELINE } from './saved-pipeline';
import type { SavingPipelineApplyAction } from './saving-pipeline';
import { SAVING_PIPELINE_APPLY } from './saving-pipeline';
import { isAction } from '../utils/is-action';
import { isAction } from '@mongodb-js/compass-utils';

export type NameState = string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type { Document } from 'mongodb';
import { UUID } from 'bson';

import type { PipelineBuilderThunkAction } from '../';
import { isAction } from '../../utils/is-action';
import type { PipelineParserError } from './pipeline-parser/utils';
import type Stage from './stage';
import { updatePipelinePreview } from './builder-helpers';
Expand All @@ -15,6 +14,7 @@ import type { Logger } from '@mongodb-js/compass-logging/provider';
import { mongoLogId } from '@mongodb-js/compass-logging/provider';
import type { TrackFunction } from '@mongodb-js/compass-telemetry';
import type { ConnectionInfo } from '@mongodb-js/compass-connections/provider';
import { isAction } from '@mongodb-js/compass-utils';

const emptyPipelineError =
'No pipeline was returned. Please try again with a different prompt.';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Action, Reducer } from 'redux';
import type { Document } from 'mongodb';
import type { PipelineBuilderThunkAction } from '..';
import { isAction } from '../../utils/is-action';
import { isAction } from '@mongodb-js/compass-utils';
import {
getPipelineFromBuilderState,
mapPipelineModeToEditorViewType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { prettify } from '@mongodb-js/compass-editor';
import type { RestorePipelineAction } from '../saved-pipeline';
import { RESTORE_PIPELINE } from '../saved-pipeline';
import type { PipelineBuilderThunkAction } from '../';
import { isAction } from '../../utils/is-action';
import { isAction } from '@mongodb-js/compass-utils';
import type Stage from './stage';
import type { NewPipelineConfirmedAction } from '../is-new-pipeline-confirm';
import { ActionTypes as ConfirmNewPipelineActions } from '../is-new-pipeline-confirm';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Action, Reducer } from 'redux';
import type { AggregateOptions, MongoServerError } from 'mongodb';
import type { PipelineBuilderThunkAction } from '..';
import { DEFAULT_MAX_TIME_MS } from '../../constants';
import { isAction } from '../../utils/is-action';
import { isAction } from '@mongodb-js/compass-utils';
import { EditorActionTypes, canRunPipeline } from './text-editor-pipeline';
import type { EditorValueChangeAction } from './text-editor-pipeline';
import type { NewPipelineConfirmedAction } from '../is-new-pipeline-confirm';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
DEFAULT_PREVIEW_LIMIT,
DEFAULT_SAMPLE_SIZE,
} from './pipeline-preview-manager';
import { isAction } from '../../utils/is-action';
import { isAction } from '@mongodb-js/compass-utils';
import type { PipelineParserError } from './pipeline-parser/utils';
import { ActionTypes as PipelineModeActionTypes } from './pipeline-mode';
import type { PipelineModeToggledAction } from './pipeline-mode';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ActionTypes as ConfirmNewPipelineActions } from './is-new-pipeline-conf
import { getPipelineFromBuilderState } from './pipeline-builder/builder-helpers';
import type { PipelineBuilderThunkAction } from '.';
import type { AnyAction } from 'redux';
import { isAction } from '../utils/is-action';
import { isAction } from '@mongodb-js/compass-utils';

export const SAVING_PIPELINE_NAME_CHANGED =
'aggregations/saving-pipeline/NAME_CHANGED' as const;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Action, Reducer } from 'redux';
import type { PipelineBuilderThunkAction } from '.';
import type { SearchIndex } from 'mongodb-data-service';
import { isAction } from '../utils/is-action';
import { isAction } from '@mongodb-js/compass-utils';

enum SearchIndexesStatuses {
INITIAL = 'INITIAL',
Expand Down
Loading
Loading