@processmaker/screen-builder 3.8.25 → 3.8.27

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.25",
3
+ "version": "3.8.27",
4
4
  "scripts": {
5
5
  "dev": "VITE_COVERAGE=true vite",
6
6
  "build": "vite build",
@@ -341,6 +341,9 @@ export default {
341
341
  },
342
342
  ],
343
343
  valueTypeReturned: '',
344
+ assetType: null,
345
+ assetTypeResolved: false,
346
+ screenId: null,
344
347
  };
345
348
  },
346
349
  watch: {
@@ -504,9 +507,37 @@ export default {
504
507
  monacoMounted(editor) {
505
508
  editor.getAction('editor.action.formatDocument').run();
506
509
  },
507
- getDataSourceList() {
510
+ resolveAssetType() {
511
+ if (this.assetTypeResolved) {
512
+ return Promise.resolve(this.assetType);
513
+ }
514
+ const match = window.location.pathname.match(/screen-builder\/(\d+)\/edit/);
515
+ if (!match) {
516
+ this.assetTypeResolved = true;
517
+ return Promise.resolve(this.assetType);
518
+ }
519
+ this.screenId = match[1];
520
+ return this.$dataProvider
521
+ .get(`/screens/${this.screenId}`)
522
+ .then(response => {
523
+ this.assetType = response.data.asset_type || null;
524
+ this.assetTypeResolved = true;
525
+ return this.assetType;
526
+ })
527
+ .catch(() => {
528
+ this.assetTypeResolved = true;
529
+ return this.assetType;
530
+ });
531
+ },
532
+ async getDataSourceList() {
533
+ await this.resolveAssetType();
534
+ const params = {};
535
+ if (this.assetType) {
536
+ // For PM Block screens, expose both regular and PM Block connectors.
537
+ params.asset_type = this.assetType === 'PM_BLOCK' ? 'all' : this.assetType;
538
+ }
508
539
  this.$dataProvider
509
- .get('/data_sources')
540
+ .get('/data_sources', { params })
510
541
  .then(response => {
511
542
  let jsonData = response.data.data;
512
543
  // Map the data sources response to value/text items list
@@ -912,43 +912,53 @@ export default {
912
912
  * @param {Object} data - The event data containing the tokenId of the task.
913
913
  */
914
914
  async handleRedirectToTask(data) {
915
- if (
916
- (data?.params[0]?.tokenId &&
917
- this.task.user?.id === data.params[0]?.userId) ||
918
- this.task.elementDestination?.type === 'taskSource' ||
919
- (data.params[0]?.userId === null && data.params[0]?.userCanClaim === true)
920
- ) {
921
- this.loadingTask = true;
922
- // Check if interstitial tasks are allowed for this task.
923
- if (this.task && !(this.task.allow_interstitial || this.isSameUser(this.task, data))) {
924
- // The getDestinationUrl() function is called asynchronously to retrieve the URL
925
- window.location.href = await this.getDestinationUrl();
926
- return;
927
- }
928
- this.nodeId = data.params[0].nodeId;
929
- this.taskId = data.params[0].tokenId;
930
-
931
- // Force a redirect to ensure the correct task is loaded immediately for ConversationalForm.
932
- // This prevents async reloads that may cause inconsistencies specific to ConversationalForm.
933
- if (this.renderComponent === "ConversationalForm") {
934
- window.location.href = `/tasks/${this.taskId}/edit`;
915
+ const tokenId = data?.params[0]?.tokenId;
916
+ const newTaskUserId = data?.params[0]?.userId; // User assigned to the new task (from the backend)
917
+ const nodeId = data?.params[0]?.nodeId;
918
+ // Current user: prop > window.ProcessMaker.user > task assignee (when viewing assigned task)
919
+ const currentUserId = this.userId ?? window.ProcessMaker?.user?.id ?? this.task?.user?.id;
920
+ const elementDestType = this.task?.elementDestination?.type;
921
+ const userCanClaim = data?.params?.[0]?.userCanClaim;
922
+ // Redirect if the new task is assigned to the current user, or if it is taskSource
923
+ const isNewTaskForCurrentUser = tokenId && (newTaskUserId === currentUserId || (newTaskUserId == null && (elementDestType === 'displayNextAssignedTask' || elementDestType === 'taskSource')));
924
+ const isTaskSource = elementDestType === 'taskSource';
925
+ // Redirect when task is unclaimed and user can claim it (pool tasks)
926
+ const isUnclaimedAndClaimable = newTaskUserId === null && userCanClaim === true;
927
+ const shouldHandle = isNewTaskForCurrentUser || isTaskSource || isUnclaimedAndClaimable;
928
+
929
+ if (shouldHandle) {
930
+ this.loadingTask = true;
931
+ // Check if interstitial tasks are allowed for this task.
932
+ if (this.task && !(this.task.allow_interstitial || this.isSameUser(data))) {
933
+ window.location.href = await this.getDestinationUrl();
934
+ return;
935
+ }
936
+ this.nodeId = nodeId;
937
+ this.taskId = tokenId;
938
+
939
+ // Force a redirect to ensure the correct task is loaded immediately for ConversationalForm.
940
+ if (this.renderComponent === "ConversationalForm") {
941
+ window.location.href = `/tasks/${this.taskId}/edit`;
942
+ }
943
+
944
+ this.reload();
935
945
  }
936
-
937
- this.reload();
938
- }
939
946
  },
940
947
 
941
948
  /**
942
- * Checks if the current task and the redirect data belong to the same user.
943
- * and the destination is taskSource.
949
+ * Checks if the redirect applies to the current user.
950
+ * - userId of event = user assigned to the new task
951
+ * - It is considered a match if: new task assigned to the current user, or taskSource/displayNextAssignedTask with user null
944
952
  *
945
- * @param {Object} currentTask - The current task object.
946
953
  * @param {Object} redirectData - The redirect data object.
947
954
  */
948
- isSameUser(currentTask, redirectData) {
949
- const userIdMatch = currentTask.user?.id === redirectData.params[0].userId;
950
- const typeMatch = currentTask.elementDestination?.type === null
951
- || currentTask.elementDestination?.type === 'taskSource';
955
+ isSameUser(redirectData) {
956
+ const newTaskUserId = redirectData?.params?.[0]?.userId;
957
+ const currentUserId = this.userId ?? window.ProcessMaker?.user?.id ?? this.task?.user?.id;
958
+ const elementDestType = this.task?.elementDestination?.type;
959
+ const userIdMatch = newTaskUserId === currentUserId
960
+ || (newTaskUserId == null && (elementDestType === 'displayNextAssignedTask' || elementDestType === 'taskSource'));
961
+ const typeMatch = elementDestType === null || elementDestType === 'taskSource' || elementDestType === 'displayNextAssignedTask';
952
962
 
953
963
  return userIdMatch && typeMatch;
954
964
  },