Skip to content

Commit

Permalink
fix(aggregations): disregard env in snippets COMPASS-6976 (#4906)
Browse files Browse the repository at this point in the history
  • Loading branch information
mabaasit authored Oct 2, 2023
1 parent 86fbc93 commit da76e43
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 28 deletions.
17 changes: 0 additions & 17 deletions packages/compass-aggregations/src/modules/env.js

This file was deleted.

9 changes: 9 additions & 0 deletions packages/compass-aggregations/src/modules/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ON_PREM, type ENVS } from '@mongodb-js/mongodb-constants';

export type ServerEnvironment = typeof ENVS[number];

export const INITIAL_STATE: ServerEnvironment = ON_PREM;

export default function reducer(state = INITIAL_STATE) {
return state;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type { PipelineBuilderThunkAction } from '../';
import { isAction } from '../../utils/is-action';
import type Stage from './stage';
import { ActionTypes as ConfirmNewPipelineActions } from '../is-new-pipeline-confirm';
import type { ENVS } from '@mongodb-js/mongodb-constants';
import { STAGE_OPERATORS } from '@mongodb-js/mongodb-constants';
import { DEFAULT_MAX_TIME_MS } from '../../constants';
import type { PreviewOptions } from './pipeline-preview-manager';
Expand All @@ -26,6 +25,7 @@ import { mapPipelineModeToEditorViewType } from './builder-helpers';
import { getId } from './stage-ids';
import { fetchExplainForPipeline } from '../insights';
import { AIPipelineActionTypes } from './pipeline-ai';
import type { ServerEnvironment } from './../env';
import type {
LoadGeneratedPipelineAction,
PipelineGeneratedFromQueryAction,
Expand Down Expand Up @@ -417,21 +417,19 @@ const ESCAPED_STAGE_OPERATORS = STAGE_OPERATORS.map((stage) => {

function getStageSnippet(
stageOperator: string | null,
env: string,
env: ServerEnvironment,
shouldAddComment: boolean,
escaped = false
) {
const stage = (escaped ? ESCAPED_STAGE_OPERATORS : STAGE_OPERATORS).find(
(stageOp) => {
return (
stageOp.value === stageOperator &&
(stageOp.env as readonly typeof ENVS[number][]).includes(
env as typeof ENVS[number]
)
);
}
const stages = (escaped ? ESCAPED_STAGE_OPERATORS : STAGE_OPERATORS).filter(
(stageOp) => stageOp.value === stageOperator
);

const stage =
stages.find((stageOp) =>
(stageOp.env as readonly ServerEnvironment[]).includes(env)
) ?? stages[0];

if (!stage) {
return `{}`;
}
Expand Down

0 comments on commit da76e43

Please sign in to comment.