Skip to content

Commit 4b9ac1e

Browse files
attempting to add model
1 parent 6c47264 commit 4b9ac1e

File tree

4 files changed

+114
-8
lines changed

4 files changed

+114
-8
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React from 'react';
2+
import { FormModal } from '@mongodb-js/compass-components';
3+
import type { UpdateViewState } from '../../modules/update-view';
4+
import { closeConfirmUpdateModal, updateView } from '../../modules/update-view';
5+
import { connect } from 'react-redux';
6+
7+
type ConfirmUpdateViewModalProps = {
8+
updateView: () => void;
9+
isOpen?: boolean;
10+
closeModal: () => void;
11+
};
12+
13+
const ConfirmUpdateViewModal: React.FunctionComponent<
14+
ConfirmUpdateViewModalProps
15+
> = ({ updateView, isOpen, closeModal }) => {
16+
const isSearchCompatibleUpdate = true;
17+
return (
18+
<FormModal
19+
title={'Are you sure you want to update the view?'}
20+
open={isOpen}
21+
onSubmit={updateView}
22+
onCancel={closeModal}
23+
submitButtonText="Update"
24+
data-testid="confirm-update-view-modal"
25+
>
26+
{isSearchCompatibleUpdate
27+
? 'There are search indexes created on this view. Updating the view will result in an ' +
28+
'index rebuild, which will consume additional resources on your cluster.'
29+
: 'This update will make the view incompatible with search indexes and will cause all ' +
30+
'search indexes to fail. Only views containing $addFields, $set or $match stages with ' +
31+
'the $expr operator are compatible with search indexes.'}
32+
</FormModal>
33+
);
34+
};
35+
36+
const mapStateToProps = (state: UpdateViewState) => ({
37+
isOpen: state.isOpen,
38+
});
39+
40+
// Connect actions for dispatching
41+
const MappedConfirmUpdateViewModal = connect(mapStateToProps, {
42+
updateView,
43+
closeModal: closeConfirmUpdateModal,
44+
})(ConfirmUpdateViewModal);
45+
46+
export default MappedConfirmUpdateViewModal;
47+
export { ConfirmUpdateViewModal };
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import MappedConfirmUpdateViewModal, {
2+
ConfirmUpdateViewModal,
3+
} from './confirm-update-view-modal';
4+
export default MappedConfirmUpdateViewModal;
5+
export { ConfirmUpdateViewModal };

packages/compass-aggregations/src/components/pipeline-toolbar/pipeline-header/pipeline-actions.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
exportAggregationResults,
1515
runAggregation,
1616
} from '../../../modules/aggregation';
17-
import { updateView } from '../../../modules/update-view';
17+
import { openConfirmUpdateModal } from '../../../modules/update-view';
1818
import { explainAggregation } from '../../../modules/explain';
1919
import {
2020
getIsPipelineInvalidFromBuilderState,
@@ -59,6 +59,7 @@ type PipelineActionsProps = {
5959

6060
showCollectionScanInsight?: boolean;
6161
onCollectionScanInsightActionButtonClick: () => void;
62+
resultPipeline: any;
6263
};
6364

6465
export const PipelineActions: React.FunctionComponent<PipelineActionsProps> = ({
@@ -189,7 +190,7 @@ const mapState = (state: RootState) => {
189190
};
190191

191192
const mapDispatch = {
192-
onUpdateView: updateView,
193+
onUpdateView: openConfirmUpdateModal,
193194
onRunAggregation: runAggregation,
194195
onExportAggregationResults: exportAggregationResults,
195196
onExplainAggregation: explainAggregation,

packages/compass-aggregations/src/modules/update-view.ts

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,29 @@ import type { PipelineBuilderThunkAction } from '.';
99
import { isAction } from '../utils/is-action';
1010
import type { AnyAction } from 'redux';
1111

12-
export type UpdateViewState = null | string;
12+
export type UpdateViewState = {
13+
isOpen: boolean;
14+
updateViewError: null | string;
15+
};
1316

14-
/**
15-
* State `null` when there is no error, or string if there's an error.
16-
*/
17-
export const INITIAL_STATE: UpdateViewState = null;
17+
export const INITIAL_STATE: UpdateViewState = {
18+
isOpen: false,
19+
updateViewError: null,
20+
};
21+
22+
// Action for opening model.
23+
export const OPEN_CONFIRM_UPDATE_MODEL =
24+
'aggregations/update-view/OPEN_CONFIRM_UPDATE_MODEL' as const;
25+
interface OpenConfirmUpdateModel {
26+
type: typeof OPEN_CONFIRM_UPDATE_MODEL;
27+
}
28+
29+
// Action for closing model.
30+
export const CLOSE_CONFIRM_UPDATE_MODEL =
31+
'aggregations/update-view/CLOSE_CONFIRM_UPDATE_MODEL' as const;
32+
interface CloseConfirmUpdateModel {
33+
type: typeof CLOSE_CONFIRM_UPDATE_MODEL;
34+
}
1835

1936
// Action for when an error occurs when updating a view.
2037
export const ERROR_UPDATING_VIEW =
@@ -32,15 +49,34 @@ interface DismissViewUpdateErrorAction {
3249
}
3350

3451
export type UpdateViewAction =
52+
| OpenConfirmUpdateModel
53+
| CloseConfirmUpdateModel
3554
| ErrorUpdatingViewAction
3655
| DismissViewUpdateErrorAction;
3756

3857
export default function reducer(
3958
state: UpdateViewState = INITIAL_STATE,
4059
action: AnyAction
4160
): UpdateViewState {
61+
if (isAction<OpenConfirmUpdateModel>(action, OPEN_CONFIRM_UPDATE_MODEL)) {
62+
return {
63+
...state,
64+
isOpen: true,
65+
};
66+
}
67+
68+
if (isAction<CloseConfirmUpdateModel>(action, CLOSE_CONFIRM_UPDATE_MODEL)) {
69+
return {
70+
...state,
71+
isOpen: false,
72+
};
73+
}
74+
4275
if (isAction<ErrorUpdatingViewAction>(action, ERROR_UPDATING_VIEW)) {
43-
return action.error;
76+
return {
77+
...state,
78+
updateViewError: action.error,
79+
};
4480
}
4581
if (
4682
isAction<DismissViewUpdateErrorAction>(action, DISMISS_VIEW_UPDATE_ERROR) ||
@@ -54,6 +90,23 @@ export default function reducer(
5490
return state;
5591
}
5692

93+
/**
94+
* Action creator for opening the confirmation modal.
95+
*
96+
* @returns {Object} The action to open the modal.
97+
*/
98+
export const openConfirmUpdateModal = (): OpenConfirmUpdateModel => ({
99+
type: OPEN_CONFIRM_UPDATE_MODEL,
100+
});
101+
102+
/**
103+
* Action creator for closing the confirmation modal.
104+
*
105+
* @returns {Object} The action to close the modal.
106+
*/
107+
export const closeConfirmUpdateModal = (): CloseConfirmUpdateModel => ({
108+
type: CLOSE_CONFIRM_UPDATE_MODEL,
109+
});
57110
/**
58111
* Action creator for showing the error that occured with updating the view.
59112
*/

0 commit comments

Comments
 (0)