From 998c3a5b46148758ef3ba581056333f7ac75ffc5 Mon Sep 17 00:00:00 2001 From: Rupato Braganza Date: Wed, 11 Dec 2024 12:35:53 +0800 Subject: [PATCH 1/6] fix: converted const to a arrow function --- src/external/bot-skeleton/scratch/utils/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/external/bot-skeleton/scratch/utils/index.js b/src/external/bot-skeleton/scratch/utils/index.js index 9d83f9c0..298234e9 100644 --- a/src/external/bot-skeleton/scratch/utils/index.js +++ b/src/external/bot-skeleton/scratch/utils/index.js @@ -643,7 +643,7 @@ export const excludeOptionFromContextMenu = (menu, exclude_items) => { const common_included_items = [download_option]; -const all_context_menu_options = [ +const all_context_menu_options = () => [ localize('Duplicate'), localize('Add Comment'), localize('Remove Comment'), @@ -677,7 +677,7 @@ export const modifyContextMenu = (menu, add_new_items = []) => { } } else { const localized_text = localize(menu[i].text); - if (all_context_menu_options.includes(localized_text)) { + if (all_context_menu_options().includes(localized_text)) { menu[i].text = localized_text; } } From 9270ffeebb7f6cecbe1eb6a4f3b45a43f2bbe9af Mon Sep 17 00:00:00 2001 From: Rupato Braganza Date: Wed, 11 Dec 2024 13:04:48 +0800 Subject: [PATCH 2/6] fix: converted to arrow fucnction --- .../bot-skeleton/scratch/utils/index.js | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/external/bot-skeleton/scratch/utils/index.js b/src/external/bot-skeleton/scratch/utils/index.js index 298234e9..7a2470d8 100644 --- a/src/external/bot-skeleton/scratch/utils/index.js +++ b/src/external/bot-skeleton/scratch/utils/index.js @@ -624,11 +624,11 @@ const downloadBlock = () => { saveAs({ data: xml_text, type: 'text/xml;charset=utf-8', filename: 'block.xml' }); }; -const download_option = { - text: localize('Download Block'), +const download_option = () => ({ + text: localize('Download Block') || 'Download Block', enabled: true, callback: downloadBlock, -}; +}); export const excludeOptionFromContextMenu = (menu, exclude_items) => { for (let i = 0; i <= menu.length - 1; i++) { @@ -641,7 +641,7 @@ export const excludeOptionFromContextMenu = (menu, exclude_items) => { } }; -const common_included_items = [download_option]; +const common_included_items = [download_option()]; const all_context_menu_options = () => [ localize('Duplicate'), @@ -654,10 +654,13 @@ const all_context_menu_options = () => [ localize('Download Block'), ]; -const deleteBlocksLocaleText = localize('Delete Block'); -const deleteAllBlocksLocaleText = localize('Delete All Blocks'); +const deleteBlocksLocaleText = () => localize('Delete Block'); +const deleteAllBlocksLocaleText = () => localize('Delete All Blocks'); export const modifyContextMenu = (menu, add_new_items = []) => { + const all_context_menu_options_ = all_context_menu_options(); + const delete_block_lacale_text_ = deleteBlocksLocaleText(); + const delete_all_blocks_locale_text_ = deleteAllBlocksLocaleText(); const include_items = [...common_included_items, ...add_new_items]; include_items.forEach(item => { menu.push({ @@ -671,13 +674,13 @@ export const modifyContextMenu = (menu, add_new_items = []) => { const menu_text = menu[i]?.text?.toLowerCase(); if (menu_text?.includes('delete')) { if (menu_text.includes('block') && !menu_text.includes('blocks')) { - menu[i].text = deleteBlocksLocaleText; + menu[i].text = delete_block_lacale_text_; } else { - menu[i].text = deleteAllBlocksLocaleText; + menu[i].text = delete_all_blocks_locale_text_; } } else { const localized_text = localize(menu[i].text); - if (all_context_menu_options().includes(localized_text)) { + if (all_context_menu_options_.includes(localized_text)) { menu[i].text = localized_text; } } From ab979a94bb4f5fce0b6429f088302aff7791c03f Mon Sep 17 00:00:00 2001 From: Rupato Braganza Date: Wed, 11 Dec 2024 13:10:07 +0800 Subject: [PATCH 3/6] fix: converted to arrow fucnction --- .../bot-skeleton/scratch/utils/index.js | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/external/bot-skeleton/scratch/utils/index.js b/src/external/bot-skeleton/scratch/utils/index.js index 7a2470d8..e160c7f7 100644 --- a/src/external/bot-skeleton/scratch/utils/index.js +++ b/src/external/bot-skeleton/scratch/utils/index.js @@ -643,16 +643,22 @@ export const excludeOptionFromContextMenu = (menu, exclude_items) => { const common_included_items = [download_option()]; -const all_context_menu_options = () => [ - localize('Duplicate'), - localize('Add Comment'), - localize('Remove Comment'), - localize('Collapse Block'), - localize('Expand Block'), - localize('Disable Block'), - localize('Enable Block'), - localize('Download Block'), -]; +const getLocalizedText = text => { + if (!text) return text; + return localize(text) || text; +}; + +const all_context_menu_options = () => + [ + 'Duplicate', + 'Add Comment', + 'Remove Comment', + 'Collapse Block', + 'Expand Block', + 'Disable Block', + 'Enable Block', + 'Download Block', + ].map(getLocalizedText); const deleteBlocksLocaleText = () => localize('Delete Block'); const deleteAllBlocksLocaleText = () => localize('Delete All Blocks'); From c156818f32adb6b51077a4ed890425f9b6cd21ce Mon Sep 17 00:00:00 2001 From: Rupato Braganza Date: Wed, 11 Dec 2024 13:11:23 +0800 Subject: [PATCH 4/6] fix: made a general functionl to localize --- src/external/bot-skeleton/scratch/utils/index.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/external/bot-skeleton/scratch/utils/index.js b/src/external/bot-skeleton/scratch/utils/index.js index e160c7f7..1d23f7bd 100644 --- a/src/external/bot-skeleton/scratch/utils/index.js +++ b/src/external/bot-skeleton/scratch/utils/index.js @@ -623,9 +623,13 @@ const downloadBlock = () => { const xml_text = window.Blockly.Xml.domToPrettyText(xml_block); saveAs({ data: xml_text, type: 'text/xml;charset=utf-8', filename: 'block.xml' }); }; +const getLocalizedText = text => { + if (!text) return text; + return localize(text) || text; +}; const download_option = () => ({ - text: localize('Download Block') || 'Download Block', + text: getLocalizedText('Download Block') || 'Download Block', enabled: true, callback: downloadBlock, }); @@ -643,11 +647,6 @@ export const excludeOptionFromContextMenu = (menu, exclude_items) => { const common_included_items = [download_option()]; -const getLocalizedText = text => { - if (!text) return text; - return localize(text) || text; -}; - const all_context_menu_options = () => [ 'Duplicate', From 6eb4908206d5744b975be83cf6c08090bff50b43 Mon Sep 17 00:00:00 2001 From: Rupato Braganza Date: Wed, 11 Dec 2024 17:01:38 +0800 Subject: [PATCH 5/6] fix: for missing blocks --- .../blocks/Binary/Before Purchase/purchase.js | 2 +- .../bot-skeleton/scratch/utils/index.js | 46 ++++++++++++---- .../bot-skeleton/utils/error-config.js | 52 ++++++------------- .../bot-skeleton/utils/error-handling.js | 6 +-- 4 files changed, 55 insertions(+), 51 deletions(-) diff --git a/src/external/bot-skeleton/scratch/blocks/Binary/Before Purchase/purchase.js b/src/external/bot-skeleton/scratch/blocks/Binary/Before Purchase/purchase.js index 5904b9e1..467f8d08 100755 --- a/src/external/bot-skeleton/scratch/blocks/Binary/Before Purchase/purchase.js +++ b/src/external/bot-skeleton/scratch/blocks/Binary/Before Purchase/purchase.js @@ -11,7 +11,7 @@ window.Blockly.Blocks.purchase = { }, definition() { return { - message0: localize('Purchase {{ contract_type }}', { contract_type: '%1' }), + message0: localize('Purchase test {{ contract_type }}', { contract_type: '%1' }), args0: [ { type: 'field_dropdown', diff --git a/src/external/bot-skeleton/scratch/utils/index.js b/src/external/bot-skeleton/scratch/utils/index.js index 1d23f7bd..8df18929 100644 --- a/src/external/bot-skeleton/scratch/utils/index.js +++ b/src/external/bot-skeleton/scratch/utils/index.js @@ -410,24 +410,47 @@ const getDisabledBlocks = required_blocks_check => { }); }; -const throwNewErrorMessage = (error_blocks, key) => { - return error_blocks.forEach(block => { - if (key === 'misplaced' && block) globalObserver.emit('ui.log.error', error_message_map[block?.type]?.[key]); - else if (key === 'missing' && block) globalObserver.emit('ui.log.error', error_message_map[block]?.[key]); - else if (key === 'disabled' && block) { +const throwNewErrorMessage = async (error_blocks, key) => { + for (const block of error_blocks) { + const error_message_map_ = async (type, key) => { + try { + const data = await error_message_map[type]; + return data[key]; + } catch (error) { + console.error('Error fetching error message:', error); + return null; + } + }; + if (key === 'misplaced' && block) { + const error_message = await error_message_map_(block, key); + if (error_message) { + globalObserver.emit('ui.log.error', error_message); + } + } else if (key === 'missing' && block) { + // console.log('block send outside', block, key); + const error_message = await error_message_map_(block, key); + if (error_message) { + globalObserver.emit('ui.log.error', error_message); + } + } else if (key === 'disabled' && block) { let parent_block_error = false; - const parent_error_message = error_message_map[block.type]?.[key]; + // console.log('block send outside', block.type, key); + + const parent_error_message = await error_message_map_(block?.type, key); + if (block.disabled && parent_error_message) { globalObserver.emit('ui.log.error', parent_error_message); parent_block_error = true; } else if (!parent_block_error && block.childBlocks_) { - block.childBlocks_.forEach(childBlock => { - const child_error_message = error_message_map[childBlock.type]?.[key]; - if (child_error_message) globalObserver.emit('ui.log.error', child_error_message); - }); + for (const childBlock of block.childBlocks_) { + const child_error_message = await error_message_map_(childBlock.type, key); + if (child_error_message) { + globalObserver.emit('ui.log.error', child_error_message); + } + } } } - }); + } }; export const isAllRequiredBlocksEnabled = workspace => { @@ -448,6 +471,7 @@ export const isAllRequiredBlocksEnabled = workspace => { const error_blocks = [...missing_blocks, ...disabled_blocks]; const blocks_required = error_blocks.length === 0; + console.log('blocks_required', error_blocks); return blocks_required; }; diff --git a/src/external/bot-skeleton/utils/error-config.js b/src/external/bot-skeleton/utils/error-config.js index 5e9ab581..a0f3c09c 100644 --- a/src/external/bot-skeleton/utils/error-config.js +++ b/src/external/bot-skeleton/utils/error-config.js @@ -1,41 +1,21 @@ -import { Localize } from '@deriv-com/translations'; +const generateErrorMessage = async (block_type, missing_space) => { + const { localize } = await import('@deriv-com/translations'); + if (!missing_space) missing_space = localize('workspace'); -const generateErrorMessage = (block_type, missing_space = 'workspace') => { return { - missing: ( - - ), - misplaced: ( - - ), - - disabled: ( - - ), - default: ( - - ), + missing: localize('The {{block_type}} block is mandatory and cannot be deleted/disabled.', { + block_type, + }), + misplaced: localize('The {{block_type}} block is misplaced from {{missing_space}}.', { + block_type, + missing_space, + }), + disabled: localize('The {{block_type}} block is mandatory and cannot be deleted/disabled.', { + block_type, + }), + default: localize('The {{block_type}} block is mandatory and cannot be deleted/disabled.', { + block_type, + }), }; }; diff --git a/src/external/bot-skeleton/utils/error-handling.js b/src/external/bot-skeleton/utils/error-handling.js index 4ede7f8c..3277c5a4 100644 --- a/src/external/bot-skeleton/utils/error-handling.js +++ b/src/external/bot-skeleton/utils/error-handling.js @@ -20,9 +20,9 @@ export const initErrorHandlingListener = (type = 'keydown') => { export const handleError = (errorCode, observer) => { switch (errorCode) { case 'BLOCK_DELETION': - if (error_message_map[window.Blockly.getSelected().type]) { - observer.emit('ui.log.error', error_message_map[window.Blockly.getSelected().type]?.default); - } + error_message_map[window.Blockly.getSelected().type].then(data => { + observer.emit('ui.log.error', data?.default?.()); + }); break; default: break; From 561d5ba1e1bdcb2bc722d2835b937459bd46c60b Mon Sep 17 00:00:00 2001 From: Rupato Braganza Date: Wed, 11 Dec 2024 17:02:13 +0800 Subject: [PATCH 6/6] fix: for missing blocks --- .../scratch/blocks/Binary/Before Purchase/purchase.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/external/bot-skeleton/scratch/blocks/Binary/Before Purchase/purchase.js b/src/external/bot-skeleton/scratch/blocks/Binary/Before Purchase/purchase.js index 467f8d08..5904b9e1 100755 --- a/src/external/bot-skeleton/scratch/blocks/Binary/Before Purchase/purchase.js +++ b/src/external/bot-skeleton/scratch/blocks/Binary/Before Purchase/purchase.js @@ -11,7 +11,7 @@ window.Blockly.Blocks.purchase = { }, definition() { return { - message0: localize('Purchase test {{ contract_type }}', { contract_type: '%1' }), + message0: localize('Purchase {{ contract_type }}', { contract_type: '%1' }), args0: [ { type: 'field_dropdown',