Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 52 additions & 11 deletions packages/compass-data-modeling/src/store/diagram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -696,38 +696,56 @@ export function deleteRelationship(

export function deleteCollection(
ns: string
): DataModelingThunkAction<boolean, ApplyEditAction | ApplyEditFailedAction> {
return applyEdit({ type: 'RemoveCollection', ns });
): DataModelingThunkAction<void, ApplyEditAction | ApplyEditFailedAction> {
return (dispatch, getState, { track }) => {
track('Data Modeling Collection Removed', {
source: 'side_panel',
});

dispatch(applyEdit({ type: 'RemoveCollection', ns }));
};
}

export function updateCollectionNote(
ns: string,
note: string
): DataModelingThunkAction<boolean, ApplyEditAction | ApplyEditFailedAction> {
): DataModelingThunkAction<void, ApplyEditAction | ApplyEditFailedAction> {
return applyEdit({ type: 'UpdateCollectionNote', ns, note });
}

export function removeField(
ns: string,
field: FieldPath
): DataModelingThunkAction<boolean, ApplyEditAction | ApplyEditFailedAction> {
return applyEdit({ type: 'RemoveField', ns, field });
): DataModelingThunkAction<void, ApplyEditAction | ApplyEditFailedAction> {
return (dispatch, getState, { track }) => {
track('Data Modeling Field Removed', {
source: 'side_panel',
});

dispatch(applyEdit({ type: 'RemoveField', ns, field }));
};
}

export function renameField(
ns: string,
field: FieldPath,
newName: string
): DataModelingThunkAction<boolean, ApplyEditAction | ApplyEditFailedAction> {
return applyEdit({ type: 'RenameField', ns, field, newName });
): DataModelingThunkAction<void, ApplyEditAction | ApplyEditFailedAction> {
return (dispatch, getState, { track }) => {
track('Data Modeling Field Renamed', {
source: 'side_panel',
});

dispatch(applyEdit({ type: 'RenameField', ns, field, newName }));
};
}

export function changeFieldType(
ns: string,
fieldPath: FieldPath,
newTypes: string[]
): DataModelingThunkAction<void, ApplyEditAction | ApplyEditFailedAction> {
return (dispatch, getState) => {
return (dispatch, getState, { track }) => {
const collectionSchema = selectCurrentModelFromState(
getState()
).collections.find((collection) => collection.ns === ns)?.jsonSchema;
Expand All @@ -738,6 +756,26 @@ export function changeFieldType(
});
if (!field) throw new Error('Field not found in schema');
const to = getSchemaWithNewTypes(field.jsonSchema, newTypes);

track('Data Modeling Field Type Changed', {
source: 'side_panel',
// If the field had a single type, we report that, otherwise 'mixed'.
from: field.jsonSchema.bsonType
? Array.isArray(field.jsonSchema.bsonType)
? field.jsonSchema.bsonType.length === 1
? field.jsonSchema.bsonType[0]
: 'mixed'
: field.jsonSchema.bsonType
: undefined,
to: to.bsonType
? Array.isArray(to.bsonType)
? to.bsonType.length === 1
? to.bsonType[0]
: 'mixed'
: to.bsonType
: undefined,
});

dispatch(
applyEdit({
type: 'ChangeFieldType',
Expand Down Expand Up @@ -786,10 +824,10 @@ export function addCollection(
ns?: string,
position?: [number, number]
): DataModelingThunkAction<
boolean,
void,
ApplyEditAction | ApplyEditFailedAction | CollectionSelectedAction
> {
return (dispatch, getState) => {
return (dispatch, getState, { track }) => {
const existingCollections = selectCurrentModelFromState(
getState()
).collections;
Expand All @@ -802,6 +840,10 @@ export function addCollection(
});
}

track('Data Modeling Collection Added', {
source: 'toolbar',
});

const edit: Omit<
Extract<Edit, { type: 'AddCollection' }>,
'id' | 'timestamp'
Expand All @@ -820,7 +862,6 @@ export function addCollection(
position,
};
dispatch(applyEdit(edit));
return true;
};
}

Expand Down
90 changes: 85 additions & 5 deletions packages/compass-telemetry/src/telemetry-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2919,6 +2919,42 @@ type CreateIndexStrategiesDocumentationClicked = CommonEvent<{
};
}>;

/**
* This event is fired when user adds a collection in a data modeling diagram.
*
* @category Data Modeling
*/
type DataModelingDiagramCollectionAdded = CommonEvent<{
name: 'Data Modeling Collection Added';
payload: {
source: 'toolbar';
};
}>;

/**
* This event is fired when user removes a collection in a data modeling diagram.
*
* @category Data Modeling
*/
type DataModelingDiagramCollectionRemoved = CommonEvent<{
name: 'Data Modeling Collection Removed';
payload: {
source: 'side_panel';
};
}>;

/**
* This event is fired when user renames a collection in a data modeling diagram.
*
* @category Data Modeling
*/
type DataModelingDiagramCollectionRenamed = CommonEvent<{
name: 'Data Modeling Collection Renamed';
payload: {
source: 'side_panel';
};
}>;

/**
* This event is fired when a new data modeling diagram is created
*
Expand All @@ -2943,6 +2979,44 @@ type DataModelingDiagramExported = CommonEvent<{
};
}>;

/**
* This event is fired when user removes a field in a data modeling diagram.
*
* @category Data Modeling
*/
type DataModelingDiagramFieldRemoved = CommonEvent<{
name: 'Data Modeling Field Removed';
payload: {
source: 'side_panel';
};
}>;

/**
* This event is fired when user renames a field in a data modeling diagram.
*
* @category Data Modeling
*/
type DataModelingDiagramFieldRenamed = CommonEvent<{
name: 'Data Modeling Field Renamed';
payload: {
source: 'side_panel';
};
}>;

/**
* This event is fired when user changes a field type in a data modeling diagram.
*
* @category Data Modeling
*/
type DataModelingDiagramFieldTypeChanged = CommonEvent<{
name: 'Data Modeling Field Type Changed';
payload: {
source: 'side_panel';
from?: string;
to?: string;
};
}>;

/**
* This event is fired when user imports data modeling diagram.
*
Expand Down Expand Up @@ -3064,7 +3138,18 @@ export type TelemetryEvent =
| ConnectionRemovedEvent
| CurrentOpShowOperationDetailsEvent
| DatabaseCreatedEvent
| DataModelingDiagramCollectionAdded
| DataModelingDiagramCollectionRemoved
| DataModelingDiagramCollectionRenamed
| DataModelingDiagramCreated
| DataModelingDiagramExported
| DataModelingDiagramFieldRemoved
| DataModelingDiagramFieldRenamed
| DataModelingDiagramFieldTypeChanged
| DataModelingDiagramImported
| DataModelingDiagramRelationshipAdded
| DataModelingDiagramRelationshipEdited
| DataModelingDiagramRelationshipDeleted
| DeleteExportedEvent
| DeleteExportOpenedEvent
| DetailViewHideOperationDetailsEvent
Expand Down Expand Up @@ -3161,10 +3246,5 @@ export type TelemetryEvent =
| CreateIndexIndexSuggestionsCopied
| CreateIndexStrategiesDocumentationClicked
| UUIDEncounteredEvent
| DataModelingDiagramExported
| DataModelingDiagramImported
| DataModelingDiagramRelationshipAdded
| DataModelingDiagramRelationshipEdited
| DataModelingDiagramRelationshipDeleted
| ContextMenuOpened
| ContextMenuItemClicked;
Loading