pxt icon indicating copy to clipboard operation
pxt copied to clipboard

groups attribute is not properly processed

Open FranklinWhale opened this issue 5 years ago • 4 comments

Describe the bug

According to https://makecode.com/defining-blocks#category,

To define your groups, add the groups attribute to your namespace. The groups attribute is an array of group names.

The order in which you define your groups is the order in which the groups will appear in the toolbox flyout

, and it has a sample syntax of the groups attribute:

//% groups=['LED matrix', 'Control flow', 'others']

Unfortunately, that does work.

On https://makecode.com/playground#basic-groups, another syntax is shown:

//% groups="['Fruits', 'Veggies']"

Sadly, that does not work either.

The only syntax that appears to work is as follows:

//% groups='["Fruits", "Veggies"]'

I think either the above samples should amended, or the parser should support all of them.

To Reproduce

  1. Go to https://makecode.com/playground#basic-groups
  2. Click "Run"
  3. Replace //% groups="['Fruits', 'Veggies']" with //% groups=['Fruits', 'Veggies']
  4. Click "Run"
  5. Replace //% groups=['Fruits', 'Veggies'] with //% groups=["Fruits", "Veggies"]
  6. Click "Run"
  7. Replace //% groups=["Fruits", "Veggies"] with //% groups='["Fruits", "Veggies"]'
  8. Click "Run"

Actual behavior After Step 2, 4 and 6: image

After Step 8: image

FranklinWhale avatar Jun 29 '20 06:06 FranklinWhale

@ganicke looks like a docs issue.

pelikhan avatar Nov 10 '20 11:11 pelikhan

@pelikhan - It seems that the first member of the namespace with its group attribute set determines the display order in the Toolbox and not the order set for groups. The playground example below will cause the Fruits group to display first despite the order of groups.

/**
 * Organize your blocks in groups
 */
//% color="#AA278D"
//% groups="['Veggies', 'Fruits']"
namespace food {
    //% block
    //% group="Fruits"
    export function apple() {

    }
    //% block
    //% group="Veggies"
    export function potato() {

    }
    //% block
    //% group="Fruits"
    export function banana() {

    }
    //% block
    //% group="Veggies"
    export function bean() {

    }
}

ganicke avatar Nov 10 '20 20:11 ganicke

@ganicke I think the groups attribute is working, if it is specified in the correct format. The code below should work:

/**
 * Organize your blocks in groups
 */
//% color="#AA278D"
//% groups='["Veggies", "Fruits"]'
namespace food {
    //% block
    //% group="Fruits"
    export function apple() {

    }
    //% block
    //% group="Veggies"
    export function potato() {

    }
    //% block
    //% group="Fruits"
    export function banana() {

    }
    //% block
    //% group="Veggies"
    export function bean() {

    }
}

FranklinWhale avatar Nov 17 '20 07:11 FranklinWhale

This is just nuts and are we sure if those are a fruit or veggie?

ganicke avatar Nov 17 '20 23:11 ganicke