@nocobase/plugin-flow-engine 2.1.0-alpha.29 → 2.1.0-alpha.30

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.
@@ -165,6 +165,7 @@ const FILTER_TARGET_BLOCK_USES = /* @__PURE__ */ new Set([
165
165
  ]);
166
166
  const TREE_CONNECT_TARGET_BLOCK_USES = new Set(FILTER_TARGET_BLOCK_USES);
167
167
  const EDITABLE_FIELD_WRAPPER_USES = /* @__PURE__ */ new Set(["FormItemModel", "FilterFormItemModel", "PatternFormItemModel"]);
168
+ const REQUIRED_COLLECTION_FIELD_FORM_WRAPPER_USES = /* @__PURE__ */ new Set(["FormItemModel", "PatternFormItemModel"]);
168
169
  const DISPLAY_FIELD_WRAPPER_USES = /* @__PURE__ */ new Set([
169
170
  "DetailsItemModel",
170
171
  "TableColumnModel",
@@ -1418,11 +1419,24 @@ class FlowSurfacesService {
1418
1419
  filterByTk,
1419
1420
  associationName,
1420
1421
  sourceId,
1422
+ sourceIdInferred: !(0, import_service_helpers.hasConfiguredFlowContextValue)(openView == null ? void 0 : openView.sourceId) && (0, import_service_helpers.hasConfiguredFlowContextValue)(sourceId) && this.isSameConfiguredFlowContextValue(sourceId, "{{ctx.view.inputArgs.sourceId}}"),
1421
1423
  hasCurrentRecord,
1422
1424
  hasAssociationContext,
1423
1425
  scene
1424
1426
  };
1425
1427
  }
1428
+ resolvePopupCurrentRecordResourceFilterByTk(popupProfile, options = {}) {
1429
+ if (!(popupProfile == null ? void 0 : popupProfile.currentCollection)) {
1430
+ return popupProfile == null ? void 0 : popupProfile.filterByTk;
1431
+ }
1432
+ if (popupProfile.popupKind !== "associationPopup") {
1433
+ return popupProfile.filterByTk;
1434
+ }
1435
+ if (options.usePopupInputArgsWhenSourceIdInferred && popupProfile.sourceIdInferred && popupProfile.popupHostUse && POPUP_ACTION_USES.has(popupProfile.popupHostUse)) {
1436
+ return "{{ctx.view.inputArgs.filterByTk}}";
1437
+ }
1438
+ return `{{ctx.record.${this.getCollectionFilterTargetKey(popupProfile.currentCollection)}}}`;
1439
+ }
1426
1440
  resolvePopupAssociationFields(popupProfile, blockUse) {
1427
1441
  var _a;
1428
1442
  if (!popupProfile.currentCollection || !popupProfile.hasCurrentRecord) {
@@ -1662,7 +1676,9 @@ class FlowSurfacesService {
1662
1676
  return (0, import_service_utils.buildDefinedPayload)({
1663
1677
  dataSourceKey: input.popupProfile.dataSourceKey || "main",
1664
1678
  collectionName: input.popupProfile.collectionName,
1665
- filterByTk: input.popupProfile.filterByTk,
1679
+ filterByTk: this.resolvePopupCurrentRecordResourceFilterByTk(input.popupProfile, {
1680
+ usePopupInputArgsWhenSourceIdInferred: true
1681
+ }),
1666
1682
  ...preserveAssociationContext ? {
1667
1683
  associationName: input.popupProfile.associationName,
1668
1684
  sourceId: input.popupProfile.sourceId
@@ -2526,7 +2542,8 @@ class FlowSurfacesService {
2526
2542
  );
2527
2543
  }
2528
2544
  return (0, import_blueprint.compileFlowSurfaceApplyBlueprintRequest)(document, {
2529
- replaceTarget
2545
+ replaceTarget,
2546
+ getCollection: (dataSourceKey, collectionName) => this.getCollection(dataSourceKey || "main", collectionName || "")
2530
2547
  });
2531
2548
  }
2532
2549
  async applyBlueprint(values, options = {}) {
@@ -2893,34 +2910,41 @@ class FlowSurfacesService {
2893
2910
  })
2894
2911
  );
2895
2912
  }
2896
- async assertPopupTemplateCompatibility(actionName, hostUid, template, transaction) {
2913
+ async assertPopupTemplateCompatibility(actionName, hostUid, template, options = {}) {
2897
2914
  const normalizedHostUid = String(hostUid || "").trim();
2898
2915
  if (!normalizedHostUid) {
2899
2916
  return;
2900
2917
  }
2901
2918
  const hostNode = await this.repository.findModelById(normalizedHostUid, {
2902
- transaction,
2919
+ transaction: options.transaction,
2903
2920
  includeAsyncNode: true
2904
2921
  });
2905
2922
  if (!(hostNode == null ? void 0 : hostNode.uid)) {
2906
2923
  return;
2907
2924
  }
2908
- const popupProfile = await this.resolvePopupBlockProfile(normalizedHostUid, null, hostNode, transaction).catch(
2909
- () => null
2910
- );
2925
+ const popupProfile = await this.resolvePopupBlockProfile(
2926
+ normalizedHostUid,
2927
+ null,
2928
+ hostNode,
2929
+ options.transaction
2930
+ ).catch(() => null);
2911
2931
  if (!(popupProfile == null ? void 0 : popupProfile.isPopupSurface)) {
2912
2932
  return;
2913
2933
  }
2914
- const disabledReason = await this.getPopupTemplateDisabledReason(template, {
2915
- target: { uid: normalizedHostUid },
2916
- resolved: {
2917
- uid: normalizedHostUid,
2934
+ const disabledReason = await this.getPopupTemplateDisabledReason(
2935
+ template,
2936
+ {
2918
2937
  target: { uid: normalizedHostUid },
2919
- kind: "node"
2938
+ resolved: {
2939
+ uid: normalizedHostUid,
2940
+ target: { uid: normalizedHostUid },
2941
+ kind: "node"
2942
+ },
2943
+ node: hostNode,
2944
+ popupProfile
2920
2945
  },
2921
- node: hostNode,
2922
- popupProfile
2923
- });
2946
+ options.popupActionContext
2947
+ );
2924
2948
  if (!disabledReason) {
2925
2949
  return;
2926
2950
  }
@@ -3123,6 +3147,67 @@ class FlowSurfacesService {
3123
3147
  buildPopupTemplateReferenceOpenView(template, templateTargetUid) {
3124
3148
  return this.buildPopupTemplateOpenView(template, "reference", templateTargetUid);
3125
3149
  }
3150
+ shouldHydrateDetachedPopupTemplateBlockResourceContext(blockNode, context) {
3151
+ if (!this.isCollectionBlockUse(blockNode == null ? void 0 : blockNode.use) || !context.associationName || !context.sourceId) {
3152
+ return false;
3153
+ }
3154
+ const init = import_lodash.default.get(blockNode, ["stepParams", "resourceSettings", "init"]) || {};
3155
+ const popupDataSourceKey = context.dataSourceKey || "main";
3156
+ const blockDataSourceKey = init.dataSourceKey || "main";
3157
+ if (!context.collectionName || blockDataSourceKey !== popupDataSourceKey || init.collectionName !== context.collectionName) {
3158
+ return false;
3159
+ }
3160
+ const blockAssociationName = String(init.associationName || "").trim();
3161
+ if (blockAssociationName && blockAssociationName !== context.associationName) {
3162
+ return false;
3163
+ }
3164
+ if ((0, import_service_helpers.hasConfiguredFlowContextValue)(init.sourceId) && !this.isSameConfiguredFlowContextValue(init.sourceId, context.sourceId)) {
3165
+ return false;
3166
+ }
3167
+ return blockAssociationName !== context.associationName || !this.isSameConfiguredFlowContextValue(init.sourceId, context.sourceId);
3168
+ }
3169
+ collectDetachedPopupTemplateBlockResourceContextPatches(node, context, patches = []) {
3170
+ if (!node || typeof node !== "object") {
3171
+ return patches;
3172
+ }
3173
+ if (node.uid && this.shouldHydrateDetachedPopupTemplateBlockResourceContext(node, context)) {
3174
+ const nextStepParams = import_lodash.default.cloneDeep(node.stepParams || {});
3175
+ const currentInit = import_lodash.default.get(nextStepParams, ["resourceSettings", "init"]) || {};
3176
+ import_lodash.default.set(
3177
+ nextStepParams,
3178
+ ["resourceSettings", "init"],
3179
+ (0, import_service_utils.buildDefinedPayload)({
3180
+ ...currentInit,
3181
+ dataSourceKey: context.dataSourceKey || currentInit.dataSourceKey || "main",
3182
+ collectionName: context.collectionName || currentInit.collectionName,
3183
+ associationName: context.associationName,
3184
+ sourceId: context.sourceId
3185
+ })
3186
+ );
3187
+ patches.push({
3188
+ uid: node.uid,
3189
+ stepParams: nextStepParams
3190
+ });
3191
+ }
3192
+ for (const value of Object.values(node.subModels || {})) {
3193
+ for (const child of import_lodash.default.castArray(value)) {
3194
+ this.collectDetachedPopupTemplateBlockResourceContextPatches(child, context, patches);
3195
+ }
3196
+ }
3197
+ return patches;
3198
+ }
3199
+ async hydrateDetachedPopupTemplateBlockResourceContext(detachedTarget, context, transaction) {
3200
+ const patches = this.collectDetachedPopupTemplateBlockResourceContextPatches(detachedTarget, context);
3201
+ for (const patch of patches) {
3202
+ await this.repository.patch(
3203
+ {
3204
+ uid: patch.uid,
3205
+ stepParams: patch.stepParams
3206
+ },
3207
+ { transaction }
3208
+ );
3209
+ }
3210
+ }
3126
3211
  async hydrateDetachedPopupTemplateSourceContext(templateTargetUid, inferred, transaction) {
3127
3212
  if (inferred.templateType !== "popup") {
3128
3213
  return;
@@ -3139,32 +3224,32 @@ class FlowSurfacesService {
3139
3224
  return;
3140
3225
  }
3141
3226
  const resolvedOpenViewStep = (0, import_template_service_utils.findFlowTemplateOpenViewStep)(detachedTarget) || inferred.openViewStep;
3142
- if (!resolvedOpenViewStep) {
3143
- return;
3144
- }
3145
- const nextStepParams = import_lodash.default.cloneDeep(detachedTarget.stepParams || {});
3146
- const currentGroup = import_lodash.default.isPlainObject(nextStepParams[resolvedOpenViewStep.flowKey]) ? import_lodash.default.cloneDeep(nextStepParams[resolvedOpenViewStep.flowKey]) : {};
3147
- const currentOpenView = import_lodash.default.isPlainObject(currentGroup[resolvedOpenViewStep.stepKey]) ? import_lodash.default.omit((0, import_template_service_utils.stripTemplateInternalOpenViewFields)(currentGroup[resolvedOpenViewStep.stepKey]) || {}, ["uid"]) : {};
3148
- const nextOpenView = (0, import_service_utils.buildDefinedPayload)({
3149
- ...currentOpenView,
3150
- dataSourceKey: inferred.dataSourceKey || currentOpenView.dataSourceKey,
3151
- collectionName: inferred.collectionName || currentOpenView.collectionName,
3152
- associationName: inferred.associationName || currentOpenView.associationName,
3153
- filterByTk: inferred.filterByTk || currentOpenView.filterByTk,
3154
- sourceId: inferred.sourceId || currentOpenView.sourceId
3155
- });
3156
- if (import_lodash.default.isEqual(nextOpenView, currentOpenView)) {
3157
- return;
3227
+ if (resolvedOpenViewStep) {
3228
+ const nextStepParams = import_lodash.default.cloneDeep(detachedTarget.stepParams || {});
3229
+ const currentGroup = import_lodash.default.isPlainObject(nextStepParams[resolvedOpenViewStep.flowKey]) ? import_lodash.default.cloneDeep(nextStepParams[resolvedOpenViewStep.flowKey]) : {};
3230
+ const currentOpenView = import_lodash.default.isPlainObject(currentGroup[resolvedOpenViewStep.stepKey]) ? import_lodash.default.omit((0, import_template_service_utils.stripTemplateInternalOpenViewFields)(currentGroup[resolvedOpenViewStep.stepKey]) || {}, ["uid"]) : {};
3231
+ const nextOpenView = (0, import_service_utils.buildDefinedPayload)({
3232
+ ...currentOpenView,
3233
+ dataSourceKey: inferred.dataSourceKey || currentOpenView.dataSourceKey,
3234
+ collectionName: inferred.collectionName || currentOpenView.collectionName,
3235
+ associationName: inferred.associationName || currentOpenView.associationName,
3236
+ filterByTk: inferred.filterByTk || currentOpenView.filterByTk,
3237
+ sourceId: inferred.sourceId || currentOpenView.sourceId
3238
+ });
3239
+ if (!import_lodash.default.isEqual(nextOpenView, currentOpenView)) {
3240
+ currentGroup[resolvedOpenViewStep.stepKey] = nextOpenView;
3241
+ nextStepParams[resolvedOpenViewStep.flowKey] = currentGroup;
3242
+ await this.repository.patch(
3243
+ {
3244
+ uid: detachedTarget.uid,
3245
+ stepParams: nextStepParams
3246
+ },
3247
+ { transaction }
3248
+ );
3249
+ detachedTarget.stepParams = nextStepParams;
3250
+ }
3158
3251
  }
3159
- currentGroup[resolvedOpenViewStep.stepKey] = nextOpenView;
3160
- nextStepParams[resolvedOpenViewStep.flowKey] = currentGroup;
3161
- await this.repository.patch(
3162
- {
3163
- uid: detachedTarget.uid,
3164
- stepParams: nextStepParams
3165
- },
3166
- { transaction }
3167
- );
3252
+ await this.hydrateDetachedPopupTemplateBlockResourceContext(detachedTarget, inferred, transaction);
3168
3253
  }
3169
3254
  async clearFlowTemplateUsagesByModelUids(modelUids, transaction) {
3170
3255
  const usageRepo = this.getFlowTemplateUsageRepositorySafe();
@@ -3381,7 +3466,7 @@ class FlowSurfacesService {
3381
3466
  }
3382
3467
  const nextStepParams = import_lodash.default.cloneDeep(sourceNode.stepParams || {});
3383
3468
  const currentGroup = import_lodash.default.isPlainObject(nextStepParams[openViewStep.flowKey]) ? import_lodash.default.cloneDeep(nextStepParams[openViewStep.flowKey]) : {};
3384
- currentGroup[openViewStep.stepKey] = {
3469
+ let nextOpenView = {
3385
3470
  ...import_lodash.default.omit(openViewStep.openView || {}, [
3386
3471
  "popupTemplateUid",
3387
3472
  "popupTemplateMode",
@@ -3391,6 +3476,10 @@ class FlowSurfacesService {
3391
3476
  ]),
3392
3477
  ...this.buildPopupTemplateReferenceOpenView(template, templateTargetUid)
3393
3478
  };
3479
+ if (String(sourceNode.use || "").trim() === "AddChildActionModel") {
3480
+ nextOpenView = await this.normalizeAddChildOpenViewForAction(sourceNode, nextOpenView, transaction);
3481
+ }
3482
+ currentGroup[openViewStep.stepKey] = nextOpenView;
3394
3483
  nextStepParams[openViewStep.flowKey] = currentGroup;
3395
3484
  await this.cleanupLocalPopupSurfaceForHost(sourceNode.uid, transaction, sourceNode);
3396
3485
  await this.repository.patch(
@@ -3682,6 +3771,13 @@ class FlowSurfacesService {
3682
3771
  ]),
3683
3772
  ...this.buildPopupTemplateOpenView(resolved.template, "copy", popupUid)
3684
3773
  };
3774
+ if (String(node.use || "").trim() === "AddChildActionModel") {
3775
+ currentGroup[resolved.openViewStep.stepKey] = await this.normalizeAddChildOpenViewForAction(
3776
+ node,
3777
+ currentGroup[resolved.openViewStep.stepKey],
3778
+ options.transaction
3779
+ );
3780
+ }
3685
3781
  nextStepParams[resolved.openViewStep.flowKey] = currentGroup;
3686
3782
  await this.cleanupLocalPopupSurfaceForHost(node.uid, options.transaction, node);
3687
3783
  await this.repository.patch(
@@ -5128,6 +5224,7 @@ class FlowSurfacesService {
5128
5224
  use: catalogItem.use,
5129
5225
  containerUse: parentNode == null ? void 0 : parentNode.use,
5130
5226
  resourceInit: effectiveResourceInit,
5227
+ enableDefaultSorting: this.shouldEnableCreatedAtDefaultSorting(effectiveResourceInit),
5131
5228
  props: blockProps,
5132
5229
  decoratorProps: values.decoratorProps,
5133
5230
  stepParams: catalogItem.use === "CalendarBlockModel" ? this.buildCalendarInitialStepParams({
@@ -5482,6 +5579,7 @@ class FlowSurfacesService {
5482
5579
  collectionName: resolvedField.collectionName,
5483
5580
  fieldPath: resolvedField.fieldPath,
5484
5581
  associationPathName: resolvedField.associationPathName,
5582
+ ...(0, import_service_utils.hasOwnDefined)(values, "titleField") ? { explicitTitleField: values.titleField } : {},
5485
5583
  bindingChange: true,
5486
5584
  hasExistingTitleField: false,
5487
5585
  enabledPackages
@@ -5605,6 +5703,10 @@ class FlowSurfacesService {
5605
5703
  boundFieldCapability.fieldUse,
5606
5704
  values.fieldProps || {}
5607
5705
  );
5706
+ const requiredFieldWrapperDefaults = this.buildRequiredCollectionFieldFormWrapperDefaults({
5707
+ wrapperUse: boundFieldCapability.wrapperUse,
5708
+ field: resolvedField.field
5709
+ });
5608
5710
  const tree = (0, import_builder.buildFieldTree)({
5609
5711
  wrapperUse: boundFieldCapability.wrapperUse,
5610
5712
  fieldUse: boundFieldCapability.fieldUse,
@@ -5617,6 +5719,7 @@ class FlowSurfacesService {
5617
5719
  {},
5618
5720
  defaultFieldState.wrapperProps || {},
5619
5721
  wrapperShouldPersistTitleField ? { titleField: defaultTitleField } : {},
5722
+ requiredFieldWrapperDefaults.props,
5620
5723
  values.wrapperProps || {}
5621
5724
  ),
5622
5725
  fieldProps: import_lodash.default.merge(
@@ -5627,6 +5730,18 @@ class FlowSurfacesService {
5627
5730
  )
5628
5731
  });
5629
5732
  this.contractGuard.validateNodeTreeAgainstContract(tree.model);
5733
+ if (wrapperShouldPersistTitleField && boundFieldCapability.wrapperUse === "TableColumnModel") {
5734
+ tree.model.stepParams = import_lodash.default.merge({}, tree.model.stepParams || {}, {
5735
+ tableColumnSettings: {
5736
+ fieldNames: {
5737
+ label: defaultTitleField
5738
+ }
5739
+ }
5740
+ });
5741
+ }
5742
+ if (requiredFieldWrapperDefaults.stepParams) {
5743
+ tree.model.stepParams = import_lodash.default.merge({}, tree.model.stepParams || {}, requiredFieldWrapperDefaults.stepParams);
5744
+ }
5630
5745
  await this.repository.upsertModel(
5631
5746
  {
5632
5747
  parentId: container.parentUid,
@@ -5816,10 +5931,11 @@ class FlowSurfacesService {
5816
5931
  });
5817
5932
  const materializedContainer = await this.materializeRecordActionContainer(container, options.transaction);
5818
5933
  const resourceContext = container.ownerUid ? await this.locator.resolveCollectionContext(container.ownerUid, options.transaction).catch(() => null) : null;
5934
+ const resourceInit = this.isAddChildCatalogItem(actionCatalogItem) ? await this.resolveAddChildResourceInitForOwnerNode(container.ownerNode, options.transaction) : values.resourceInit || (resourceContext == null ? void 0 : resourceContext.resourceInit);
5819
5935
  const action = (0, import_builder.buildActionTree)({
5820
5936
  use: actionCatalogItem.use,
5821
5937
  containerUse: container.containerUse,
5822
- resourceInit: values.resourceInit || (resourceContext == null ? void 0 : resourceContext.resourceInit),
5938
+ resourceInit,
5823
5939
  props: values.props,
5824
5940
  decoratorProps: values.decoratorProps,
5825
5941
  stepParams: values.stepParams,
@@ -6111,7 +6227,8 @@ class FlowSurfacesService {
6111
6227
  const availableAliases = new Set(popupTemplateAliasSession ? popupTemplateAliasSession.keys() : []);
6112
6228
  document.tabs.forEach((tab, tabIndex) => {
6113
6229
  const composeValues = (0, import_compile_blocks.compileTabComposeValues)(tab, document, tabIndex, {
6114
- mode: document.mode === "replace" ? "replace" : "append"
6230
+ mode: document.mode === "replace" ? "replace" : "append",
6231
+ getCollection: (dataSourceKey, collectionName) => this.getCollection(dataSourceKey || "main", collectionName || "")
6115
6232
  });
6116
6233
  this.validatePopupTemplateAliasesInBlocks(
6117
6234
  import_lodash.default.castArray(composeValues.blocks || []),
@@ -6129,6 +6246,21 @@ class FlowSurfacesService {
6129
6246
  }
6130
6247
  return settings;
6131
6248
  }
6249
+ shouldEnableCreatedAtDefaultSorting(resourceInit) {
6250
+ const collectionName = String((resourceInit == null ? void 0 : resourceInit.collectionName) || "").trim();
6251
+ if (!collectionName) {
6252
+ return false;
6253
+ }
6254
+ const dataSourceKey = String((resourceInit == null ? void 0 : resourceInit.dataSourceKey) || "main").trim() || "main";
6255
+ const collection = this.getCollection(dataSourceKey, collectionName);
6256
+ return !!(0, import_service_helpers.resolveFieldFromCollection)(collection, "createdAt");
6257
+ }
6258
+ normalizeBlockSortingInput(value, context) {
6259
+ return (0, import_public_compatibility.normalizeFlowSurfaceDefaultSorting)(value, context);
6260
+ }
6261
+ normalizeMapSortingInput(value, context) {
6262
+ return (0, import_public_compatibility.normalizeFlowSurfaceEmptySortingAsDefault)(value, context);
6263
+ }
6132
6264
  normalizeInlinePopup(actionName, popup) {
6133
6265
  if (import_lodash.default.isUndefined(popup)) {
6134
6266
  return void 0;
@@ -6289,6 +6421,9 @@ class FlowSurfacesService {
6289
6421
  }
6290
6422
  resolveDefaultActionPopupSemanticUse(use) {
6291
6423
  const normalizedUse = String(use || "").trim();
6424
+ if (normalizedUse === "AddChildActionModel") {
6425
+ return "AddNewActionModel";
6426
+ }
6292
6427
  if (normalizedUse === "CalendarQuickCreateActionModel") {
6293
6428
  return "AddNewActionModel";
6294
6429
  }
@@ -6500,13 +6635,16 @@ class FlowSurfacesService {
6500
6635
  return ["-updatedAt", "-createdAt", "uid"];
6501
6636
  }
6502
6637
  getPopupTryTemplateExpectedAssociationName(targetContext) {
6503
- var _a, _b, _c;
6504
- if ((_a = targetContext == null ? void 0 : targetContext.popupProfile) == null ? void 0 : _a.isPopupSurface) {
6638
+ var _a, _b, _c, _d, _e;
6639
+ if (String(((_a = targetContext == null ? void 0 : targetContext.node) == null ? void 0 : _a.use) || "").trim() === "AddChildActionModel") {
6640
+ return String(((_b = this.resolvePopupHostOpenView(targetContext.node)) == null ? void 0 : _b.associationName) || "").trim() || void 0;
6641
+ }
6642
+ if ((_c = targetContext == null ? void 0 : targetContext.popupProfile) == null ? void 0 : _c.isPopupSurface) {
6505
6643
  return String(targetContext.popupProfile.associationName || "").trim() || void 0;
6506
6644
  }
6507
- return String(((_c = (_b = targetContext == null ? void 0 : targetContext.resourceContext) == null ? void 0 : _b.resourceInit) == null ? void 0 : _c.associationName) || "").trim() || void 0;
6645
+ return String(((_e = (_d = targetContext == null ? void 0 : targetContext.resourceContext) == null ? void 0 : _d.resourceInit) == null ? void 0 : _e.associationName) || "").trim() || void 0;
6508
6646
  }
6509
- getPopupTryTemplatePriority(template, expectedAssociationName) {
6647
+ getPopupTryTemplatePriority(template, expectedAssociationName, options = {}) {
6510
6648
  const templateAssociationName = String(template.associationName || "").trim() || void 0;
6511
6649
  if (!expectedAssociationName) {
6512
6650
  return templateAssociationName ? null : 0;
@@ -6514,11 +6652,18 @@ class FlowSurfacesService {
6514
6652
  if (templateAssociationName === expectedAssociationName) {
6515
6653
  return 0;
6516
6654
  }
6655
+ if (options.requireExactAssociationName) {
6656
+ return null;
6657
+ }
6517
6658
  if (!templateAssociationName) {
6518
6659
  return 1;
6519
6660
  }
6520
6661
  return null;
6521
6662
  }
6663
+ shouldRequireExactPopupTryTemplateAssociation(targetContext) {
6664
+ var _a;
6665
+ return String(((_a = targetContext == null ? void 0 : targetContext.node) == null ? void 0 : _a.use) || "").trim() === "AddChildActionModel" && !!this.getPopupTryTemplateExpectedAssociationName(targetContext);
6666
+ }
6522
6667
  getRequestedPopupDefaultType(popup) {
6523
6668
  const normalized = String((popup == null ? void 0 : popup.defaultType) || "").trim();
6524
6669
  if (normalized === "view" || normalized === "edit") {
@@ -6625,9 +6770,12 @@ class FlowSurfacesService {
6625
6770
  targetContext,
6626
6771
  options.popupActionContext
6627
6772
  );
6773
+ const requireExactAssociationName = this.shouldRequireExactPopupTryTemplateAssociation(targetContext);
6628
6774
  for (const priority of [0, 1]) {
6629
6775
  for (const template of annotatedTemplates) {
6630
- if (template.available !== true || this.getPopupTryTemplatePriority(template, expectedAssociationName) !== priority) {
6776
+ if (template.available !== true || this.getPopupTryTemplatePriority(template, expectedAssociationName, {
6777
+ requireExactAssociationName
6778
+ }) !== priority) {
6631
6779
  continue;
6632
6780
  }
6633
6781
  if (await this.popupTemplateMatchesDefaultType(template, popup, {
@@ -6802,12 +6950,10 @@ class FlowSurfacesService {
6802
6950
  transaction: options.transaction,
6803
6951
  expectedType: "popup"
6804
6952
  });
6805
- await this.assertPopupTemplateCompatibility(
6806
- actionName,
6807
- options.popupTemplateHostUid,
6808
- template,
6809
- options.transaction
6810
- );
6953
+ await this.assertPopupTemplateCompatibility(actionName, options.popupTemplateHostUid, template, {
6954
+ transaction: options.transaction,
6955
+ popupActionContext: options.popupActionContext
6956
+ });
6811
6957
  const resolvedUid = templateRef.mode === "copy" ? String(
6812
6958
  ((_a = await this.duplicateDetachedFlowModelTree(actionName, template.targetUid, options.transaction)) == null ? void 0 : _a.uid) || ""
6813
6959
  ) : template.targetUid;
@@ -6820,12 +6966,15 @@ class FlowSurfacesService {
6820
6966
  if (templateRef.mode === "copy") {
6821
6967
  await this.ensurePopupSurface(resolvedUid, options.transaction);
6822
6968
  }
6823
- const nextTemplateOpenView = this.buildPopupTemplateOpenView(template, templateRef.mode, resolvedUid);
6969
+ let nextTemplateOpenView = this.buildPopupTemplateOpenView(template, templateRef.mode, resolvedUid);
6824
6970
  Object.keys(normalizedOpenView).forEach((key) => {
6825
6971
  if (key === "template" || key === "popupTemplateUid" || key === "popupTemplateMode" || key === "popupTemplateContext" || key === "popupTemplateHasFilterByTk" || key === "popupTemplateHasSourceId") {
6826
6972
  delete normalizedOpenView[key];
6827
6973
  }
6828
6974
  });
6975
+ if (String(options.popupTemplateHostUse || "").trim() === "AddChildActionModel") {
6976
+ nextTemplateOpenView = import_lodash.default.omit(nextTemplateOpenView, ["sourceId"]);
6977
+ }
6829
6978
  Object.assign(normalizedOpenView, nextTemplateOpenView);
6830
6979
  }
6831
6980
  if (!import_lodash.default.isUndefined(normalizedOpenView.uid)) {
@@ -7896,15 +8045,27 @@ class FlowSurfacesService {
7896
8045
  return;
7897
8046
  }
7898
8047
  const currentOpenView = import_lodash.default.isPlainObject(openViewStep.openView) ? openViewStep.openView : {};
7899
- if (this.normalizeOptionalPopupTitle(currentOpenView.title) === openViewTitle) {
8048
+ const popupProfile = await this.resolvePopupBlockProfile(
8049
+ actionNode.uid,
8050
+ null,
8051
+ actionNode,
8052
+ options.transaction
8053
+ ).catch(() => null);
8054
+ const filterTargetKey = (popupProfile == null ? void 0 : popupProfile.currentCollection) ? this.getCollectionFilterTargetKey(popupProfile.currentCollection) : null;
8055
+ const defaultFilterByTk = this.resolvePopupCurrentRecordResourceFilterByTk(popupProfile);
8056
+ const currentFilterByTk = import_lodash.default.isString(currentOpenView.filterByTk) ? currentOpenView.filterByTk.trim() : "";
8057
+ const preserveCustomFilterByTk = currentFilterByTk && currentFilterByTk !== "{{ctx.view.inputArgs.filterByTk}}" && currentFilterByTk !== (filterTargetKey ? `{{ctx.record.${filterTargetKey}}}` : "");
8058
+ const nextOpenView = (0, import_service_utils.buildDefinedPayload)({
8059
+ ...currentOpenView,
8060
+ title: openViewTitle,
8061
+ filterByTk: preserveCustomFilterByTk ? currentOpenView.filterByTk : defaultFilterByTk || currentOpenView.filterByTk
8062
+ });
8063
+ if (import_lodash.default.isEqual(nextOpenView, currentOpenView)) {
7900
8064
  return;
7901
8065
  }
7902
8066
  const nextStepParams = import_lodash.default.cloneDeep((actionNode == null ? void 0 : actionNode.stepParams) || {});
7903
8067
  const currentGroup = import_lodash.default.isPlainObject(nextStepParams[openViewStep.flowKey]) ? import_lodash.default.cloneDeep(nextStepParams[openViewStep.flowKey]) : {};
7904
- currentGroup[openViewStep.stepKey] = (0, import_service_utils.buildDefinedPayload)({
7905
- ...currentOpenView,
7906
- title: openViewTitle
7907
- });
8068
+ currentGroup[openViewStep.stepKey] = nextOpenView;
7908
8069
  nextStepParams[openViewStep.flowKey] = currentGroup;
7909
8070
  await this.repository.patch(
7910
8071
  {
@@ -7939,12 +8100,16 @@ class FlowSurfacesService {
7939
8100
  const nextStepParams = import_lodash.default.cloneDeep(actionNode.stepParams || {});
7940
8101
  const currentGroup = import_lodash.default.isPlainObject(nextStepParams[flowKey]) ? import_lodash.default.cloneDeep(nextStepParams[flowKey]) : {};
7941
8102
  const currentGroupOpenView = import_lodash.default.isPlainObject(currentGroup[stepKey]) ? currentGroup[stepKey] : {};
8103
+ const filterTargetKey = (popupProfile == null ? void 0 : popupProfile.currentCollection) ? this.getCollectionFilterTargetKey(popupProfile.currentCollection) : null;
8104
+ const currentFilterByTk = import_lodash.default.isString(currentGroupOpenView == null ? void 0 : currentGroupOpenView.filterByTk) ? currentGroupOpenView.filterByTk.trim() : "";
8105
+ const defaultFilterByTk = this.resolvePopupCurrentRecordResourceFilterByTk(popupProfile);
8106
+ const preserveCustomFilterByTk = currentFilterByTk && currentFilterByTk !== "{{ctx.view.inputArgs.filterByTk}}" && currentFilterByTk !== "{{ctx.record." + filterTargetKey + "}}";
7942
8107
  const nextOpenView = (0, import_service_utils.buildDefinedPayload)({
7943
8108
  ...currentGroupOpenView,
7944
8109
  dataSourceKey: (currentOpenView == null ? void 0 : currentOpenView.dataSourceKey) || (popupProfile == null ? void 0 : popupProfile.dataSourceKey) || "main",
7945
8110
  collectionName,
7946
8111
  associationName: (currentOpenView == null ? void 0 : currentOpenView.associationName) || (popupProfile == null ? void 0 : popupProfile.associationName),
7947
- filterByTk: (popupProfile == null ? void 0 : popupProfile.filterByTk) || "{{ctx.view.inputArgs.filterByTk}}",
8112
+ filterByTk: preserveCustomFilterByTk ? currentGroupOpenView.filterByTk : defaultFilterByTk || (popupProfile == null ? void 0 : popupProfile.filterByTk) || "{{ctx.view.inputArgs.filterByTk}}",
7948
8113
  sourceId: (currentOpenView == null ? void 0 : currentOpenView.sourceId) || (popupProfile == null ? void 0 : popupProfile.sourceId)
7949
8114
  });
7950
8115
  if (import_lodash.default.isEqual(nextOpenView, currentGroupOpenView)) {
@@ -8053,6 +8218,12 @@ class FlowSurfacesService {
8053
8218
  openViewActionName: actionName
8054
8219
  }
8055
8220
  );
8221
+ if (this.isDefaultActionPopupUseForNode(actionNode)) {
8222
+ await this.syncDefaultActionPopupOpenViewTitle(actionUid, actionNode, {
8223
+ ...options,
8224
+ openViewTitle: templateOpenViewTitle
8225
+ });
8226
+ }
8056
8227
  this.registerInlinePopupTemplateAlias(actionName, popup, matchedTemplate, options.popupTemplateAliasSession);
8057
8228
  return;
8058
8229
  }
@@ -8149,6 +8320,7 @@ class FlowSurfacesService {
8149
8320
  );
8150
8321
  this.syncCalendarPopupPropsForUpdateSettings(current, normalizedValues, nextPayload);
8151
8322
  this.syncKanbanPopupPropsForUpdateSettings(current, normalizedValues, nextPayload);
8323
+ this.syncDefaultSortingForUpdateSettings(current, normalizedValues, nextPayload);
8152
8324
  this.syncFilterActionSettingsForUpdateSettings(current, normalizedValues, nextPayload);
8153
8325
  this.syncMirroredStepParamsForUpdateSettings(current, nextPayload);
8154
8326
  const updateActionAssignedValues = this.syncUpdateActionAssignedValuesForUpdateSettings(
@@ -8164,6 +8336,7 @@ class FlowSurfacesService {
8164
8336
  {
8165
8337
  transaction: options.transaction,
8166
8338
  popupTemplateHostUid: options.popupTemplateHostUid,
8339
+ popupTemplateHostUse: current == null ? void 0 : current.use,
8167
8340
  popupActionContext
8168
8341
  }
8169
8342
  );
@@ -8327,6 +8500,68 @@ class FlowSurfacesService {
8327
8500
  }
8328
8501
  }
8329
8502
  }
8503
+ syncDefaultSortingForUpdateSettings(current, normalizedValues, nextPayload) {
8504
+ if (!import_lodash.default.isPlainObject(normalizedValues == null ? void 0 : normalizedValues.stepParams)) {
8505
+ return;
8506
+ }
8507
+ const currentUse = current == null ? void 0 : current.use;
8508
+ const nextStepParams = import_lodash.default.cloneDeep(nextPayload.stepParams ?? (current == null ? void 0 : current.stepParams) ?? {});
8509
+ let changed = false;
8510
+ const normalizeGroupSort = (groupPath, context) => {
8511
+ const currentGroup = import_lodash.default.get(nextStepParams, groupPath);
8512
+ if (!import_lodash.default.isPlainObject(currentGroup)) {
8513
+ return;
8514
+ }
8515
+ if (!import_lodash.default.has(normalizedValues.stepParams, [...groupPath, "defaultSorting", "sort"])) {
8516
+ return;
8517
+ }
8518
+ const defaultSorting = import_lodash.default.get(currentGroup, ["defaultSorting", "sort"]);
8519
+ const normalizedSort = (0, import_public_compatibility.normalizeFlowSurfaceDefaultSorting)(defaultSorting, context);
8520
+ if (import_lodash.default.isEqual(defaultSorting, normalizedSort)) {
8521
+ return;
8522
+ }
8523
+ import_lodash.default.set(nextStepParams, [...groupPath, "defaultSorting", "sort"], normalizedSort);
8524
+ changed = true;
8525
+ };
8526
+ if (currentUse === "TableBlockModel" && Object.prototype.hasOwnProperty.call(normalizedValues.stepParams, "tableSettings")) {
8527
+ normalizeGroupSort(["tableSettings"], "tableSettings.defaultSorting.sort");
8528
+ }
8529
+ if (currentUse === "DetailsBlockModel" && Object.prototype.hasOwnProperty.call(normalizedValues.stepParams, "detailsSettings")) {
8530
+ normalizeGroupSort(["detailsSettings"], "detailsSettings.defaultSorting.sort");
8531
+ }
8532
+ if (currentUse === "ListBlockModel" && Object.prototype.hasOwnProperty.call(normalizedValues.stepParams, "listSettings")) {
8533
+ normalizeGroupSort(["listSettings"], "listSettings.defaultSorting.sort");
8534
+ }
8535
+ if (currentUse === "GridCardBlockModel" && Object.prototype.hasOwnProperty.call(normalizedValues.stepParams, "GridCardSettings")) {
8536
+ normalizeGroupSort(["GridCardSettings"], "GridCardSettings.defaultSorting.sort");
8537
+ }
8538
+ if (currentUse === "TreeBlockModel" && Object.prototype.hasOwnProperty.call(normalizedValues.stepParams, "treeSettings")) {
8539
+ normalizeGroupSort(["treeSettings"], "treeSettings.defaultSorting.sort");
8540
+ }
8541
+ if (currentUse === "KanbanBlockModel" && Object.prototype.hasOwnProperty.call(normalizedValues.stepParams, "kanbanSettings")) {
8542
+ normalizeGroupSort(["kanbanSettings"], "kanbanSettings.defaultSorting.sort");
8543
+ }
8544
+ if (currentUse === "MapBlockModel" && Object.prototype.hasOwnProperty.call(normalizedValues.stepParams, "createMapBlock")) {
8545
+ const createMapBlock = import_lodash.default.get(nextStepParams, ["createMapBlock"]);
8546
+ if (import_lodash.default.isPlainObject(createMapBlock)) {
8547
+ if (!import_lodash.default.has(normalizedValues.stepParams, ["createMapBlock", "lineSort", "sort"])) {
8548
+ return;
8549
+ }
8550
+ const defaultSorting = import_lodash.default.get(createMapBlock, ["lineSort", "sort"]);
8551
+ const normalizedSort = (0, import_public_compatibility.normalizeFlowSurfaceEmptySortingAsDefault)(
8552
+ defaultSorting,
8553
+ "createMapBlock.lineSort.sort"
8554
+ );
8555
+ if (!import_lodash.default.isEqual(defaultSorting, normalizedSort)) {
8556
+ import_lodash.default.set(nextStepParams, ["createMapBlock", "lineSort", "sort"], normalizedSort);
8557
+ changed = true;
8558
+ }
8559
+ }
8560
+ }
8561
+ if (changed) {
8562
+ nextPayload.stepParams = nextStepParams;
8563
+ }
8564
+ }
8330
8565
  syncKanbanPopupPropsForUpdateSettings(current, normalizedValues, nextPayload) {
8331
8566
  if (!import_lodash.default.isPlainObject(normalizedValues == null ? void 0 : normalizedValues.props)) {
8332
8567
  return;
@@ -8500,7 +8735,7 @@ class FlowSurfacesService {
8500
8735
  continue;
8501
8736
  }
8502
8737
  nextStepParams = nextStepParams ?? import_lodash.default.cloneDeep(nextPayload.stepParams ?? (current == null ? void 0 : current.stepParams) ?? {});
8503
- if (import_lodash.default.has(nextStepParams, mirror.stepParamsPath)) {
8738
+ if (import_lodash.default.has(nextStepParams, mirror.stepParamsPath) && (!import_lodash.default.isEqual(import_lodash.default.get(current == null ? void 0 : current.stepParams, mirror.stepParamsPath), import_lodash.default.get(current == null ? void 0 : current[mirror.domain], mirror.key)) || !import_lodash.default.isEqual(import_lodash.default.get(nextStepParams, mirror.stepParamsPath), import_lodash.default.get(current == null ? void 0 : current.stepParams, mirror.stepParamsPath)))) {
8504
8739
  continue;
8505
8740
  }
8506
8741
  import_lodash.default.set(nextStepParams, mirror.stepParamsPath, value);
@@ -8776,11 +9011,15 @@ class FlowSurfacesService {
8776
9011
  }
8777
9012
  const requestedOpenView = import_lodash.default.get(nextPayload, openViewPath);
8778
9013
  const currentOpenView = import_lodash.default.get(current, openViewPath);
8779
- const nextOpenView = await this.normalizeOpenView(actionName, requestedOpenView, {
9014
+ let nextOpenView = await this.normalizeOpenView(actionName, requestedOpenView, {
8780
9015
  transaction: options.transaction,
8781
9016
  popupTemplateHostUid,
9017
+ popupTemplateHostUse: options.popupTemplateHostUse || (current == null ? void 0 : current.use),
8782
9018
  popupActionContext: options.popupActionContext
8783
9019
  });
9020
+ if (flowKey === "popupSettings" && String((current == null ? void 0 : current.use) || "").trim() === "AddChildActionModel" && import_lodash.default.isPlainObject(nextOpenView)) {
9021
+ nextOpenView = await this.normalizeAddChildOpenViewForAction(current, nextOpenView, options.transaction);
9022
+ }
8784
9023
  if (this.isTryTemplateOnlyOpenViewRequest(requestedOpenView) && import_lodash.default.isPlainObject(nextOpenView) && !Object.keys(nextOpenView).length) {
8785
9024
  this.unsetPayloadPathAndPruneEmptyParents(nextPayload, openViewPath);
8786
9025
  if (import_lodash.default.isEqual(nextPayload.stepParams, current.stepParams)) {
@@ -9814,6 +10053,19 @@ class FlowSurfacesService {
9814
10053
  isAddChildCatalogItem(item) {
9815
10054
  return (item == null ? void 0 : item.key) === "addChild" || (item == null ? void 0 : item.use) === "AddChildActionModel";
9816
10055
  }
10056
+ resolveTreeChildrenField(collection) {
10057
+ return (0, import_service_helpers.getCollectionFields)(collection).find(
10058
+ (field) => {
10059
+ var _a;
10060
+ return (field == null ? void 0 : field.treeChildren) === true || ((_a = field == null ? void 0 : field.options) == null ? void 0 : _a.treeChildren) === true;
10061
+ }
10062
+ );
10063
+ }
10064
+ resolveTreeChildrenAssociationName(collection) {
10065
+ const collectionName = (0, import_service_helpers.getCollectionName)(collection);
10066
+ const childrenFieldName = (0, import_service_helpers.getFieldName)(this.resolveTreeChildrenField(collection));
10067
+ return collectionName && childrenFieldName ? `${collectionName}.${childrenFieldName}` : void 0;
10068
+ }
9817
10069
  isTreeCollection(collection) {
9818
10070
  var _a;
9819
10071
  return (collection == null ? void 0 : collection.template) === "tree" || ((_a = collection == null ? void 0 : collection.options) == null ? void 0 : _a.template) === "tree" || (collection == null ? void 0 : collection.tree) === true;
@@ -9835,11 +10087,49 @@ class FlowSurfacesService {
9835
10087
  includeAsyncNode: true
9836
10088
  }) || node;
9837
10089
  }
9838
- async resolveOwnerCollectionForAddChild(node, transaction) {
10090
+ async resolveAddChildOwnerResourceContext(node, transaction) {
9839
10091
  var _a;
9840
10092
  const ownerNode = await this.resolveAddChildOwnerNode(node, transaction);
9841
10093
  const resourceInit = import_lodash.default.get(ownerNode, ["stepParams", "resourceSettings", "init"]) || ((ownerNode == null ? void 0 : ownerNode.uid) ? (_a = await this.locator.resolveCollectionContext(ownerNode.uid, transaction).catch(() => null)) == null ? void 0 : _a.resourceInit : null);
9842
- return this.resolveCollectionFromInit(resourceInit);
10094
+ return {
10095
+ ownerNode,
10096
+ resourceInit,
10097
+ collection: this.resolveCollectionFromInit(resourceInit)
10098
+ };
10099
+ }
10100
+ async resolveOwnerCollectionForAddChild(node, transaction) {
10101
+ return (await this.resolveAddChildOwnerResourceContext(node, transaction)).collection;
10102
+ }
10103
+ async resolveAddChildResourceInitForOwnerNode(node, transaction) {
10104
+ const { resourceInit, collection } = await this.resolveAddChildOwnerResourceContext(node, transaction);
10105
+ const associationName = this.resolveTreeChildrenAssociationName(collection);
10106
+ if (!associationName) {
10107
+ (0, import_errors.throwBadRequest)(
10108
+ `flowSurfaces addRecordAction type 'addChild' cannot resolve tree children association for '${String((resourceInit == null ? void 0 : resourceInit.collectionName) || "").trim() || "unknown"}'`
10109
+ );
10110
+ }
10111
+ return (0, import_service_utils.buildDefinedPayload)({
10112
+ dataSourceKey: (resourceInit == null ? void 0 : resourceInit.dataSourceKey) || "main",
10113
+ collectionName: resourceInit == null ? void 0 : resourceInit.collectionName,
10114
+ associationName
10115
+ });
10116
+ }
10117
+ async normalizeAddChildOpenViewForAction(actionNode, openView, transaction) {
10118
+ if (!import_lodash.default.isPlainObject(openView)) {
10119
+ return openView;
10120
+ }
10121
+ const parentUid = String((actionNode == null ? void 0 : actionNode.parentId) || "").trim() || ((actionNode == null ? void 0 : actionNode.uid) ? await this.locator.findParentUid(actionNode.uid, transaction).catch(() => "") : "");
10122
+ const parentNode = parentUid ? await this.repository.findModelById(parentUid, {
10123
+ transaction,
10124
+ includeAsyncNode: true
10125
+ }) : null;
10126
+ const addChildResourceInit = await this.resolveAddChildResourceInitForOwnerNode(parentNode, transaction);
10127
+ return (0, import_service_utils.buildDefinedPayload)({
10128
+ ...import_lodash.default.omit(import_lodash.default.cloneDeep(openView), ["sourceId"]),
10129
+ dataSourceKey: addChildResourceInit.dataSourceKey,
10130
+ collectionName: addChildResourceInit.collectionName,
10131
+ associationName: addChildResourceInit.associationName
10132
+ });
9843
10133
  }
9844
10134
  async canUseAddChildOnOwnerNode(node, transaction) {
9845
10135
  const ownerNode = await this.resolveAddChildOwnerNode(node, transaction);
@@ -9847,15 +10137,26 @@ class FlowSurfacesService {
9847
10137
  return false;
9848
10138
  }
9849
10139
  const collection = await this.resolveOwnerCollectionForAddChild(ownerNode, transaction);
9850
- return this.isTreeCollection(collection);
10140
+ return this.isTreeCollection(collection) && !!this.resolveTreeChildrenAssociationName(collection);
9851
10141
  }
9852
10142
  async assertAddChildSupportedForOwnerNode(node, context, transaction) {
9853
- if (await this.canUseAddChildOnOwnerNode(node, transaction)) {
9854
- return;
10143
+ const ownerNode = await this.resolveAddChildOwnerNode(node, transaction);
10144
+ if ((ownerNode == null ? void 0 : ownerNode.use) !== "TableBlockModel" || !this.isTreeTableEnabled(ownerNode)) {
10145
+ (0, import_errors.throwBadRequest)(
10146
+ `flowSurfaces ${context} type 'addChild' only supports tables bound to tree collections with tree table enabled`
10147
+ );
10148
+ }
10149
+ const collection = await this.resolveOwnerCollectionForAddChild(ownerNode, transaction);
10150
+ if (!this.isTreeCollection(collection)) {
10151
+ (0, import_errors.throwBadRequest)(
10152
+ `flowSurfaces ${context} type 'addChild' only supports tables bound to tree collections with tree table enabled`
10153
+ );
10154
+ }
10155
+ if (!this.resolveTreeChildrenAssociationName(collection)) {
10156
+ (0, import_errors.throwBadRequest)(
10157
+ `flowSurfaces ${context} type 'addChild' tree collection '${(0, import_service_helpers.getCollectionName)(collection) || "unknown"}' does not expose a tree children field`
10158
+ );
9855
10159
  }
9856
- (0, import_errors.throwBadRequest)(
9857
- `flowSurfaces ${context} type 'addChild' only supports tables bound to tree collections with tree table enabled`
9858
- );
9859
10160
  }
9860
10161
  async filterTargetRecordActions(items, node, transaction) {
9861
10162
  if (!items.some((item) => this.isAddChildCatalogItem(item))) {
@@ -10738,7 +11039,11 @@ class FlowSurfacesService {
10738
11039
  ...(0, import_service_utils.hasOwnDefined)(changes, "density") ? { tableDensity: { size: changes.density } } : {},
10739
11040
  ...(0, import_service_utils.hasOwnDefined)(changes, "quickEdit") ? { quickEdit: { editable: changes.quickEdit } } : {},
10740
11041
  ...(0, import_service_utils.hasOwnDefined)(changes, "showRowNumbers") ? { showRowNumbers: { showIndex: changes.showRowNumbers } } : {},
10741
- ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? { defaultSorting: { sort: changes.sorting } } : {},
11042
+ ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? {
11043
+ defaultSorting: {
11044
+ sort: this.normalizeBlockSortingInput(changes.sorting, "tableSettings.sorting")
11045
+ }
11046
+ } : {},
10742
11047
  ...(0, import_service_utils.hasOwnDefined)(changes, "dataScope") ? { dataScope: { filter: changes.dataScope } } : {},
10743
11048
  ...(0, import_service_utils.hasOwnDefined)(changes, "treeTable") ? { treeTable: { treeTable: changes.treeTable } } : {},
10744
11049
  ...(0, import_service_utils.hasOwnDefined)(changes, "defaultExpandAllRows") ? { defaultExpandAllRows: { defaultExpandAllRows: changes.defaultExpandAllRows } } : {},
@@ -10937,7 +11242,11 @@ class FlowSurfacesService {
10937
11242
  ...(0, import_service_utils.hasOwnDefined)(changes, "titleField") ? { titleField: { titleField: nextFieldNames.title } } : {},
10938
11243
  ...(0, import_service_utils.hasOwnDefined)(changes, "pageSize") ? { pageSize: { pageSize: changes.pageSize } } : {},
10939
11244
  ...(0, import_service_utils.hasOwnDefined)(changes, "dataScope") ? { dataScope: { filter: changes.dataScope } } : {},
10940
- ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? { defaultSorting: { sort: changes.sorting } } : {}
11245
+ ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? {
11246
+ defaultSorting: {
11247
+ sort: this.normalizeBlockSortingInput(changes.sorting, "treeSettings.sorting")
11248
+ }
11249
+ } : {}
10941
11250
  })
10942
11251
  } : {}
10943
11252
  }
@@ -11161,7 +11470,7 @@ class FlowSurfacesService {
11161
11470
  groupOptions: nextGroupOptions || []
11162
11471
  } : {},
11163
11472
  ...(0, import_service_utils.hasOwnDefined)(changes, "styleVariant") ? { styleVariant: nextStyleVariantProp } : {},
11164
- ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? { globalSort: changes.sorting } : {},
11473
+ ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? { globalSort: this.normalizeBlockSortingInput(changes.sorting, "kanban.globalSort") } : {},
11165
11474
  ...shouldWriteDrag ? {
11166
11475
  dragEnabled: nextDragEnabled,
11167
11476
  dragSortBy: nextDragSortBy ?? null
@@ -11196,7 +11505,7 @@ class FlowSurfacesService {
11196
11505
  } : {},
11197
11506
  ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? {
11198
11507
  defaultSorting: {
11199
- sort: changes.sorting
11508
+ sort: this.normalizeBlockSortingInput(changes.sorting, "kanbanSettings.defaultSorting.sort")
11200
11509
  }
11201
11510
  } : {},
11202
11511
  ...shouldWriteDrag ? {
@@ -11435,7 +11744,11 @@ class FlowSurfacesService {
11435
11744
  colon: changes.colon
11436
11745
  })
11437
11746
  } : {},
11438
- ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? { defaultSorting: { sort: changes.sorting } } : {},
11747
+ ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? {
11748
+ defaultSorting: {
11749
+ sort: this.normalizeBlockSortingInput(changes.sorting, "detailsSettings.sorting")
11750
+ }
11751
+ } : {},
11439
11752
  ...(0, import_service_utils.hasOwnDefined)(changes, "dataScope") ? { dataScope: { filter: changes.dataScope } } : {},
11440
11753
  ...(0, import_service_utils.hasOwnDefined)(changes, "linkageRules") ? { linkageRules: { value: changes.linkageRules } } : {}
11441
11754
  })
@@ -11505,7 +11818,11 @@ class FlowSurfacesService {
11505
11818
  listSettings: (0, import_service_utils.buildDefinedPayload)({
11506
11819
  ...(0, import_service_utils.hasOwnDefined)(changes, "pageSize") ? { pageSize: { pageSize: changes.pageSize } } : {},
11507
11820
  ...(0, import_service_utils.hasOwnDefined)(changes, "dataScope") ? { dataScope: { filter: changes.dataScope } } : {},
11508
- ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? { defaultSorting: { sort: changes.sorting } } : {},
11821
+ ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? {
11822
+ defaultSorting: {
11823
+ sort: this.normalizeBlockSortingInput(changes.sorting, "listSettings.sorting")
11824
+ }
11825
+ } : {},
11509
11826
  ...(0, import_service_utils.hasOwnDefined)(changes, "layout") ? { layout: { layout: layoutValue } } : {}
11510
11827
  })
11511
11828
  } : {}
@@ -11535,7 +11852,11 @@ class FlowSurfacesService {
11535
11852
  ...columns ? { columnCount: { columnCount: columns } } : {},
11536
11853
  ...(0, import_service_utils.hasOwnDefined)(changes, "rowCount") ? { rowCount: { rowCount: changes.rowCount } } : {},
11537
11854
  ...(0, import_service_utils.hasOwnDefined)(changes, "dataScope") ? { dataScope: { filter: changes.dataScope } } : {},
11538
- ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? { defaultSorting: { sort: changes.sorting } } : {},
11855
+ ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? {
11856
+ defaultSorting: {
11857
+ sort: this.normalizeBlockSortingInput(changes.sorting, "GridCardSettings.sorting")
11858
+ }
11859
+ } : {},
11539
11860
  ...(0, import_service_utils.hasOwnDefined)(changes, "layout") ? { layout: { layout: layoutValue } } : {}
11540
11861
  })
11541
11862
  } : {}
@@ -11712,7 +12033,11 @@ class FlowSurfacesService {
11712
12033
  })
11713
12034
  } : {},
11714
12035
  ...(0, import_service_utils.hasOwnDefined)(changes, "dataScope") ? { dataScope: { filter: changes.dataScope } } : {},
11715
- ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? { lineSort: { sort: changes.sorting } } : {},
12036
+ ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? {
12037
+ lineSort: {
12038
+ sort: this.normalizeMapSortingInput(changes.sorting, "createMapBlock.lineSort.sort")
12039
+ }
12040
+ } : {},
11716
12041
  ...(0, import_service_utils.hasOwnDefined)(changes, "zoom") ? { mapZoom: { zoom: changes.zoom } } : {}
11717
12042
  })
11718
12043
  } : {}
@@ -12277,6 +12602,10 @@ class FlowSurfacesService {
12277
12602
  return import_lodash.default.cloneDeep(value);
12278
12603
  }
12279
12604
  async configureActionNode(target, use, changes, options) {
12605
+ const currentNode = options.current || (target.uid ? await this.repository.findModelById(target.uid, {
12606
+ transaction: options.transaction,
12607
+ includeAsyncNode: true
12608
+ }) : null);
12280
12609
  changes = await this.normalizeActionPanelActionChanges(changes, options);
12281
12610
  const allowedKeys = (0, import_configure_options.getConfigureOptionKeysForUse)(use);
12282
12611
  (0, import_service_utils.assertSupportedSimpleChanges)("action", changes, allowedKeys);
@@ -12344,8 +12673,12 @@ class FlowSurfacesService {
12344
12673
  } else if (!POPUP_ACTION_USES.has(use)) {
12345
12674
  (0, import_errors.throwBadRequest)(`flowSurfaces configure action '${use}' does not support openView`);
12346
12675
  } else {
12676
+ let openView = import_lodash.default.cloneDeep(changes.openView);
12677
+ if (use === "AddChildActionModel") {
12678
+ openView = await this.normalizeAddChildOpenViewForAction(currentNode, openView, options.transaction);
12679
+ }
12347
12680
  stepParams.popupSettings = {
12348
- openView: import_lodash.default.cloneDeep(changes.openView)
12681
+ openView
12349
12682
  };
12350
12683
  }
12351
12684
  }
@@ -12474,24 +12807,25 @@ class FlowSurfacesService {
12474
12807
  })
12475
12808
  };
12476
12809
  }
12810
+ const props = (0, import_service_utils.buildDefinedPayload)({
12811
+ title: changes.title,
12812
+ tooltip: changes.tooltip,
12813
+ icon: changes.icon,
12814
+ type: changes.type,
12815
+ htmlType: changes.htmlType,
12816
+ position: changes.position,
12817
+ danger: changes.danger,
12818
+ color: changes.color,
12819
+ ...(0, import_service_utils.hasOwnDefined)(changes, "filterableFieldNames") ? { filterableFieldNames: import_lodash.default.cloneDeep(changes.filterableFieldNames) } : {},
12820
+ ...(0, import_service_utils.hasOwnDefined)(changes, "defaultFilter") ? {
12821
+ defaultFilterValue: normalizedDefaultFilter,
12822
+ filterValue: import_lodash.default.cloneDeep(normalizedDefaultFilter)
12823
+ } : {}
12824
+ });
12477
12825
  return this.updateSettings(
12478
12826
  {
12479
12827
  target,
12480
- props: (0, import_service_utils.buildDefinedPayload)({
12481
- title: changes.title,
12482
- tooltip: changes.tooltip,
12483
- icon: changes.icon,
12484
- type: changes.type,
12485
- htmlType: changes.htmlType,
12486
- position: changes.position,
12487
- danger: changes.danger,
12488
- color: changes.color,
12489
- ...(0, import_service_utils.hasOwnDefined)(changes, "filterableFieldNames") ? { filterableFieldNames: import_lodash.default.cloneDeep(changes.filterableFieldNames) } : {},
12490
- ...(0, import_service_utils.hasOwnDefined)(changes, "defaultFilter") ? {
12491
- defaultFilterValue: normalizedDefaultFilter,
12492
- filterValue: import_lodash.default.cloneDeep(normalizedDefaultFilter)
12493
- } : {}
12494
- }),
12828
+ ...Object.keys(props).length ? { props } : {},
12495
12829
  stepParams: Object.keys(stepParams).length ? stepParams : void 0
12496
12830
  },
12497
12831
  {
@@ -14059,7 +14393,8 @@ class FlowSurfacesService {
14059
14393
  "styleVariant",
14060
14394
  "dragEnabled",
14061
14395
  "dragSortBy",
14062
- "quickCreateEnabled"
14396
+ "quickCreateEnabled",
14397
+ "globalSort"
14063
14398
  ]) : {},
14064
14399
  ...import_lodash.default.cloneDeep(input.props || {})
14065
14400
  };
@@ -14128,7 +14463,8 @@ class FlowSurfacesService {
14128
14463
  styleVariant: currentProps.styleVariant || "color",
14129
14464
  quickCreateEnabled: currentProps.quickCreateEnabled === true,
14130
14465
  dragEnabled: nextDragEnabled,
14131
- dragSortBy: nextDragSortBy || void 0
14466
+ dragSortBy: nextDragSortBy || void 0,
14467
+ ...Object.prototype.hasOwnProperty.call(currentProps, "globalSort") ? { globalSort: this.normalizeBlockSortingInput(currentProps.globalSort, "kanban.globalSort") } : {}
14132
14468
  });
14133
14469
  delete props.quickCreatePopup;
14134
14470
  delete props.quickCreatePopupSettings;
@@ -15069,6 +15405,31 @@ class FlowSurfacesService {
15069
15405
  usesAssociationValueBinding: false
15070
15406
  };
15071
15407
  }
15408
+ collectionFieldHasRequiredValidation(field) {
15409
+ var _a, _b, _c;
15410
+ const rules = [
15411
+ ...import_lodash.default.castArray(((_a = field == null ? void 0 : field.validation) == null ? void 0 : _a.rules) || []),
15412
+ ...import_lodash.default.castArray(((_c = (_b = field == null ? void 0 : field.options) == null ? void 0 : _b.validation) == null ? void 0 : _c.rules) || [])
15413
+ ];
15414
+ return rules.some((rule) => String((rule == null ? void 0 : rule.name) || "").trim() === "required");
15415
+ }
15416
+ buildRequiredCollectionFieldFormWrapperDefaults(input) {
15417
+ if (!REQUIRED_COLLECTION_FIELD_FORM_WRAPPER_USES.has(input.wrapperUse || "") || !this.collectionFieldHasRequiredValidation(input.field)) {
15418
+ return {};
15419
+ }
15420
+ return {
15421
+ props: {
15422
+ required: true
15423
+ },
15424
+ stepParams: {
15425
+ editItemSettings: {
15426
+ required: {
15427
+ required: true
15428
+ }
15429
+ }
15430
+ }
15431
+ };
15432
+ }
15072
15433
  getCollectionFieldOrBadRequest(collection, fieldPath, context) {
15073
15434
  const field = (0, import_service_helpers.resolveFieldFromCollection)(collection, fieldPath);
15074
15435
  if (!field) {