Skip to content

Commit

Permalink
fix: upload strategy complete event on rudderstack (#16834)
Browse files Browse the repository at this point in the history
  • Loading branch information
farabi-deriv committed Sep 17, 2024
1 parent 4c928b5 commit 6dbbc39
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
5 changes: 3 additions & 2 deletions packages/bot-skeleton/src/scratch/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ export const inject_workspace_options = {

export const updateXmlValues = blockly_options => {
if (!window.Blockly) return;
const { strategy_id, convertedDom, file_name, from } = blockly_options;
const { strategy_id, convertedDom, file_name, from, block_string } = blockly_options;
window.Blockly.xmlValues = {
...window.Blockly.xmlValues,
strategy_id,
convertedDom,
file_name,
from,
block_string,
};
};

Expand Down Expand Up @@ -208,7 +209,7 @@ export const load = async ({
workspace,
Array.from(blockly_xml).map(xml_block => xml_block.getAttribute('type'))
);
updateXmlValues({ strategy_id, convertedDom: xml, file_name, from });
updateXmlValues({ strategy_id, convertedDom: xml, file_name, from, block_string });
if (is_collection) {
loadBlocks(xml, drop_event, event_group, workspace);
} else {
Expand Down
47 changes: 25 additions & 22 deletions packages/bot-web-ui/src/stores/load-modal-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,6 @@ export default class LoadModalStore implements ILoadModalStore {
};

readFile = (is_preview: boolean, drop_event: DragEvent, file: File): void => {
if (this.upload_id && is_preview) {
rudderStackSendUploadStrategyStartEvent({ upload_provider: 'my_computer', upload_id: this.upload_id });
}
const reader = new FileReader();
const file_name = file?.name.replace(/\.[^/.]+$/, '') || '';

Expand All @@ -531,24 +528,8 @@ export default class LoadModalStore implements ILoadModalStore {
strategy_id: '',
showIncompatibleStrategyDialog: false,
};
const upload_type = getStrategyType(load_options?.block_string ?? '');

const result = await load(load_options);
await load(load_options);
this.loadStrategyOnModalLocalPreview(load_options);
if (!is_preview && !result?.error) {
rudderStackSendUploadStrategyCompletedEvent({
upload_provider: 'my_computer',
upload_type,
upload_id: this.upload_id,
});
} else if (!is_preview && result?.error) {
rudderStackSendUploadStrategyFailedEvent({
upload_provider: 'my_computer',
upload_id: this.upload_id,
upload_type,
error_message: result.error,
});
}
this.is_open_button_loading = false;
});

Expand All @@ -566,13 +547,24 @@ export default class LoadModalStore implements ILoadModalStore {
};

loadStrategyOnBotBuilder = async () => {
const { strategy_id = window.Blockly.utils.idGenerator.genUid(), convertedDom } = window.Blockly.xmlValues;
const {
strategy_id = window.Blockly.utils.idGenerator.genUid(),
convertedDom,
block_string,
} = window.Blockly.xmlValues;
const derivWorkspace = window.Blockly.derivWorkspace;

window.Blockly.Xml.clearWorkspaceAndLoadFromXml(convertedDom, derivWorkspace);
derivWorkspace.cleanUp();
derivWorkspace.clearUndo();
derivWorkspace.current_strategy_id = strategy_id;

const upload_type = getStrategyType(block_string ?? '');
rudderStackSendUploadStrategyCompletedEvent({
upload_provider: 'my_computer',
upload_type,
upload_id: this.upload_id,
});
};

updateXmlValuesOnStrategySelection = () => {
Expand Down Expand Up @@ -624,6 +616,17 @@ export default class LoadModalStore implements ILoadModalStore {
(load_options.workspace as any).RTL = isDbotRTL();
}

await load(load_options);
const upload_type = getStrategyType(load_options?.block_string ?? '');
const result = await load(load_options);
if (!result?.error) {
rudderStackSendUploadStrategyStartEvent({ upload_provider: 'my_computer', upload_id: this.upload_id });
} else if (result?.error) {
rudderStackSendUploadStrategyFailedEvent({
upload_provider: 'my_computer',
upload_id: this.upload_id,
upload_type,
error_message: result.error,
});
}
};
}

0 comments on commit 6dbbc39

Please sign in to comment.