Skip to content

Commit

Permalink
Merge branch 'v2' into v2-develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mguellsegarra committed Sep 6, 2024
2 parents 5824f14 + a6547a0 commit c299b6c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gisce/ooui",
"version": "2.9.2",
"version": "2.10.0",
"engines": {
"node": "20.5.0"
},
Expand Down
12 changes: 11 additions & 1 deletion src/ButtonGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ class ButtonGroup extends ContainerWidget {
return btn || this.buttons[0];
}

get colspan(): number {
return this.defaultButton?.colspan || 1;
}

set colspan(value: number) {
if (this.defaultButton) {
this.defaultButton.colspan = value;
}
}

get secondaryButtons(): Button[] {
const btns = this.buttons.filter(
(button) => button.id !== this.defaultButton?.id,
Expand All @@ -20,7 +30,7 @@ class ButtonGroup extends ContainerWidget {
}

get buttons(): Button[] {
return this._container.rows[0].filter((b) => !b.invisible) as Button[];
return this._container.rows.flat().filter((b) => !b.invisible) as Button[];
}

constructor(props: any) {
Expand Down
8 changes: 8 additions & 0 deletions src/spec/ButtonGroup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe("A ButtonsGroup widget", () => {
type: "object",
icon: "gtk-execute",
string: "Button 1",
colspan: 4,
});
const btn2 = new Button({
name: "btn2",
Expand Down Expand Up @@ -53,6 +54,13 @@ describe("A ButtonsGroup widget", () => {
expect(buttonGroup.secondaryButtons[0].id).toBe("btn2");
expect(buttonGroup.secondaryButtons[1].id).toBe("btn3");
});
it("should have the same colspan as the default button", () => {
expect(buttonGroup.colspan).toBe(4);
});
it("should set the same colspan to the default button", () => {
buttonGroup.colspan = 2;
expect(buttonGroup.defaultButton?.colspan).toBe(2);
});
});
describe("Working with invisible buttons", () => {
it("Only should return visible buttons", () => {
Expand Down
20 changes: 20 additions & 0 deletions src/spec/Form.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,26 @@ describe("A Form", () => {
expect(button).toBeInstanceOf(Button);
});
});
it("should be able to parse a ButtonGroup with colspan", () => {
const fields = {};
const xmlViewForm = `<?xml version="1.0"?>
<form string="Form1">
<buttonGroup name="aButtonGroup" default="main">
<button name="main" type="object" string="Main action" colspan="4" />
<button name="secondary" type="object" string="Secondary action" />
</buttonGroup>
</form>`;
const form = new Form(fields);
form.parse(xmlViewForm);

const buttonGroup = form.container.rows[0][0] as ButtonGroup;
expect(buttonGroup).toBeInstanceOf(ButtonGroup);
expect(buttonGroup.buttons).toHaveLength(2);
buttonGroup.buttons.forEach((button) => {
expect(button).toBeInstanceOf(Button);
});
expect(buttonGroup.colspan).toBe(4);
});
});

it("should be able to parse a Button by default to type workflow", () => {
Expand Down

0 comments on commit c299b6c

Please sign in to comment.