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

Pull hw options from target config #9696

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions localtypings/pxtarget.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ declare namespace pxt {
// localized galleries
localizedGalleries?: pxt.Map<pxt.Map<string>>;
windowsStoreLink?: string;
// localized options on download dialog; name, description, url, imageUrl, variant used.
hardwareOptions?: CodeCard[];
// release manifest for the electron app
electronManifest?: pxt.electron.ElectronManifest;
profileNotification?: ProfileNotification;
Expand Down
38 changes: 13 additions & 25 deletions webapp/src/projects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1642,20 +1642,6 @@ export class ChooseHwDialog extends data.Component<ISettingsProps, ChooseHwDialo
this.setState({ visible: true, skipDownload: !!skipDownload });
}

fetchGallery(): pxt.CodeCard[] {
const path = "/hardware";
let res = this.getData(`gallery:${encodeURIComponent(path)}`) as pxt.gallery.Gallery[];
if (res) {
if (res instanceof Error) {
// ignore
} else {
this.prevGalleries = pxt.Util.concat(res.map(g => g.cards))
.filter(c => !!c.variant);
}
}
return this.prevGalleries || [];
}

private setHwVariant(cfg: pxt.PackageConfig, card: pxt.CodeCard) {
pxt.tickEvent("projects.choosehwvariant", {
hwid: cfg.name,
Expand All @@ -1682,17 +1668,19 @@ export class ChooseHwDialog extends data.Component<ISettingsProps, ChooseHwDialo
const savedV = v
v.card.onClick = () => this.setHwVariant(savedV, null)
}
let cards = this.fetchGallery();
for (const card of cards) {
const savedV = variants.find(variant => variant.name == card.variant);
const savedCard = card;
if (savedV)
card.onClick = () => this.setHwVariant(savedV, savedCard);
else {
pxt.reportError("hw", "invalid variant");

const targetConfig = this.getData("target-config:") as pxt.TargetConfig;
const cards = targetConfig?.hardwareOptions?.map(el => {
const displayCard = { ...el };
const matchingVariant = variants.find(variant => variant.name === displayCard.variant);
if (!matchingVariant) {
// Variant may be experimental hw, ignore this option
return undefined;
}
}
cards = cards.filter(card => !!card.onClick);

displayCard.onClick = () => this.setHwVariant(matchingVariant, displayCard);
return displayCard;
}).filter(el => !!el);

return (
<sui.Modal isOpen={visible} className="hardwaredialog" size="large"
Expand All @@ -1702,7 +1690,7 @@ export class ChooseHwDialog extends data.Component<ISettingsProps, ChooseHwDialo
>
<div className="group">
<div className="ui cards centered" role="listbox">
{cards.map(card =>
{cards?.map(card =>
<codecard.CodeCardView
key={'card' + card.name}
name={card.name}
Expand Down
Loading