Skip to content

Commit 3adb574

Browse files
authored
fix(saved-pipelines): open pipeline in correct namespace COMPASS-5871 (#3150)
1 parent 5b93635 commit 3adb574

File tree

6 files changed

+38
-24
lines changed

6 files changed

+38
-24
lines changed

packages/compass-aggregations/src/components/aggregations/aggregations.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import { setIsModified } from '../../modules/is-modified';
5050
import {
5151
newPipelineFromPaste,
5252
restoreSavedPipeline,
53-
getPipelineFromIndexedDB
53+
openPipelineById
5454
} from '../../modules/index';
5555
import {
5656
restorePipelineModalToggle,
@@ -206,7 +206,7 @@ const MappedAggregations = connect(
206206
createNew,
207207
confirmNew,
208208
openLink,
209-
getPipelineFromIndexedDB,
209+
openPipelineById,
210210
applySettings,
211211
setIsModified,
212212
limitChanged,

packages/compass-aggregations/src/components/pipeline/modals/restore-pipeline-modal.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class RestorePipelineModal extends Component {
1212

1313
static propTypes = {
1414
restorePipelineModalToggle: PropTypes.func.isRequired,
15-
getPipelineFromIndexedDB: PropTypes.func.isRequired,
15+
openPipelineById: PropTypes.func.isRequired,
1616
restorePipeline: PropTypes.object.isRequired
1717
}
1818

@@ -24,7 +24,7 @@ class RestorePipelineModal extends Component {
2424
openPipeline = () => {
2525
const id = this.props.restorePipeline.pipelineObjectID;
2626
track('Aggregation Opened', { id, screen: 'aggregations' });
27-
this.props.getPipelineFromIndexedDB(id);
27+
this.props.openPipelineById(id);
2828
}
2929

3030
/**

packages/compass-aggregations/src/components/pipeline/pipeline.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Pipeline extends PureComponent {
3535
allowWrites: PropTypes.bool.isRequired,
3636
env: PropTypes.string.isRequired,
3737
isAtlasDeployed: PropTypes.bool.isRequired,
38-
getPipelineFromIndexedDB: PropTypes.func.isRequired,
38+
openPipelineById: PropTypes.func.isRequired,
3939
savedPipelinesListToggle: PropTypes.func.isRequired,
4040
getSavedPipelines: PropTypes.func.isRequired,
4141
toggleComments: PropTypes.func.isRequired,
@@ -162,7 +162,7 @@ class Pipeline extends PureComponent {
162162
return (
163163
<RestorePipelineModal
164164
restorePipelineModalToggle={this.props.restorePipelineModalToggle}
165-
getPipelineFromIndexedDB={this.props.getPipelineFromIndexedDB}
165+
openPipelineById={this.props.openPipelineById}
166166
restorePipeline={this.props.restorePipeline}
167167
/>
168168
);

packages/compass-aggregations/src/modules/index.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -711,28 +711,31 @@ export const deletePipeline = (pipelineId: string): ThunkAction<void, RootState,
711711
};
712712

713713
/**
714-
* Get a pipeline from the db.
715-
*
716-
* @param {String} pipelineId - The id.
717-
*
718-
* @returns {Function} The thunk function.
714+
* Restore pipeline by an ID
719715
*/
720-
export const getPipelineFromIndexedDB = (pipelineId: string): ThunkAction<void, RootState, void, AnyAction> => {
716+
export const openPipelineById = (id: string): ThunkAction<void, RootState, void, AnyAction> => {
721717
return async (dispatch) => {
722-
const file = path.join(getDirectory(), `${pipelineId}.json`);
718+
const file = path.join(getDirectory(), `${id}.json`);
723719
try {
724720
const data = await fs.promises.readFile(file, 'utf8')
725-
const pipe = JSON.parse(data);
726-
dispatch(clearPipeline());
727-
dispatch(restoreSavedPipeline(pipe));
728-
dispatch(globalAppRegistryEmit('compass:aggregations:pipeline-opened'));
729-
dispatch(runStage(0, true /* force execute */));
721+
dispatch(openPipeline(JSON.parse(data)));
730722
} catch (e: unknown) {
731723
console.log(e);
732724
}
733725
};
734726
};
735727

728+
/**
729+
* Restore pipeline
730+
*/
731+
export const openPipeline = (pipeline: any): ThunkAction<void, RootState, void, AnyAction> => {
732+
return (dispatch) => {
733+
dispatch(clearPipeline());
734+
dispatch(restoreSavedPipeline(pipeline));
735+
dispatch(globalAppRegistryEmit('compass:aggregations:pipeline-opened'));
736+
dispatch(runStage(0, true /* force execute */));
737+
};
738+
}
736739

737740
/**
738741
* Make view pipeline.

packages/compass-aggregations/src/stores/store.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint complexity: 0 */
22
import { createStore, applyMiddleware } from 'redux';
33
import thunk from 'redux-thunk';
4-
import reducer, { getPipelineFromIndexedDB } from '../modules';
4+
import reducer, { openPipeline } from '../modules';
55
import toNS from 'mongodb-ns';
66
import { namespaceChanged } from '../modules/namespace';
77
import { dataServiceConnected } from '../modules/data-service';
@@ -304,7 +304,7 @@ const configureStore = (options = {}) => {
304304
}
305305

306306
if (options.aggregation) {
307-
getPipelineFromIndexedDB(options.aggregation.id)(store.dispatch);
307+
openPipeline(options.aggregation)(store.dispatch);
308308
}
309309

310310
if (options.isDataLake) {

packages/compass-saved-aggregations-queries/src/stores/open-item.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,22 @@ const openItem =
237237
}
238238
);
239239

240-
appRegistry.emit('open-namespace-in-new-tab', {
240+
const emitData = {
241241
...metadata,
242-
aggregation: item.type === 'aggregation' ? item.aggregation : null,
243-
query: item.type === 'query' ? item.query : null,
244-
});
242+
[item.type]:
243+
item.type === 'aggregation'
244+
? {
245+
...item.aggregation,
246+
namespace: metadata.namespace,
247+
}
248+
: {
249+
...item.query,
250+
_ns: metadata.namespace,
251+
ns: metadata.namespace,
252+
},
253+
};
254+
255+
appRegistry.emit('open-namespace-in-new-tab', emitData);
245256
};
246257

247258
export const openSavedItem =

0 commit comments

Comments
 (0)