@@ -696,38 +696,56 @@ export function deleteRelationship(
696696
697697export function deleteCollection (
698698 ns : string
699- ) : DataModelingThunkAction < boolean , ApplyEditAction | ApplyEditFailedAction > {
700- return applyEdit ( { type : 'RemoveCollection' , ns } ) ;
699+ ) : DataModelingThunkAction < void , ApplyEditAction | ApplyEditFailedAction > {
700+ return ( dispatch , getState , { track } ) => {
701+ track ( 'Data Modeling Collection Removed' , {
702+ source : 'side_panel' ,
703+ } ) ;
704+
705+ dispatch ( applyEdit ( { type : 'RemoveCollection' , ns } ) ) ;
706+ } ;
701707}
702708
703709export function updateCollectionNote (
704710 ns : string ,
705711 note : string
706- ) : DataModelingThunkAction < boolean , ApplyEditAction | ApplyEditFailedAction > {
712+ ) : DataModelingThunkAction < void , ApplyEditAction | ApplyEditFailedAction > {
707713 return applyEdit ( { type : 'UpdateCollectionNote' , ns, note } ) ;
708714}
709715
710716export function removeField (
711717 ns : string ,
712718 field : FieldPath
713- ) : DataModelingThunkAction < boolean , ApplyEditAction | ApplyEditFailedAction > {
714- return applyEdit ( { type : 'RemoveField' , ns, field } ) ;
719+ ) : DataModelingThunkAction < void , ApplyEditAction | ApplyEditFailedAction > {
720+ return ( dispatch , getState , { track } ) => {
721+ track ( 'Data Modeling Field Removed' , {
722+ source : 'side_panel' ,
723+ } ) ;
724+
725+ dispatch ( applyEdit ( { type : 'RemoveField' , ns, field } ) ) ;
726+ } ;
715727}
716728
717729export function renameField (
718730 ns : string ,
719731 field : FieldPath ,
720732 newName : string
721- ) : DataModelingThunkAction < boolean , ApplyEditAction | ApplyEditFailedAction > {
722- return applyEdit ( { type : 'RenameField' , ns, field, newName } ) ;
733+ ) : DataModelingThunkAction < void , ApplyEditAction | ApplyEditFailedAction > {
734+ return ( dispatch , getState , { track } ) => {
735+ track ( 'Data Modeling Field Renamed' , {
736+ source : 'side_panel' ,
737+ } ) ;
738+
739+ dispatch ( applyEdit ( { type : 'RenameField' , ns, field, newName } ) ) ;
740+ } ;
723741}
724742
725743export function changeFieldType (
726744 ns : string ,
727745 fieldPath : FieldPath ,
728746 newTypes : string [ ]
729747) : DataModelingThunkAction < void , ApplyEditAction | ApplyEditFailedAction > {
730- return ( dispatch , getState ) => {
748+ return ( dispatch , getState , { track } ) => {
731749 const collectionSchema = selectCurrentModelFromState (
732750 getState ( )
733751 ) . collections . find ( ( collection ) => collection . ns === ns ) ?. jsonSchema ;
@@ -738,6 +756,26 @@ export function changeFieldType(
738756 } ) ;
739757 if ( ! field ) throw new Error ( 'Field not found in schema' ) ;
740758 const to = getSchemaWithNewTypes ( field . jsonSchema , newTypes ) ;
759+
760+ track ( 'Data Modeling Field Type Changed' , {
761+ source : 'side_panel' ,
762+ // If the field had a single type, we report that, otherwise 'mixed'.
763+ from : field . jsonSchema . bsonType
764+ ? Array . isArray ( field . jsonSchema . bsonType )
765+ ? field . jsonSchema . bsonType . length === 1
766+ ? field . jsonSchema . bsonType [ 0 ]
767+ : 'mixed'
768+ : field . jsonSchema . bsonType
769+ : undefined ,
770+ to : to . bsonType
771+ ? Array . isArray ( to . bsonType )
772+ ? to . bsonType . length === 1
773+ ? to . bsonType [ 0 ]
774+ : 'mixed'
775+ : to . bsonType
776+ : undefined ,
777+ } ) ;
778+
741779 dispatch (
742780 applyEdit ( {
743781 type : 'ChangeFieldType' ,
@@ -786,10 +824,10 @@ export function addCollection(
786824 ns ?: string ,
787825 position ?: [ number , number ]
788826) : DataModelingThunkAction <
789- boolean ,
827+ void ,
790828 ApplyEditAction | ApplyEditFailedAction | CollectionSelectedAction
791829> {
792- return ( dispatch , getState ) => {
830+ return ( dispatch , getState , { track } ) => {
793831 const existingCollections = selectCurrentModelFromState (
794832 getState ( )
795833 ) . collections ;
@@ -802,6 +840,10 @@ export function addCollection(
802840 } ) ;
803841 }
804842
843+ track ( 'Data Modeling Collection Added' , {
844+ source : 'toolbar' ,
845+ } ) ;
846+
805847 const edit : Omit <
806848 Extract < Edit , { type : 'AddCollection' } > ,
807849 'id' | 'timestamp'
@@ -820,7 +862,6 @@ export function addCollection(
820862 position,
821863 } ;
822864 dispatch ( applyEdit ( edit ) ) ;
823- return true ;
824865 } ;
825866}
826867
0 commit comments