Skip to content

Commit

Permalink
chore(query-bar, aggregations): replace isAtlasDeployed with preferen…
Browse files Browse the repository at this point in the history
…ces (#5018)
  • Loading branch information
gribnoysup authored Oct 24, 2023
1 parent a74a2c0 commit b75076d
Show file tree
Hide file tree
Showing 23 changed files with 150 additions and 113 deletions.
1 change: 0 additions & 1 deletion packages/compass-aggregations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ const aggregationsStore = configureAggregationsStore({
namespace: 'db.coll',
serverVersion: '4.2.0',
fields: [],
isAtlasDeployed: true,
outResultsFn: handleOut,
env: 'atlas',
localAppRegistry: appRegistry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ const mapStateToProps = (state) => ({
name: state.name,
collationString: state.collationString,
isCommenting: state.comments,
isAtlasDeployed: state.isAtlasDeployed,
isAutoPreviewing: state.autoPreview,
settings: state.settings,
limit: state.limit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import userEvent from '@testing-library/user-event';
import configureStore from '../../../../test/configure-store';

import { OutputStagePreview } from './pipeline-stages-preview';
import preferencesAccess from 'compass-preferences-model';

const renderStageBanner = (
props: Partial<ComponentProps<typeof OutputStagePreview>> = {}
Expand All @@ -17,7 +18,6 @@ const renderStageBanner = (
<Provider store={configureStore()}>
<OutputStagePreview
stageOperator="$out"
isAtlas={false}
isComplete={false}
isLoading={false}
onOpenCollection={() => {}}
Expand All @@ -30,12 +30,9 @@ const renderStageBanner = (

describe('OutputStagePreview', function () {
(['$out', '$merge'] as const).forEach((stageOperator) => {
describe(`${stageOperator} - not on atlas`, function () {
describe(`${stageOperator} with run aggregation enabled`, function () {
it('renders stage banner', function () {
renderStageBanner({
stageOperator,
isAtlas: false,
});
renderStageBanner({ stageOperator });
expect(screen.getByTestId(`${stageOperator}-preview-banner`)).to.exist;
expect(() => {
screen.getByRole('button', {
Expand All @@ -45,19 +42,35 @@ describe('OutputStagePreview', function () {
});
});

describe(`${stageOperator} on atlas`, function () {
describe(`${stageOperator} with run aggregation disabled`, function () {
let enableAggregationBuilderRunPipeline: boolean;

before(async function () {
enableAggregationBuilderRunPipeline =
preferencesAccess.getPreferences()
.enableAggregationBuilderRunPipeline;

await preferencesAccess.savePreferences({
enableAggregationBuilderRunPipeline: false,
});
});

after(async function () {
await preferencesAccess.savePreferences({
enableAggregationBuilderRunPipeline,
});
});

it(`renders stage banner`, function () {
renderStageBanner({
stageOperator,
isAtlas: true,
});
expect(screen.getByTestId(`${stageOperator}-preview-banner`)).to.exist;
});

it(`renders stage action`, function () {
renderStageBanner({
stageOperator,
isAtlas: true,
});
expect(
screen.getByRole('button', {
Expand All @@ -70,7 +83,6 @@ describe('OutputStagePreview', function () {
const onSaveCollection = sinon.spy();
renderStageBanner({
stageOperator,
isAtlas: true,
onSaveCollection,
});
const button = screen.getByRole('button', {
Expand All @@ -84,7 +96,6 @@ describe('OutputStagePreview', function () {
it('renders loading state', function () {
renderStageBanner({
stageOperator,
isAtlas: true,
isLoading: true,
});
const button = screen.getByRole('button', {
Expand All @@ -96,7 +107,6 @@ describe('OutputStagePreview', function () {
it('renders complete state', function () {
renderStageBanner({
stageOperator,
isAtlas: true,
isComplete: true,
});
expect(screen.getByTestId(`${stageOperator}-is-complete-banner`)).to
Expand All @@ -106,7 +116,6 @@ describe('OutputStagePreview', function () {
it('renders complete state action button', function () {
renderStageBanner({
stageOperator,
isAtlas: true,
isComplete: true,
});
const button = screen.getByRole('button', {
Expand All @@ -119,7 +128,6 @@ describe('OutputStagePreview', function () {
const onOpenCollection = sinon.spy();
renderStageBanner({
stageOperator,
isAtlas: true,
isComplete: true,
onOpenCollection,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
MERGE_STAGE_PREVIEW_TEXT,
OUT_STAGE_PREVIEW_TEXT,
} from '../../../constants';
import { usePreference } from 'compass-preferences-model';

const bannerStyles = css({
alignItems: 'center',
Expand All @@ -39,7 +40,6 @@ const actionButtonStyles = css({

type OutputStageProps = {
stageOperator: '$out' | '$merge' | null;
isAtlas: boolean;
isLoading: boolean;
isComplete: boolean;
onSaveCollection: () => void;
Expand Down Expand Up @@ -77,16 +77,23 @@ const PipelineStageBanner = ({

export const OutputStagePreview = ({
stageOperator,
isAtlas,
isLoading,
isComplete,
onSaveCollection,
onOpenCollection,
}: OutputStageProps) => {
// When explicit pipeline run is not enabled, we allow to run output stage
// from the preview
const showOutputActions = !usePreference(
'enableAggregationBuilderRunPipeline',
React
);

if (!stageOperator) {
return null;
}
if (isComplete && isAtlas) {

if (isComplete && showOutputActions) {
return (
<PipelineStageBanner
data-testid={`${stageOperator}-is-complete-banner`}
Expand All @@ -110,7 +117,7 @@ export const OutputStagePreview = ({
: MERGE_STAGE_PREVIEW_TEXT
}
actionButton={
isAtlas ? (
showOutputActions ? (
<Button
{...buttonProps}
disabled={isLoading}
Expand All @@ -126,15 +133,13 @@ export const OutputStagePreview = ({
};

const mapState = ({
isAtlasDeployed,
pipelineBuilder: {
textEditor: {
outputStage: { isComplete, isLoading },
},
},
}: RootState) => {
return {
isAtlas: isAtlasDeployed,
isComplete,
isLoading,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,6 @@ export const PipelineHeader: React.FunctionComponent<PipelineHeaderProps> = ({

export default connect((state: RootState) => {
return {
isOpenPipelineVisible: !state.editViewName && !state.isAtlasDeployed,
isOpenPipelineVisible: !state.editViewName,
};
})(PipelineHeader);
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ConnectedPipelineActions, { PipelineActions } from './pipeline-actions';
import configureStore from '../../../../test/configure-store';
import { Provider } from 'react-redux';
import { changeStageDisabled } from '../../../modules/pipeline-builder/stage-editor';
import preferencesAccess from 'compass-preferences-model';

describe('PipelineActions', function () {
afterEach(cleanup);
Expand Down Expand Up @@ -104,7 +105,6 @@ describe('PipelineActions', function () {
onExportAggregationResults={() => {}}
onUpdateView={() => {}}
onExplainAggregation={() => {}}
isAtlasDeployed={false}
onCollectionScanInsightActionButtonClick={() => {}}
onShowAIInputClick={() => {}}
/>
Expand All @@ -125,9 +125,25 @@ describe('PipelineActions', function () {
});
});

describe('options disabled in atlas', function () {
describe('extra options disabled', function () {
let enableAggregationBuilderExtraOptions: boolean;
let onRunAggregationSpy: SinonSpy;
let onToggleOptionsSpy: SinonSpy;

before(async function () {
enableAggregationBuilderExtraOptions =
preferencesAccess.getPreferences().enableAggregationBuilderExtraOptions;
await preferencesAccess.savePreferences({
enableAggregationBuilderExtraOptions: false,
});
});

after(async function () {
await preferencesAccess.savePreferences({
enableAggregationBuilderExtraOptions,
});
});

beforeEach(function () {
onRunAggregationSpy = spy();
onToggleOptionsSpy = spy();
Expand All @@ -143,7 +159,6 @@ describe('PipelineActions', function () {
onExportAggregationResults={() => {}}
onUpdateView={() => {}}
onExplainAggregation={() => {}}
isAtlasDeployed={true}
onCollectionScanInsightActionButtonClick={() => {}}
onShowAIInputClick={() => {}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ type PipelineActionsProps = {
isOptionsVisible?: boolean;
onToggleOptions: () => void;

isAtlasDeployed?: boolean;

showAIEntry: boolean;
onShowAIInputClick: () => void;

Expand All @@ -80,10 +78,13 @@ export const PipelineActions: React.FunctionComponent<PipelineActionsProps> = ({
onToggleOptions,
onExportAggregationResults,
onExplainAggregation,
isAtlasDeployed,
showCollectionScanInsight,
onCollectionScanInsightActionButtonClick,
}) => {
const enableAggregationBuilderExtraOptions = usePreference(
'enableAggregationBuilderExtraOptions',
React
);
const showInsights = usePreference('showInsights', React);
const isAIFeatureEnabled = useIsAIFeatureEnabled(React);

Expand Down Expand Up @@ -151,7 +152,7 @@ export const PipelineActions: React.FunctionComponent<PipelineActionsProps> = ({
Run
</Button>
)}
{!isAtlasDeployed && (
{enableAggregationBuilderExtraOptions && (
<MoreOptionsToggle
isExpanded={!!isOptionsVisible}
aria-controls="pipeline-options"
Expand Down Expand Up @@ -181,7 +182,6 @@ const mapState = (state: RootState) => {
isBuilderView,
showUpdateViewButton: Boolean(state.editViewName),
isUpdateViewButtonDisabled: !state.isModified || hasSyntaxErrors,
isAtlasDeployed: state.isAtlasDeployed,
showCollectionScanInsight: state.insights.isCollectionScan,
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ describe('PipelineSettings', function () {
<Provider store={configureStore()}>
<PipelineSettings
isExportToLanguageEnabled={true}
isCreatePipelineDisplayed={true}
onExportToLanguage={onExportToLanguageSpy}
onCreateNewPipeline={onCreateNewPipelineSpy}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import PipelineExtraSettings from './pipeline-extra-settings';
import type { RootState } from '../../../modules';
import { getIsPipelineInvalidFromBuilderState } from '../../../modules/pipeline-builder/builder-helpers';
import { confirmNewPipeline } from '../../../modules/is-new-pipeline-confirm';
import { usePreference } from 'compass-preferences-model';

const containerStyles = css({
display: 'grid',
Expand All @@ -30,8 +31,7 @@ const extraSettingsStyles = css({
});

type PipelineSettingsProps = {
isSavePipelineDisplayed?: boolean;
isCreatePipelineDisplayed?: boolean;
isEditingViewPipeline?: boolean;
isExportToLanguageEnabled?: boolean;
onExportToLanguage: () => void;
onCreateNewPipeline: () => void;
Expand All @@ -40,12 +40,19 @@ type PipelineSettingsProps = {
export const PipelineSettings: React.FunctionComponent<
PipelineSettingsProps
> = ({
isSavePipelineDisplayed,
isCreatePipelineDisplayed,
isEditingViewPipeline = false,
isExportToLanguageEnabled,
onExportToLanguage,
onCreateNewPipeline,
}) => {
const enableSavedAggregationsQueries = usePreference(
'enableSavedAggregationsQueries',
React
);
const isSavePipelineDisplayed =
!isEditingViewPipeline && enableSavedAggregationsQueries;
const isCreatePipelineDisplayed = !isEditingViewPipeline;

return (
<div className={containerStyles} data-testid="pipeline-settings">
<div className={settingsStyles}>
Expand Down Expand Up @@ -88,8 +95,7 @@ export default connect(
(state: RootState) => {
const hasSyntaxErrors = getIsPipelineInvalidFromBuilderState(state, false);
return {
isSavePipelineDisplayed: !state.editViewName && !state.isAtlasDeployed,
isCreatePipelineDisplayed: !state.editViewName,
isEditingViewPipeline: state.editViewName,
isExportToLanguageEnabled: !hasSyntaxErrors,
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class Pipeline extends PureComponent {
static displayName = 'PipelineComponent';

static propTypes = {
isAtlasDeployed: PropTypes.bool.isRequired,
saveCurrentPipeline: PropTypes.func.isRequired,
clonePipeline: PropTypes.func.isRequired,
isCommenting: PropTypes.bool.isRequired,
Expand Down Expand Up @@ -115,7 +114,6 @@ class Pipeline extends PureComponent {
return (
<div className={styles.pipeline}>
<Settings
isAtlasDeployed={this.props.isAtlasDeployed}
isExpanded={this.props.settings.isExpanded}
toggleSettingsIsExpanded={this.props.toggleSettingsIsExpanded}
toggleSettingsIsCommentMode={this.props.toggleSettingsIsCommentMode}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ describe('Settings [Component]', function () {
state = {
...INITIAL_STATE,
applySettings: applySettingsSpy,
isAtlasDeployed: false,
toggleSettingsIsExpanded: toggleSettingsIsExpandedSpy,
toggleSettingsIsCommentMode: toggleSettingsIsCommentModeSpy,
setSettingsSampleSize: setSettingsSampleSizeSpy,
Expand Down Expand Up @@ -125,7 +124,7 @@ describe('Settings [Component]', function () {
});

it('hides the large limit option', function () {
const props = { ...state, isAtlasDeployed: true };
const props = { ...state };
component = mount(<Settings {...props} />);
expect(component.find('label[innerText="Limit"]')).to.not.be.present();
});
Expand Down
Loading

0 comments on commit b75076d

Please sign in to comment.