@sumaris-net/ngx-components 2.4.23-rc3 → 2.4.23-rc4

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.
@@ -19708,9 +19708,15 @@ class CustomReuseStrategy extends IonicRouteStrategy {
19708
19708
  const futureId = future.params[pathIdParam] === 'new'
19709
19709
  ? (future.queryParams[pathIdParam] || future.queryParams['id'] || 'new') // e.g. path like '/new/?id=<ID>'
19710
19710
  : future.params[pathIdParam]; // e.g. path like '/<ID>'
19711
- // Reuse if same ID, but never when 'new' expected
19712
- return futureId !== 'new' && currId !== 'new'
19713
- && futureId === currId;
19711
+ // Reuse if same ID, using a futureId, if exists
19712
+ if (isNotNil(futureId)) {
19713
+ // Allow reuse when changing from /new to /new?id=:id
19714
+ if (currId === 'new' && isNil(curr.queryParams[pathIdParam]) && future.params[pathIdParam] === 'new' && isNotNil(future.queryParams[pathIdParam])) {
19715
+ return true;
19716
+ }
19717
+ // Allow reuse same id, expect when expected '/new'
19718
+ return futureId !== 'new' && futureId === currId;
19719
+ }
19714
19720
  }
19715
19721
  return result;
19716
19722
  }
@@ -28315,17 +28321,14 @@ class AppEntityEditor extends AppTabEditor {
28315
28321
  const queryParams = { ...this.queryParams };
28316
28322
  // Open the next tab
28317
28323
  this.updateTabIndex(opts && opts.openTabIndex);
28318
- // Update queryParams
28319
- queryParams.tab = this.selectedTabIndex;
28320
- queryParams[this._pathIdAttribute] = isNotNil(data?.id) ? data.id : 'new';
28321
28324
  // Update route location
28322
- await this.updateRoute(data, queryParams);
28325
+ await this.updateRoute(data, { ...queryParams, tab: this.selectedTabIndex });
28323
28326
  }
28324
28327
  /**
28325
28328
  * Update the route location, and open the next tab
28326
28329
  */
28327
28330
  updateTabIndex(tabIndex) {
28328
- if (isNotNil(tabIndex) && tabIndex !== this.selectedTabIndex) {
28331
+ if (isNotNil(tabIndex) && tabIndex >= 0 && tabIndex !== this.selectedTabIndex) {
28329
28332
  this.selectedTabIndex = tabIndex;
28330
28333
  this.markForCheck();
28331
28334
  }
@@ -28615,7 +28618,7 @@ class AppEntityEditor extends AppTabEditor {
28615
28618
  let parentUrl = this.defaultBackHref;
28616
28619
  // Remove query params
28617
28620
  if (withQueryParams !== true && parentUrl && parentUrl.indexOf('?') !== -1) {
28618
- parentUrl = parentUrl.substr(0, parentUrl.indexOf('?'));
28621
+ parentUrl = parentUrl.substring(0, parentUrl.indexOf('?'));
28619
28622
  }
28620
28623
  return parentUrl;
28621
28624
  }
@@ -28641,27 +28644,55 @@ class AppEntityEditor extends AppTabEditor {
28641
28644
  this.markForCheck();
28642
28645
  }
28643
28646
  }
28647
+ /**
28648
+ * Update the route, without reloading the component
28649
+ * @param data
28650
+ * @param queryParams
28651
+ * @protected
28652
+ */
28644
28653
  async updateRoute(data, queryParams) {
28645
- const path = this.computePageUrl(isNotNil(data.id) ? data.id : 'new');
28646
- const commands = (path && typeof path === 'string') ? path.split('/') : path;
28647
- if (isNotEmptyArray(commands)) {
28648
- this.queryParams = queryParams || this.queryParams;
28649
- // Disabling router animation
28650
- this.routerOutlet.animated = false;
28651
- try {
28652
- return await this.router.navigate(commands, {
28653
- replaceUrl: true,
28654
+ const currId = this.route.snapshot.paramMap.get(this.pathIdAttribute);
28655
+ const futureId = isNotNil(data.id) ? data.id.toString() : 'new';
28656
+ this.queryParams = {
28657
+ ...this.queryParams,
28658
+ ...queryParams
28659
+ };
28660
+ if (currId === futureId) {
28661
+ // Update queryParam only (not the path)
28662
+ if (!equals(this.route.snapshot.queryParams, this.queryParams)) {
28663
+ if (this.debug)
28664
+ console.debug('[entity-editor] Updating route using queryParams: ', queryParams);
28665
+ return await this.router.navigate(['.'], {
28666
+ relativeTo: this.route,
28654
28667
  queryParams: this.queryParams
28655
28668
  });
28656
28669
  }
28657
- finally {
28658
- // Re enabling router animation
28659
- this.routerOutlet.animated = true;
28660
- }
28661
28670
  }
28662
28671
  else {
28663
- console.warn('Skip page route update. Invalid page path: ', path);
28664
- return Promise.resolve(false);
28672
+ // Current route was '/new' => change to '/new?id=:id' (to allow CustomReuseStrategy to detect that route can be reused)
28673
+ if (currId === 'new') {
28674
+ const res = await this.router.navigate(['.'], {
28675
+ relativeTo: this.route,
28676
+ replaceUrl: true,
28677
+ queryParams: {
28678
+ ...this.queryParams,
28679
+ [this.pathIdAttribute]: futureId
28680
+ }
28681
+ });
28682
+ if (!res)
28683
+ return false;
28684
+ }
28685
+ const path = this.computePageUrl(isNotNil(data.id) ? data.id : 'new');
28686
+ const commands = (path && typeof path === 'string') ? path.split('/').slice(1) : path;
28687
+ if (isNotEmptyArray(commands)) {
28688
+ if (this.debug)
28689
+ console.debug('[entity-editor] Updating route to: ' + path);
28690
+ return await this.router.navigate(commands, {
28691
+ replaceUrl: true,
28692
+ queryParams: this.queryParams
28693
+ });
28694
+ }
28695
+ return Promise.reject('Missing page URL');
28665
28696
  }
28666
28697
  }
28667
28698
  }