Skip to content

Commit ed8e462

Browse files
committed
merge main
2 parents 38f589a + 837784b commit ed8e462

File tree

7 files changed

+123
-3
lines changed

7 files changed

+123
-3
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, 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
import { isAction } from '../util';
814

915
const ERROR_CODE_MAX_TIME_MS_EXPIRED = 50;
@@ -141,6 +147,29 @@ export const stopRulesGeneration = (): SchemaValidationThunkAction<void> => {
141147
};
142148
};
143149

150+
const _trackRulesGenerated = async ({
151+
schemaAccessor,
152+
track,
153+
connectionInfoRef,
154+
}: {
155+
schemaAccessor: Awaited<ReturnType<typeof analyzeSchemaType>>;
156+
track: TrackFunction;
157+
connectionInfoRef: ConnectionInfoRef;
158+
}) => {
159+
const internalSchema = await schemaAccessor?.getInternalSchema();
160+
if (!internalSchema) return;
161+
const { variable_type_count, optional_field_count } =
162+
await calculateSchemaMetadata(internalSchema);
163+
track(
164+
'Schema Validation Generated',
165+
{
166+
variable_type_count,
167+
optional_field_count,
168+
},
169+
connectionInfoRef.current
170+
);
171+
};
172+
144173
/**
145174
* Get $jsonSchema from schema analysis
146175
* @returns
@@ -157,6 +186,8 @@ export const generateValidationRules = (): SchemaValidationThunkAction<
157186
preferences,
158187
rulesGenerationAbortControllerRef,
159188
analyzeSchema,
189+
track,
190+
connectionInfoRef,
160191
}
161192
) => {
162193
dispatch({ type: RulesGenerationActions.generationStarted });
@@ -205,6 +236,12 @@ export const generateValidationRules = (): SchemaValidationThunkAction<
205236
dispatch(enableEditRules());
206237
dispatch({ type: RulesGenerationActions.generationFinished });
207238
dispatch(zeroStateChanged(false));
239+
240+
void _trackRulesGenerated({
241+
schemaAccessor,
242+
connectionInfoRef,
243+
track,
244+
});
208245
} catch (error) {
209246
if (abortSignal.aborted) {
210247
dispatch({ type: RulesGenerationActions.generationFinished });

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ const schemaAccessor = {
8585
setTimeout(() => resolve({ required: ['prop1'] }), 100); // waiting to give abort a chance
8686
});
8787
},
88+
getInternalSchema: () => {
89+
return new Promise((resolve) => {
90+
setTimeout(() => resolve({ required: ['prop1'] }), 100); // waiting to give abort a chance
91+
});
92+
},
8893
};
8994

9095
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)