@alfresco/adf-process-services-cloud 9.2.0-35585925590 → 9.2.0-35636294809

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.
@@ -8693,6 +8693,7 @@ class FormCloudComponent extends FormBaseComponent {
8693
8693
  }
8694
8694
  refreshFormData(previousData = []) {
8695
8695
  const snapshot = this.snapshotRuntimeState();
8696
+ const variableSnapshot = this.snapshotVariablesRuntimeState();
8696
8697
  this.mergeProcessVariables(this.data ?? []);
8697
8698
  this.form = this.parseForm(this.formCloudRepresentationJSON);
8698
8699
  if (!this.form) {
@@ -8700,6 +8701,7 @@ class FormCloudComponent extends FormBaseComponent {
8700
8701
  }
8701
8702
  const changedFieldIds = this.getChangedFieldIds(previousData, this.data ?? []);
8702
8703
  this.restoreRuntimeState(this.form, snapshot, changedFieldIds);
8704
+ this.restoreVariablesRuntimeState(this.form, variableSnapshot, changedFieldIds, this.data ?? []);
8703
8705
  this.setCheckParentVisibilityForValidationOnFields();
8704
8706
  this.visibilityService.refreshVisibility(this.form, this.data);
8705
8707
  this.form.validateForm();
@@ -8721,7 +8723,8 @@ class FormCloudComponent extends FormBaseComponent {
8721
8723
  const byName = new Map();
8722
8724
  for (const variable of [...existing, ...updates]) {
8723
8725
  if (variable?.name) {
8724
- byName.set(variable.name, variable);
8726
+ const name = variable.name.startsWith('variables.') ? variable.name.slice('variables.'.length) : variable.name;
8727
+ byName.set(name, variable);
8725
8728
  }
8726
8729
  }
8727
8730
  this.formCloudRepresentationJSON.processVariables = Array.from(byName.values());
@@ -8771,6 +8774,45 @@ class FormCloudComponent extends FormBaseComponent {
8771
8774
  field.visibilityCondition = prior.visibilityCondition;
8772
8775
  }
8773
8776
  }
8777
+ snapshotVariablesRuntimeState() {
8778
+ const snapshot = new Map();
8779
+ if (!this.form?.variables?.length) {
8780
+ return snapshot;
8781
+ }
8782
+ for (const variable of this.form.variables) {
8783
+ snapshot.set(variable.id, {
8784
+ value: variable.value,
8785
+ runtimeSet: variable.runtimeSet
8786
+ });
8787
+ }
8788
+ return snapshot;
8789
+ }
8790
+ restoreVariablesRuntimeState(form, snapshot, changedVariableNames, updates) {
8791
+ if (!form?.variables?.length || !snapshot.size) {
8792
+ return;
8793
+ }
8794
+ for (const variable of form.variables) {
8795
+ const prior = snapshot.get(variable.id);
8796
+ if (!prior?.runtimeSet) {
8797
+ continue;
8798
+ }
8799
+ const identifiers = [variable.id, variable.name, `variables.${variable.name}`];
8800
+ const changedIdentifier = identifiers.find((identifier) => changedVariableNames.has(identifier));
8801
+ /*
8802
+ Form variables are shared with the stored representation, so a value set at runtime survives
8803
+ the re-parse on its own. It has to be cleared explicitly once the refresh brings a newer value,
8804
+ otherwise the runtime value would mask every later update from the server.
8805
+ */
8806
+ if (changedIdentifier) {
8807
+ const refreshed = updates.find((update) => update?.name === changedIdentifier);
8808
+ variable.value = refreshed ? refreshed.value : variable.value;
8809
+ variable.runtimeSet = false;
8810
+ continue;
8811
+ }
8812
+ variable.value = prior.value;
8813
+ variable.runtimeSet = true;
8814
+ }
8815
+ }
8774
8816
  recomputeVisibleOutcomes() {
8775
8817
  const outcomes = this.form?.outcomes;
8776
8818
  if (!outcomes) {
@@ -9941,12 +9983,25 @@ class DropdownCloudWidgetComponent extends WidgetComponent {
9941
9983
  this.dropdownControl.setValue(value, { emitEvent: false });
9942
9984
  });
9943
9985
  this.setupDropdown();
9944
- this.formService.onFormVariableChanged.subscribe(({ field }) => {
9945
- if (field.id === this.field.id) {
9986
+ /*
9987
+ Wired once: both read `this.field` when they emit, so they survive every later setup run.
9988
+ Re-wiring them on each setup would stack subscriptions and duplicate the events they raise.
9989
+ */
9990
+ this.subscribeToInputChanges();
9991
+ this.initFilter();
9992
+ this.formService.onFormVariableChanged.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(({ field }) => {
9993
+ if (this.isDependentOnChangedVariable(field)) {
9946
9994
  this.setupDropdown();
9947
9995
  }
9948
9996
  });
9949
9997
  }
9998
+ isDependentOnChangedVariable(field) {
9999
+ const variableName = this.field?.variableConfig?.variableName;
10000
+ if (field.id === this.field.id) {
10001
+ return true;
10002
+ }
10003
+ return this.isVariableOptionType && !!variableName && field?.variableConfig?.variableName === variableName;
10004
+ }
9950
10005
  computeReadOnlyDisplayValue() {
9951
10006
  const value = this.field.value;
9952
10007
  const isFormattableValue = value != null && (typeof value !== 'string' || this.formatter.hasFormatter(this.field.type));
@@ -9988,8 +10043,6 @@ class DropdownCloudWidgetComponent extends WidgetComponent {
9988
10043
  this.updateOptions();
9989
10044
  this.setFormControlValue();
9990
10045
  this.updateFormControlState();
9991
- this.subscribeToInputChanges();
9992
- this.initFilter();
9993
10046
  this.handleErrors();
9994
10047
  }
9995
10048
  subscribeToInputChanges() {
@@ -10065,10 +10118,8 @@ class DropdownCloudWidgetComponent extends WidgetComponent {
10065
10118
  persistFieldOptionsFromVariable() {
10066
10119
  const optionsPath = this.field?.variableConfig?.optionsPath ?? this.defaultVariableOptionPath;
10067
10120
  const variableName = this.field?.variableConfig?.variableName;
10068
- const processVariables = this.field?.form?.processVariables;
10069
- const formVariables = this.field?.form?.variables;
10070
- const dropdownOptions = this.getOptionsFromVariable(processVariables, formVariables, variableName);
10071
- if (dropdownOptions) {
10121
+ const dropdownOptions = this.field?.form?.resolveVariableValue(variableName);
10122
+ if (dropdownOptions != null) {
10072
10123
  const formVariableOptions = this.getOptionsFromPath(dropdownOptions, optionsPath);
10073
10124
  this.updateOptions(formVariableOptions);
10074
10125
  this.resetInvalidValue();
@@ -10117,15 +10168,6 @@ class DropdownCloudWidgetComponent extends WidgetComponent {
10117
10168
  }
10118
10169
  return option;
10119
10170
  }
10120
- getOptionsFromVariable(processVariables, formVariables, variableName) {
10121
- const processVariableDropdownOptions = this.getVariableValueByName(processVariables, variableName);
10122
- const formVariableDropdownOptions = this.getVariableValueByName(formVariables, variableName);
10123
- return processVariableDropdownOptions ?? formVariableDropdownOptions;
10124
- }
10125
- getVariableValueByName(variables, variableName) {
10126
- return variables?.find((variable) => variable?.name === `variables.${variableName}` || variable?.name === variableName)
10127
- ?.value;
10128
- }
10129
10171
  persistFieldOptionsFromRestApi() {
10130
10172
  if (this.isValidRestConfig) {
10131
10173
  this.resetRestApiErrorMessage();
@@ -15775,15 +15817,20 @@ class DataTableWidgetComponent extends WidgetComponent {
15775
15817
  this.defaultResponseProperty = 'data';
15776
15818
  this.pathParserHelper = new DataTablePathParserHelper();
15777
15819
  this.formCloudService = inject(FormCloudService);
15820
+ this.destroyRef = inject(DestroyRef);
15778
15821
  }
15779
15822
  ngOnInit() {
15780
15823
  this.init();
15781
- this.formService.onFormVariableChanged.subscribe(({ field }) => {
15782
- if (field.id === this.field.id) {
15824
+ this.formService.onFormVariableChanged.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(({ field }) => {
15825
+ if (this.isDependentOnChangedVariable(field)) {
15783
15826
  this.init();
15784
15827
  }
15785
15828
  });
15786
15829
  }
15830
+ isDependentOnChangedVariable(field) {
15831
+ const variableName = this.field?.variableConfig?.variableName;
15832
+ return field.id === this.field.id || (!!variableName && field?.variableConfig?.variableName === variableName);
15833
+ }
15787
15834
  init() {
15788
15835
  this.dataTableLoadFailed = false;
15789
15836
  this.setPreviewState();
@@ -15823,15 +15870,7 @@ class DataTableWidgetComponent extends WidgetComponent {
15823
15870
  return this.pathParserHelper.retrieveDataFromPath(rowsData, optionsPath);
15824
15871
  }
15825
15872
  getDataFromVariable() {
15826
- const processVariables = this.field?.form?.processVariables;
15827
- const formVariables = this.field?.form?.variables;
15828
- const processVariableData = this.getVariableValueByName(processVariables, this.variableName);
15829
- const formVariableData = this.getVariableValueByName(formVariables, this.variableName);
15830
- return processVariableData ?? formVariableData;
15831
- }
15832
- getVariableValueByName(variables, variableName) {
15833
- return variables?.find((variable) => variable?.name === `variables.${variableName}` || variable?.name === variableName)
15834
- ?.value;
15873
+ return this.field?.form?.resolveVariableValue(this.variableName);
15835
15874
  }
15836
15875
  setPreviewState() {
15837
15876
  this.previewState = this.formCloudService.getPreviewState();