diff --git a/common-docs/teachertool/test/validator-plans-shared.json b/common-docs/teachertool/test/validator-plans-shared.json index a13f74c3de17..7f8975ae6c01 100644 --- a/common-docs/teachertool/test/validator-plans-shared.json +++ b/common-docs/teachertool/test/validator-plans-shared.json @@ -7,9 +7,12 @@ "checks": [ { "validator": "blocksExist", - "blockCounts": { - "": 0 - } + "blockCounts": [ + { + "blockId": "", + "count": 0 + } + ] } ] } diff --git a/common-docs/teachertool/validator-plans-shared.json b/common-docs/teachertool/validator-plans-shared.json index 2ba6a8ccb317..0ffe198ee652 100644 --- a/common-docs/teachertool/validator-plans-shared.json +++ b/common-docs/teachertool/validator-plans-shared.json @@ -7,27 +7,39 @@ "checks": [ { "validator": "blocksExist", - "blockCounts": { - "controls_repeat_ext": 1 - } + "blockCounts": [ + { + "blockId": "controls_repeat_ext", + "count": 1 + } + ] }, { "validator": "blocksExist", - "blockCounts": { - "device_while": 1 - } + "blockCounts": [ + { + "blockId": "device_while", + "count": 1 + } + ] }, { "validator": "blocksExist", - "blockCounts": { - "pxt_controls_for": 1 - } + "blockCounts": [ + { + "blockId": "pxt_controls_for", + "count": 1 + } + ] }, { "validator": "blocksExist", - "blockCounts": { - "pxt_controls_for_of": 1 - } + "blockCounts": [ + { + "blockId": "pxt_controls_for_of", + "count": 1 + } + ] } ] }, @@ -65,9 +77,12 @@ }, { "validator": "blocksExist", - "blockCounts": { - "function_definition": 1 - } + "blockCounts": [ + { + "blockId": "function_definition", + "count": 1 + } + ] } ] }, @@ -78,9 +93,12 @@ "checks": [ { "validator": "blocksExist", - "blockCounts": { - "variables_set": 1 - } + "blockCounts": [ + { + "blockId": "variables_set", + "count": 1 + } + ] } ] }, @@ -91,9 +109,12 @@ "checks": [ { "validator": "blocksExist", - "blockCounts": { - "variables_get": 1 - } + "blockCounts": [ + { + "blockId": "variables_get", + "count": 1 + } + ] } ] }, @@ -104,39 +125,57 @@ "checks": [ { "validator": "blocksExist", - "blockCounts": { - "argument_reporter_string": 1 - } + "blockCounts": [ + { + "blockId": "argument_reporter_string", + "count": 1 + } + ] }, { "validator": "blocksExist", - "blockCounts": { - "argument_reporter_number": 1 - } + "blockCounts": [ + { + "blockId": "argument_reporter_number", + "count": 1 + } + ] }, { "validator": "blocksExist", - "blockCounts": { - "argument_reporter_boolean": 1 - } + "blockCounts": [ + { + "blockId": "argument_reporter_boolean", + "count": 1 + } + ] }, { "validator": "blocksExist", - "blockCounts": { - "argument_reporter_array": 1 - } + "blockCounts": [ + { + "blockId": "argument_reporter_array", + "count": 1 + } + ] }, { "validator": "blocksExist", - "blockCounts": { - "argument_reporter_custom": 1 - } + "blockCounts": [ + { + "blockId": "argument_reporter_custom", + "count": 1 + } + ] }, { "validator": "blocksExist", - "blockCounts": { - "variables_get_reporter": 1 - } + "blockCounts": [ + { + "blockId": "variables_get_reporter", + "count": 1 + } + ] } ] }, @@ -147,9 +186,12 @@ "checks": [ { "validator": "blocksExist", - "blockCounts": { - "argument_reporter_number": 1 - } + "blockCounts": [ + { + "blockId": "argument_reporter_number", + "count": 1 + } + ] } ] }, @@ -160,9 +202,12 @@ "checks": [ { "validator": "blocksExist", - "blockCounts": { - "variables_set": 1 - }, + "blockCounts": [ + { + "blockId": "variables_set", + "count": 1 + } + ], "childValidatorPlans": ["device_random_used"] } ] @@ -174,9 +219,12 @@ "checks": [ { "validator": "blocksExist", - "blockCounts": { - "device_random": 1 - } + "blockCounts": [ + { + "blockId": "device_random", + "count": 1 + } + ] } ] }, @@ -201,9 +249,12 @@ "checks": [ { "validator": "blocksExist", - "blockCounts": { - "math_number": 2 - } + "blockCounts": [ + { + "blockId": "math_number", + "count": 2 + } + ] } ] }, @@ -214,9 +265,12 @@ "checks": [ { "validator": "blocksExist", - "blockCounts": { - "math_number": 1 - } + "blockCounts": [ + { + "blockId": "math_number", + "count": 1 + } + ] } ] } diff --git a/localtypings/validatorPlan.d.ts b/localtypings/validatorPlan.d.ts index 53d683cfc9f0..86c1ad57334e 100644 --- a/localtypings/validatorPlan.d.ts +++ b/localtypings/validatorPlan.d.ts @@ -16,9 +16,13 @@ declare namespace pxt.blocks { } // Inputs for "Blocks Exist" validation. + export interface BlocksExistCountInfo extends ValidatorCheckBase { + blockId: string; + count: number; + } export interface BlocksExistValidatorCheck extends ValidatorCheckBase { validator: "blocksExist"; - blockCounts: pxt.Map; + blockCounts: BlocksExistCountInfo[]; } export interface BlockCommentsExistValidatorCheck extends ValidatorCheckBase { @@ -46,4 +50,4 @@ declare namespace pxt.blocks { fieldValue: string; blockType: string; } -} \ No newline at end of file +} diff --git a/pxteditor/code-validation/runValidatorPlan.ts b/pxteditor/code-validation/runValidatorPlan.ts index 6d41b5ca288c..441dabdde634 100644 --- a/pxteditor/code-validation/runValidatorPlan.ts +++ b/pxteditor/code-validation/runValidatorPlan.ts @@ -65,7 +65,11 @@ export function runValidatorPlan(usedBlocks: Blockly.Block[], plan: pxt.blocks.V } function runBlocksExistValidation(usedBlocks: Blockly.Block[], inputs: pxt.blocks.BlocksExistValidatorCheck): [Blockly.Block[], boolean] { - const blockResults = validateBlocksExist({ usedBlocks, requiredBlockCounts: inputs.blockCounts }); + const requiredBlockCounts = inputs.blockCounts.reduce((acc, info) => { + acc[info.blockId] = info.count; + return acc; + }, {} as pxt.Map); + const blockResults = validateBlocksExist({ usedBlocks, requiredBlockCounts }); let successfulBlocks: Blockly.Block[] = []; if (blockResults.passed) { const blockIdsFromValidator = Object.keys(inputs.blockCounts) @@ -98,4 +102,4 @@ function runBlockFieldValueExistsValidation(usedBlocks: Blockly.Block[], inputs: specifiedBlock: inputs.blockType }); return [blockResults.successfulBlocks, blockResults.passed]; -} \ No newline at end of file +}