-
Notifications
You must be signed in to change notification settings - Fork 588
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
allow packages to filter the toolbox #10291
base: master
Are you sure you want to change the base?
Conversation
also, not sure where to document this. maybe here? i'm not sure if anyone reads that page though |
What does the extension author need to do to filter the toolbox? Can you share a sample extension which does this? |
@abchatra it's exactly the same as how you do it for a project! simply add the "toolboxFilter" object in the extension's pxt.json. here's a project that does it: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small nit and a learning question. Looks good!
|
||
const deps = mainPkg.sortedDeps(); | ||
// sort the dependencies by level and then id. lower level overrides | ||
// higher level |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can we have the "lower level overrides higher level" on a line together?
return b.level - a.level; | ||
}); | ||
|
||
const applyProjectFilter = (projectFilter: pxt.PackageConfig["toolboxFilter"], key: keyof pxt.PackageConfig["toolboxFilter"]) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just wanted to ask about this because I don't think I've seen keyof
being used before. I looked at the documentation, but just wanted some clarification.
So using keyof
here is basically saying, "hey, the type we are expecting has to be the keys defined within this object. If the string (in our case) or type does not exist within this object, we can't accept that parameter". And the benefit of using something like this is that we can use the object itself as a growing type definition if we ever have any fields that we want to add to the toolboxFilter
object rather than having to create a separate type definition.
if (filters.blocks[blockId] !== undefined) { | ||
blockFilter = filters.blocks[blockId]; | ||
} | ||
else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this change! This is much more readable!
this adds the ability for projects and extensions to filter the toolbox. inspired by https://forum.makecode.com/t/creating-micro-bit-sandbox-restrict-available-blocks/32008
an extension or project can add a "toolboxFilter" entry in
pxt.json
like so:the possible values for each block or category are "hidden", "visible", and "disabled", though i don't think disabled actually does anything? i'm just matching the values we have available in our current toolbox filtering for tutorials and afaik disabled is just ignored.
toolbox filters are merged starting with the leaf extensions in the dependency tree and moving upwards to the main package. in other words, the top-level project overrides its dependencies, which override their dependencies, etc.
these filters can all be overridden by the filters that exist today. e.g., tutorial blocks filters will always trump project blocks filters.