Skip to content

Commit 5abe2f0

Browse files
add confirmation banner
1 parent 1a5f09c commit 5abe2f0

File tree

3 files changed

+38
-34
lines changed

3 files changed

+38
-34
lines changed

packages/compass-aggregations/src/modules/search-indexes.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,18 @@ const reducer: Reducer<State, Action> = (state = INITIAL_STATE, action) => {
8080
return state;
8181
};
8282

83-
export const fetchIndexes = (): PipelineBuilderThunkAction<Promise<void>> => {
83+
export const fetchIndexes = (
84+
viewNamespace?: string
85+
): PipelineBuilderThunkAction<Promise<void>> => {
8486
return async (dispatch, getState) => {
8587
const {
86-
namespace,
88+
namespace: collectionNamespace,
8789
dataService: { dataService },
8890
searchIndexes: { status },
8991
} = getState();
9092

93+
const namespace = viewNamespace || collectionNamespace; // fetch indexes for view if passed in
94+
9195
if (
9296
!dataService ||
9397
status === SearchIndexesStatuses.LOADING ||

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

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { isAction } from '../utils/is-action';
1010
import type { AnyAction } from 'redux';
1111
import { showConfirmation } from '@mongodb-js/compass-components';
1212
import { fetchIndexes } from './search-indexes';
13+
import { isPipelineSearchQueryable } from 'mongodb-compass/src/app/utils/view-search-queryable';
1314

1415
export type UpdateViewState = null | string;
1516

@@ -75,37 +76,6 @@ export const dismissViewError = (): DismissViewUpdateErrorAction => ({
7576
type: DISMISS_VIEW_UPDATE_ERROR,
7677
});
7778

78-
const isPipelineSearchQueryable = (
79-
pipeline: Array<Record<string, any>>
80-
): boolean => {
81-
for (const stage of pipeline) {
82-
const stageKey = Object.keys(stage)[0];
83-
84-
// Check if the stage is $addFields, $set, or $match
85-
if (
86-
!(
87-
stageKey === '$addFields' ||
88-
stageKey === '$set' ||
89-
stageKey === '$match'
90-
)
91-
) {
92-
return false; // Not searchable
93-
}
94-
95-
// If the stage is $match, check if uses $expr
96-
if (stageKey === '$match') {
97-
const matchStage = stage['$match'];
98-
const allKeys = Object.keys(matchStage);
99-
100-
if (!(allKeys.length === 1 && allKeys.includes('$expr'))) {
101-
return false; // Not searchable
102-
}
103-
}
104-
}
105-
106-
return true;
107-
};
108-
10979
/**
11080
* Updates a view.
11181
*
@@ -141,7 +111,7 @@ export const updateView = (): PipelineBuilderThunkAction<Promise<void>> => {
141111
pipelineBuilder
142112
);
143113

144-
await dispatch(fetchIndexes());
114+
await dispatch(fetchIndexes(viewNamespace));
145115
if (state.searchIndexes.indexes.length > 0) {
146116
const pipelineIsSearchQueryable = isPipelineSearchQueryable(viewPipeline);
147117
const confirmed = await showConfirmation({
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
export const isPipelineSearchQueryable = (
2+
pipeline: Array<Record<string, any>>
3+
): boolean => {
4+
for (const stage of pipeline) {
5+
const stageKey = Object.keys(stage)[0];
6+
7+
// Check if the stage is $addFields, $set, or $match
8+
if (
9+
!(
10+
stageKey === '$addFields' ||
11+
stageKey === '$set' ||
12+
stageKey === '$match'
13+
)
14+
) {
15+
return false;
16+
}
17+
18+
// If the stage is $match, check if uses $expr
19+
if (stageKey === '$match') {
20+
const matchStage = stage['$match'];
21+
const matchKeys = Object.keys(matchStage);
22+
23+
if (!(matchKeys.length === 1 && matchKeys.includes('$expr'))) {
24+
return false;
25+
}
26+
}
27+
}
28+
29+
return true;
30+
};

0 commit comments

Comments
 (0)