@nocobase/plugin-flow-engine 2.1.0-beta.22 → 2.1.0-beta.24

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.
@@ -77,6 +77,7 @@ var import_route_sync = require("./route-sync");
77
77
  var import_surface_context = require("./surface-context");
78
78
  var import_context = require("./context");
79
79
  var import_configure_options = require("./configure-options");
80
+ var import_public_compatibility = require("./public-compatibility");
80
81
  var import_service_helpers = require("./service-helpers");
81
82
  var import_errors2 = require("./reaction/errors");
82
83
  var import_template_display = require("./template-display");
@@ -262,6 +263,7 @@ const APPROVAL_CONFIRM_ACTION_USES = /* @__PURE__ */ new Set([
262
263
  "ApplyFormWithdrawModel"
263
264
  ]);
264
265
  const APPROVAL_ASSIGN_ACTION_USES = /* @__PURE__ */ new Set(["ApplyFormSubmitModel", "ApplyFormSaveDraftModel"]);
266
+ const UPDATE_ASSIGN_ACTION_USES = /* @__PURE__ */ new Set(["UpdateRecordActionModel", "BulkUpdateActionModel"]);
265
267
  const APPROVAL_COMMENT_ACTION_USES = /* @__PURE__ */ new Set([
266
268
  "ProcessFormApproveModel",
267
269
  "ProcessFormRejectModel",
@@ -288,6 +290,15 @@ const POPUP_RECORD_ACTION_CONTAINER_USES = /* @__PURE__ */ new Set([
288
290
  "GridCardItemModel"
289
291
  ]);
290
292
  const POPUP_UNSUPPORTED_COLLECTION_SCENES = /* @__PURE__ */ new Set(["select", "subForm", "bulkEditForm"]);
293
+ const POPUP_ASSOCIATED_RECORDS_BLOCK_USES = /* @__PURE__ */ new Set([
294
+ "TableBlockModel",
295
+ "CalendarBlockModel",
296
+ "KanbanBlockModel",
297
+ "ListBlockModel",
298
+ "GridCardBlockModel",
299
+ "MapBlockModel",
300
+ "CommentsBlockModel"
301
+ ]);
291
302
  const POPUP_COLLECTION_BLOCK_SCENES = {
292
303
  CreateFormModel: ["new"],
293
304
  EditFormModel: ["one", "many"],
@@ -306,6 +317,15 @@ const POPUP_COLLECTION_BLOCK_SCENES = {
306
317
  FilterFormBlockModel: ["filter"],
307
318
  FormBlockModel: []
308
319
  };
320
+ const UPDATE_ACTION_ASSIGN_SETTINGS_ASSIGNED_VALUES_PATH = [
321
+ "stepParams",
322
+ "assignSettings",
323
+ "assignFieldValues",
324
+ "assignedValues"
325
+ ];
326
+ const UPDATE_ACTION_APPLY_ASSIGNED_VALUES_PATH = ["stepParams", "apply", "apply", "assignedValues"];
327
+ const UPDATE_ACTION_ASSIGN_SETTINGS_STEP_PATH = ["assignSettings", "assignFieldValues", "assignedValues"];
328
+ const UPDATE_ACTION_APPLY_STEP_PATH = ["apply", "apply", "assignedValues"];
309
329
  const TABLE_COLUMN_STEP_PARAM_MIRRORS = [
310
330
  { domain: "props", key: "title", stepParamsPath: ["tableColumnSettings", "title", "title"] },
311
331
  { domain: "props", key: "tooltip", stepParamsPath: ["tableColumnSettings", "tooltip", "tooltip"] },
@@ -994,8 +1014,7 @@ class FlowSurfacesService {
994
1014
  fieldTypes: relationFieldTypes,
995
1015
  current: (0, import_service_utils.buildDefinedPayload)({
996
1016
  fieldType: (0, import_field_type_resolver.getPublicFieldTypeForUse)(((_g = (_f = innerField == null ? void 0 : innerField.stepParams) == null ? void 0 : _f.fieldBinding) == null ? void 0 : _g.use) || (innerField == null ? void 0 : innerField.use)),
997
- fields: this.collectRelationNestedFieldPaths(innerField),
998
- selectorFields: this.collectRelationSelectorFieldPaths(innerField),
1017
+ fields: this.collectRelationFieldPaths(innerField),
999
1018
  titleField: ((_h = innerField == null ? void 0 : innerField.props) == null ? void 0 : _h.titleField) || ((_i = node == null ? void 0 : node.props) == null ? void 0 : _i.titleField)
1000
1019
  }),
1001
1020
  defaults: (0, import_service_utils.buildDefinedPayload)({
@@ -1014,12 +1033,11 @@ class FlowSurfacesService {
1014
1033
  const defaults = {
1015
1034
  titleField: defaultTitleField
1016
1035
  };
1017
- if (["subForm", "subFormList", "subDetails", "subDetailsList", "subTable", "popupSubTable"].includes(fieldType) && defaultTitleField) {
1036
+ if (["picker", "subForm", "subFormList", "subDetails", "subDetailsList", "subTable", "popupSubTable"].includes(
1037
+ fieldType
1038
+ ) && defaultTitleField) {
1018
1039
  defaults.fields = [defaultTitleField];
1019
1040
  }
1020
- if (fieldType === "picker" && defaultTitleField) {
1021
- defaults.selectorFields = [defaultTitleField];
1022
- }
1023
1041
  return {
1024
1042
  fieldType,
1025
1043
  defaults: (0, import_service_utils.buildDefinedPayload)(defaults)
@@ -1060,6 +1078,9 @@ class FlowSurfacesService {
1060
1078
  }
1061
1079
  return void 0;
1062
1080
  }
1081
+ collectRelationFieldPaths(fieldNode) {
1082
+ return this.collectRelationNestedFieldPaths(fieldNode) || this.collectRelationSelectorFieldPaths(fieldNode);
1083
+ }
1063
1084
  collectRelationSelectorFieldPaths(fieldNode) {
1064
1085
  var _a, _b, _c, _d, _e, _f;
1065
1086
  const fieldUse = String(((_b = (_a = fieldNode == null ? void 0 : fieldNode.stepParams) == null ? void 0 : _a.fieldBinding) == null ? void 0 : _b.use) || (fieldNode == null ? void 0 : fieldNode.use) || "").trim();
@@ -1067,7 +1088,7 @@ class FlowSurfacesService {
1067
1088
  return void 0;
1068
1089
  }
1069
1090
  const table = import_lodash.default.castArray(((_e = (_d = (_c = fieldNode == null ? void 0 : fieldNode.subModels) == null ? void 0 : _c["grid-block"]) == null ? void 0 : _d.subModels) == null ? void 0 : _e.items) || []).find(
1070
- (item) => (item == null ? void 0 : item.use) === "TableBlockModel"
1091
+ (item) => (item == null ? void 0 : item.use) === "TableSelectModel" || (item == null ? void 0 : item.use) === "TableBlockModel"
1071
1092
  );
1072
1093
  return import_lodash.default.castArray(((_f = table == null ? void 0 : table.subModels) == null ? void 0 : _f.columns) || []).map((item) => {
1073
1094
  var _a2, _b2, _c2;
@@ -1110,6 +1131,9 @@ class FlowSurfacesService {
1110
1131
  isPopupCollectionBlockSceneUnsupported(scene) {
1111
1132
  return POPUP_UNSUPPORTED_COLLECTION_SCENES.has(scene);
1112
1133
  }
1134
+ supportsPopupAssociatedRecordsBinding(blockUse) {
1135
+ return POPUP_ASSOCIATED_RECORDS_BLOCK_USES.has(blockUse);
1136
+ }
1113
1137
  isPopupCollectionBlockVisibleForScene(blockUse, popupProfile) {
1114
1138
  const blockScenes = this.getPopupCollectionBlockScenes(blockUse);
1115
1139
  if (this.isPopupCollectionBlockSceneUnsupported(popupProfile.scene)) {
@@ -1282,7 +1306,7 @@ class FlowSurfacesService {
1282
1306
  collectionName: popupProfile.collectionName
1283
1307
  });
1284
1308
  }
1285
- if (popupProfile.hasCurrentRecord && associationFields.length) {
1309
+ if (this.supportsPopupAssociatedRecordsBinding(blockUse) && popupProfile.hasCurrentRecord && associationFields.length) {
1286
1310
  bindings.push({
1287
1311
  key: "associatedRecords",
1288
1312
  label: "Associated records",
@@ -1526,7 +1550,17 @@ class FlowSurfacesService {
1526
1550
  );
1527
1551
  }
1528
1552
  const resourceBindings = this.buildPopupBlockResourceBindings(input.blockUse, input.popupProfile);
1529
- const requestedBinding = ((_b = input.semanticResource) == null ? void 0 : _b.binding) || this.classifyPopupRawResourceInit(input.popupProfile, input.resourceInit || {});
1553
+ let requestedBinding = ((_b = input.semanticResource) == null ? void 0 : _b.binding) || this.classifyPopupRawResourceInit(input.popupProfile, input.resourceInit || {});
1554
+ const useLegacyAssociationPopupCurrentRecord = this.shouldUseLegacyAssociationPopupCurrentRecordBinding({
1555
+ blockUse: input.blockUse,
1556
+ popupProfile: input.popupProfile,
1557
+ requestedBinding,
1558
+ semanticResource: input.semanticResource,
1559
+ resourceInit: input.resourceInit || {}
1560
+ });
1561
+ if (useLegacyAssociationPopupCurrentRecord) {
1562
+ requestedBinding = "currentRecord";
1563
+ }
1530
1564
  if (!this.isCatalogBlockVisibleForPopupProfile(input.blockUse, input.popupProfile) && requestedBinding && !["currentCollection", "otherRecords"].includes(requestedBinding)) {
1531
1565
  (0, import_errors.throwBadRequest)(
1532
1566
  `flowSurfaces ${input.actionName} block '${blockKey}' is not available in ${this.describePopupKind(
@@ -1548,6 +1582,17 @@ class FlowSurfacesService {
1548
1582
  resource: input.semanticResource
1549
1583
  });
1550
1584
  }
1585
+ if (useLegacyAssociationPopupCurrentRecord) {
1586
+ return this.compilePopupSemanticResourceInit({
1587
+ actionName: input.actionName,
1588
+ blockUse: input.blockUse,
1589
+ popupProfile: input.popupProfile,
1590
+ resourceBindings,
1591
+ resource: {
1592
+ binding: "currentRecord"
1593
+ }
1594
+ });
1595
+ }
1551
1596
  return this.assertPopupRawResourceInit({
1552
1597
  actionName: input.actionName,
1553
1598
  blockUse: input.blockUse,
@@ -1556,6 +1601,25 @@ class FlowSurfacesService {
1556
1601
  resourceInit: input.resourceInit || {}
1557
1602
  });
1558
1603
  }
1604
+ shouldUseLegacyAssociationPopupCurrentRecordBinding(input) {
1605
+ return !input.semanticResource && input.requestedBinding === "currentCollection" && this.shouldNormalizeLegacyAssociationPopupRecordBlockResource({
1606
+ blockUse: input.blockUse,
1607
+ popupProfile: input.popupProfile,
1608
+ resourceInit: input.resourceInit
1609
+ });
1610
+ }
1611
+ shouldNormalizeLegacyAssociationPopupRecordBlockResource(input) {
1612
+ if (!["DetailsBlockModel", "EditFormModel"].includes(input.blockUse)) {
1613
+ return false;
1614
+ }
1615
+ if (input.popupProfile.popupKind !== "associationPopup" || !input.popupProfile.hasCurrentRecord || !input.popupProfile.hasAssociationContext) {
1616
+ return false;
1617
+ }
1618
+ const normalized = (0, import_service_utils.normalizeSimpleResourceInit)(input.resourceInit) || {};
1619
+ const popupDataSourceKey = input.popupProfile.dataSourceKey || "main";
1620
+ const resourceDataSourceKey = normalized.dataSourceKey || "main";
1621
+ return !!input.popupProfile.collectionName && resourceDataSourceKey === popupDataSourceKey && normalized.collectionName === input.popupProfile.collectionName && !(0, import_service_helpers.hasConfiguredFlowContextValue)(normalized.filterByTk) && !(0, import_service_helpers.hasConfiguredFlowContextValue)(normalized.associationName) && !(0, import_service_helpers.hasConfiguredFlowContextValue)(normalized.sourceId);
1622
+ }
1559
1623
  compilePopupSemanticResourceInit(input) {
1560
1624
  const binding = input.resource.binding;
1561
1625
  const supportedBinding = input.resourceBindings.find((item) => item.key === binding);
@@ -3893,83 +3957,89 @@ class FlowSurfacesService {
3893
3957
  if (!import_lodash.default.isPlainObject(values.changes) || !Object.keys(values.changes).length) {
3894
3958
  (0, import_errors.throwBadRequest)("flowSurfaces configure requires a non-empty changes object");
3895
3959
  }
3896
- (0, import_service_utils.ensureNoRawSimpleChangeKeys)(values.changes);
3960
+ let changes = values.changes;
3961
+ (0, import_service_utils.ensureNoRawSimpleChangeKeys)(changes);
3897
3962
  const resolved = await this.locator.resolve(target, options);
3898
3963
  const current = await this.loadResolvedNode(resolved, options.transaction);
3964
+ changes = (0, import_public_compatibility.normalizeFlowSurfacePublicSortingAlias)({
3965
+ context: "flowSurfaces configure changes",
3966
+ use: current == null ? void 0 : current.use,
3967
+ settings: changes
3968
+ });
3899
3969
  if (resolved.kind === "page" && resolved.pageRoute) {
3900
- return this.configurePage(target, values.changes, options);
3970
+ return this.configurePage(target, changes, options);
3901
3971
  }
3902
3972
  if (resolved.kind === "tab" && resolved.tabRoute) {
3903
- return this.configureTab(target, values.changes, options);
3973
+ return this.configureTab(target, changes, options);
3904
3974
  }
3905
3975
  if ((current == null ? void 0 : current.use) === "TableBlockModel") {
3906
- return this.configureTableBlock(target, values.changes, options);
3976
+ return this.configureTableBlock(target, changes, options);
3907
3977
  }
3908
3978
  if ((current == null ? void 0 : current.use) === "CalendarBlockModel") {
3909
- return this.configureCalendarBlock(target, current, values.changes, options);
3979
+ return this.configureCalendarBlock(target, current, changes, options);
3910
3980
  }
3911
3981
  if ((current == null ? void 0 : current.use) === "TreeBlockModel") {
3912
- return this.configureTreeBlock(target, current, values.changes, options);
3982
+ return this.configureTreeBlock(target, current, changes, options);
3913
3983
  }
3914
3984
  if ((current == null ? void 0 : current.use) === "KanbanBlockModel") {
3915
- return this.configureKanbanBlock(target, current, values.changes, options);
3985
+ return this.configureKanbanBlock(target, current, changes, options);
3916
3986
  }
3917
3987
  if (SIMPLE_FORM_BLOCK_USES.has((current == null ? void 0 : current.use) || "")) {
3918
- return this.configureFormBlock(target, current.use, values.changes, options);
3988
+ return this.configureFormBlock(target, current.use, changes, options);
3919
3989
  }
3920
3990
  if (DETAILS_BLOCK_USES.has((current == null ? void 0 : current.use) || "")) {
3921
- return this.configureDetailsBlock(target, values.changes, options);
3991
+ return this.configureDetailsBlock(target, changes, options);
3922
3992
  }
3923
3993
  if ((current == null ? void 0 : current.use) === "FilterFormBlockModel") {
3924
- return this.configureFilterFormBlock(target, values.changes, options);
3994
+ return this.configureFilterFormBlock(target, changes, options);
3925
3995
  }
3926
3996
  if (LIST_BLOCK_USES.has((current == null ? void 0 : current.use) || "")) {
3927
- return this.configureListBlock(target, values.changes, options);
3997
+ return this.configureListBlock(target, changes, options);
3928
3998
  }
3929
3999
  if (GRID_CARD_BLOCK_USES.has((current == null ? void 0 : current.use) || "")) {
3930
- return this.configureGridCardBlock(target, values.changes, options);
4000
+ return this.configureGridCardBlock(target, changes, options);
3931
4001
  }
3932
4002
  if (import_node_use_sets.JS_BLOCK_USES.has((current == null ? void 0 : current.use) || "")) {
3933
- return this.configureJSBlock(target, values.changes, options);
4003
+ return this.configureJSBlock(target, changes, options);
3934
4004
  }
3935
4005
  if ((current == null ? void 0 : current.use) === "MarkdownBlockModel") {
3936
- return this.configureMarkdownBlock(target, values.changes, options);
4006
+ return this.configureMarkdownBlock(target, changes, options);
3937
4007
  }
3938
4008
  if ((current == null ? void 0 : current.use) === "IframeBlockModel") {
3939
- return this.configureIframeBlock(target, values.changes, options);
4009
+ return this.configureIframeBlock(target, changes, options);
3940
4010
  }
3941
4011
  if ((current == null ? void 0 : current.use) === "ChartBlockModel") {
3942
- return this.configureChartBlock(target, values.changes, options);
4012
+ return this.configureChartBlock(target, changes, options);
3943
4013
  }
3944
4014
  if ((current == null ? void 0 : current.use) === "ActionPanelBlockModel") {
3945
- return this.configureActionPanelBlock(target, values.changes, options);
4015
+ return this.configureActionPanelBlock(target, changes, options);
3946
4016
  }
3947
4017
  if ((current == null ? void 0 : current.use) === "MapBlockModel") {
3948
- return this.configureMapBlock(target, values.changes, options);
4018
+ return this.configureMapBlock(target, changes, options);
3949
4019
  }
3950
4020
  if ((current == null ? void 0 : current.use) === "CommentsBlockModel") {
3951
- return this.configureCommentsBlock(target, values.changes, options);
4021
+ return this.configureCommentsBlock(target, changes, options);
3952
4022
  }
3953
4023
  if ((current == null ? void 0 : current.use) === "TableActionsColumnModel") {
3954
- return this.configureActionColumn(target, values.changes, options);
4024
+ return this.configureActionColumn(target, changes, options);
3955
4025
  }
3956
4026
  if (import_node_use_sets.FIELD_WRAPPER_USES.has((current == null ? void 0 : current.use) || "")) {
3957
- return this.configureFieldWrapper(target, current, values.changes, options);
4027
+ return this.configureFieldWrapper(target, current, changes, options);
3958
4028
  }
3959
4029
  if (import_node_use_sets.STANDALONE_FIELD_NODE_USES.has((current == null ? void 0 : current.use) || "")) {
3960
4030
  if ((current == null ? void 0 : current.use) === "JSColumnModel") {
3961
- return this.configureJSColumn(target, values.changes, options);
4031
+ return this.configureJSColumn(target, changes, options);
3962
4032
  }
3963
4033
  if ((current == null ? void 0 : current.use) === "DividerItemModel") {
3964
- return this.configureDividerItem(target, values.changes, options);
4034
+ return this.configureDividerItem(target, changes, options);
3965
4035
  }
3966
- return this.configureJSItem(target, values.changes, options);
4036
+ return this.configureJSItem(target, changes, options);
3967
4037
  }
3968
4038
  if ((0, import_service_utils.isFieldNodeUse)(current == null ? void 0 : current.use)) {
3969
- return this.configureFieldNode(target, values.changes, options);
4039
+ return this.configureFieldNode(target, changes, options);
3970
4040
  }
3971
4041
  if (import_node_use_sets.ACTION_BUTTON_USES.has((current == null ? void 0 : current.use) || "")) {
3972
- return this.configureActionNode(target, current.use, values.changes, {
4042
+ return this.configureActionNode(target, current.use, changes, {
3973
4043
  ...options,
3974
4044
  current
3975
4045
  });
@@ -5072,7 +5142,6 @@ class FlowSurfacesService {
5072
5142
  ...fieldSpec.type ? { type: fieldSpec.type } : {},
5073
5143
  ...fieldSpec.fieldType ? { fieldType: fieldSpec.fieldType } : {},
5074
5144
  ...!import_lodash.default.isUndefined(fieldSpec.fields) ? { fields: fieldSpec.fields } : {},
5075
- ...!import_lodash.default.isUndefined(fieldSpec.selectorFields) ? { selectorFields: fieldSpec.selectorFields } : {},
5076
5145
  ...fieldSpec.titleField ? { titleField: fieldSpec.titleField } : {},
5077
5146
  ...fieldSpec.openMode ? { openMode: fieldSpec.openMode } : {},
5078
5147
  ...fieldSpec.popupSize ? { popupSize: fieldSpec.popupSize } : {},
@@ -5314,7 +5383,6 @@ class FlowSurfacesService {
5314
5383
  dataSourceKey: resolvedField.dataSourceKey,
5315
5384
  getCollection: (dataSourceKey, collectionName) => this.getCollection(dataSourceKey, collectionName),
5316
5385
  fields: values.fields,
5317
- selectorFields: values.selectorFields,
5318
5386
  titleField: values.titleField,
5319
5387
  openMode: values.openMode,
5320
5388
  popupSize: values.popupSize,
@@ -7883,6 +7951,11 @@ class FlowSurfacesService {
7883
7951
  });
7884
7952
  this.syncFilterActionSettingsForUpdateSettings(current, normalizedValues, nextPayload);
7885
7953
  this.syncMirroredStepParamsForUpdateSettings(current, nextPayload);
7954
+ const updateActionAssignedValues = this.syncUpdateActionAssignedValuesForUpdateSettings(
7955
+ current,
7956
+ normalizedValues,
7957
+ nextPayload
7958
+ );
7886
7959
  const popupActionContext = options.popupActionContext || await this.resolveRecordContextPopupActionContextForHost(current, options.transaction);
7887
7960
  await this.normalizeOpenViewForUpdateSettings(
7888
7961
  options.openViewActionName || "updateSettings",
@@ -7935,6 +8008,9 @@ class FlowSurfacesService {
7935
8008
  };
7936
8009
  }
7937
8010
  await this.repository.patch(nextPayload, { transaction: options.transaction });
8011
+ if (!import_lodash.default.isUndefined(updateActionAssignedValues)) {
8012
+ await this.syncUpdateActionAssignFormItems(current.uid, updateActionAssignedValues, options.transaction);
8013
+ }
7938
8014
  if (!import_lodash.default.isUndefined((_a = nextPayload.stepParams) == null ? void 0 : _a.fieldSettings)) {
7939
8015
  await this.syncFieldBindingSettingsForNode(current, effectiveNode, options.transaction);
7940
8016
  } else if (current.use === "FilterFormItemModel") {
@@ -8057,6 +8133,173 @@ class FlowSurfacesService {
8057
8133
  nextPayload.stepParams = nextStepParams;
8058
8134
  }
8059
8135
  }
8136
+ syncUpdateActionAssignedValuesForUpdateSettings(current, values, nextPayload) {
8137
+ if (!UPDATE_ASSIGN_ACTION_USES.has(current == null ? void 0 : current.use)) {
8138
+ return void 0;
8139
+ }
8140
+ const hasAssignSettingsAssignedValues = import_lodash.default.has(values, UPDATE_ACTION_ASSIGN_SETTINGS_ASSIGNED_VALUES_PATH);
8141
+ const hasApplyAssignedValues = import_lodash.default.has(values, UPDATE_ACTION_APPLY_ASSIGNED_VALUES_PATH);
8142
+ if (!hasAssignSettingsAssignedValues && !hasApplyAssignedValues) {
8143
+ return void 0;
8144
+ }
8145
+ const nextStepParams = import_lodash.default.cloneDeep(nextPayload.stepParams ?? (current == null ? void 0 : current.stepParams) ?? {});
8146
+ const clearsAssignSettingsAssignedValues = hasAssignSettingsAssignedValues && import_lodash.default.isPlainObject(import_lodash.default.get(values, UPDATE_ACTION_ASSIGN_SETTINGS_ASSIGNED_VALUES_PATH)) && !Object.keys(import_lodash.default.get(values, UPDATE_ACTION_ASSIGN_SETTINGS_ASSIGNED_VALUES_PATH)).length;
8147
+ const clearsApplyAssignedValues = hasApplyAssignedValues && import_lodash.default.isPlainObject(import_lodash.default.get(values, UPDATE_ACTION_APPLY_ASSIGNED_VALUES_PATH)) && !Object.keys(import_lodash.default.get(values, UPDATE_ACTION_APPLY_ASSIGNED_VALUES_PATH)).length;
8148
+ const assignSettingsAssignedValues = clearsAssignSettingsAssignedValues ? {} : import_lodash.default.cloneDeep(import_lodash.default.get(nextStepParams, UPDATE_ACTION_ASSIGN_SETTINGS_STEP_PATH));
8149
+ const applyAssignedValues = clearsApplyAssignedValues ? {} : import_lodash.default.cloneDeep(import_lodash.default.get(nextStepParams, UPDATE_ACTION_APPLY_STEP_PATH));
8150
+ if (hasAssignSettingsAssignedValues && hasApplyAssignedValues && !import_lodash.default.isEqual(assignSettingsAssignedValues, applyAssignedValues)) {
8151
+ (0, import_errors.throwBadRequest)(
8152
+ "flowSurfaces updateSettings update action values 'stepParams.assignSettings.assignFieldValues.assignedValues' and 'stepParams.apply.apply.assignedValues' must match"
8153
+ );
8154
+ }
8155
+ const assignedValues = hasAssignSettingsAssignedValues ? assignSettingsAssignedValues : applyAssignedValues;
8156
+ if (!import_lodash.default.isPlainObject(assignedValues)) {
8157
+ (0, import_errors.throwBadRequest)(
8158
+ "flowSurfaces updateSettings update action values 'stepParams.assignSettings.assignFieldValues.assignedValues' requires an object payload"
8159
+ );
8160
+ }
8161
+ import_lodash.default.set(nextStepParams, UPDATE_ACTION_ASSIGN_SETTINGS_STEP_PATH, import_lodash.default.cloneDeep(assignedValues));
8162
+ import_lodash.default.set(nextStepParams, UPDATE_ACTION_APPLY_STEP_PATH, import_lodash.default.cloneDeep(assignedValues));
8163
+ nextPayload.stepParams = nextStepParams;
8164
+ return assignedValues;
8165
+ }
8166
+ async syncUpdateActionAssignFormItems(actionUid, assignedValues, transaction) {
8167
+ var _a, _b, _c, _d, _e, _f;
8168
+ const actionNode = await this.repository.findModelById(actionUid, {
8169
+ transaction,
8170
+ includeAsyncNode: true
8171
+ });
8172
+ if (!UPDATE_ASSIGN_ACTION_USES.has(actionNode == null ? void 0 : actionNode.use)) {
8173
+ return;
8174
+ }
8175
+ const resourceContext = await this.locator.resolveCollectionContext(actionUid, transaction).catch(() => null);
8176
+ const resourceInit = (resourceContext == null ? void 0 : resourceContext.resourceInit) || {};
8177
+ const dataSourceKey = resourceInit.dataSourceKey || "main";
8178
+ const collectionName = resourceInit.collectionName;
8179
+ const assignFormUid = await this.ensureUpdateActionAssignForm(actionNode, resourceInit, transaction);
8180
+ const assignFormGridUid = await this.ensureUpdateActionAssignFormGrid(assignFormUid, transaction);
8181
+ const refreshedGrid = await this.repository.findModelById(assignFormGridUid, {
8182
+ transaction,
8183
+ includeAsyncNode: true
8184
+ });
8185
+ const existingItems = import_lodash.default.castArray(((_a = refreshedGrid == null ? void 0 : refreshedGrid.subModels) == null ? void 0 : _a.items) || []);
8186
+ const existingItemsByFieldPath = /* @__PURE__ */ new Map();
8187
+ existingItems.forEach((item) => {
8188
+ var _a2, _b2, _c2;
8189
+ const fieldPath = String(((_c2 = (_b2 = (_a2 = item == null ? void 0 : item.stepParams) == null ? void 0 : _a2.fieldSettings) == null ? void 0 : _b2.init) == null ? void 0 : _c2.fieldPath) || "").trim();
8190
+ if (fieldPath && !existingItemsByFieldPath.has(fieldPath)) {
8191
+ existingItemsByFieldPath.set(fieldPath, item);
8192
+ }
8193
+ });
8194
+ const nextFieldPaths = new Set(Object.keys(assignedValues || {}).filter((fieldPath) => String(fieldPath).trim()));
8195
+ const keptFieldPaths = /* @__PURE__ */ new Set();
8196
+ for (const staleItem of existingItems) {
8197
+ const fieldPath = String(((_d = (_c = (_b = staleItem == null ? void 0 : staleItem.stepParams) == null ? void 0 : _b.fieldSettings) == null ? void 0 : _c.init) == null ? void 0 : _d.fieldPath) || "").trim();
8198
+ if (!fieldPath || !nextFieldPaths.has(fieldPath) || keptFieldPaths.has(fieldPath)) {
8199
+ await this.repository.remove(staleItem.uid, { transaction });
8200
+ continue;
8201
+ }
8202
+ keptFieldPaths.add(fieldPath);
8203
+ }
8204
+ for (const fieldPath of nextFieldPaths) {
8205
+ const existingItem = existingItemsByFieldPath.get(fieldPath);
8206
+ await this.repository.upsertModel(
8207
+ this.buildUpdateActionAssignFormItemTree({
8208
+ existingItem,
8209
+ uid: existingItem == null ? void 0 : existingItem.uid,
8210
+ fieldUid: (_f = (_e = existingItem == null ? void 0 : existingItem.subModels) == null ? void 0 : _e.field) == null ? void 0 : _f.uid,
8211
+ parentId: assignFormGridUid,
8212
+ dataSourceKey,
8213
+ collectionName,
8214
+ fieldPath,
8215
+ value: assignedValues[fieldPath]
8216
+ }),
8217
+ { transaction }
8218
+ );
8219
+ }
8220
+ }
8221
+ async ensureUpdateActionAssignForm(actionNode, resourceInit, transaction) {
8222
+ var _a;
8223
+ const existing = (_a = actionNode == null ? void 0 : actionNode.subModels) == null ? void 0 : _a.assignForm;
8224
+ if (existing == null ? void 0 : existing.uid) {
8225
+ return existing.uid;
8226
+ }
8227
+ const assignFormUid = (0, import_utils.uid)();
8228
+ await this.repository.upsertModel(
8229
+ {
8230
+ uid: assignFormUid,
8231
+ parentId: actionNode.uid,
8232
+ subKey: "assignForm",
8233
+ subType: "object",
8234
+ use: "AssignFormModel",
8235
+ stepParams: {
8236
+ resourceSettings: {
8237
+ init: import_lodash.default.cloneDeep(resourceInit || {})
8238
+ }
8239
+ }
8240
+ },
8241
+ { transaction }
8242
+ );
8243
+ return assignFormUid;
8244
+ }
8245
+ async ensureUpdateActionAssignFormGrid(assignFormUid, transaction) {
8246
+ return this.ensureGridChild(assignFormUid, "AssignFormGridModel", transaction);
8247
+ }
8248
+ buildUpdateActionAssignFormItemTree(input) {
8249
+ var _a;
8250
+ const init = import_lodash.default.pickBy(
8251
+ {
8252
+ dataSourceKey: input.dataSourceKey,
8253
+ collectionName: input.collectionName,
8254
+ fieldPath: input.fieldPath
8255
+ },
8256
+ (value) => !import_lodash.default.isUndefined(value)
8257
+ );
8258
+ const fieldUse = this.resolveUpdateActionAssignFormFieldUse(
8259
+ input.dataSourceKey,
8260
+ input.collectionName,
8261
+ input.fieldPath
8262
+ );
8263
+ const existingItem = input.existingItem || {};
8264
+ const existingField = ((_a = existingItem == null ? void 0 : existingItem.subModels) == null ? void 0 : _a.field) || {};
8265
+ const itemStepParams = import_lodash.default.cloneDeep(existingItem.stepParams || {});
8266
+ import_lodash.default.set(itemStepParams, ["fieldSettings", "init"], init);
8267
+ import_lodash.default.set(itemStepParams, ["fieldSettings", "assignValue", "value"], import_lodash.default.cloneDeep(input.value));
8268
+ const fieldStepParams = import_lodash.default.cloneDeep(existingField.stepParams || {});
8269
+ import_lodash.default.set(fieldStepParams, ["fieldSettings", "init"], init);
8270
+ return {
8271
+ uid: input.uid || (0, import_utils.uid)(),
8272
+ parentId: input.parentId,
8273
+ subKey: "items",
8274
+ subType: "array",
8275
+ use: "AssignFormItemModel",
8276
+ stepParams: itemStepParams,
8277
+ subModels: {
8278
+ field: {
8279
+ uid: input.fieldUid || (0, import_utils.uid)(),
8280
+ use: existingField.use || fieldUse,
8281
+ stepParams: fieldStepParams
8282
+ }
8283
+ }
8284
+ };
8285
+ }
8286
+ resolveUpdateActionAssignFormFieldUse(dataSourceKey, collectionName, fieldPath) {
8287
+ const collection = collectionName ? this.getCollection(dataSourceKey, collectionName) : null;
8288
+ const field = (0, import_service_helpers.resolveFieldFromCollection)(collection, fieldPath);
8289
+ if (field) {
8290
+ const registeredBinding = this.resolveRegisteredFieldBinding({
8291
+ containerUse: "AssignFormGridModel",
8292
+ field,
8293
+ dataSourceKey,
8294
+ useStrictOnly: true
8295
+ });
8296
+ if (registeredBinding == null ? void 0 : registeredBinding.modelClassName) {
8297
+ return registeredBinding.modelClassName;
8298
+ }
8299
+ return (0, import_service_helpers.inferFieldMenuEditableFieldUse)((0, import_service_helpers.getFieldInterface)(field)) || "InputFieldModel";
8300
+ }
8301
+ return "InputFieldModel";
8302
+ }
8060
8303
  normalizeCanonicalBlockHeaderWriteForUpdateSettings(current, values) {
8061
8304
  const semanticUse = (0, import_approval.normalizeApprovalSemanticUse)(current == null ? void 0 : current.use);
8062
8305
  if (!CANONICAL_BLOCK_HEADER_USES.has(semanticUse)) {
@@ -11162,7 +11405,6 @@ class FlowSurfacesService {
11162
11405
  "version",
11163
11406
  "fieldType",
11164
11407
  "fields",
11165
- "selectorFields",
11166
11408
  "openMode",
11167
11409
  "popupSize",
11168
11410
  "pageSize",
@@ -11277,7 +11519,7 @@ class FlowSurfacesService {
11277
11519
  let effectiveInnerFieldUse = innerField == null ? void 0 : innerField.use;
11278
11520
  let fieldTypeResolution;
11279
11521
  let relationTitleFieldToApply;
11280
- if ((0, import_service_utils.hasOwnDefined)(changes, "fieldType") || (0, import_service_utils.hasOwnDefined)(changes, "fields") || (0, import_service_utils.hasOwnDefined)(changes, "selectorFields") || (0, import_service_utils.hasOwnDefined)(changes, "titleField") || (0, import_service_utils.hasOwnDefined)(changes, "openMode") || (0, import_service_utils.hasOwnDefined)(changes, "popupSize") || (0, import_service_utils.hasOwnDefined)(changes, "pageSize") || (0, import_service_utils.hasOwnDefined)(changes, "showIndex")) {
11522
+ if ((0, import_service_utils.hasOwnDefined)(changes, "fieldType") || (0, import_service_utils.hasOwnDefined)(changes, "fields") || (0, import_service_utils.hasOwnDefined)(changes, "titleField") || (0, import_service_utils.hasOwnDefined)(changes, "openMode") || (0, import_service_utils.hasOwnDefined)(changes, "popupSize") || (0, import_service_utils.hasOwnDefined)(changes, "pageSize") || (0, import_service_utils.hasOwnDefined)(changes, "showIndex")) {
11281
11523
  if (!innerUid) {
11282
11524
  (0, import_errors.throwConflict)(
11283
11525
  `flowSurfaces configure field wrapper '${current == null ? void 0 : current.use}' cannot resolve inner field`,
@@ -11296,7 +11538,6 @@ class FlowSurfacesService {
11296
11538
  dataSourceKey: (_l = fieldSource.fieldSettingsInit) == null ? void 0 : _l.dataSourceKey,
11297
11539
  getCollection: (dataSourceKey, collectionName) => this.getCollection(dataSourceKey, collectionName),
11298
11540
  fields: changes.fields,
11299
- selectorFields: changes.selectorFields,
11300
11541
  titleField: (0, import_service_utils.hasOwnDefined)(wrapperChanges, "titleField") ? wrapperChanges.titleField : void 0,
11301
11542
  openMode: (0, import_service_utils.hasOwnDefined)(changes, "openMode") ? changes.openMode : void 0,
11302
11543
  popupSize: (0, import_service_utils.hasOwnDefined)(changes, "popupSize") ? changes.popupSize : void 0,
@@ -11327,7 +11568,7 @@ class FlowSurfacesService {
11327
11568
  targetCollection: fieldTypeResolution.targetCollection,
11328
11569
  relationFieldInit: fieldSource.fieldSettingsInit,
11329
11570
  fields: (0, import_service_utils.hasOwnDefined)(changes, "fields") || shouldApplyFieldTypeDefaults ? fieldTypeResolution.fields : void 0,
11330
- selectorFields: (0, import_service_utils.hasOwnDefined)(changes, "selectorFields") || shouldApplyFieldTypeDefaults ? fieldTypeResolution.selectorFields : void 0,
11571
+ selectorFields: (0, import_service_utils.hasOwnDefined)(changes, "fields") || shouldApplyFieldTypeDefaults ? fieldTypeResolution.selectorFields : void 0,
11331
11572
  titleField: relationTitleFieldToApply,
11332
11573
  openMode: fieldTypeResolution.openMode,
11333
11574
  popupSize: fieldTypeResolution.popupSize,
@@ -11547,6 +11788,12 @@ class FlowSurfacesService {
11547
11788
  }
11548
11789
  return import_lodash.default.cloneDeep(value);
11549
11790
  }
11791
+ normalizeActionAssignValues(actionName, value) {
11792
+ if (!import_lodash.default.isPlainObject(value)) {
11793
+ (0, import_errors.throwBadRequest)(`flowSurfaces ${actionName} assignValues must be an object`);
11794
+ }
11795
+ return import_lodash.default.cloneDeep(value);
11796
+ }
11550
11797
  async configureActionNode(target, use, changes, options) {
11551
11798
  changes = await this.normalizeActionPanelActionChanges(changes, options);
11552
11799
  const allowedKeys = (0, import_configure_options.getConfigureOptionKeysForUse)(use);
@@ -11634,7 +11881,7 @@ class FlowSurfacesService {
11634
11881
  stepParams.submitSettings = {
11635
11882
  confirm: (0, import_service_utils.normalizeSimpleConfirm)(changes.confirm)
11636
11883
  };
11637
- } else if (["UpdateRecordActionModel", "BulkUpdateActionModel"].includes(use)) {
11884
+ } else if (UPDATE_ASSIGN_ACTION_USES.has(use)) {
11638
11885
  stepParams.assignSettings = {
11639
11886
  confirm: (0, import_service_utils.normalizeSimpleConfirm)(changes.confirm)
11640
11887
  };
@@ -11643,25 +11890,26 @@ class FlowSurfacesService {
11643
11890
  }
11644
11891
  }
11645
11892
  if ((0, import_service_utils.hasOwnDefined)(changes, "assignValues")) {
11893
+ const assignValues = this.normalizeActionAssignValues("configure", changes.assignValues);
11646
11894
  if (APPROVAL_ASSIGN_ACTION_USES.has(use)) {
11647
11895
  stepParams.clickSettings = {
11648
11896
  ...stepParams.clickSettings || {},
11649
11897
  assignFieldValues: {
11650
- assignedValues: changes.assignValues
11898
+ assignedValues: assignValues
11651
11899
  }
11652
11900
  };
11653
- } else if (!["UpdateRecordActionModel", "BulkUpdateActionModel"].includes(use)) {
11901
+ } else if (!UPDATE_ASSIGN_ACTION_USES.has(use)) {
11654
11902
  (0, import_errors.throwBadRequest)(`flowSurfaces configure action '${use}' does not support assignValues`);
11655
11903
  } else {
11656
11904
  stepParams.assignSettings = {
11657
11905
  ...stepParams.assignSettings || {},
11658
11906
  assignFieldValues: {
11659
- assignedValues: changes.assignValues
11907
+ assignedValues: assignValues
11660
11908
  }
11661
11909
  };
11662
11910
  stepParams.apply = {
11663
11911
  apply: {
11664
- assignedValues: changes.assignValues
11912
+ assignedValues: assignValues
11665
11913
  }
11666
11914
  };
11667
11915
  }
@@ -11677,7 +11925,7 @@ class FlowSurfacesService {
11677
11925
  };
11678
11926
  }
11679
11927
  if ((0, import_service_utils.hasOwnDefined)(changes, "updateMode")) {
11680
- if (!["UpdateRecordActionModel", "BulkUpdateActionModel"].includes(use)) {
11928
+ if (!UPDATE_ASSIGN_ACTION_USES.has(use)) {
11681
11929
  (0, import_errors.throwBadRequest)(`flowSurfaces configure action '${use}' does not support updateMode`);
11682
11930
  }
11683
11931
  stepParams.assignSettings = {
@@ -14874,10 +15122,12 @@ class FlowSurfacesService {
14874
15122
  }
14875
15123
  if (input.fieldUse === "RecordPickerFieldModel") {
14876
15124
  await this.applyRecordPickerFieldTypeSettings(input);
15125
+ } else if (input.fieldUse === "PopupSubTableFieldModel") {
15126
+ await this.ensureRelationSelectorGridTable(input);
14877
15127
  }
14878
15128
  }
14879
15129
  async applyRecordPickerFieldTypeSettings(input) {
14880
- var _a, _b, _c;
15130
+ var _a;
14881
15131
  const fieldNode = await this.repository.findModelById(input.fieldUid, {
14882
15132
  transaction: input.transaction,
14883
15133
  includeAsyncNode: true
@@ -14902,6 +15152,10 @@ class FlowSurfacesService {
14902
15152
  { transaction: input.transaction }
14903
15153
  );
14904
15154
  }
15155
+ await this.ensureRelationSelectorGridTable(input);
15156
+ }
15157
+ async ensureRelationSelectorGridTable(input) {
15158
+ var _a, _b, _c;
14905
15159
  if (!input.selectorFields) {
14906
15160
  return;
14907
15161
  }
@@ -14918,6 +15172,7 @@ class FlowSurfacesService {
14918
15172
  parentId: input.fieldUid,
14919
15173
  subKey: "grid-block",
14920
15174
  subType: "object",
15175
+ async: true,
14921
15176
  use: "BlockGridModel"
14922
15177
  },
14923
15178
  { transaction: input.transaction }
@@ -14930,30 +15185,67 @@ class FlowSurfacesService {
14930
15185
  if (!(grid == null ? void 0 : grid.uid)) {
14931
15186
  return;
14932
15187
  }
14933
- const existingTable = import_lodash.default.castArray(((_b = grid == null ? void 0 : grid.subModels) == null ? void 0 : _b.items) || []).find(
14934
- (item) => (item == null ? void 0 : item.use) === "TableBlockModel"
14935
- );
15188
+ const gridItems = import_lodash.default.castArray(((_a = grid == null ? void 0 : grid.subModels) == null ? void 0 : _a.items) || []);
15189
+ const existingTable = gridItems.find((item) => (item == null ? void 0 : item.use) === "TableSelectModel") || gridItems.find((item) => (item == null ? void 0 : item.use) === "TableBlockModel");
14936
15190
  const tableUid = (existingTable == null ? void 0 : existingTable.uid) || (0, import_utils.uid)();
14937
- if (!(existingTable == null ? void 0 : existingTable.uid)) {
14938
- await this.repository.upsertModel(
14939
- {
14940
- uid: tableUid,
14941
- parentId: grid.uid,
14942
- subKey: "items",
14943
- subType: "array",
14944
- use: "TableBlockModel",
14945
- stepParams: {
14946
- resourceSettings: {
14947
- init: {
14948
- dataSourceKey: ((_c = input.targetCollection) == null ? void 0 : _c.dataSourceKey) || "main",
14949
- collectionName: (0, import_service_helpers.getCollectionName)(input.targetCollection)
14950
- }
15191
+ for (const item of gridItems) {
15192
+ if ((item == null ? void 0 : item.uid) && item.uid !== tableUid) {
15193
+ await this.removeNodeTreeWithBindings(item.uid, input.transaction);
15194
+ }
15195
+ }
15196
+ await this.repository.upsertModel(
15197
+ {
15198
+ ...import_lodash.default.omit(import_lodash.default.cloneDeep(existingTable || {}), [
15199
+ "uid",
15200
+ "use",
15201
+ "subModels",
15202
+ "sortIndex",
15203
+ "parentId",
15204
+ "subKey",
15205
+ "subType"
15206
+ ]),
15207
+ uid: tableUid,
15208
+ parentId: grid.uid,
15209
+ subKey: "items",
15210
+ subType: "array",
15211
+ use: "TableSelectModel",
15212
+ stepParams: import_lodash.default.merge({}, import_lodash.default.cloneDeep((existingTable == null ? void 0 : existingTable.stepParams) || {}), {
15213
+ resourceSettings: {
15214
+ init: {
15215
+ dataSourceKey: ((_b = input.targetCollection) == null ? void 0 : _b.dataSourceKey) || "main",
15216
+ collectionName: (0, import_service_helpers.getCollectionName)(input.targetCollection)
14951
15217
  }
14952
15218
  }
15219
+ })
15220
+ },
15221
+ { transaction: input.transaction }
15222
+ );
15223
+ const layout = {
15224
+ rows: {
15225
+ row1: [[tableUid]]
15226
+ },
15227
+ sizes: {
15228
+ row1: [24]
15229
+ },
15230
+ rowOrder: ["row1"]
15231
+ };
15232
+ await this.repository.patch(
15233
+ {
15234
+ uid: grid.uid,
15235
+ props: {
15236
+ ...grid.props || {},
15237
+ ...layout
14953
15238
  },
14954
- { transaction: input.transaction }
14955
- );
14956
- }
15239
+ stepParams: {
15240
+ ...grid.stepParams || {},
15241
+ [GRID_SETTINGS_FLOW_KEY]: {
15242
+ ...((_c = grid.stepParams) == null ? void 0 : _c[GRID_SETTINGS_FLOW_KEY]) || {},
15243
+ [GRID_SETTINGS_LAYOUT_STEP_KEY]: layout
15244
+ }
15245
+ }
15246
+ },
15247
+ { transaction: input.transaction }
15248
+ );
14957
15249
  await this.replaceFieldSubModelArray({
14958
15250
  parentUid: tableUid,
14959
15251
  subKey: "columns",