@masterteam/client-components 0.0.117 → 0.0.118

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.
@@ -4,7 +4,7 @@ import * as i1 from '@angular/common';
4
4
  import { NgTemplateOutlet, CommonModule } from '@angular/common';
5
5
  import * as i4 from '@jsverse/transloco';
6
6
  import { TranslocoService, TranslocoModule, TranslocoPipe } from '@jsverse/transloco';
7
- import { switchMap, of, range, concatMap, reduce, map, forkJoin, catchError, shareReplay, Observable, share, take, Subscription } from 'rxjs';
7
+ import { switchMap, of, range, concatMap, reduce, map, tap, forkJoin, catchError, shareReplay, Observable, share, take, Subscription } from 'rxjs';
8
8
  import { Button } from '@masterteam/components/button';
9
9
  import { provideEntityListTablePreview } from '@masterteam/components/business-fields';
10
10
  import { RuntimeActionRunner, resolveActionLabel } from '@masterteam/components/runtime-action';
@@ -45,12 +45,29 @@ const CLIENT_LIST_DEFAULT_INCLUDE_STATE = ['escalation'];
45
45
  const CLIENT_LIST_RECORD_ID_FILTER_KEY = 'id';
46
46
 
47
47
  const DEFAULT_INCLUDE_STATE = CLIENT_LIST_DEFAULT_INCLUDE_STATE;
48
+ /** How long a module's table display catalog is reused. See {@link ClientListApiService}. */
49
+ const TABLE_SETTINGS_CACHE_TTL_MS = 5 * 60_000;
50
+ function tableColumnKeysCacheKey(context) {
51
+ return `${context.levelId}/${context.moduleId}`;
52
+ }
48
53
  class ClientListApiService {
49
54
  http = inject(HttpClient);
50
55
  runtimeFetchBaseUrl = 'fetch/query';
51
56
  informativeBaseUrl = 'LevelData';
52
57
  /** Card layouts already read back, keyed by context. See {@link getCardLayout}. */
53
58
  cardLayouts = new Map();
59
+ /**
60
+ * Table columns already read from the display catalog, keyed by level/module.
61
+ *
62
+ * Every table load waited for this catalog before its `fetch/query` (on Dev,
63
+ * 2026-11-25: 0.3-0.4 s on each module tab open). It is configuration, so
64
+ * reopening a module tab, or a second list of the same module, reuses it for
65
+ * five minutes - long enough to drop the wait from tab switches, short enough
66
+ * that a Control Panel edit shows up without a reload. Concurrent loads share
67
+ * the request in flight; a failure is never kept, and a failed table request
68
+ * drops the keys it used.
69
+ */
70
+ tableColumnKeys = new Map();
54
71
  /** Native grids analyse a complete matching array; page boundaries must never change the result. */
55
72
  getAllRows(contextKey, query, filters = [], hierarchy) {
56
73
  return this.getRows(contextKey, { ...query, skip: 0, take: 500 }, filters, hierarchy).pipe(switchMap((first) => {
@@ -141,7 +158,12 @@ class ClientListApiService {
141
158
  page: this.toPage(query.skip, query.take),
142
159
  pageSize: query.take,
143
160
  ...(hierarchy ? { hierarchy: this.toHierarchyScope(hierarchy) } : {}),
144
- }).pipe(map((response) => ({ response, propertyKeys })));
161
+ }).pipe(map((response) => ({ response, propertyKeys })),
162
+ // Cached keys can be up to five minutes old. A property removed in
163
+ // Control Panel since then fails the whole table (an unknown
164
+ // `propertyKeys` entry is a 400), so the next load reads the catalog
165
+ // again instead of repeating the same request.
166
+ tap({ error: () => this.forgetTableColumnKeys(contextKey, query) }));
145
167
  }));
146
168
  }
147
169
  /**
@@ -316,9 +338,26 @@ class ClientListApiService {
316
338
  if (!context) {
317
339
  return of(undefined);
318
340
  }
319
- return this.http
341
+ const cacheKey = tableColumnKeysCacheKey(context);
342
+ const cached = this.tableColumnKeys.get(cacheKey);
343
+ if (cached && Date.now() - cached.at < TABLE_SETTINGS_CACHE_TTL_MS) {
344
+ return cached.keys$;
345
+ }
346
+ const keys$ = this.http
320
347
  .get(`LevelData/levels/${context.levelId}/modules/${context.moduleId}/table-display-settings/catalog?surfaceKey=table`)
321
- .pipe(map((response) => this.toEffectiveColumnKeys(response.data?.effectiveColumns ?? [])));
348
+ .pipe(map((response) => this.toEffectiveColumnKeys(response.data?.effectiveColumns ?? [])), tap({ error: () => this.tableColumnKeys.delete(cacheKey) }), shareReplay({ bufferSize: 1, refCount: false }));
349
+ this.tableColumnKeys.set(cacheKey, { keys$, at: Date.now() });
350
+ return keys$;
351
+ }
352
+ /** Drops the cached catalog keys a table request of this list used. */
353
+ forgetTableColumnKeys(contextKey, query) {
354
+ if (query.columnKeys?.length) {
355
+ return;
356
+ }
357
+ const context = this.readTableSettingsContext(contextKey);
358
+ if (context) {
359
+ this.tableColumnKeys.delete(tableColumnKeysCacheKey(context));
360
+ }
322
361
  }
323
362
  toPage(skip, take) {
324
363
  if (take <= 0) {