Skip to content

Commit d1d271e

Browse files
Merge remote-tracking branch 'origin/main' into beta-releases
2 parents 8b0393e + 837784b commit d1d271e

File tree

9 files changed

+124
-66
lines changed

9 files changed

+124
-66
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 **Mongodb Compass**.
2-
This document was automatically generated on Mon Mar 10 2025.
2+
This document was automatically generated on Sun Mar 16 2025.
33

44
## List of dependencies
55

docs/tracking-plan.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
> the tracking plan for the specific Compass version you can use the following
88
> URL: `https://github.com/mongodb-js/compass/blob/<compass version>/docs/tracking-plan.md`
99
10-
Generated on Mon, Mar 10, 2025
10+
Generated on Sun, Mar 16, 2025
1111

1212
## Table of Contents
1313

@@ -162,6 +162,7 @@ Generated on Mon, Mar 10, 2025
162162
- [Schema Validation Added](#event--SchemaValidationAddedEvent)
163163
- [Schema Validation Edited](#event--SchemaValidationEditedEvent)
164164
- [Schema Validation Updated](#event--SchemaValidationUpdatedEvent)
165+
- [Schema Validation Generated](#event--SchemaValidationGeneratedEvent)
165166

166167
### Settings
167168
- [Theme Changed](#event--ThemeChangedEvent)
@@ -1995,6 +1996,22 @@ This event is fired when user saves validation rules.
19951996
- **connection_id** (optional): `string | undefined`
19961997
- The id of the connection associated to this event.
19971998

1999+
<a name="event--SchemaValidationGeneratedEvent"></a>
2000+
2001+
### Schema Validation Generated
2002+
2003+
This event is fired when user generates validation rules.
2004+
2005+
**Properties**:
2006+
2007+
- **variable_type_count** (required): `number`
2008+
- **optional_field_count** (required): `number`
2009+
- The count of fields that don't appear on all documents.
2010+
This is only calculated for the top level fields, not nested fields and arrays.
2011+
- **is_compass_web** (optional): `true | undefined`
2012+
- **connection_id** (optional): `string | undefined`
2013+
- The id of the connection associated to this event.
2014+
19982015

19992016
## Settings
20002017

packages/compass-schema-validation/src/modules/rules-generation.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import { enableEditRules } from './edit-mode';
44
import type { MongoError } from 'mongodb';
55
import type { Action, AnyAction, Reducer } from 'redux';
66
import { validationLevelChanged, validatorChanged } from './validation';
7+
import {
8+
type analyzeSchema as analyzeSchemaType,
9+
calculateSchemaMetadata,
10+
} from '@mongodb-js/compass-schema';
11+
import type { TrackFunction } from '@mongodb-js/compass-telemetry';
12+
import type { ConnectionInfoRef } from '@mongodb-js/compass-connections/provider';
713

814
export function isAction<A extends AnyAction>(
915
action: AnyAction,
@@ -150,6 +156,29 @@ export const stopRulesGeneration = (): SchemaValidationThunkAction<void> => {
150156
};
151157
};
152158

159+
const _trackRulesGenerated = async ({
160+
schemaAccessor,
161+
track,
162+
connectionInfoRef,
163+
}: {
164+
schemaAccessor: Awaited<ReturnType<typeof analyzeSchemaType>>;
165+
track: TrackFunction;
166+
connectionInfoRef: ConnectionInfoRef;
167+
}) => {
168+
const internalSchema = await schemaAccessor?.getInternalSchema();
169+
if (!internalSchema) return;
170+
const { variable_type_count, optional_field_count } =
171+
await calculateSchemaMetadata(internalSchema);
172+
track(
173+
'Schema Validation Generated',
174+
{
175+
variable_type_count,
176+
optional_field_count,
177+
},
178+
connectionInfoRef.current
179+
);
180+
};
181+
153182
/**
154183
* Get $jsonSchema from schema analysis
155184
* @returns
@@ -166,6 +195,8 @@ export const generateValidationRules = (): SchemaValidationThunkAction<
166195
preferences,
167196
rulesGenerationAbortControllerRef,
168197
analyzeSchema,
198+
track,
199+
connectionInfoRef,
169200
}
170201
) => {
171202
dispatch({ type: RulesGenerationActions.generationStarted });
@@ -214,6 +245,12 @@ export const generateValidationRules = (): SchemaValidationThunkAction<
214245
dispatch(enableEditRules());
215246
dispatch({ type: RulesGenerationActions.generationFinished });
216247
dispatch(zeroStateChanged(false));
248+
249+
void _trackRulesGenerated({
250+
schemaAccessor,
251+
connectionInfoRef,
252+
track,
253+
});
217254
} catch (error) {
218255
if (abortSignal.aborted) {
219256
dispatch({ type: RulesGenerationActions.generationFinished });

packages/compass-schema-validation/src/modules/validation.spec.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@ import reducer, {
99
validationFetched,
1010
validationCanceled,
1111
validationSaveFailed,
12-
syntaxErrorOccurred,
1312
validationFromCollection,
1413
VALIDATOR_CHANGED,
1514
VALIDATION_CANCELED,
1615
VALIDATION_SAVE_FAILED,
1716
VALIDATION_FETCHED,
1817
VALIDATION_ACTION_CHANGED,
1918
VALIDATION_LEVEL_CHANGED,
20-
SYNTAX_ERROR_OCCURRED,
2119
} from './validation';
2220

2321
describe('validation module', function () {
@@ -119,15 +117,6 @@ describe('validation module', function () {
119117
});
120118
});
121119

122-
describe('#syntaxErrorOccurred', function () {
123-
it('returns the SYNTAX_ERROR_OCCURRED action', function () {
124-
expect(syntaxErrorOccurred({ message: 'Syntax Error!' })).to.deep.equal({
125-
type: SYNTAX_ERROR_OCCURRED,
126-
syntaxError: { message: 'Syntax Error!' },
127-
});
128-
});
129-
});
130-
131120
describe('validationFromCollection', function () {
132121
context('when an error occurs listing the collection', function () {
133122
it('includes the error', function () {
@@ -324,23 +313,5 @@ describe('validation module', function () {
324313
});
325314
});
326315
});
327-
328-
context('when the action is syntaxErrorOccurred', function () {
329-
it('returns the new state', function () {
330-
const validation = reducer(
331-
undefined,
332-
syntaxErrorOccurred({ message: 'Syntax Error!' })
333-
);
334-
335-
expect(validation).to.deep.equal({
336-
validator: '',
337-
validationAction: 'error',
338-
validationLevel: 'strict',
339-
isChanged: true,
340-
syntaxError: { message: 'Syntax Error!' },
341-
error: null,
342-
});
343-
});
344-
});
345316
});
346317
});

packages/compass-schema-validation/src/modules/validation.ts

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,13 @@ interface ValidationLevelChangedAction {
7575
validationLevel: ValidationLevel;
7676
}
7777

78-
/**
79-
* Syntax error occurred action name.
80-
*/
81-
export const SYNTAX_ERROR_OCCURRED = `${PREFIX}/SYNTAX_ERROR_OCCURRED` as const;
82-
interface SyntaxErrorOccurredAction {
83-
type: typeof SYNTAX_ERROR_OCCURRED;
84-
syntaxError: null | { message: string };
85-
}
86-
8778
export type ValidationAction =
8879
| ValidatorChangedAction
8980
| ValidationCanceledAction
9081
| ValidationSaveFailedAction
9182
| ValidationFetchedAction
9283
| ValidationActionChangedAction
93-
| ValidationLevelChangedAction
94-
| SyntaxErrorOccurredAction;
84+
| ValidationLevelChangedAction;
9585

9686
export interface Validation {
9787
validator: string;
@@ -178,18 +168,6 @@ const changeValidator = (
178168
};
179169
};
180170

181-
/**
182-
* Sets syntax error.
183-
*/
184-
const setSyntaxError = (
185-
state: ValidationState,
186-
action: SyntaxErrorOccurredAction
187-
): ValidationState => ({
188-
...state,
189-
isChanged: true,
190-
syntaxError: action.syntaxError,
191-
});
192-
193171
/**
194172
* Set validation.
195173
*/
@@ -291,7 +269,6 @@ const MAPPINGS: {
291269
[VALIDATION_SAVE_FAILED]: setError,
292270
[VALIDATION_ACTION_CHANGED]: changeValidationAction,
293271
[VALIDATION_LEVEL_CHANGED]: changeValidationLevel,
294-
[SYNTAX_ERROR_OCCURRED]: setSyntaxError,
295272
};
296273

297274
/**
@@ -372,16 +349,6 @@ export const validationSaveFailed = (error: {
372349
error,
373350
});
374351

375-
/**
376-
* Action creator for syntax error occurred events.
377-
*/
378-
export const syntaxErrorOccurred = (
379-
syntaxError: null | { message: string }
380-
): SyntaxErrorOccurredAction => ({
381-
type: SYNTAX_ERROR_OCCURRED,
382-
syntaxError,
383-
});
384-
385352
export const fetchValidation = (namespace: {
386353
database: string;
387354
collection: string;

packages/compass-schema-validation/src/stores/store.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ const schemaAccessor = {
8282
setTimeout(() => resolve({ required: ['prop1'] }), 100); // waiting to give abort a chance
8383
});
8484
},
85+
getInternalSchema: () => {
86+
return new Promise((resolve) => {
87+
setTimeout(() => resolve({ required: ['prop1'] }), 100); // waiting to give abort a chance
88+
});
89+
},
8590
};
8691

8792
describe('Schema Validation Store', function () {

packages/compass-telemetry/src/telemetry-events.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,27 @@ type SchemaValidationUpdatedEvent = ConnectionScopedEvent<{
19061906
};
19071907
}>;
19081908

1909+
/**
1910+
* This event is fired when user generates validation rules.
1911+
*
1912+
* @category Schema Validation
1913+
*/
1914+
type SchemaValidationGeneratedEvent = ConnectionScopedEvent<{
1915+
name: 'Schema Validation Generated';
1916+
payload: {
1917+
/* The count of fields with multiple types in a given schema (not counting undefined).
1918+
* This is only calculated for the top level fields, not nested fields and arrays.
1919+
*/
1920+
variable_type_count: number;
1921+
1922+
/**
1923+
* The count of fields that don't appear on all documents.
1924+
* This is only calculated for the top level fields, not nested fields and arrays.
1925+
*/
1926+
optional_field_count: number;
1927+
};
1928+
}>;
1929+
19091930
/**
19101931
* This event is fired when user adds validation rules.
19111932
*
@@ -2754,6 +2775,7 @@ export type TelemetryEvent =
27542775
| SchemaValidationAddedEvent
27552776
| SchemaValidationEditedEvent
27562777
| SchemaValidationUpdatedEvent
2778+
| SchemaValidationGeneratedEvent
27572779
| ScreenEvent
27582780
| ShellEvent
27592781
| SignalActionButtonClickedEvent

packages/compass/src/app/index.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { globalAppRegistry } from 'hadron-app-registry';
1010
import { defaultPreferencesInstance } from 'compass-preferences-model';
1111
import semver from 'semver';
1212
import { CompassElectron } from './components/entrypoint';
13-
import { openToast } from '@mongodb-js/compass-components';
13+
import { openToast, ToastBody } from '@mongodb-js/compass-components';
1414

1515
// https://github.com/nodejs/node/issues/40537
1616
dns.setDefaultResultOrder('ipv4first');
@@ -324,6 +324,28 @@ const app = {
324324
ipcRenderer?.on('compass:open-import', () => {
325325
globalAppRegistry.emit('open-active-namespace-import');
326326
});
327+
ipcRenderer?.on('download-finished', (event, { path }) => {
328+
openToast('file-download-complete', {
329+
title: 'Success',
330+
description: (
331+
<ToastBody
332+
statusMessage="File download complete"
333+
actionHandler={() => ipcRenderer?.send('show-file', path)}
334+
actionText="show file"
335+
/>
336+
),
337+
variant: 'success',
338+
});
339+
});
340+
ipcRenderer?.on('download-failed', (event, { filename }) => {
341+
openToast('file-download-failed', {
342+
title: 'Failure',
343+
description: filename
344+
? `Failed to download ${filename}`
345+
: 'Download failed',
346+
variant: 'warning',
347+
});
348+
});
327349
// Autoupdate handlers
328350
ipcRenderer?.on(
329351
'autoupdate:download-update-externally',

packages/compass/src/main/application.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,23 @@ class CompassApplication {
470470
// Accessing defaultSession is not allowed when app is not ready
471471
await app.whenReady();
472472

473+
session.defaultSession.on(
474+
'will-download',
475+
function (event, item, webContents) {
476+
item.once('done', (event, state) => {
477+
if (state === 'completed') {
478+
webContents.send('download-finished', {
479+
path: item.getSavePath(),
480+
});
481+
} else if (state === 'interrupted') {
482+
webContents.send('download-failed', {
483+
filename: item.getFilename(),
484+
});
485+
}
486+
});
487+
}
488+
);
489+
473490
session.defaultSession.webRequest.onBeforeSendHeaders(
474491
allowedCloudEndpoints,
475492
(details, callback) => {

0 commit comments

Comments
 (0)