@veloceapps/sdk 10.0.0-2 → 10.0.0-20

Sign up to get free protection for your applications and to get access to all the features.
@@ -478,7 +478,8 @@ class FlowStateService {
478
478
  this.EXECUTION_BUFFER_TIME = 100;
479
479
  this.executedFunctions = {};
480
480
  this.stateId$ = new BehaviorSubject(null);
481
- this._hasStatefulUnsavedChanges = true;
481
+ this.initialStatefulData = {};
482
+ this.trackedStatefulChangesMap = new Map();
482
483
  this.processors = {};
483
484
  this.subscriptions = {};
484
485
  this.flowStore = {};
@@ -561,7 +562,7 @@ class FlowStateService {
561
562
  }
562
563
  get hasUnsavedChanges() {
563
564
  return this.getFlowSafe().properties.stateful
564
- ? this._hasStatefulUnsavedChanges
565
+ ? Array.from(this.trackedStatefulChangesMap.values()).some(Boolean)
565
566
  : this.quoteDraftService.hasUnsavedChanges;
566
567
  }
567
568
  get stateId() {
@@ -625,6 +626,9 @@ class FlowStateService {
625
626
  data$: new BehaviorSubject(this.NOT_INITIALIZED),
626
627
  };
627
628
  this.subscriptions[requestId] = subscription;
629
+ if (options?.trackedChanges) {
630
+ this.trackedStatefulChangesMap.set(requestId, false);
631
+ }
628
632
  if (!options?.cold) {
629
633
  this.executeRequest$(request).subscribe();
630
634
  }
@@ -638,14 +642,18 @@ class FlowStateService {
638
642
  save$() {
639
643
  if (this.getFlowSafe().properties.stateful) {
640
644
  if (this.stateId$.value) {
641
- return this.flowStateApiService.save(this.stateId$.value);
645
+ return this.flowStateApiService.save(this.stateId$.value).pipe(tap$1(() => {
646
+ Array.from(this.trackedStatefulChangesMap.keys()).forEach(key => {
647
+ this.trackedStatefulChangesMap.set(key, false);
648
+ });
649
+ }));
642
650
  }
643
651
  }
644
652
  else {
645
653
  const quoteDraft = this.quoteDraftService.quoteDraft;
646
654
  if (quoteDraft) {
647
- return this.quoteApiService.upsertQuote(quoteDraft).pipe(tap$1(({ configurationId }) => {
648
- this.contextService.update({ properties: { ConfigurationId: configurationId } });
655
+ return this.quoteApiService.upsertQuote(quoteDraft).pipe(tap$1(({ versionId }) => {
656
+ this.contextService.update({ properties: { VELOCPQ__VersionId__c: versionId } });
649
657
  }));
650
658
  }
651
659
  }
@@ -660,8 +668,8 @@ class FlowStateService {
660
668
  else {
661
669
  const quoteDraft = this.quoteDraftService.quoteDraft;
662
670
  if (quoteDraft) {
663
- return this.quoteApiService.submitQuote(quoteDraft).pipe(tap$1(({ configurationId }) => {
664
- this.contextService.update({ properties: { ConfigurationId: configurationId } });
671
+ return this.quoteApiService.submitQuote(quoteDraft).pipe(tap$1(({ versionId }) => {
672
+ this.contextService.update({ properties: { VELOCPQ__VersionId__c: versionId } });
665
673
  }));
666
674
  }
667
675
  }
@@ -715,6 +723,7 @@ class FlowStateService {
715
723
  }
716
724
  const subscription$ = this.subscriptions[requestId]?.data$;
717
725
  if (subscription$ && subscription$.value !== selectorResult) {
726
+ this.checkStatefulChanges(requestId, selectorResult);
718
727
  subscription$.next(selectorResult);
719
728
  }
720
729
  });
@@ -954,6 +963,15 @@ class FlowStateService {
954
963
  });
955
964
  return request;
956
965
  }
966
+ checkStatefulChanges(requestId, selectorResult) {
967
+ if (this.trackedStatefulChangesMap.has(requestId)) {
968
+ if (!this.initialStatefulData[requestId]) {
969
+ this.initialStatefulData[requestId] = selectorResult;
970
+ }
971
+ const hasChanges = !isEqual(this.initialStatefulData[requestId], selectorResult);
972
+ this.trackedStatefulChangesMap.set(requestId, hasChanges);
973
+ }
974
+ }
957
975
  }
958
976
  FlowStateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateService, deps: [{ token: ContextService }, { token: QuoteDraftService }, { token: FlowInfoService }, { token: FlowConfigurationService }, { token: i1.ConfigurationProcessorsApiService }, { token: i1.FlowStateApiService }, { token: i1.QuoteApiService }, { token: i6.ToastService }, { token: FLOW_CUSTOMIZATION, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
959
977
  FlowStateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: FlowStateService });
@@ -2071,6 +2089,7 @@ class ConfigurationStateService {
2071
2089
  this.configurationStore = {};
2072
2090
  this.executionInProgress$ = new BehaviorSubject(false);
2073
2091
  this.statefulRequestStream$ = new Subject();
2092
+ this.statelessExecutionRequest$ = null;
2074
2093
  this.statefulExecutionRequest$ = this.initBufferedRequest$();
2075
2094
  }
2076
2095
  get isExecutionInProgress$() {
@@ -2117,7 +2136,15 @@ class ConfigurationStateService {
2117
2136
  actions: [{ name: actionName, inputData }],
2118
2137
  };
2119
2138
  const request = this.execToRequest(exec);
2120
- return this.executeRequest$(request);
2139
+ const executionRequest$ = this.executeRequest$(request);
2140
+ if (this.isStatefulConfiguration) {
2141
+ return executionRequest$;
2142
+ }
2143
+ // prevent parallel configuration requests in stateless mode
2144
+ if (!this.statelessExecutionRequest$) {
2145
+ this.statelessExecutionRequest$ = executionRequest$.pipe(shareReplay$1(), take$1(1), finalize(() => (this.statelessExecutionRequest$ = null)));
2146
+ }
2147
+ return this.statelessExecutionRequest$;
2121
2148
  }
2122
2149
  select$(selectorName, inputData = {}) {
2123
2150
  const requestId = UUID.UUID();