@processmaker/screen-builder 3.8.22 → 3.8.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@processmaker/screen-builder",
3
- "version": "3.8.22",
3
+ "version": "3.8.23",
4
4
  "scripts": {
5
5
  "dev": "VITE_COVERAGE=true vite",
6
6
  "build": "vite build",
@@ -739,6 +739,83 @@ export default {
739
739
  });
740
740
  //sets Collection result(columns and rows) into this.collectionData
741
741
  this.collectionData = result;
742
+ this.reapplyCollectionSelections(result);
743
+ },
744
+ // Keep selected rows in sync after collection refreshes triggered by PMQL filters.
745
+ reapplyCollectionSelections(newCollection) {
746
+ if (!this.shouldPersistCollectionSelection()) {
747
+ return;
748
+ }
749
+
750
+ if (!Array.isArray(this.selectedRows) || this.selectedRows.length === 0) {
751
+ return;
752
+ }
753
+
754
+ const keyCounts = this.selectedRows.reduce((accumulator, item) => {
755
+ const key = this.getCollectionRowKey(item);
756
+ if (!key) {
757
+ return accumulator;
758
+ }
759
+ const occurrences = accumulator.get(key) || 0;
760
+ accumulator.set(key, occurrences + 1);
761
+ return accumulator;
762
+ }, new Map());
763
+
764
+ if (keyCounts.size === 0) {
765
+ this.selectedRows = [];
766
+ return;
767
+ }
768
+
769
+ const updatedSelection = [];
770
+
771
+ newCollection.forEach((row, index) => {
772
+ const rowKey = this.getCollectionRowKey(row);
773
+ const occurrences = keyCounts.get(rowKey);
774
+ if (!occurrences) {
775
+ return;
776
+ }
777
+
778
+ // eslint-disable-next-line no-param-reassign
779
+ row.selectedRowsIndex = index;
780
+ updatedSelection.push(row);
781
+
782
+ if (occurrences === 1) {
783
+ keyCounts.delete(rowKey);
784
+ } else {
785
+ keyCounts.set(rowKey, occurrences - 1);
786
+ }
787
+ });
788
+
789
+ this.selectedRows = updatedSelection;
790
+ },
791
+ shouldPersistCollectionSelection() {
792
+ const pmql = this.source?.collectionFields?.pmql;
793
+ return (
794
+ this.source?.sourceOptions === "Collection" &&
795
+ this.source?.dataSelectionOptions === "multiple-records" &&
796
+ typeof pmql === "string" &&
797
+ pmql.trim().length > 0
798
+ );
799
+ },
800
+ getCollectionRowKey(item) {
801
+ if (!item || typeof item !== "object") {
802
+ return null;
803
+ }
804
+
805
+ const entries = Object.entries(item).filter(
806
+ ([key]) => key !== "selectedRowsIndex"
807
+ );
808
+
809
+ if (entries.length === 0) {
810
+ return null;
811
+ }
812
+
813
+ entries.sort(([keyA], [keyB]) => {
814
+ if (keyA > keyB) return 1;
815
+ if (keyA < keyB) return -1;
816
+ return 0;
817
+ });
818
+ return JSON.stringify(entries);
742
819
  },
743
820
  updateRowDataNamePrefix() {
744
821
  this.setUploadDataNamePrefix(this.currentRowIndex);
@@ -831,6 +831,12 @@ export default {
831
831
  * @param {Object} data - The event data received from the socket listener.
832
832
  */
833
833
  handleProcessUpdate(data) {
834
+ if (!this.task) {
835
+ // reload the task if it is not found
836
+ this.reload();
837
+ return;
838
+ }
839
+
834
840
  const { event, elementDestination, tokenId } = data;
835
841
 
836
842
  // If the activity is completed and there is an element destination, set the element destination to the task