@pattern-stack/frontend-patterns 0.2.0-alpha.19 → 0.2.0-alpha.20

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.
package/dist/index.js CHANGED
@@ -19340,7 +19340,8 @@ function createEntityHooks(config) {
19340
19340
  };
19341
19341
  }
19342
19342
  function createStore(config) {
19343
- const { entities, collections } = config;
19343
+ const { entities, collections, fields, lookups: lookupsEngine } = config;
19344
+ const defaultGetRowId = (row) => String(row.id);
19344
19345
  const resolve = {};
19345
19346
  for (const [name, collection] of Object.entries(collections)) {
19346
19347
  const singular = name.endsWith("ies") ? name.slice(0, -3) + "y" : name.endsWith("s") ? name.slice(0, -1) : name;
@@ -19370,8 +19371,75 @@ function createStore(config) {
19370
19371
  lookupCache = null;
19371
19372
  }
19372
19373
  };
19374
+ function makeUseData(entityName, entity) {
19375
+ const meta = fields ? fields[entityName] : void 0;
19376
+ return function useData(opts = {}) {
19377
+ const { pageSize } = opts;
19378
+ const list = entity.useList({ pageSize });
19379
+ React.useEffect(() => {
19380
+ if (lookupsEngine) {
19381
+ void lookupsEngine.hydrate().catch(() => {
19382
+ });
19383
+ }
19384
+ }, []);
19385
+ const hydratedLookups = lookupsEngine ? lookupsEngine.current : null;
19386
+ const result = React.useMemo(
19387
+ () => ({
19388
+ rows: list.data,
19389
+ isLoading: list.isLoading,
19390
+ isError: list.isError,
19391
+ error: list.error,
19392
+ refetch: list.refetch,
19393
+ page: list.page,
19394
+ pageCount: list.pageCount,
19395
+ total: list.total,
19396
+ pageSize: list.pageSize,
19397
+ setPage: list.setPage,
19398
+ next: list.next,
19399
+ prev: list.prev,
19400
+ hasNext: list.hasNext,
19401
+ hasPrev: list.hasPrev,
19402
+ getRowId: defaultGetRowId,
19403
+ meta,
19404
+ lookups: hydratedLookups,
19405
+ // Reserved (inert):
19406
+ sort: null,
19407
+ setSort: () => {
19408
+ },
19409
+ filter: null,
19410
+ setFilter: () => {
19411
+ }
19412
+ }),
19413
+ [
19414
+ list.data,
19415
+ list.isLoading,
19416
+ list.isError,
19417
+ list.error,
19418
+ list.refetch,
19419
+ list.page,
19420
+ list.pageCount,
19421
+ list.total,
19422
+ list.pageSize,
19423
+ list.setPage,
19424
+ list.next,
19425
+ list.prev,
19426
+ list.hasNext,
19427
+ list.hasPrev,
19428
+ hydratedLookups
19429
+ ]
19430
+ );
19431
+ return result;
19432
+ };
19433
+ }
19434
+ const augmentedEntities = {};
19435
+ for (const [name, entity] of Object.entries(entities)) {
19436
+ augmentedEntities[name] = {
19437
+ ...entity,
19438
+ useData: makeUseData(name, entity)
19439
+ };
19440
+ }
19373
19441
  return {
19374
- ...entities,
19442
+ ...augmentedEntities,
19375
19443
  collections,
19376
19444
  resolve,
19377
19445
  lookups