You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by hn...@apache.org on 2024/08/09 08:00:51 UTC
(myfaces-tobago) branch main updated (088701f593 -> 33c59d6bd0)
This is an automated email from the ASF dual-hosted git repository.
hnoeth pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git
from 088701f593 build(deps-dev): bump junit-jupiter.version from 5.10.2 to 5.10.3
new f9773f87ba fix(sheet): selection change
new 33c59d6bd0 build(theme): rebuild after fixing sheet selection change event
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../25-selection/Sheet_Selectionchange.test.js | 55 ++++++++++++++++++++++
.../25-selection/Sheet_Selectionchange.xhtml | 7 +--
.../tobago-theme-standard/src/main/js/tobago.js | 2 +-
.../src/main/js/tobago.js.map | 2 +-
.../src/main/ts/tobago-sheet.ts | 25 +++++-----
5 files changed, 72 insertions(+), 19 deletions(-)
create mode 100644 tobago-example/tobago-example-demo/src/main/webapp/content/080-sheet/25-selection/Sheet_Selectionchange.test.js
(myfaces-tobago) 01/02: fix(sheet): selection change
Posted by hn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
hnoeth pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git
commit f9773f87baf243349983ca05e3c8da9afac730dd
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Fri Aug 9 09:17:05 2024 +0200
fix(sheet): selection change
Add test for selection change event.
This got broken after: fix(columnSelector): columnPanel/sheet-in-sheet(1c7c3a152cb1c0a488cf15d198f8619e6fbc8394)
---
.../25-selection/Sheet_Selectionchange.test.js | 55 ++++++++++++++++++++++
.../25-selection/Sheet_Selectionchange.xhtml | 7 +--
.../src/main/ts/tobago-sheet.ts | 25 +++++-----
3 files changed, 70 insertions(+), 17 deletions(-)
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/080-sheet/25-selection/Sheet_Selectionchange.test.js b/tobago-example/tobago-example-demo/src/main/webapp/content/080-sheet/25-selection/Sheet_Selectionchange.test.js
new file mode 100644
index 0000000000..1b400a32a5
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/080-sheet/25-selection/Sheet_Selectionchange.test.js
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import {elementByIdFn, querySelectorFn} from "/script/tobago-test.js";
+import {JasmineTestTool} from "/tobago/test/tobago-test-tool.js";
+
+it("select 'Sun', select 'Venus', select all, deselect 'Mercury'", function (done) {
+ const selectedRows = querySelectorFn("#page\\:mainForm\\:selectedRows .form-control-plaintext");
+ const resetSelected = elementByIdFn("page:mainForm:resetSelected");
+ const hiddenSelectedField = elementByIdFn("page:mainForm:sheet::selected");
+ const selectAllCheckbox = querySelectorFn("input[name='page:mainForm:sheet::columnSelector']");
+ const sun = querySelectorFn("tr[row-index='0']");
+ const mercury = querySelectorFn("tr[row-index='1']");
+ const venus = querySelectorFn("tr[row-index='2']");
+ const earth = querySelectorFn("tr[row-index='3']");
+ const firstPageButton = elementByIdFn("page:mainForm:sheet:pageActionfirst");
+
+ const test = new JasmineTestTool(done);
+ test.setup(() => hiddenSelectedField().value === "[]", null, "click", resetSelected);
+ test.setup(() => firstPageButton().disabled, null, "click", firstPageButton);
+
+ test.do(() => expect(selectAllCheckbox().getAttribute("type")).toBe("checkbox"));
+ test.do(() => expect(selectAllCheckbox().checked).toBe(false));
+
+ test.event("click", sun, () => selectedRows().textContent === "0");
+ test.do(() => expect(selectedRows().textContent).toBe("0"));
+ test.do(() => expect(selectAllCheckbox().checked).toBe(false));
+
+ test.event("click", venus, () => selectedRows().textContent === "0, 2");
+ test.do(() => expect(selectedRows().textContent).toBe("0, 2"));
+ test.do(() => expect(selectAllCheckbox().checked).toBe(false));
+
+ test.event("click", selectAllCheckbox, () => selectedRows().textContent === "0, 2, 1, 3");
+ test.do(() => expect(selectedRows().textContent).toBe("0, 2, 1, 3"));
+ test.do(() => expect(selectAllCheckbox().checked).toBe(true));
+
+ test.event("click", mercury, () => selectedRows().textContent === "0, 2, 3");
+ test.do(() => expect(selectedRows().textContent).toBe("0, 2, 3"));
+ test.do(() => expect(selectAllCheckbox().checked).toBe(false));
+ test.start();
+});
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/080-sheet/25-selection/Sheet_Selectionchange.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/080-sheet/25-selection/Sheet_Selectionchange.xhtml
index c5ea7b5eb2..1495715b70 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/080-sheet/25-selection/Sheet_Selectionchange.xhtml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/080-sheet/25-selection/Sheet_Selectionchange.xhtml
@@ -24,11 +24,12 @@
xmlns:ui="jakarta.faces.facelets">
<tc:panel id="panel">
- <tc:out label="Timestamp" value="#{eventController.currentTimestamp}"/>
- <tc:out label="selectedRows" value="#{sheetController.selectedRows}"/>
+ <tc:out id="timestamp" label="Timestamp" value="#{eventController.currentTimestamp}"/>
+ <tc:out id="selectedRows" label="selectedRows" value="#{sheetController.selectedRows}"/>
+ <tc:button id="resetSelected" label="Reset selected" action="#{sheetController.sheetState.resetSelected()}"/>
</tc:panel>
- <tc:sheet id="s1" value="#{sheetController.solarList}" var="object" rows="4" state="#{sheetController.sheetState}">
+ <tc:sheet id="sheet" value="#{sheetController.solarList}" var="object" rows="4" state="#{sheetController.sheetState}">
<tc:style maxHeight="500px"/>
<f:ajax event="tobago.sheet.rowSelectionChange" render="::panel"/>
<tc:columnSelector/>
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-sheet.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-sheet.ts
index 9e389a6e90..bec6910805 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-sheet.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-sheet.ts
@@ -277,7 +277,18 @@ export class Sheet extends HTMLElement {
}
set selected(value: Set<number>) {
+ const oldSelectedSet = this.selected;
this.hiddenInputSelected.value = JSON.stringify(Array.from(value));
+
+ const fireSelectionChangeEvent = oldSelectedSet.size !== value.size
+ || ![...oldSelectedSet].every((x) => value.has(x));
+ if (fireSelectionChangeEvent) {
+ this.dispatchEvent(new CustomEvent(ClientBehaviors.ROW_SELECTION_CHANGE, {
+ detail: {
+ selection: value,
+ },
+ }));
+ }
}
private get hiddenInputSelected(): HTMLInputElement {
@@ -771,7 +782,6 @@ Type: ${data.type}`);
}
this.lastClickedRowIndex = rowIndex;
- this.fireSelectionChange(this.selected, selected);
this.selected = selected;
});
}
@@ -811,7 +821,6 @@ Type: ${data.type}`);
}
}
- this.fireSelectionChange(this.selected, selected);
this.selected = selected;
}
@@ -853,18 +862,6 @@ Type: ${data.type}`);
}
}
- private fireSelectionChange(oldSelectedSet: Set<number>, newSelectedSet: Set<number>) {
- const fireEvent = (oldSelectedSet, newSelectedSet) =>
- oldSelectedSet.size == newSelectedSet.size && [...oldSelectedSet].every((x) => newSelectedSet.has(x));
- if (fireEvent) {
- this.dispatchEvent(new CustomEvent(ClientBehaviors.ROW_SELECTION_CHANGE, {
- detail: {
- selection: newSelectedSet,
- },
- }));
- }
- }
-
clickOnPaging(event: MouseEvent): void {
const element = event.currentTarget as HTMLElement;
(myfaces-tobago) 02/02: build(theme): rebuild after fixing sheet selection change event
Posted by hn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
hnoeth pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git
commit 33c59d6bd00d0838f128ea036154605385f18bd4
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Fri Aug 9 09:48:03 2024 +0200
build(theme): rebuild after fixing sheet selection change event
---
tobago-theme/tobago-theme-standard/src/main/js/tobago.js | 2 +-
tobago-theme/tobago-theme-standard/src/main/js/tobago.js.map | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/tobago-theme/tobago-theme-standard/src/main/js/tobago.js b/tobago-theme/tobago-theme-standard/src/main/js/tobago.js
index c84c41d00d..d7ecb1e11d 100644
--- a/tobago-theme/tobago-theme-standard/src/main/js/tobago.js
+++ b/tobago-theme/tobago-theme-standard/src/main/js/tobago.js
@@ -15,5 +15,5 @@ const Me=new Map,Pe={set(e,t,s){Me.has(e)||Me.set(e,new Map);const i=Me.get(e);i
${s>0?" tabindex='"+String(s)+"'":""}
@click="${this.removeBadge.bind(this)}"
@focus="${this.focusEvent.bind(this)}"
- @blur="${this.blurEvent.bind(this)}"><i class='bi-x-lg'></i></button>`}removeBadge(e){var t;const s=e.target.closest(".btn-group").dataset.tobagoValue,i=this.hiddenSelect.querySelector(`[value="${s}"]`);i.selected=!1;const n=this.badges.querySelector(`[data-tobago-value="${s}"]`),o=n.previousElementSibling,r="SPAN"===(null===(t=n.nextElementSibling)||void 0===t?void 0:t.tagName)?n.nextElementSibling:null;o?o.querySelector("button.btn.badge").focus():r?r.querySelector("button.btn.ba [...]
+ @blur="${this.blurEvent.bind(this)}"><i class='bi-x-lg'></i></button>`}removeBadge(e){var t;const s=e.target.closest(".btn-group").dataset.tobagoValue,i=this.hiddenSelect.querySelector(`[value="${s}"]`);i.selected=!1;const n=this.badges.querySelector(`[data-tobago-value="${s}"]`),o=n.previousElementSibling,r="SPAN"===(null===(t=n.nextElementSibling)||void 0===t?void 0:t.tagName)?n.nextElementSibling:null;o?o.querySelector("button.btn.badge").focus():r?r.querySelector("button.btn.ba [...]
//# sourceMappingURL=tobago.js.map
diff --git a/tobago-theme/tobago-theme-standard/src/main/js/tobago.js.map b/tobago-theme/tobago-theme-standard/src/main/js/tobago.js.map
index ed70106c76..ceebb4e67b 100644
--- a/tobago-theme/tobago-theme-standard/src/main/js/tobago.js.map
+++ b/tobago-theme/tobago-theme-standard/src/main/js/tobago.js.map
@@ -1 +1 @@
-{"version":3,"file":"tobago.js","sources":["../ts/tobago-css.ts","../ts/tobago-collapse-operation.ts","../ts/tobago-bar.ts","../../../../node_modules/@popperjs/core/lib/enums.js","../../../../node_modules/@popperjs/core/lib/dom-utils/getNodeName.js","../../../../node_modules/@popperjs/core/lib/dom-utils/getWindow.js","../../../../node_modules/@popperjs/core/lib/dom-utils/instanceOf.js","../../../../node_modules/@popperjs/core/lib/modifiers/applyStyles.js","../../../../node_modules/@poppe [...]
\ No newline at end of file
+{"version":3,"file":"tobago.js","sources":["../ts/tobago-css.ts","../ts/tobago-collapse-operation.ts","../ts/tobago-bar.ts","../../../../node_modules/@popperjs/core/lib/enums.js","../../../../node_modules/@popperjs/core/lib/dom-utils/getNodeName.js","../../../../node_modules/@popperjs/core/lib/dom-utils/getWindow.js","../../../../node_modules/@popperjs/core/lib/dom-utils/instanceOf.js","../../../../node_modules/@popperjs/core/lib/modifiers/applyStyles.js","../../../../node_modules/@poppe [...]
\ No newline at end of file