Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: converted const to a arrow function #187

Closed
Closed
Changes from 4 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
46 changes: 27 additions & 19 deletions src/external/bot-skeleton/scratch/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,12 +623,16 @@ 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'),
const download_option = () => ({
text: getLocalizedText('Download Block') || 'Download Block',
enabled: true,
callback: downloadBlock,
};
});

export const excludeOptionFromContextMenu = (menu, exclude_items) => {
for (let i = 0; i <= menu.length - 1; i++) {
Expand All @@ -641,23 +645,27 @@ 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'),
localize('Add Comment'),
localize('Remove Comment'),
localize('Collapse Block'),
localize('Expand Block'),
localize('Disable Block'),
localize('Enable Block'),
localize('Download Block'),
];
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');
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({
Expand All @@ -671,13 +679,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;
}
}
Expand Down
Loading