Skip to content

Commit

Permalink
feat(mixpanel): add formFieldTypes to diagram closed event
Browse files Browse the repository at this point in the history
Closes #3132
  • Loading branch information
Niklas Kiefer committed Nov 2, 2023
1 parent 81c6b7c commit 5b762e2
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
*/

import {
getEngineProfile
getEngineProfile,
parseFormFieldCounts
} from '../../../util/parse';

import { getTemplateIds } from '../util';
Expand Down Expand Up @@ -65,7 +66,7 @@ export default class TabEventHandler {

const engineProfile = await getEngineProfile(contents, type);

let payload = { diagramType: tab.type };
let payload = { diagramType: type };

if (engineProfile) {
payload = {
Expand All @@ -74,6 +75,13 @@ export default class TabEventHandler {
};
}

if (type === types.FORM) {
payload = {
...payload,
formFieldTypes: parseFormFieldCounts(contents)
};
}

this.track('diagram:closed', payload);
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import engineProfilePlatformDMN from './fixtures/engine-platform.dmn';

import engineProfileCloudDMN from './fixtures/engine-cloud.dmn';

import nestedForm from './fixtures/nested.form';


describe('<TabEventHandler>', () => {

Expand Down Expand Up @@ -501,6 +503,72 @@ describe('<TabEventHandler>', () => {
expect(templateIds).to.have.length(2);
});


describe('should send form field types', () => {

it('closed - simple form', async () => {

// given
const tab = createTab({
file: {
contents: engineProfileCloud
},
type: 'form'
});

// when
const callback = subscribe.getCall(3).args[1];

await callback({
tab
});

// then
expect(track).to.have.been.calledWith('diagram:closed', {
diagramType: 'form',
executionPlatform: 'Camunda Cloud',
executionPlatformVersion: '1.1',
formFieldTypes: {
textfield: 1,
button: 1
}
});
});


it('closed - nested form', async () => {

// given
const tab = createTab({
file: {
contents: nestedForm
},
type: 'form'
});

// when
const callback = subscribe.getCall(3).args[1];

await callback({
tab
});

// then
expect(track).to.have.been.calledWith('diagram:closed', {
diagramType: 'form',
executionPlatform: 'Camunda Cloud',
executionPlatformVersion: '8.4',
formFieldTypes: {
group: 5,
image: 5,
textfield: 6
}
});
});

});


});


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"components": [
{
"key": "text_root",
"type": "textfield"
},
{
"alt": "=alt_root",
"type": "image"
},
{
"label": "flat group",
"path": "",
"type": "group",
"components": [
{
"key": "text_flat",
"type": "textfield"
},
{
"alt": "=alt_flat",
"type": "image"
}
]
},
{
"label": "nested group",
"path": "",
"type": "group",
"components": [
{
"label": "nested group",
"path": "",
"type": "group",
"components": [
{
"key": "text_nested",
"type": "textfield"
},
{
"alt": "=alt_nested",
"type": "image"
}
]
}
]
},
{
"label": "pathed group",
"path": "pathed",
"type": "group",
"components": [
{
"key": "text_pathed",
"type": "textfield"
},
{
"alt": "=alt_pathed",
"type": "image"
}
]
},
{
"label": "separated path group",
"path": "separated.path",
"type": "group",
"components": [
{
"key": "text_separated",
"type": "textfield"
},
{
"alt": "=alt_separated",
"type": "image"
}
]
},
{
"label": "separated key textfield",
"key": "separated2.key",
"type": "textfield"
}
],
"type": "default",
"executionPlatform": "Camunda Cloud",
"executionPlatformVersion": "8.4"
}
49 changes: 49 additions & 0 deletions client/src/util/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,55 @@ export async function getAllElementsByType(xml, elementType, diagramType) {
return elements;
}

export function parseFormFieldCounts(contents) {

if (!contents) {
return {};
}

// parse form content
let form;
try {
form = JSON.parse(contents);
} catch (error) {
return {};
}

// flatten nested components
const components = form.components || [];

function getComponents(components) {
const formFields = [];

components.forEach((component) => {
formFields.push(component);

if (component.components && component.components.length > 0) {
formFields.push(...getComponents(component.components));
}
});

return formFields;
}

const formFields = getComponents(components);

// collect form field counts by type
const typeCounts = {};

formFields.forEach((component) => {
const { type } = component;

if (typeCounts[type]) {
typeCounts[type]++;
} else {
typeCounts[type] = 1;
}
});

return typeCounts;
}

function getDefaultExecutionPlatform(type) {
if (/^cloud/.test(type)) {
return ENGINES.CLOUD;
Expand Down

0 comments on commit 5b762e2

Please sign in to comment.