Skip to content

Commit dd06562

Browse files
committed
Merge remote-tracking branch 'origin/main' into 1.36-releases
2 parents 7ba69a8 + 513877e commit dd06562

File tree

9 files changed

+277
-335
lines changed

9 files changed

+277
-335
lines changed

THIRD-PARTY-NOTICES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
The following third-party software is used by and included in **compass**.
2-
This document was automatically generated on Fri Mar 03 2023.
2+
This document was automatically generated on Sun Mar 05 2023.
33

44
## List of dependencies
55

packages/compass-import-export/src/components/import-modal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
spacing,
1111
FormFieldContainer,
1212
} from '@mongodb-js/compass-components';
13+
import { useTrackOnChange } from '@mongodb-js/compass-logging';
1314

1415
import {
1516
FINISHED_STATUSES,
@@ -42,7 +43,6 @@ import {
4243
import { ImportErrorList } from './import-error-list';
4344
import type { RootImportState } from '../stores/import-store';
4445
import type { CSVDelimiter, FieldFromCSV } from '../modules/import';
45-
import { useTrackOnChange } from '@mongodb-js/compass-logging';
4646
import { ImportFileInput } from './import-file-input';
4747

4848
/**
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React from 'react';
2+
import { connect } from 'react-redux';
3+
import {
4+
Button,
5+
Modal,
6+
ModalFooter,
7+
ModalHeader,
8+
} from '@mongodb-js/compass-components';
9+
10+
import { closeInProgressMessage } from '../modules/import';
11+
import type { RootImportState } from '../stores/import-store';
12+
13+
type InProgressModalProps = {
14+
closeInProgressMessage?: () => void;
15+
isInProgressMessageOpen: boolean;
16+
};
17+
18+
function InProgressModal({
19+
closeInProgressMessage,
20+
isInProgressMessageOpen,
21+
}: InProgressModalProps) {
22+
return (
23+
<Modal
24+
open={isInProgressMessageOpen}
25+
setOpen={closeInProgressMessage}
26+
data-testid="import-modal"
27+
>
28+
<ModalHeader
29+
title="Sorry, currently only one import operation is possible at a time"
30+
subtitle="Import is disabled as there is an import already in progress."
31+
/>
32+
<ModalFooter>
33+
<Button onClick={closeInProgressMessage}>Cancel</Button>
34+
</ModalFooter>
35+
</Modal>
36+
);
37+
}
38+
39+
const mapStateToProps = (state: RootImportState) => ({
40+
isInProgressMessageOpen: state.importData.isInProgressMessageOpen,
41+
});
42+
export default connect(mapStateToProps, {
43+
closeInProgressMessage,
44+
})(InProgressModal);

packages/compass-import-export/src/import-plugin.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import React from 'react';
22
import { Provider } from 'react-redux';
33

44
import ImportModal from './components/import-modal';
5+
import InProgressModal from './components/in-progress-modal';
56
import importStore from './stores/import-store';
67

78
function ImportPlugin() {
89
return (
910
<Provider store={importStore}>
1011
<ImportModal />
12+
<InProgressModal />
1113
</Provider>
1214
);
1315
}

packages/compass-import-export/src/modules/import.spec.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import thunk from 'redux-thunk';
66
import path from 'path';
77

88
import {
9+
onStarted,
10+
openImport,
911
selectImportFileType,
1012
selectImportFileName,
1113
INITIAL_STATE,
@@ -41,6 +43,43 @@ describe('import [module]', function () {
4143
);
4244
});
4345

46+
describe('#openImport', function () {
47+
it('sets isInProgressMessageOpen to true when import is in progress and does not open', function () {
48+
const abortController = new AbortController();
49+
mockStore.dispatch(onStarted(abortController));
50+
51+
expect(mockStore.getState().importData.status).to.equal('STARTED');
52+
expect(mockStore.getState().importData.isInProgressMessageOpen).to.equal(
53+
false
54+
);
55+
56+
mockStore.dispatch(openImport('test.test'));
57+
58+
expect(mockStore.getState().importData.isInProgressMessageOpen).to.equal(
59+
true
60+
);
61+
expect(mockStore.getState().importData.isOpen).to.equal(false);
62+
});
63+
64+
it('opens and sets the namespace', function () {
65+
const testNS = 'test.test';
66+
expect(mockStore.getState().importData.status).to.equal('UNSPECIFIED');
67+
expect(mockStore.getState().ns).to.not.equal(testNS);
68+
expect(mockStore.getState().importData.isInProgressMessageOpen).to.equal(
69+
false
70+
);
71+
expect(mockStore.getState().importData.isOpen).to.equal(false);
72+
73+
mockStore.dispatch(openImport('test.test'));
74+
75+
expect(mockStore.getState().ns).to.equal(testNS);
76+
expect(mockStore.getState().importData.isInProgressMessageOpen).to.equal(
77+
false
78+
);
79+
expect(mockStore.getState().importData.isOpen).to.equal(true);
80+
});
81+
});
82+
4483
describe('#selectImportFileType', function () {
4584
it('should update fileType to csv', async function () {
4685
// changing file type uses fileName from the state, so set it first

packages/compass-import-export/src/modules/import.ts

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ export const FILE_TYPE_SELECTED = `${PREFIX}/FILE_TYPE_SELECTED`;
6666
export const FILE_SELECTED = `${PREFIX}/FILE_SELECTED`;
6767
export const OPEN = `${PREFIX}/OPEN`;
6868
export const CLOSE = `${PREFIX}/CLOSE`;
69+
export const OPEN_IN_PROGRESS_MESSAGE = `${PREFIX}/OPEN_IN_PROGRESS_MESSAGE`;
70+
export const CLOSE_IN_PROGRESS_MESSAGE = `${PREFIX}/CLOSE_IN_PROGRESS_MESSAGE`;
6971
export const SET_PREVIEW = `${PREFIX}/SET_PREVIEW`;
7072
export const SET_DELIMITER = `${PREFIX}/SET_DELIMITER`;
7173
export const SET_GUESSTIMATED_TOTAL = `${PREFIX}/SET_GUESSTIMATED_TOTAL`;
@@ -89,6 +91,7 @@ export type CSVDelimiter = ',' | '\t' | ';' | ' ';
8991

9092
type State = {
9193
isOpen: boolean;
94+
isInProgressMessageOpen: boolean;
9295
errors: Error[];
9396
fileType: AcceptedFileType | '';
9497
fileName: string;
@@ -117,6 +120,7 @@ type State = {
117120

118121
export const INITIAL_STATE: State = {
119122
isOpen: false,
123+
isInProgressMessageOpen: false,
120124
errors: [],
121125
fileName: '',
122126
fileIsMultilineJSON: false,
@@ -177,7 +181,7 @@ export const onProgress = ({
177181
errors,
178182
});
179183

180-
const onStarted = (abortController: AbortController) => ({
184+
export const onStarted = (abortController: AbortController) => ({
181185
type: STARTED,
182186
abortController,
183187
});
@@ -642,13 +646,26 @@ export const setIgnoreBlanks = (ignoreBlanks: boolean) => ({
642646
/**
643647
* Open the import modal.
644648
*/
645-
export const openImport =
646-
(namespace: string) =>
647-
(dispatch: ThunkDispatch<RootImportState, void, AnyAction>) => {
649+
export const openImport = (namespace: string) => {
650+
return (
651+
dispatch: ThunkDispatch<RootImportState, void, AnyAction>,
652+
getState: () => RootImportState
653+
) => {
654+
// TODO(COMPASS-6540): Once we have importing in the background
655+
// we'll need to update how we check if an import is in progress here.
656+
const { status } = getState().importData;
657+
if (status === 'STARTED') {
658+
dispatch({
659+
type: OPEN_IN_PROGRESS_MESSAGE,
660+
});
661+
return;
662+
}
663+
648664
track('Import Opened');
649665
dispatch(nsChanged(namespace));
650666
dispatch({ type: OPEN });
651667
};
668+
};
652669

653670
/**
654671
* Close the import modal.
@@ -658,6 +675,10 @@ export const closeImport = () => ({
658675
type: CLOSE,
659676
});
660677

678+
export const closeInProgressMessage = () => ({
679+
type: CLOSE_IN_PROGRESS_MESSAGE,
680+
});
681+
661682
/**
662683
* The import module reducer.
663684
*/
@@ -884,6 +905,21 @@ const reducer = (state = INITIAL_STATE, action: AnyAction): State => {
884905
isOpen: false,
885906
};
886907
}
908+
909+
if (action.type === OPEN_IN_PROGRESS_MESSAGE) {
910+
return {
911+
...state,
912+
isInProgressMessageOpen: true,
913+
};
914+
}
915+
916+
if (action.type === CLOSE_IN_PROGRESS_MESSAGE) {
917+
return {
918+
...state,
919+
isInProgressMessageOpen: false,
920+
};
921+
}
922+
887923
return state;
888924
};
889925
export default reducer;

0 commit comments

Comments
 (0)