@rivet-health/design-system 37.2.1 → 37.3.0

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.
@@ -6116,15 +6116,16 @@ var RivTable;
6116
6116
  }
6117
6117
  RivTable.createManager = createManager;
6118
6118
  function createInMemoryManager(fetchDataset, columns, pluralEntityName, options) {
6119
+ var _a, _b, _c;
6119
6120
  let data;
6120
6121
  let fuse;
6121
6122
  const source = (query, mostRecentAction) => __awaiter(this, void 0, void 0, function* () {
6122
- var _a, _b, _c, _d;
6123
+ var _d, _e, _f, _g;
6123
6124
  //For inMemoryManagers that do not utilize searchColumns,
6124
6125
  //we do not want to overwrite their fuseOptions
6125
6126
  if (mostRecentAction.type === 'load') {
6126
6127
  //Prevent searching on columns that are in fuse options but not supported by search.
6127
- const nonSearchableColumnsKeys = ((_a = options === null || options === void 0 ? void 0 : options.fuseOptions) === null || _a === void 0 ? void 0 : _a.keys)
6128
+ const nonSearchableColumnsKeys = ((_d = options === null || options === void 0 ? void 0 : options.fuseOptions) === null || _d === void 0 ? void 0 : _d.keys)
6128
6129
  ? Array.from(columns.entries())
6129
6130
  .filter(([key, column]) => {
6130
6131
  return column.searchable == false;
@@ -6135,7 +6136,7 @@ var RivTable;
6135
6136
  })
6136
6137
  : undefined;
6137
6138
  const fuseOptions = (options === null || options === void 0 ? void 0 : options.fuseOptions) && nonSearchableColumnsKeys
6138
- ? Object.assign(Object.assign({}, options === null || options === void 0 ? void 0 : options.fuseOptions), { keys: (_c = (_b = options === null || options === void 0 ? void 0 : options.fuseOptions) === null || _b === void 0 ? void 0 : _b.keys) === null || _c === void 0 ? void 0 : _c.filter(k => !nonSearchableColumnsKeys.includes(k.toString())) }) : options === null || options === void 0 ? void 0 : options.fuseOptions;
6139
+ ? Object.assign(Object.assign({}, options === null || options === void 0 ? void 0 : options.fuseOptions), { keys: (_f = (_e = options === null || options === void 0 ? void 0 : options.fuseOptions) === null || _e === void 0 ? void 0 : _e.keys) === null || _f === void 0 ? void 0 : _f.filter(k => !nonSearchableColumnsKeys.includes(k.toString())) }) : options === null || options === void 0 ? void 0 : options.fuseOptions;
6139
6140
  data = yield fetchDataset();
6140
6141
  fuse = new Fuse(data, fuseOptions);
6141
6142
  }
@@ -6150,13 +6151,38 @@ var RivTable;
6150
6151
  }) }));
6151
6152
  }
6152
6153
  const orderColumn = query.order
6153
- ? (_d = columns.get(query.order.column)) === null || _d === void 0 ? void 0 : _d.orderKey
6154
+ ? (_g = columns.get(query.order.column)) === null || _g === void 0 ? void 0 : _g.orderKey
6154
6155
  : undefined;
6155
- const ordered = query.search
6156
- ? fuse.search(query.search).map(result => result.item)
6157
- : query.order && orderColumn
6158
- ? orderBy(data, orderColumn, query.order.direction)
6159
- : data;
6156
+ const hasExplicitSort = query.order != null && orderColumn !== undefined;
6157
+ const defaultSortSpec = (() => {
6158
+ var _a;
6159
+ if (options === null || options === void 0 ? void 0 : options.defaultSort) {
6160
+ const key = (_a = columns.get(options.defaultSort.column)) === null || _a === void 0 ? void 0 : _a.orderKey;
6161
+ if (key !== undefined) {
6162
+ return { key, direction: options.defaultSort.direction };
6163
+ }
6164
+ }
6165
+ const firstOrderable = [...columns.entries()].find(([, meta]) => meta.orderKey != null);
6166
+ const key = firstOrderable === null || firstOrderable === void 0 ? void 0 : firstOrderable[1].orderKey;
6167
+ return key !== undefined ? { key, direction: 'asc' } : null;
6168
+ })();
6169
+ let ordered;
6170
+ if (query.search) {
6171
+ const matches = fuse.search(query.search).map(result => result.item);
6172
+ ordered =
6173
+ hasExplicitSort && query.order
6174
+ ? orderBy(matches, orderColumn, query.order.direction)
6175
+ : matches;
6176
+ }
6177
+ else if (hasExplicitSort && query.order) {
6178
+ ordered = orderBy(data, orderColumn, query.order.direction);
6179
+ }
6180
+ else if (query.order == null && defaultSortSpec) {
6181
+ ordered = orderBy(data, defaultSortSpec.key, defaultSortSpec.direction);
6182
+ }
6183
+ else {
6184
+ ordered = data;
6185
+ }
6160
6186
  const filter = options === null || options === void 0 ? void 0 : options.filter;
6161
6187
  const filtered = filter
6162
6188
  ? ordered.filter(row => filter(query.filters, row))
@@ -6184,6 +6210,12 @@ var RivTable;
6184
6210
  displayName: metadata.displayName,
6185
6211
  },
6186
6212
  ]));
6213
+ // When a defaultSort is specified, seed the initial query.order so the
6214
+ // table header shows the sort indicator from the start.
6215
+ if ((options === null || options === void 0 ? void 0 : options.defaultSort) && !((_b = (_a = options === null || options === void 0 ? void 0 : options.initialState) === null || _a === void 0 ? void 0 : _a.query) === null || _b === void 0 ? void 0 : _b.order)) {
6216
+ const order = options.defaultSort;
6217
+ options = Object.assign(Object.assign({}, options), { initialState: Object.assign(Object.assign({}, options.initialState), { query: Object.assign(Object.assign({}, (_c = options.initialState) === null || _c === void 0 ? void 0 : _c.query), { order }) }) });
6218
+ }
6187
6219
  return createManager(source, columnMetadata, pluralEntityName, options);
6188
6220
  }
6189
6221
  RivTable.createInMemoryManager = createInMemoryManager;