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

🐛 [Frontend] Fix: Selected Pricing Unit bgColor #6646

Merged
merged 5 commits into from
Nov 1, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,30 +64,16 @@ qx.Class.define("osparc.service.PricingUnitsList", {
__populateList: function(pricingUnits) {
this.getChildControl("pricing-units-container").removeAll();

if (pricingUnits.length === 0) {
if (pricingUnits.length) {
const pUnits = new osparc.study.PricingUnits(pricingUnits, null, false);
this.getChildControl("pricing-units-container").add(pUnits);
} else {
const notFound = new qx.ui.basic.Label().set({
value: this.tr("No Tiers found"),
font: "text-14"
});
this.getChildControl("pricing-units-container").add(notFound);
return;
}

pricingUnits.forEach(pricingUnit => {
const pUnit = new osparc.study.PricingUnit(pricingUnit).set({
allowGrowY: false
});
this.getChildControl("pricing-units-container").add(pUnit);
});

const buttons = this.getChildControl("pricing-units-container").getChildren();
const keepDefaultSelected = () => {
buttons.forEach(btn => {
btn.setValue(btn.getUnitData().isDefault());
});
};
keepDefaultSelected();
buttons.forEach(btn => btn.addListener("execute", () => keepDefaultSelected()));
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
qx.Class.define("osparc.study.PricingUnits", {
extend: qx.ui.container.Composite,

construct: function(pricingUnits, preselectedPricingUnit) {
construct: function(pricingUnits, preselectedPricingUnit, changeSelectionAllowed = true) {
this.base(arguments);

this.set({
layout: new qx.ui.layout.HBox(5)
layout: new qx.ui.layout.HBox(5),
allowGrowY: false,
});

this.__buildLayout(pricingUnits, preselectedPricingUnit);
this.__buildLayout(pricingUnits, preselectedPricingUnit, changeSelectionAllowed);
},

properties: {
Expand All @@ -38,7 +39,7 @@ qx.Class.define("osparc.study.PricingUnits", {
},

members: {
__buildLayout: function(pricingUnits, preselectedPricingUnit) {
__buildLayout: function(pricingUnits, preselectedPricingUnit, changeSelectionAllowed) {
const buttons = [];
pricingUnits.forEach(pricingUnit => {
const button = new osparc.study.PricingUnit(pricingUnit);
Expand All @@ -47,7 +48,12 @@ qx.Class.define("osparc.study.PricingUnits", {
});

const groupOptions = new qx.ui.form.RadioGroup();
buttons.forEach(btn => groupOptions.add(btn));
buttons.forEach(btn => {
groupOptions.add(btn);
btn.bind("value", btn, "backgroundColor", {
converter: selected => selected ? "background-main-1" : "transparent"
});
});

if (preselectedPricingUnit) {
const buttonFound = buttons.find(button => button.getUnitData().getPricingUnitId() === preselectedPricingUnit["pricingUnitId"]);
Expand All @@ -63,12 +69,19 @@ qx.Class.define("osparc.study.PricingUnits", {
});
}

buttons.forEach(button => button.addListener("changeValue", e => {
if (e.getData()) {
const selectedUnitId = button.getUnitData().getPricingUnitId();
this.setSelectedUnitId(selectedUnitId);
buttons.forEach(button => {
if (!changeSelectionAllowed) {
button.setCursor("default");
}
}));
button.addListener("execute", () => {
if (changeSelectionAllowed) {
const selectedUnitId = button.getUnitData().getPricingUnitId();
this.setSelectedUnitId(selectedUnitId);
} else {
buttons.forEach(btn => btn.setValue(btn.getUnitData().isDefault()));
}
});
});
}
}
});
Loading