@masterteam/client-components 0.0.60 → 0.0.62

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.
@@ -1327,6 +1327,76 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImpor
1327
1327
  args: [{ selector: 'mt-client-list-informative-view', standalone: true, imports: [CommonModule, Card, DashboardViewer, SkeletonModule, TranslocoPipe], template: "<div class=\"grid gap-4\" [style.gridTemplateColumns]=\"gridTemplateColumns\">\r\n @if (informativeState().config.contentStart) {\r\n <div\r\n [style.gridColumn]=\"\r\n slotGridSpan(informativeState().config.layout.startSpan)\r\n \"\r\n >\r\n <ng-container\r\n [ngTemplateOutlet]=\"informativeState().config.contentStart\"\r\n [ngTemplateOutletContext]=\"templateContext(informativeState())\"\r\n />\r\n </div>\r\n }\r\n\r\n <div\r\n [style.gridColumn]=\"\r\n slotGridSpan(informativeState().config.layout.tableSpan)\r\n \"\r\n >\r\n <mt-card>\r\n @if (\r\n informativeState().loading &&\r\n !informativeState().dashboardData?.charts?.length\r\n ) {\r\n <div class=\"flex flex-col gap-3 py-3\">\r\n <p-skeleton height=\"6rem\" />\r\n <p-skeleton height=\"12rem\" />\r\n <p-skeleton height=\"12rem\" />\r\n </div>\r\n } @else if (informativeState().error) {\r\n <div\r\n class=\"rounded-lg border border-red-200 bg-red-50 p-3 text-sm text-red-700\"\r\n >\r\n {{ informativeState().error }}\r\n </div>\r\n } @else if (!informativeState().dashboardData?.charts?.length) {\r\n <div class=\"p-6 text-center text-gray-400\">\r\n {{\r\n \"components.clientComponents.list.noInformativeDashboard\"\r\n | transloco\r\n }}\r\n </div>\r\n } @else {\r\n <div class=\"min-h-[420px]\">\r\n <mt-dashboard-viewer\r\n [isPage]=\"false\"\r\n [showFilters]=\"false\"\r\n [dashboardData]=\"informativeState().dashboardData\"\r\n [extraFilters]=\"dashboardExtraFilters()\"\r\n />\r\n </div>\r\n }\r\n </mt-card>\r\n </div>\r\n\r\n @if (informativeState().config.contentEnd) {\r\n <div\r\n [style.gridColumn]=\"\r\n slotGridSpan(informativeState().config.layout.endSpan)\r\n \"\r\n >\r\n <ng-container\r\n [ngTemplateOutlet]=\"informativeState().config.contentEnd\"\r\n [ngTemplateOutletContext]=\"templateContext(informativeState())\"\r\n />\r\n </div>\r\n }\r\n</div>\r\n" }]
1328
1328
  }], propDecorators: { state: [{ type: i0.Input, args: [{ isSignal: true, alias: "state", required: true }] }] } });
1329
1329
 
1330
+ function mergeRuntimeFilters(configured = [], runtime = {}, columns = []) {
1331
+ const filters = [...configured];
1332
+ for (const [rawKey, rawValue] of Object.entries(runtime)) {
1333
+ const key = rawKey === 'generalSearch' ? 'Name' : rawKey;
1334
+ const column = columns.find((item) => item.key === rawKey);
1335
+ const filterType = column
1336
+ ? TableValueResolver.getColumnFilterType(column)
1337
+ : null;
1338
+ if (isRange(rawValue)) {
1339
+ appendRange(filters, key, rawValue, filterType === 'date');
1340
+ continue;
1341
+ }
1342
+ const scalar = toScalar(rawValue);
1343
+ const value = rawKey === 'generalSearch' && typeof scalar === 'string'
1344
+ ? scalar.trim()
1345
+ : scalar;
1346
+ if (value === null)
1347
+ continue;
1348
+ filters.push({
1349
+ key,
1350
+ operator: rawKey === 'generalSearch' || filterType === 'text'
1351
+ ? 'Contains'
1352
+ : 'Equals',
1353
+ value,
1354
+ });
1355
+ }
1356
+ return filters;
1357
+ }
1358
+ function appendRange(filters, key, range, isDate) {
1359
+ const from = toRangeValue(range.from, isDate);
1360
+ const to = toRangeValue(range.to, isDate);
1361
+ if (from !== null) {
1362
+ filters.push({ key, operator: 'GreaterThanOrEqual', value: from });
1363
+ }
1364
+ if (to !== null) {
1365
+ filters.push({ key, operator: 'LessThanOrEqual', value: to });
1366
+ }
1367
+ }
1368
+ function isRange(value) {
1369
+ return (!!value && typeof value === 'object' && ('from' in value || 'to' in value));
1370
+ }
1371
+ function toRangeValue(value, isDate) {
1372
+ if (value === null || value === undefined || value === '')
1373
+ return null;
1374
+ if (!isDate)
1375
+ return value;
1376
+ const date = value instanceof Date ? value : new Date(String(value));
1377
+ if (Number.isNaN(date.getTime()))
1378
+ return null;
1379
+ const year = date.getFullYear();
1380
+ const month = String(date.getMonth() + 1).padStart(2, '0');
1381
+ const day = String(date.getDate()).padStart(2, '0');
1382
+ return `${year}-${month}-${day}`;
1383
+ }
1384
+ function toScalar(value) {
1385
+ if (Array.isArray(value)) {
1386
+ return value.length === 1 ? toScalar(value[0]) : null;
1387
+ }
1388
+ if (value === null || value === undefined || value === '')
1389
+ return null;
1390
+ if (typeof value !== 'object')
1391
+ return value;
1392
+ const item = value;
1393
+ return toScalar(item['value'] ??
1394
+ item['id'] ??
1395
+ item['key'] ??
1396
+ item['userName'] ??
1397
+ item['displayName']);
1398
+ }
1399
+
1330
1400
  const DEFAULT_AREA_TYPE = 'table';
1331
1401
  const DEFAULT_MODE = 'auto';
1332
1402
  const DEFAULT_TYPE = 'form';
@@ -1357,6 +1427,7 @@ class ClientList {
1357
1427
  subscriptions = new Map();
1358
1428
  inFlightRequestSignatures = new Map();
1359
1429
  fulfilledRequestSignatures = new Map();
1430
+ runtimeFilters = new Map();
1360
1431
  constructor() {
1361
1432
  effect(() => {
1362
1433
  const configs = this.configurations();
@@ -1370,10 +1441,12 @@ class ClientList {
1370
1441
  }
1371
1442
  onLazyLoad(itemKey, event) {
1372
1443
  const item = this.state.itemsByKey()[itemKey];
1373
- if (!item ||
1374
- item.type === 'informative' ||
1375
- item.areaType !== 'table' ||
1376
- !item.config.isPaginated) {
1444
+ if (!item || item.type === 'informative' || !item.config.isPaginated) {
1445
+ return;
1446
+ }
1447
+ this.runtimeFilters.set(item.key, event.filters ?? {});
1448
+ if (item.areaType === 'cards') {
1449
+ this.loadCards(item.key, item.config);
1377
1450
  return;
1378
1451
  }
1379
1452
  const take = this.resolvePositiveInteger(event.pageSize) ?? item.take;
@@ -1805,7 +1878,8 @@ class ClientList {
1805
1878
  return;
1806
1879
  }
1807
1880
  const query = this.toTableQuery(config, skip, take);
1808
- const requestSignature = this.createTableRequestSignature(config, query);
1881
+ const filters = this.resolveFetchFilters(key, config);
1882
+ const requestSignature = this.createTableRequestSignature(config, query, filters);
1809
1883
  if (force) {
1810
1884
  this.inFlightRequestSignatures.delete(key);
1811
1885
  this.fulfilledRequestSignatures.delete(key);
@@ -1818,9 +1892,7 @@ class ClientList {
1818
1892
  this.inFlightRequestSignatures.set(key, requestSignature);
1819
1893
  this.state.setLoading(key, true);
1820
1894
  this.state.setError(key, null);
1821
- const sub = this.api
1822
- .getRows(config.contextKey, query, config.filters)
1823
- .subscribe({
1895
+ const sub = this.api.getRows(config.contextKey, query, filters).subscribe({
1824
1896
  next: (response) => {
1825
1897
  let hasLoadedData = false;
1826
1898
  if (response.data) {
@@ -1859,7 +1931,8 @@ class ClientList {
1859
1931
  this.state.setError(key, this.getMissingIdentifiersMessage(config));
1860
1932
  return;
1861
1933
  }
1862
- const requestSignature = this.createCardsRequestSignature(config);
1934
+ const filters = this.resolveFetchFilters(key, config);
1935
+ const requestSignature = this.createCardsRequestSignature(config, filters);
1863
1936
  if (force) {
1864
1937
  this.inFlightRequestSignatures.delete(key);
1865
1938
  this.fulfilledRequestSignatures.delete(key);
@@ -1872,9 +1945,7 @@ class ClientList {
1872
1945
  this.inFlightRequestSignatures.set(key, requestSignature);
1873
1946
  this.state.setLoading(key, true);
1874
1947
  this.state.setError(key, null);
1875
- const sub = this.api
1876
- .getCards(config.contextKey, config.filters)
1877
- .subscribe({
1948
+ const sub = this.api.getCards(config.contextKey, filters).subscribe({
1878
1949
  next: (response) => {
1879
1950
  let hasLoadedData = false;
1880
1951
  if (response.data) {
@@ -2091,6 +2162,11 @@ class ClientList {
2091
2162
  this.fulfilledRequestSignatures.delete(key);
2092
2163
  }
2093
2164
  }
2165
+ for (const key of this.runtimeFilters.keys()) {
2166
+ if (!activeKeys.has(key)) {
2167
+ this.runtimeFilters.delete(key);
2168
+ }
2169
+ }
2094
2170
  for (const key of this.rowActionsLoadingFnCache.keys()) {
2095
2171
  if (!activeKeys.has(key)) {
2096
2172
  this.rowActionsLoadingFnCache.delete(key);
@@ -2128,24 +2204,24 @@ class ClientList {
2128
2204
  take: queryTake,
2129
2205
  };
2130
2206
  }
2131
- createTableRequestSignature(config, query) {
2207
+ createTableRequestSignature(config, query, filters) {
2132
2208
  return [
2133
2209
  config.type,
2134
2210
  config.areaType,
2135
2211
  config.contextKey ?? 'x',
2136
- this.serializeFilters(config.filters),
2212
+ this.serializeFilters(filters),
2137
2213
  query.mode,
2138
2214
  query.skip,
2139
2215
  query.take,
2140
2216
  ...(query.columnKeys ?? []),
2141
2217
  ].join('|');
2142
2218
  }
2143
- createCardsRequestSignature(config) {
2219
+ createCardsRequestSignature(config, filters) {
2144
2220
  return [
2145
2221
  config.type,
2146
2222
  config.areaType,
2147
2223
  config.contextKey ?? 'x',
2148
- this.serializeFilters(config.filters),
2224
+ this.serializeFilters(filters),
2149
2225
  'Card',
2150
2226
  ].join('|');
2151
2227
  }
@@ -2186,6 +2262,9 @@ class ClientList {
2186
2262
  serializeFilters(filters) {
2187
2263
  return JSON.stringify(filters ?? []);
2188
2264
  }
2265
+ resolveFetchFilters(key, config) {
2266
+ return mergeRuntimeFilters(config.filters, this.runtimeFilters.get(key), this.state.itemsByKey()[key]?.columns);
2267
+ }
2189
2268
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: ClientList, deps: [], target: i0.ɵɵFactoryTarget.Component });
2190
2269
  static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.8", type: ClientList, isStandalone: true, selector: "mt-client-list", inputs: { configurations: { classPropertyName: "configurations", publicName: "configurations", isSignal: true, isRequired: true, transformFunction: null }, defaultTake: { classPropertyName: "defaultTake", publicName: "defaultTake", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { loaded: "loaded", errored: "errored", itemClicked: "itemClicked" }, providers: [
2191
2270
  ClientListStateService,