Skip to content

Commit 0a4fc42

Browse files
authored
fix: complete field telemetry events COMPASS-10066 (#7563)
1 parent 3f88c82 commit 0a4fc42

File tree

4 files changed

+88
-29
lines changed

4 files changed

+88
-29
lines changed

packages/compass-data-modeling/src/components/diagram-editor.tsx

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,30 @@ const DiagramContent: React.FunctionComponent<{
161161
model: StaticModel | null;
162162
isInRelationshipDrawingMode: boolean;
163163
newCollection?: string;
164-
onAddFieldToObjectField: (ns: string, parentPath: string[]) => void;
165-
onAddNewFieldToCollection: (ns: string) => void;
164+
onAddFieldToObjectField: (
165+
ns: string,
166+
parentPath: string[],
167+
source: 'side_panel' | 'diagram'
168+
) => void;
169+
onAddNewFieldToCollection: (
170+
ns: string,
171+
source: 'side_panel' | 'diagram'
172+
) => void;
166173
onMoveCollection: (ns: string, newPosition: [number, number]) => void;
167174
onCollectionSelect: (namespace: string) => void;
168175
onRelationshipSelect: (rId: string) => void;
169176
onFieldSelect: (namespace: string, fieldPath: FieldPath) => void;
170-
onRenameField: (
171-
namespace: string,
172-
fieldPath: FieldPath,
173-
newName: string
174-
) => void;
177+
onRenameField: ({
178+
ns,
179+
field,
180+
newName,
181+
source,
182+
}: {
183+
ns: string;
184+
field: FieldPath;
185+
newName: string;
186+
source: 'diagram';
187+
}) => void;
175188
onDiagramBackgroundClicked: () => void;
176189
onDeleteCollection: (ns: string) => void;
177190
onDeleteRelationship: (rId: string) => void;
@@ -389,14 +402,14 @@ const DiagramContent: React.FunctionComponent<{
389402
const onClickAddFieldToCollection = useCallback(
390403
(event: React.MouseEvent<Element>, ns: string) => {
391404
event.stopPropagation();
392-
onAddNewFieldToCollection(ns);
405+
onAddNewFieldToCollection(ns, 'diagram');
393406
},
394407
[onAddNewFieldToCollection]
395408
);
396409

397410
const onClickAddFieldToObjectField = useCallback(
398411
(event: React.MouseEvent, nodeId: string, parentPath: string[]) => {
399-
onAddFieldToObjectField(nodeId, parentPath);
412+
onAddFieldToObjectField(nodeId, parentPath, 'diagram');
400413
},
401414
[onAddFieldToObjectField]
402415
);
@@ -448,7 +461,8 @@ const DiagramContent: React.FunctionComponent<{
448461
onPaneClick,
449462
onEdgeClick,
450463
onFieldClick,
451-
onFieldNameChange: onRenameField,
464+
onFieldNameChange: (ns, field, newName) =>
465+
onRenameField({ ns, field, newName, source: 'diagram' }),
452466
onNodeDragStop,
453467
onConnect,
454468
onNodeExpandToggle: isCollapseFlagEnabled

packages/compass-data-modeling/src/components/drawer/field-drawer-content.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,29 @@ type FieldDrawerContentProps = {
4949
}) => void;
5050
onEditRelationshipClick: (rId: string) => void;
5151
onDeleteRelationshipClick: (rId: string) => void;
52-
onRenameField: (
53-
namespace: string,
54-
fromFieldPath: FieldPath,
55-
newName: string
56-
) => void;
52+
onRenameField: ({
53+
ns,
54+
field,
55+
newName,
56+
source,
57+
}: {
58+
ns: string;
59+
field: FieldPath;
60+
newName: string;
61+
source: 'side_panel' | 'diagram';
62+
}) => void;
5763
onChangeFieldType: ({
5864
ns,
5965
fieldPath,
6066
oldTypes,
6167
newTypes,
68+
source,
6269
}: {
6370
ns: string;
6471
fieldPath: FieldPath;
6572
oldTypes: string[];
6673
newTypes: string[];
74+
source: 'side_panel' | 'diagram';
6775
}) => void;
6876
};
6977

@@ -138,7 +146,12 @@ const FieldDrawerContent: React.FunctionComponent<FieldDrawerContentProps> = ({
138146
if (!isFieldNameValid) {
139147
return;
140148
}
141-
onRenameField(namespace, fieldPath, trimmedName);
149+
onRenameField({
150+
ns: namespace,
151+
field: fieldPath,
152+
newName: trimmedName,
153+
source: 'side_panel',
154+
});
142155
}
143156
);
144157

@@ -160,6 +173,7 @@ const FieldDrawerContent: React.FunctionComponent<FieldDrawerContentProps> = ({
160173
fieldPath,
161174
oldTypes: fieldTypes,
162175
newTypes,
176+
source: 'side_panel',
163177
});
164178
};
165179

packages/compass-data-modeling/src/store/diagram.ts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,10 @@ export function redoEdit(): DataModelingThunkAction<void, RedoEditAction> {
507507

508508
export function onAddNestedField(
509509
ns: string,
510-
parentFieldPath: string[]
510+
parentFieldPath: string[],
511+
source: 'side_panel' | 'diagram'
511512
): DataModelingThunkAction<void, ApplyEditAction | RevertFailedEditAction> {
512-
return (dispatch, getState) => {
513+
return (dispatch, getState, { track }) => {
513514
const modelState = selectCurrentModelFromState(getState());
514515

515516
const collection = modelState.collections.find((c) => c.ns === ns);
@@ -533,14 +534,19 @@ export function onAddNestedField(
533534
},
534535
};
535536

537+
track('Data Modeling Field Added', {
538+
source,
539+
});
540+
536541
return dispatch(applyEdit(edit));
537542
};
538543
}
539544

540545
export function addNewFieldToCollection(
541-
ns: string
546+
ns: string,
547+
source: 'side_panel' | 'diagram'
542548
): DataModelingThunkAction<void, ApplyEditAction | RevertFailedEditAction> {
543-
return (dispatch, getState) => {
549+
return (dispatch, getState, { track }) => {
544550
const modelState = selectCurrentModelFromState(getState());
545551

546552
const collection = modelState.collections.find((c) => c.ns === ns);
@@ -561,6 +567,10 @@ export function addNewFieldToCollection(
561567
},
562568
};
563569

570+
track('Data Modeling Field Added', {
571+
source,
572+
});
573+
564574
return dispatch(applyEdit(edit));
565575
};
566576
}
@@ -791,14 +801,20 @@ export function removeField(
791801
};
792802
}
793803

794-
export function renameField(
795-
ns: string,
796-
field: FieldPath,
797-
newName: string
798-
): DataModelingThunkAction<void, ApplyEditAction | RevertFailedEditAction> {
804+
export function renameField({
805+
ns,
806+
field,
807+
newName,
808+
source,
809+
}: {
810+
ns: string;
811+
field: FieldPath;
812+
newName: string;
813+
source: 'side_panel' | 'diagram';
814+
}): DataModelingThunkAction<void, ApplyEditAction | RevertFailedEditAction> {
799815
return (dispatch, getState, { track }) => {
800816
track('Data Modeling Field Renamed', {
801-
source: 'side_panel',
817+
source,
802818
});
803819

804820
dispatch(applyEdit({ type: 'RenameField', ns, field, newName }));
@@ -832,11 +848,13 @@ export function changeFieldType({
832848
fieldPath,
833849
oldTypes,
834850
newTypes,
851+
source,
835852
}: {
836853
ns: string;
837854
fieldPath: FieldPath;
838855
oldTypes: string[];
839856
newTypes: string[];
857+
source: 'side_panel' | 'diagram';
840858
}): DataModelingThunkAction<void, ApplyEditAction | RevertFailedEditAction> {
841859
return (dispatch, getState, { track }) => {
842860
const collectionSchema = selectCurrentModelFromState(
@@ -851,7 +869,7 @@ export function changeFieldType({
851869
const to = getSchemaWithNewTypes(field.jsonSchema, newTypes);
852870

853871
track('Data Modeling Field Type Changed', {
854-
source: 'side_panel',
872+
source,
855873
from: getTypeNameForTelemetry(oldTypes),
856874
to: getTypeNameForTelemetry(newTypes),
857875
});

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2970,6 +2970,18 @@ type DataModelingDiagramFieldRemoved = CommonEvent<{
29702970
};
29712971
}>;
29722972

2973+
/**
2974+
* This event is fired when user adds a field in a data modeling diagram.
2975+
*
2976+
* @category Data Modeling
2977+
*/
2978+
type DataModelingDiagramFieldAdded = CommonEvent<{
2979+
name: 'Data Modeling Field Added';
2980+
payload: {
2981+
source: 'side_panel' | 'diagram';
2982+
};
2983+
}>;
2984+
29732985
/**
29742986
* This event is fired when user renames a field in a data modeling diagram.
29752987
*
@@ -2978,7 +2990,7 @@ type DataModelingDiagramFieldRemoved = CommonEvent<{
29782990
type DataModelingDiagramFieldRenamed = CommonEvent<{
29792991
name: 'Data Modeling Field Renamed';
29802992
payload: {
2981-
source: 'side_panel';
2993+
source: 'side_panel' | 'diagram';
29822994
};
29832995
}>;
29842996

@@ -2990,7 +3002,7 @@ type DataModelingDiagramFieldRenamed = CommonEvent<{
29903002
type DataModelingDiagramFieldTypeChanged = CommonEvent<{
29913003
name: 'Data Modeling Field Type Changed';
29923004
payload: {
2993-
source: 'side_panel';
3005+
source: 'side_panel' | 'diagram';
29943006
from?: string;
29953007
to?: string;
29963008
};
@@ -3288,6 +3300,7 @@ export type TelemetryEvent =
32883300
| DataModelingDiagramCollectionRenamed
32893301
| DataModelingDiagramCreated
32903302
| DataModelingDiagramExported
3303+
| DataModelingDiagramFieldAdded
32913304
| DataModelingDiagramFieldRemoved
32923305
| DataModelingDiagramFieldRenamed
32933306
| DataModelingDiagramFieldTypeChanged

0 commit comments

Comments
 (0)