Skip to content

Commit dbf57c1

Browse files
committed
use callback
1 parent 7a31f94 commit dbf57c1

File tree

8 files changed

+24
-20
lines changed

8 files changed

+24
-20
lines changed

package-lock.json

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

packages/compass-components/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@
9999
"@mongodb-js/prettier-config-compass": "^1.2.8",
100100
"@mongodb-js/testing-library-compass": "^1.3.1",
101101
"@mongodb-js/tsconfig-compass": "^1.2.8",
102-
"@mongodb-js/compass-telemetry": "^1.7.0",
103102
"@types/chai": "^4.2.21",
104103
"@types/chai-dom": "^0.0.10",
105104
"@types/mocha": "^9.0.0",

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ 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';
1211

1312
type ValueProps = (
1413
| {
1514
[type in keyof TypeCastMap]: { type: type; value: TypeCastMap[type] };
1615
}[keyof TypeCastMap]
1716
| { type: 'DBRef'; value: DBRef }
18-
) & { track?: TrackFunction };
17+
) & { onUUIDEncountered?: (subtype: 3 | 4) => void };
1918

2019
function truncate(str: string, length = 70): string {
2120
const truncated = str.slice(0, length);
@@ -124,7 +123,7 @@ const ObjectIdValue: React.FunctionComponent<PropsByValueType<'ObjectId'>> = ({
124123

125124
const BinaryValue: React.FunctionComponent<PropsByValueType<'Binary'>> = ({
126125
value,
127-
track,
126+
onUUIDEncountered,
128127
}) => {
129128
const { stringifiedValue, title, additionalHints } = useMemo(() => {
130129
if (value.sub_type === Binary.SUBTYPE_ENCRYPTED) {
@@ -147,7 +146,7 @@ const BinaryValue: React.FunctionComponent<PropsByValueType<'Binary'>> = ({
147146
}
148147
if (value.sub_type === Binary.SUBTYPE_UUID) {
149148
let uuid: string;
150-
track?.('UUID Encountered', { subtype: 4 });
149+
onUUIDEncountered?.(4);
151150
try {
152151
// Try to get the pretty hex version of the UUID
153152
uuid = value.toUUID().toString();
@@ -192,7 +191,7 @@ const BinaryValue: React.FunctionComponent<PropsByValueType<'Binary'>> = ({
192191
}
193192
}
194193
if (value.sub_type === Binary.SUBTYPE_UUID_OLD) {
195-
track?.('UUID Encountered', { subtype: 3 });
194+
onUUIDEncountered?.(3);
196195
}
197196
return {
198197
stringifiedValue: `Binary.createFromBase64('${truncate(
@@ -381,7 +380,10 @@ const BSONValue: React.FunctionComponent<ValueProps> = (props) => {
381380
return <DateValue value={props.value}></DateValue>;
382381
case 'Binary':
383382
return (
384-
<BinaryValue value={props.value} track={props.track}></BinaryValue>
383+
<BinaryValue
384+
value={props.value}
385+
onUUIDEncountered={props.onUUIDEncountered}
386+
></BinaryValue>
385387
);
386388
case 'Int32':
387389
case 'Double':

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ 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';
1918

2019
function useHadronDocument(doc: HadronDocumentType) {
2120
const prevDoc = usePrevious(doc);
@@ -86,15 +85,15 @@ const HadronDocument: React.FunctionComponent<{
8685
editable?: boolean;
8786
editing?: boolean;
8887
onEditStart?: () => void;
89-
track?: TrackFunction;
88+
onUUIDEncountered?: (subtype: 3 | 4) => void;
9089
extraGutterWidth?: number;
9190
}> = ({
9291
value: document,
9392
editable = false,
9493
editing = false,
9594
onEditStart,
9695
extraGutterWidth,
97-
track,
96+
onUUIDEncountered,
9897
}) => {
9998
const { elements, visibleElements } = useHadronDocument(document);
10099
const [autoFocus, setAutoFocus] = useState<{
@@ -151,7 +150,7 @@ const HadronDocument: React.FunctionComponent<{
151150
}
152151
: undefined
153152
}
154-
track={track}
153+
onUUIDEncountered={onUUIDEncountered}
155154
lineNumberSize={visibleElements.length}
156155
onAddElement={(el) => {
157156
setAutoFocus({

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ 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';
3231

3332
function getEditorByType(type: HadronElementType['type']) {
3433
switch (type) {
@@ -415,7 +414,7 @@ export const HadronElement: React.FunctionComponent<{
415414
editable: boolean;
416415
editingEnabled: boolean;
417416
onEditStart?: (id: string, field: 'key' | 'value' | 'type') => void;
418-
track?: TrackFunction;
417+
onUUIDEncountered?: (subtype: 3 | 4) => void;
419418
lineNumberSize: number;
420419
onAddElement(el: HadronElementType): void;
421420
extraGutterWidth?: number;
@@ -424,7 +423,7 @@ export const HadronElement: React.FunctionComponent<{
424423
editable,
425424
editingEnabled,
426425
onEditStart,
427-
track,
426+
onUUIDEncountered,
428427
lineNumberSize,
429428
onAddElement,
430429
extraGutterWidth = 0,
@@ -691,7 +690,7 @@ export const HadronElement: React.FunctionComponent<{
691690
<BSONValue
692691
type={type.value as any}
693692
value={value.originalValue}
694-
track={track}
693+
onUUIDEncountered={onUUIDEncountered}
695694
></BSONValue>
696695
</div>
697696
)}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,11 @@ class EditableDocument extends React.Component<
253253
editable
254254
editing={this.state.editing}
255255
onEditStart={this.handleStartEditing.bind(this)}
256-
track={track}
256+
onUUIDEncountered={(subtype: 3 | 4) => {
257+
track('UUID Encountered', {
258+
subtype,
259+
});
260+
}}
257261
/>
258262
)}
259263
</TelemetryContext.Consumer>

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ class ReadonlyDocument extends React.Component<
140140
value={this.props.doc}
141141
// Provide extra whitespace for the expand button
142142
extraGutterWidth={spacing[900]}
143-
track={track}
143+
onUUIDEncountered={(subtype: 3 | 4) => {
144+
track('UUID Encountered', {
145+
subtype,
146+
});
147+
}}
144148
/>
145149
</>
146150
)}

0 commit comments

Comments
 (0)