Skip to content

Commit c5e0386

Browse files
committed
fix: track usage of uuid subtype 3 vs 4 COMPASS-9359
1 parent aa52e82 commit c5e0386

File tree

10 files changed

+60
-16
lines changed

10 files changed

+60
-16
lines changed

package-lock.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
ignores: [
22
'@mongodb-js/prettier-config-compass',
33
'@mongodb-js/tsconfig-compass',
4+
'@mongodb-js/compass-telemetry',
45
'@types/chai-dom',
56
'@emotion/css',
67
]

packages/compass-components/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
"@mongodb-js/prettier-config-compass": "^1.2.8",
100100
"@mongodb-js/testing-library-compass": "^1.3.0",
101101
"@mongodb-js/tsconfig-compass": "^1.2.8",
102+
"@mongodb-js/compass-telemetry": "^1.7.0",
102103
"@types/chai": "^4.2.21",
103104
"@types/chai-dom": "^0.0.10",
104105
"@types/mocha": "^9.0.0",

packages/compass-components/src/components/bson-value.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ import { Icon, Link } from './leafygreen';
88
import { spacing } from '@leafygreen-ui/tokens';
99
import { css, cx } from '@leafygreen-ui/emotion';
1010
import { Theme, useDarkMode } from '../hooks/use-theme';
11+
import type { TrackFunction } from '@mongodb-js/compass-telemetry';
1112

12-
type ValueProps =
13+
type ValueProps = (
1314
| {
1415
[type in keyof TypeCastMap]: { type: type; value: TypeCastMap[type] };
1516
}[keyof TypeCastMap]
16-
| { type: 'DBRef'; value: DBRef };
17+
| { type: 'DBRef'; value: DBRef }
18+
) & { track?: TrackFunction };
1719

1820
function truncate(str: string, length = 70): string {
1921
const truncated = str.slice(0, length);
@@ -122,6 +124,7 @@ const ObjectIdValue: React.FunctionComponent<PropsByValueType<'ObjectId'>> = ({
122124

123125
const BinaryValue: React.FunctionComponent<PropsByValueType<'Binary'>> = ({
124126
value,
127+
track,
125128
}) => {
126129
const { stringifiedValue, title, additionalHints } = useMemo(() => {
127130
if (value.sub_type === Binary.SUBTYPE_ENCRYPTED) {
@@ -144,7 +147,7 @@ const BinaryValue: React.FunctionComponent<PropsByValueType<'Binary'>> = ({
144147
}
145148
if (value.sub_type === Binary.SUBTYPE_UUID) {
146149
let uuid: string;
147-
150+
track?.('UUID Encountered', { subtype: 4 });
148151
try {
149152
// Try to get the pretty hex version of the UUID
150153
uuid = value.toUUID().toString();
@@ -188,6 +191,9 @@ const BinaryValue: React.FunctionComponent<PropsByValueType<'Binary'>> = ({
188191
};
189192
}
190193
}
194+
if (value.sub_type === Binary.SUBTYPE_UUID_OLD) {
195+
track?.('UUID Encountered', { subtype: 3 });
196+
}
191197
return {
192198
stringifiedValue: `Binary.createFromBase64('${truncate(
193199
value.toString('base64'),
@@ -374,7 +380,9 @@ const BSONValue: React.FunctionComponent<ValueProps> = (props) => {
374380
case 'Date':
375381
return <DateValue value={props.value}></DateValue>;
376382
case 'Binary':
377-
return <BinaryValue value={props.value}></BinaryValue>;
383+
return (
384+
<BinaryValue value={props.value} track={props.track}></BinaryValue>
385+
);
378386
case 'Int32':
379387
case 'Double':
380388
return <NumberValue type={props.type} value={props.value}></NumberValue>;

packages/compass-components/src/components/document-list/document.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { calculateShowMoreToggleOffset, HadronElement } from './element';
1515
import { usePrevious } from './use-previous';
1616
import VisibleFieldsToggle from './visible-field-toggle';
1717
import { documentTypography } from './typography';
18+
import type { TrackFunction } from '@mongodb-js/compass-telemetry';
1819

1920
function useHadronDocument(doc: HadronDocumentType) {
2021
const prevDoc = usePrevious(doc);
@@ -85,13 +86,15 @@ const HadronDocument: React.FunctionComponent<{
8586
editable?: boolean;
8687
editing?: boolean;
8788
onEditStart?: () => void;
89+
track?: TrackFunction;
8890
extraGutterWidth?: number;
8991
}> = ({
9092
value: document,
9193
editable = false,
9294
editing = false,
9395
onEditStart,
9496
extraGutterWidth,
97+
track,
9598
}) => {
9699
const { elements, visibleElements } = useHadronDocument(document);
97100
const [autoFocus, setAutoFocus] = useState<{
@@ -148,6 +151,7 @@ const HadronDocument: React.FunctionComponent<{
148151
}
149152
: undefined
150153
}
154+
track={track}
151155
lineNumberSize={visibleElements.length}
152156
onAddElement={(el) => {
153157
setAutoFocus({

packages/compass-components/src/components/document-list/element.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { palette } from '@leafygreen-ui/palette';
2828
import { Icon } from '../leafygreen';
2929
import { useDarkMode } from '../../hooks/use-theme';
3030
import VisibleFieldsToggle from './visible-field-toggle';
31+
import type { TrackFunction } from '@mongodb-js/compass-telemetry';
3132

3233
function getEditorByType(type: HadronElementType['type']) {
3334
switch (type) {
@@ -414,6 +415,7 @@ export const HadronElement: React.FunctionComponent<{
414415
editable: boolean;
415416
editingEnabled: boolean;
416417
onEditStart?: (id: string, field: 'key' | 'value' | 'type') => void;
418+
track?: TrackFunction;
417419
lineNumberSize: number;
418420
onAddElement(el: HadronElementType): void;
419421
extraGutterWidth?: number;
@@ -422,6 +424,7 @@ export const HadronElement: React.FunctionComponent<{
422424
editable,
423425
editingEnabled,
424426
onEditStart,
427+
track,
425428
lineNumberSize,
426429
onAddElement,
427430
extraGutterWidth = 0,
@@ -688,6 +691,7 @@ export const HadronElement: React.FunctionComponent<{
688691
<BSONValue
689692
type={type.value as any}
690693
value={value.originalValue}
694+
track={track}
691695
></BSONValue>
692696
</div>
693697
)}

packages/compass-crud/src/components/editable-document.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { withPreferences } from 'compass-preferences-model/provider';
88
import { documentStyles, documentContentStyles } from './readonly-document';
99
import { getInsightsForDocument } from '../utils';
1010
import type { CrudActions } from '../stores/crud-store';
11+
import { TelemetryContext } from '@mongodb-js/compass-telemetry/provider';
1112

1213
const documentElementsContainerStyles = css({
1314
position: 'relative',
@@ -245,12 +246,17 @@ class EditableDocument extends React.Component<
245246
*/
246247
renderElements() {
247248
return (
248-
<DocumentList.Document
249-
value={this.props.doc}
250-
editable
251-
editing={this.state.editing}
252-
onEditStart={this.handleStartEditing.bind(this)}
253-
/>
249+
<TelemetryContext.Consumer>
250+
{(track) => (
251+
<DocumentList.Document
252+
value={this.props.doc}
253+
editable
254+
editing={this.state.editing}
255+
onEditStart={this.handleStartEditing.bind(this)}
256+
track={track}
257+
/>
258+
)}
259+
</TelemetryContext.Consumer>
254260
);
255261
}
256262

packages/compass-crud/src/components/readonly-document.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { TypeCastMap } from 'hadron-type-checker';
66
import { withPreferences } from 'compass-preferences-model/provider';
77
import { getInsightsForDocument } from '../utils';
88
import { DocumentEvents } from 'hadron-document';
9+
import { TelemetryContext } from '@mongodb-js/compass-telemetry/provider';
910
type BSONObject = TypeCastMap['Object'];
1011

1112
export const documentStyles = css({
@@ -132,11 +133,18 @@ class ReadonlyDocument extends React.Component<
132133
*/
133134
renderElements() {
134135
return (
135-
<DocumentList.Document
136-
value={this.props.doc}
137-
// Provide extra whitespace for the expand button
138-
extraGutterWidth={spacing[900]}
139-
/>
136+
<TelemetryContext.Consumer>
137+
{(track) => (
138+
<>
139+
<DocumentList.Document
140+
value={this.props.doc}
141+
// Provide extra whitespace for the expand button
142+
extraGutterWidth={spacing[900]}
143+
track={track}
144+
/>
145+
</>
146+
)}
147+
</TelemetryContext.Consumer>
140148
);
141149
}
142150

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,7 @@ class CrudStoreImpl
833833
* @param {Number} page - The page that is being shown.
834834
*/
835835
async getPage(page: number) {
836+
console.log('getPage');
836837
const { ns, status, docsPerPage } = this.state;
837838

838839
if (page < 0) {
@@ -1560,6 +1561,7 @@ class CrudStoreImpl
15601561
* This function is called when the collection filter changes.
15611562
*/
15621563
async refreshDocuments(onApply = false) {
1564+
console.log('refreshDocuments');
15631565
if (this.dataService && !this.dataService.isConnected()) {
15641566
this.logger.log.warn(
15651567
mongoLogId(1_001_000_072),

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2694,6 +2694,13 @@ type CreateIndexButtonClickedEvent = CommonEvent<{
26942694
};
26952695
}>;
26962696

2697+
type UUIDEncounteredEvent = CommonEvent<{
2698+
name: 'UUID Encountered';
2699+
payload: {
2700+
subtype: 3 | 4;
2701+
};
2702+
}>;
2703+
26972704
export type TelemetryEvent =
26982705
| AggregationCanceledEvent
26992706
| AggregationCopiedEvent
@@ -2816,4 +2823,5 @@ export type TelemetryEvent =
28162823
| CumulativeLayoutShiftEvent
28172824
| TimeToFirstByteEvent
28182825
| ExperimentViewedEvent
2819-
| CreateIndexButtonClickedEvent;
2826+
| CreateIndexButtonClickedEvent
2827+
| UUIDEncounteredEvent;

0 commit comments

Comments
 (0)