Skip to content

Commit 8146050

Browse files
authored
feat: Open create index modal with query context CLOUDP-311788 (#6904)
1 parent 7e3d218 commit 8146050

File tree

15 files changed

+296
-28
lines changed

15 files changed

+296
-28
lines changed

package-lock.json

Lines changed: 158 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-components/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@leafygreen-ui/button": "^22.0.2",
4040
"@leafygreen-ui/card": "^12.0.2",
4141
"@leafygreen-ui/checkbox": "^14.0.2",
42+
"@leafygreen-ui/chip": "^3.0.12",
4243
"@leafygreen-ui/code": "^16.0.2",
4344
"@leafygreen-ui/combobox": "^11.0.2",
4445
"@leafygreen-ui/confirmation-modal": "^6.0.2",
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react';
2+
import { Chip, Icon } from './leafygreen';
3+
import { css, cx } from '@leafygreen-ui/emotion';
4+
import { fontWeights } from '@leafygreen-ui/tokens';
5+
import { palette } from '@leafygreen-ui/palette';
6+
import { useDarkMode } from '../hooks/use-theme';
7+
8+
const chipLightModeStyles = css({
9+
'--chipBackgroundColor': palette.blue.light3,
10+
'--chipBorderColor': palette.blue.light2,
11+
'--chipColor': palette.blue.dark1,
12+
});
13+
14+
const chipDarkModeStyles = css({
15+
'--chipBackgroundColor': palette.blue.dark2,
16+
'--chipBorderColor': palette.blue.dark1,
17+
'--chipColor': palette.blue.light2,
18+
});
19+
20+
const chipStyles = css({
21+
fontWeight: fontWeights.bold,
22+
textTransform: 'uppercase',
23+
color: 'var(--chipColor)',
24+
backgroundColor: 'var(--chipBackgroundColor)',
25+
});
26+
27+
export const InsightsChip = () => {
28+
const isDarkMode = useDarkMode();
29+
return (
30+
<Chip
31+
className={cx(
32+
isDarkMode
33+
? [chipDarkModeStyles, chipStyles]
34+
: [chipLightModeStyles, chipStyles]
35+
)}
36+
label="insight"
37+
glyph={<Icon glyph="Bulb" />}
38+
/>
39+
);
40+
};

packages/compass-components/src/components/leafygreen.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import ConfirmationModal from '@leafygreen-ui/confirmation-modal';
1212
import { default as LeafyGreenIcon } from '@leafygreen-ui/icon';
1313
import type { Size as LeafyGreenIconSize } from '@leafygreen-ui/icon';
1414
export type { GlyphName } from '@leafygreen-ui/icon';
15+
import { Chip } from '@leafygreen-ui/chip';
1516
import {
1617
AtlasNavGraphic,
1718
MongoDBLogoMark,
@@ -142,6 +143,7 @@ export {
142143
Banner,
143144
Card,
144145
Checkbox,
146+
Chip,
145147
Code,
146148
ConfirmationModal,
147149
ExpandedContent,

packages/compass-components/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,4 @@ export {
212212
} from './components/virtual-list';
213213
export { SelectList } from './components/select-list';
214214
export { ParagraphSkeleton } from '@leafygreen-ui/skeleton-loader';
215+
export { InsightsChip } from './components/insights-chip';

packages/compass-crud/src/stores/crud-store.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ import type { MongoServerError } from 'mongodb';
66
import semver from 'semver';
77
import StateMixin from '@mongodb-js/reflux-state-mixin';
88
import type { Element } from 'hadron-document';
9-
import { Document } from 'hadron-document';
10-
import { validate } from 'mongodb-query-parser';
11-
import HadronDocument from 'hadron-document';
9+
import HadronDocument, { Document } from 'hadron-document';
10+
import { toJSString, validate } from 'mongodb-query-parser';
1211
import _parseShellBSON, { ParseMode } from '@mongodb-js/shell-bson-parser';
1312
import type { PreferencesAccess } from 'compass-preferences-model/provider';
1413
import { capMaxTimeMSAtPreferenceLimit } from 'compass-preferences-model/provider';
1514
import type { Stage } from '@mongodb-js/explain-plan-helper';
1615
import { ExplainPlan } from '@mongodb-js/explain-plan-helper';
16+
import { EJSON } from 'bson';
1717
import type {
18-
FavoriteQueryStorageAccess,
1918
FavoriteQueryStorage,
20-
RecentQueryStorageAccess,
19+
FavoriteQueryStorageAccess,
2120
RecentQueryStorage,
21+
RecentQueryStorageAccess,
2222
} from '@mongodb-js/my-queries-storage/provider';
2323

2424
import {
@@ -29,22 +29,22 @@ import {
2929

3030
import type { DOCUMENTS_STATUSES } from '../constants/documents-statuses';
3131
import {
32-
DOCUMENTS_STATUS_INITIAL,
33-
DOCUMENTS_STATUS_FETCHING,
3432
DOCUMENTS_STATUS_ERROR,
35-
DOCUMENTS_STATUS_FETCHED_INITIAL,
3633
DOCUMENTS_STATUS_FETCHED_CUSTOM,
34+
DOCUMENTS_STATUS_FETCHED_INITIAL,
3735
DOCUMENTS_STATUS_FETCHED_PAGINATION,
36+
DOCUMENTS_STATUS_FETCHING,
37+
DOCUMENTS_STATUS_INITIAL,
3838
} from '../constants/documents-statuses';
3939

4040
import type { UpdatePreview } from 'mongodb-data-service';
4141
import type { GridStore, TableHeaderType } from './grid-store';
4242
import configureGridStore from './grid-store';
4343
import type { TypeCastMap } from 'hadron-type-checker';
4444
import type AppRegistry from 'hadron-app-registry';
45+
import type { ActivateHelpers } from 'hadron-app-registry';
4546
import { BaseRefluxStore } from './base-reflux-store';
4647
import { openToast, showConfirmation } from '@mongodb-js/compass-components';
47-
import { toJSString } from 'mongodb-query-parser';
4848
import {
4949
openBulkDeleteFailureToast,
5050
openBulkDeleteProgressToast,
@@ -59,7 +59,6 @@ import type {
5959
MongoDBInstance,
6060
} from '@mongodb-js/compass-app-stores/provider';
6161
import configureActions from '../actions';
62-
import type { ActivateHelpers } from 'hadron-app-registry';
6362
import type { Logger } from '@mongodb-js/compass-logging/provider';
6463
import { mongoLogId } from '@mongodb-js/compass-logging/provider';
6564
import type { CollectionTabPluginMetadata } from '@mongodb-js/compass-collection';
@@ -1834,7 +1833,9 @@ class CrudStoreImpl
18341833
}
18351834

18361835
openCreateIndexModal() {
1837-
this.localAppRegistry.emit('open-create-index-modal');
1836+
this.localAppRegistry.emit('open-create-index-modal', {
1837+
query: EJSON.serialize(this.queryBar.getLastAppliedQuery('crud')),
1838+
});
18381839
}
18391840

18401841
openCreateSearchIndexModal() {
@@ -1999,6 +2000,7 @@ export type DocumentsPluginServices = {
19992000
queryBar: QueryBarService;
20002001
collection: Collection;
20012002
};
2003+
20022004
export function activateDocumentsPlugin(
20032005
options: CrudStoreOptions,
20042006
{
@@ -2125,6 +2127,7 @@ type ErrorOrResult =
21252127
result: undefined
21262128
]
21272129
| [error: undefined | null, result: BSONObject];
2130+
21282131
export async function findAndModifyWithFLEFallback(
21292132
ds: DataService,
21302133
ns: string,

packages/compass-indexes/src/components/create-index-form/create-index-form.spec.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ describe('CreateIndexForm', () => {
3636
onRemoveFieldClick={() => {}}
3737
onTabClick={onTabClickSpy}
3838
showIndexesGuidanceVariant={showIndexesGuidanceVariant || false}
39+
query={null}
3940
/>
4041
);
4142
};

0 commit comments

Comments
 (0)