Skip to content

Commit 9f43dba

Browse files
authored
Merge pull request code-dot-org#32533 from code-dot-org/remove-custom-behavior-button
Remove 'Create a Behavior/Function' buttons from the toolbox WYSIWYG levelbuilder page
2 parents 8f830e1 + 0d36d1b commit 9f43dba

File tree

6 files changed

+33
-23
lines changed

6 files changed

+33
-23
lines changed

apps/i18n/common/en_us.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@
341341
"createAccountDesc": "Join Code.org! With an account you’ll be able to save your course progress, keep your apps and games, and share your favorites in the public gallery.",
342342
"createAccountToShare": "Create a Code.org account to share your project",
343343
"createAccountToShareDescription": "You must create a Code.org account before you can share and publish your project. Creating an account will also let you save your progress and continue to work on your project later.",
344+
"createBlocklyBehavior": "Create a Behavior",
344345
"createNewClassroom": "Create a new classroom section to start assigning courses and seeing your student progress.",
345346
"createPassword": "Create a password",
346347
"createSection": "Create a section",

apps/src/StudioApp.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import msg from '@cdo/locale';
4343
import project from './code-studio/initApp/project';
4444
import puzzleRatingUtils from './puzzleRatingUtils';
4545
import userAgentParser from './code-studio/initApp/userAgentParser';
46-
import {KeyCodes, TestResults} from './constants';
46+
import {KeyCodes, TestResults, TOOLBOX_EDIT_MODE} from './constants';
4747
import {assets as assetsApi} from './clientApi';
4848
import {blocks as makerDropletBlocks} from './lib/kits/maker/dropletConfig';
4949
import {closeDialog as closeInstructionsDialog} from './redux/instructionsDialog';
@@ -2034,7 +2034,7 @@ StudioApp.prototype.configureDom = function(config) {
20342034
// If in level builder editing blocks, make workspace extra tall
20352035
vizHeight = 3000;
20362036
// Modify the arrangement of toolbox blocks so categories align left
2037-
if (config.level.edit_blocks === 'toolbox_blocks') {
2037+
if (config.level.edit_blocks === TOOLBOX_EDIT_MODE) {
20382038
this.blockYCoordinateInterval = 80;
20392039
config.blockArrangement = {category: {x: 20}};
20402040
}
@@ -2640,7 +2640,7 @@ StudioApp.prototype.handleUsingBlockly_ = function(config) {
26402640
this.checkForEmptyBlocks_ = false;
26412641
if (
26422642
config.level.edit_blocks === 'required_blocks' ||
2643-
config.level.edit_blocks === 'toolbox_blocks' ||
2643+
config.level.edit_blocks === TOOLBOX_EDIT_MODE ||
26442644
config.level.edit_blocks === 'recommended_blocks'
26452645
) {
26462646
// Don't show when run block for toolbox/required/recommended block editing
@@ -2681,10 +2681,9 @@ StudioApp.prototype.handleUsingBlockly_ = function(config) {
26812681
config.level.topLevelProcedureAutopopulate,
26822682
false
26832683
),
2684-
useModalFunctionEditor: utils.valueOr(
2685-
config.level.useModalFunctionEditor,
2686-
false
2687-
),
2684+
useModalFunctionEditor:
2685+
config.level.edit_blocks !== TOOLBOX_EDIT_MODE &&
2686+
!!config.level.useModalFunctionEditor,
26882687
useContractEditor: utils.valueOr(config.level.useContractEditor, false),
26892688
disableExamples: utils.valueOr(config.level.disableExamples, false),
26902689
defaultNumExampleBlocks: utils.valueOr(
@@ -2704,10 +2703,14 @@ StudioApp.prototype.handleUsingBlockly_ = function(config) {
27042703
typeHints: utils.valueOr(config.level.showTypeHints, false)
27052704
};
27062705

2707-
// Never show unused blocks or disable autopopulate in edit mode
2706+
// Never show unused blocks in edit mode. Procedure autopopulate should always
2707+
// be enabled in edit mode. Except in toolbox mode where functions/behaviors
2708+
// should never be created (and therefore the autopopulated blocks would be
2709+
// confusing).
27082710
if (options.editBlocks) {
27092711
options.showUnusedBlocks = false;
2710-
options.disableProcedureAutopopulate = false;
2712+
options.disableProcedureAutopopulate =
2713+
options.editBlocks === TOOLBOX_EDIT_MODE;
27112714
}
27122715

27132716
[

apps/src/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,5 @@ export const EXPO_SESSION_SECRET =
181181
'{"id":"fakefake-67ec-4314-a438-60589b9c0fa2","version":1,"expires_at":2000000000000}';
182182

183183
export const BASE_DIALOG_WIDTH = 700;
184+
185+
export const TOOLBOX_EDIT_MODE = 'toolbox_blocks';

apps/src/dance/blocks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ export default {
331331
if (behaviorEditor && !behaviorEditor.isOpen()) {
332332
flyout.addButtonToFlyout_(
333333
cursor,
334-
'Create a Behavior',
334+
i18n.createBlocklyBehavior(),
335335
behaviorEditor.openWithNewFunction.bind(behaviorEditor)
336336
);
337337
}

apps/src/p5lab/P5Lab.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {changeInterfaceMode, viewAnimationJson} from './actions';
77
import {startInAnimationTab} from './stateQueries';
88
import {P5LabInterfaceMode, APP_WIDTH} from './constants';
99
import {SpritelabReservedWords} from './spritelab/constants';
10+
import {TOOLBOX_EDIT_MODE} from '../constants';
1011
import experiments from '@cdo/apps/util/experiments';
1112
import {
1213
outputError,
@@ -834,7 +835,7 @@ P5Lab.prototype.onPuzzleComplete = function(submit, testResult, message) {
834835
// See StudioApp -> setStartBlocks_
835836
// Because of this, we need to remove the SharedFunctions when we are in
836837
// toolbox edit mode. Otherwise, they end up in a student's toolbox.
837-
if (this.level.edit_blocks === 'toolbox_blocks') {
838+
if (this.level.edit_blocks === TOOLBOX_EDIT_MODE) {
838839
var allBlocks = Array.from(xml.querySelectorAll('xml > block'));
839840
var toRemove = allBlocks.filter(element => {
840841
return (

apps/src/p5lab/spritelab/blocks.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {SVG_NS} from '@cdo/apps/constants';
55
import {getStore} from '@cdo/apps/redux';
66
import {getLocation} from './locationPickerModule';
77
import {APP_HEIGHT, P5LabInterfaceMode} from '../constants';
8+
import {TOOLBOX_EDIT_MODE} from '../../constants';
89
import {animationSourceUrl} from '../animationListModule';
910
import {changeInterfaceMode} from '../actions';
1011
import {Goal, show} from '../AnimationPicker/animationPickerModule';
@@ -520,17 +521,19 @@ export default {
520521
Blockly.BlockValueType.BEHAVIOR,
521522
'gamelab_behavior_get'
522523
);
523-
Blockly.Flyout.configure(Blockly.BlockValueType.BEHAVIOR, {
524-
initialize(flyout, cursor) {
525-
if (behaviorEditor && !behaviorEditor.isOpen()) {
526-
flyout.addButtonToFlyout_(
527-
cursor,
528-
'Create a Behavior',
529-
behaviorEditor.openWithNewFunction.bind(behaviorEditor)
530-
);
531-
}
532-
},
533-
addDefaultVar: false
534-
});
524+
if (blockInstallOptions.level.editBlocks !== TOOLBOX_EDIT_MODE) {
525+
Blockly.Flyout.configure(Blockly.BlockValueType.BEHAVIOR, {
526+
initialize(flyout, cursor) {
527+
if (behaviorEditor && !behaviorEditor.isOpen()) {
528+
flyout.addButtonToFlyout_(
529+
cursor,
530+
i18n.createBlocklyBehavior(),
531+
behaviorEditor.openWithNewFunction.bind(behaviorEditor)
532+
);
533+
}
534+
},
535+
addDefaultVar: false
536+
});
537+
}
535538
}
536539
};

0 commit comments

Comments
 (0)