Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
34 changes: 24 additions & 10 deletions packages/compass-data-modeling/src/components/diagram-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,30 @@ const DiagramContent: React.FunctionComponent<{
model: StaticModel | null;
isInRelationshipDrawingMode: boolean;
newCollection?: string;
onAddFieldToObjectField: (ns: string, parentPath: string[]) => void;
onAddNewFieldToCollection: (ns: string) => void;
onAddFieldToObjectField: (
ns: string,
parentPath: string[],
source: 'side_panel' | 'diagram'
) => void;
onAddNewFieldToCollection: (
ns: string,
source: 'side_panel' | 'diagram'
) => void;
onMoveCollection: (ns: string, newPosition: [number, number]) => void;
onCollectionSelect: (namespace: string) => void;
onRelationshipSelect: (rId: string) => void;
onFieldSelect: (namespace: string, fieldPath: FieldPath) => void;
onRenameField: (
namespace: string,
fieldPath: FieldPath,
newName: string
) => void;
onRenameField: ({
ns,
field,
newName,
source,
}: {
ns: string;
field: FieldPath;
newName: string;
source: 'diagram';
}) => void;
onDiagramBackgroundClicked: () => void;
onDeleteCollection: (ns: string) => void;
onDeleteRelationship: (rId: string) => void;
Expand Down Expand Up @@ -389,14 +402,14 @@ const DiagramContent: React.FunctionComponent<{
const onClickAddFieldToCollection = useCallback(
(event: React.MouseEvent<Element>, ns: string) => {
event.stopPropagation();
onAddNewFieldToCollection(ns);
onAddNewFieldToCollection(ns, 'diagram');
},
[onAddNewFieldToCollection]
);

const onClickAddFieldToObjectField = useCallback(
(event: React.MouseEvent, nodeId: string, parentPath: string[]) => {
onAddFieldToObjectField(nodeId, parentPath);
onAddFieldToObjectField(nodeId, parentPath, 'diagram');
},
[onAddFieldToObjectField]
);
Expand Down Expand Up @@ -448,7 +461,8 @@ const DiagramContent: React.FunctionComponent<{
onPaneClick,
onEdgeClick,
onFieldClick,
onFieldNameChange: onRenameField,
onFieldNameChange: (ns, field, newName) =>
onRenameField({ ns, field, newName, source: 'diagram' }),
onNodeDragStop,
onConnect,
onNodeExpandToggle: isCollapseFlagEnabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,29 @@ type FieldDrawerContentProps = {
}) => void;
onEditRelationshipClick: (rId: string) => void;
onDeleteRelationshipClick: (rId: string) => void;
onRenameField: (
namespace: string,
fromFieldPath: FieldPath,
newName: string
) => void;
onRenameField: ({
ns,
field,
newName,
source,
}: {
ns: string;
field: FieldPath;
newName: string;
source: 'side_panel' | 'diagram';
}) => void;
onChangeFieldType: ({
ns,
fieldPath,
oldTypes,
newTypes,
source,
}: {
ns: string;
fieldPath: FieldPath;
oldTypes: string[];
newTypes: string[];
source: 'side_panel' | 'diagram';
}) => void;
};

Expand Down Expand Up @@ -138,7 +146,12 @@ const FieldDrawerContent: React.FunctionComponent<FieldDrawerContentProps> = ({
if (!isFieldNameValid) {
return;
}
onRenameField(namespace, fieldPath, trimmedName);
onRenameField({
ns: namespace,
field: fieldPath,
newName: trimmedName,
source: 'side_panel',
});
}
);

Expand All @@ -160,6 +173,7 @@ const FieldDrawerContent: React.FunctionComponent<FieldDrawerContentProps> = ({
fieldPath,
oldTypes: fieldTypes,
newTypes,
source: 'side_panel',
});
};

Expand Down
40 changes: 29 additions & 11 deletions packages/compass-data-modeling/src/store/diagram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,10 @@ export function redoEdit(): DataModelingThunkAction<void, RedoEditAction> {

export function onAddNestedField(
ns: string,
parentFieldPath: string[]
parentFieldPath: string[],
source: 'side_panel' | 'diagram'
): DataModelingThunkAction<void, ApplyEditAction | RevertFailedEditAction> {
return (dispatch, getState) => {
return (dispatch, getState, { track }) => {
const modelState = selectCurrentModelFromState(getState());

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

track('Data Modeling Field Added', {
source,
});

return dispatch(applyEdit(edit));
};
}

export function addNewFieldToCollection(
ns: string
ns: string,
source: 'side_panel' | 'diagram'
): DataModelingThunkAction<void, ApplyEditAction | RevertFailedEditAction> {
return (dispatch, getState) => {
return (dispatch, getState, { track }) => {
const modelState = selectCurrentModelFromState(getState());

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

track('Data Modeling Field Added', {
source,
});

return dispatch(applyEdit(edit));
};
}
Expand Down Expand Up @@ -791,14 +801,20 @@ export function removeField(
};
}

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

dispatch(applyEdit({ type: 'RenameField', ns, field, newName }));
Expand Down Expand Up @@ -832,11 +848,13 @@ export function changeFieldType({
fieldPath,
oldTypes,
newTypes,
source,
}: {
ns: string;
fieldPath: FieldPath;
oldTypes: string[];
newTypes: string[];
source: 'side_panel' | 'diagram';
}): DataModelingThunkAction<void, ApplyEditAction | RevertFailedEditAction> {
return (dispatch, getState, { track }) => {
const collectionSchema = selectCurrentModelFromState(
Expand All @@ -851,7 +869,7 @@ export function changeFieldType({
const to = getSchemaWithNewTypes(field.jsonSchema, newTypes);

track('Data Modeling Field Type Changed', {
source: 'side_panel',
source,
from: getTypeNameForTelemetry(oldTypes),
to: getTypeNameForTelemetry(newTypes),
});
Expand Down
17 changes: 15 additions & 2 deletions packages/compass-telemetry/src/telemetry-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3063,6 +3063,18 @@ type DataModelingDiagramFieldRemoved = CommonEvent<{
};
}>;

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

/**
* This event is fired when user renames a field in a data modeling diagram.
*
Expand All @@ -3071,7 +3083,7 @@ type DataModelingDiagramFieldRemoved = CommonEvent<{
type DataModelingDiagramFieldRenamed = CommonEvent<{
name: 'Data Modeling Field Renamed';
payload: {
source: 'side_panel';
source: 'side_panel' | 'diagram';
};
}>;

Expand All @@ -3083,7 +3095,7 @@ type DataModelingDiagramFieldRenamed = CommonEvent<{
type DataModelingDiagramFieldTypeChanged = CommonEvent<{
name: 'Data Modeling Field Type Changed';
payload: {
source: 'side_panel';
source: 'side_panel' | 'diagram';
from?: string;
to?: string;
};
Expand Down Expand Up @@ -3381,6 +3393,7 @@ export type TelemetryEvent =
| DataModelingDiagramCollectionRenamed
| DataModelingDiagramCreated
| DataModelingDiagramExported
| DataModelingDiagramFieldAdded
| DataModelingDiagramFieldRemoved
| DataModelingDiagramFieldRenamed
| DataModelingDiagramFieldTypeChanged
Expand Down
Loading