@trackunit/react-components 6.0.37-alpha-b8d3d323d1a.0 → 6.0.38

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/index.cjs.js CHANGED
@@ -96,7 +96,6 @@ const cvaIcon = cssClassVarianceUtilities.cva({
96
96
  excessive_usage: "text-danger-500",
97
97
  stopped: "text-stopped-700",
98
98
  unknown: "text-unknown-400",
99
- no_data: "text-no_data-300",
100
99
  default: "text-current",
101
100
  black: "text-black",
102
101
  white: "text-white",
@@ -2295,7 +2294,6 @@ const cvaTag = cssClassVarianceUtilities.cva({
2295
2294
  stopped: ["bg-stopped-100", "text-stopped-700"],
2296
2295
  idle: ["bg-idle-100", "text-idle-700"],
2297
2296
  unknown: ["bg-unknown-100", "text-unknown-500"],
2298
- no_data: ["bg-no_data-100", "text-no_data-500"],
2299
2297
  moving: ["bg-neutral-100", "text-neutral-700"],
2300
2298
  active: ["bg-neutral-100", "text-neutral-700"],
2301
2299
  excessive_usage: ["bg-danger-100", "text-danger-700"],
@@ -6323,7 +6321,6 @@ const cvaIndicatorPing = cssClassVarianceUtilities.cva({
6323
6321
  active: "bg-active-600",
6324
6322
  excessive_usage: "bg-excessive_usage-600",
6325
6323
  unknown: "bg-unknown-400",
6326
- no_data: "bg-no_data-300",
6327
6324
  unused: "bg-unused-400",
6328
6325
  utilized: "bg-utilized-600",
6329
6326
  heavily_utilized: "bg-heavily_utilized-500",
@@ -6368,7 +6365,6 @@ const cvaIndicatorIconBackground = cssClassVarianceUtilities.cva({
6368
6365
  active: "text-active-600 bg-neutral-100",
6369
6366
  excessive_usage: "bg-excessive_usage-100 text-excessive_usage-600",
6370
6367
  unknown: "bg-unknown-100 text-unknown-400",
6371
- no_data: "bg-no_data-100 text-no_data-300",
6372
6368
  unused: "bg-unused-100 text-unused-400",
6373
6369
  utilized: "bg-utilized-100 text-utilized-600",
6374
6370
  heavily_utilized: "bg-heavily_utilized-100 text-heavily_utilized-500",
@@ -13378,6 +13374,7 @@ const useStripForeignIdentityHash = () => {
13378
13374
 
13379
13375
  const OVERSCAN = 10;
13380
13376
  const DEFAULT_ROW_HEIGHT = 50;
13377
+ const SCROLL_END_THRESHOLD_PX = 1;
13381
13378
  /**
13382
13379
  * Bidirectional infinite scroll hook that supports both forward (nextPage)
13383
13380
  * and backward (previousPage) pagination with TanStack Virtual.
@@ -13392,6 +13389,23 @@ const useBidirectionalScroll = ({ pagination, scrollElementRef, count, estimateS
13392
13389
  onTopItemChangeRef.current = onTopItemChange;
13393
13390
  }, [onTopItemChange]);
13394
13391
  const lastReportedTopIndex = react.useRef(-1);
13392
+ const tryLoadNextPage = react.useCallback((virtualizer) => {
13393
+ if (skip || !pagination.pageInfo?.hasNextPage || pagination.isLoading) {
13394
+ return;
13395
+ }
13396
+ const container = scrollElementRef.current;
13397
+ if (!container) {
13398
+ return;
13399
+ }
13400
+ const lastItem = virtualizer.getVirtualItems().at(-1);
13401
+ const reachedLastVirtualRow = lastItem !== undefined && lastItem.index >= count - 1;
13402
+ const hasInsufficientContent = container.scrollHeight <= container.clientHeight;
13403
+ const isAtScrollEnd = container.scrollHeight - container.scrollTop - container.clientHeight <= SCROLL_END_THRESHOLD_PX;
13404
+ if (!reachedLastVirtualRow && !hasInsufficientContent && !isAtScrollEnd) {
13405
+ return;
13406
+ }
13407
+ pagination.nextPage();
13408
+ }, [count, pagination, scrollElementRef, skip]);
13395
13409
  const handleChange = react.useCallback((virtualizer) => {
13396
13410
  onChange?.(virtualizer);
13397
13411
  const scrollOffset = virtualizer.scrollOffset ?? 0;
@@ -13400,7 +13414,8 @@ const useBidirectionalScroll = ({ pagination, scrollElementRef, count, estimateS
13400
13414
  lastReportedTopIndex.current = firstVisibleItem.index;
13401
13415
  onTopItemChangeRef.current?.(firstVisibleItem.index);
13402
13416
  }
13403
- }, [onChange]);
13417
+ tryLoadNextPage(virtualizer);
13418
+ }, [onChange, tryLoadNextPage]);
13404
13419
  const handleEstimateSize = react.useCallback((index) => estimateSize?.(index) ?? DEFAULT_ROW_HEIGHT, [estimateSize]);
13405
13420
  // eslint-plugin-react-hooks hardcodes `useVirtualizer` as a known-incompatible
13406
13421
  // API (its returned functions can't be memoized), so this warning is emitted
@@ -13427,57 +13442,54 @@ const useBidirectionalScroll = ({ pagination, scrollElementRef, count, estimateS
13427
13442
  // after items are prepended, preventing an infinite backward-load loop.
13428
13443
  const prevCountRef = react.useRef(count);
13429
13444
  const isLoadingBackwardRef = react.useRef(false);
13445
+ const lastResetCountRef = react.useRef(pagination.resetCount);
13430
13446
  react.useEffect(() => {
13431
- if (isLoadingBackwardRef.current && !pagination.isLoading && count > prevCountRef.current) {
13432
- const prependedCount = count - prevCountRef.current;
13433
- const container = scrollElementRef.current;
13447
+ const container = scrollElementRef.current;
13448
+ const previousCount = prevCountRef.current;
13449
+ if (isLoadingBackwardRef.current && !pagination.isLoading && count > previousCount) {
13434
13450
  if (container) {
13435
13451
  const estimatedRowHeight = estimateSize?.(0) ?? DEFAULT_ROW_HEIGHT;
13436
- container.scrollTop += prependedCount * estimatedRowHeight;
13452
+ container.scrollTop += (count - previousCount) * estimatedRowHeight;
13437
13453
  }
13438
13454
  isLoadingBackwardRef.current = false;
13455
+ prevCountRef.current = count;
13456
+ return;
13439
13457
  }
13440
13458
  prevCountRef.current = count;
13441
13459
  }, [count, pagination.isLoading, scrollElementRef, estimateSize]);
13442
- // Forward loading: scroll reached bottom or insufficient content
13460
+ // Reset scroll to top when pagination is reset (e.g. new search).
13461
+ // Keyed on resetCount rather than pageInfo: a forward page without pageInfo
13462
+ // also clears endCursor, and must not move the user back to the top.
13443
13463
  react.useEffect(() => {
13444
- if (skip || pagination.pageInfo?.hasNextPage !== true || pagination.isLoading) {
13464
+ if (pagination.resetCount === lastResetCountRef.current) {
13445
13465
  return;
13446
13466
  }
13467
+ lastResetCountRef.current = pagination.resetCount;
13468
+ isLoadingBackwardRef.current = false;
13447
13469
  const container = scrollElementRef.current;
13448
- if (!container) {
13449
- return;
13470
+ if (container) {
13471
+ container.scrollTop = 0;
13450
13472
  }
13451
- const [lastItem] = [...virtualItems].reverse();
13452
- const shouldLoadFromScroll = lastItem !== undefined && lastItem.index >= count - 1;
13453
- const shouldLoadFromInsufficientContent = container.scrollHeight <= container.clientHeight;
13454
- if (shouldLoadFromScroll || shouldLoadFromInsufficientContent) {
13455
- pagination.nextPage();
13456
- }
13457
- }, [
13458
- skip,
13459
- pagination.pageInfo?.hasNextPage,
13460
- pagination.nextPage,
13461
- pagination.isLoading,
13462
- pagination,
13463
- scrollElementRef,
13464
- virtualItems,
13465
- count,
13466
- ]);
13473
+ }, [pagination.resetCount, scrollElementRef]);
13474
+ // Forward loading: scroll reached bottom or insufficient content
13475
+ react.useEffect(() => {
13476
+ tryLoadNextPage(rowVirtualizer);
13477
+ }, [tryLoadNextPage, rowVirtualizer, virtualItems, count, pagination.pageInfo?.hasNextPage, pagination.isLoading]);
13467
13478
  // Backward loading: fires when the scroll container is at the very top.
13468
13479
  // Uses scrollTop instead of virtualItems[0].index because after data
13469
13480
  // prepends the scroll-offset effect adjusts scrollTop away from 0,
13470
13481
  // which correctly prevents re-triggering. virtualItems[0].index would
13471
13482
  // still be 0 (overscan always renders from the start) causing a loop.
13472
13483
  react.useEffect(() => {
13473
- if (skip || pagination.pageInfo?.hasPreviousPage !== true || pagination.isLoading) {
13484
+ if (skip || !pagination.pageInfo?.hasPreviousPage || pagination.isLoading) {
13474
13485
  return;
13475
13486
  }
13476
13487
  const container = scrollElementRef.current;
13477
- if (container !== null && container.scrollTop === 0) {
13478
- isLoadingBackwardRef.current = true;
13479
- pagination.previousPage();
13488
+ if (!container || container.scrollTop !== 0) {
13489
+ return;
13480
13490
  }
13491
+ isLoadingBackwardRef.current = true;
13492
+ pagination.previousPage();
13481
13493
  }, [
13482
13494
  skip,
13483
13495
  pagination.pageInfo?.hasPreviousPage,
@@ -14305,35 +14317,38 @@ const useRelayPagination = ({ onReset, pageSize, initialCursor } = { pageSize: d
14305
14317
  }));
14306
14318
  const [pageInfo, setPageInfo] = react.useState(() => initialCursor !== undefined ? { hasPreviousPage: true } : null);
14307
14319
  const [isLoading, setIsLoading] = react.useState(true);
14320
+ const [resetCount, setResetCount] = react.useState(0);
14308
14321
  // Destructure pageInfo properties early to avoid depending on the entire object
14309
14322
  const { hasNextPage, endCursor, hasPreviousPage, startCursor } = pageInfo ?? {};
14310
14323
  const nextPage = react.useCallback(() => {
14311
- if (hasNextPage === true) {
14312
- const after = endCursor === null ? undefined : endCursor;
14313
- setVariables(prev => {
14314
- // Idempotent: when the resolved variables are unchanged (e.g. the
14315
- // backend keeps reporting `hasNextPage: true` without advancing the
14316
- // cursor), return the same reference so React skips the re-render.
14317
- // Without this bail-out the forward auto-load in `useBidirectionalScroll`
14318
- // re-runs every render and calls `nextPage` again, causing an infinite
14319
- // update loop.
14320
- if (prev.after === after && prev.first === pageSize && prev.before === undefined && prev.last === undefined) {
14321
- return prev;
14322
- }
14323
- return { after, first: pageSize };
14324
- });
14324
+ if (!hasNextPage) {
14325
+ return;
14325
14326
  }
14327
+ const after = endCursor === null ? undefined : endCursor;
14328
+ setVariables(prev => {
14329
+ // Idempotent: when the resolved variables are unchanged (e.g. the
14330
+ // backend keeps reporting `hasNextPage: true` without advancing the
14331
+ // cursor), return the same reference so React skips the re-render.
14332
+ // Without this bail-out the forward auto-load in `useBidirectionalScroll`
14333
+ // re-runs every render and calls `nextPage` again, causing an infinite
14334
+ // update loop.
14335
+ if (prev.after === after && prev.first === pageSize && prev.before === undefined && prev.last === undefined) {
14336
+ return prev;
14337
+ }
14338
+ return { after, first: pageSize };
14339
+ });
14326
14340
  }, [hasNextPage, endCursor, pageSize]);
14327
14341
  const previousPage = react.useCallback(() => {
14328
- if (hasPreviousPage === true) {
14329
- const before = startCursor === null ? undefined : startCursor;
14330
- setVariables(prev => {
14331
- if (prev.before === before && prev.last === pageSize && prev.after === undefined && prev.first === undefined) {
14332
- return prev;
14333
- }
14334
- return { before, last: pageSize };
14335
- });
14342
+ if (!hasPreviousPage) {
14343
+ return;
14336
14344
  }
14345
+ const before = startCursor === null ? undefined : startCursor;
14346
+ setVariables(prev => {
14347
+ if (prev.before === before && prev.last === pageSize && prev.after === undefined && prev.first === undefined) {
14348
+ return prev;
14349
+ }
14350
+ return { before, last: pageSize };
14351
+ });
14337
14352
  }, [hasPreviousPage, startCursor, pageSize]);
14338
14353
  const reset = react.useCallback(() => {
14339
14354
  setVariables({
@@ -14342,10 +14357,25 @@ const useRelayPagination = ({ onReset, pageSize, initialCursor } = { pageSize: d
14342
14357
  after: undefined,
14343
14358
  first: pageSize,
14344
14359
  });
14345
- if (onReset) {
14346
- onReset();
14347
- }
14348
- }, [onReset, pageSize, setVariables]);
14360
+ // Clear the cursors so a forward load cannot reuse the previous result's
14361
+ // endCursor. Keep count, isCountCapped and hasNextPage so the table footer
14362
+ // does not flash from "100+" to "100" while the new first page loads; with
14363
+ // endCursor gone, nextPage resolves to the variables written above and
14364
+ // bails out. hasPreviousPage is cleared because the scroll reset puts
14365
+ // scrollTop at 0, which would otherwise trigger a backward load.
14366
+ // usePaginationQuery clears pageInfo right after calling reset(), because
14367
+ // a skipped query never gets a new page to replace the kept values.
14368
+ setPageInfo(prev => ({
14369
+ count: prev?.count,
14370
+ isCountCapped: prev?.isCountCapped,
14371
+ endCursor: undefined,
14372
+ startCursor: undefined,
14373
+ hasNextPage: prev?.hasNextPage,
14374
+ hasPreviousPage: undefined,
14375
+ }));
14376
+ setResetCount(prev => prev + 1);
14377
+ onReset?.();
14378
+ }, [onReset, pageSize]);
14349
14379
  return react.useMemo(() => {
14350
14380
  return {
14351
14381
  variables,
@@ -14357,9 +14387,10 @@ const useRelayPagination = ({ onReset, pageSize, initialCursor } = { pageSize: d
14357
14387
  reset,
14358
14388
  pageInfo: pageInfo === null ? undefined : pageInfo,
14359
14389
  setPageInfo,
14390
+ resetCount,
14360
14391
  },
14361
14392
  };
14362
- }, [variables, nextPage, previousPage, isLoading, reset, pageInfo]);
14393
+ }, [variables, nextPage, previousPage, isLoading, reset, pageInfo, resetCount]);
14363
14394
  };
14364
14395
 
14365
14396
  /**
package/index.esm.js CHANGED
@@ -95,7 +95,6 @@ const cvaIcon = cva({
95
95
  excessive_usage: "text-danger-500",
96
96
  stopped: "text-stopped-700",
97
97
  unknown: "text-unknown-400",
98
- no_data: "text-no_data-300",
99
98
  default: "text-current",
100
99
  black: "text-black",
101
100
  white: "text-white",
@@ -2294,7 +2293,6 @@ const cvaTag = cva({
2294
2293
  stopped: ["bg-stopped-100", "text-stopped-700"],
2295
2294
  idle: ["bg-idle-100", "text-idle-700"],
2296
2295
  unknown: ["bg-unknown-100", "text-unknown-500"],
2297
- no_data: ["bg-no_data-100", "text-no_data-500"],
2298
2296
  moving: ["bg-neutral-100", "text-neutral-700"],
2299
2297
  active: ["bg-neutral-100", "text-neutral-700"],
2300
2298
  excessive_usage: ["bg-danger-100", "text-danger-700"],
@@ -6322,7 +6320,6 @@ const cvaIndicatorPing = cva({
6322
6320
  active: "bg-active-600",
6323
6321
  excessive_usage: "bg-excessive_usage-600",
6324
6322
  unknown: "bg-unknown-400",
6325
- no_data: "bg-no_data-300",
6326
6323
  unused: "bg-unused-400",
6327
6324
  utilized: "bg-utilized-600",
6328
6325
  heavily_utilized: "bg-heavily_utilized-500",
@@ -6367,7 +6364,6 @@ const cvaIndicatorIconBackground = cva({
6367
6364
  active: "text-active-600 bg-neutral-100",
6368
6365
  excessive_usage: "bg-excessive_usage-100 text-excessive_usage-600",
6369
6366
  unknown: "bg-unknown-100 text-unknown-400",
6370
- no_data: "bg-no_data-100 text-no_data-300",
6371
6367
  unused: "bg-unused-100 text-unused-400",
6372
6368
  utilized: "bg-utilized-100 text-utilized-600",
6373
6369
  heavily_utilized: "bg-heavily_utilized-100 text-heavily_utilized-500",
@@ -13377,6 +13373,7 @@ const useStripForeignIdentityHash = () => {
13377
13373
 
13378
13374
  const OVERSCAN = 10;
13379
13375
  const DEFAULT_ROW_HEIGHT = 50;
13376
+ const SCROLL_END_THRESHOLD_PX = 1;
13380
13377
  /**
13381
13378
  * Bidirectional infinite scroll hook that supports both forward (nextPage)
13382
13379
  * and backward (previousPage) pagination with TanStack Virtual.
@@ -13391,6 +13388,23 @@ const useBidirectionalScroll = ({ pagination, scrollElementRef, count, estimateS
13391
13388
  onTopItemChangeRef.current = onTopItemChange;
13392
13389
  }, [onTopItemChange]);
13393
13390
  const lastReportedTopIndex = useRef(-1);
13391
+ const tryLoadNextPage = useCallback((virtualizer) => {
13392
+ if (skip || !pagination.pageInfo?.hasNextPage || pagination.isLoading) {
13393
+ return;
13394
+ }
13395
+ const container = scrollElementRef.current;
13396
+ if (!container) {
13397
+ return;
13398
+ }
13399
+ const lastItem = virtualizer.getVirtualItems().at(-1);
13400
+ const reachedLastVirtualRow = lastItem !== undefined && lastItem.index >= count - 1;
13401
+ const hasInsufficientContent = container.scrollHeight <= container.clientHeight;
13402
+ const isAtScrollEnd = container.scrollHeight - container.scrollTop - container.clientHeight <= SCROLL_END_THRESHOLD_PX;
13403
+ if (!reachedLastVirtualRow && !hasInsufficientContent && !isAtScrollEnd) {
13404
+ return;
13405
+ }
13406
+ pagination.nextPage();
13407
+ }, [count, pagination, scrollElementRef, skip]);
13394
13408
  const handleChange = useCallback((virtualizer) => {
13395
13409
  onChange?.(virtualizer);
13396
13410
  const scrollOffset = virtualizer.scrollOffset ?? 0;
@@ -13399,7 +13413,8 @@ const useBidirectionalScroll = ({ pagination, scrollElementRef, count, estimateS
13399
13413
  lastReportedTopIndex.current = firstVisibleItem.index;
13400
13414
  onTopItemChangeRef.current?.(firstVisibleItem.index);
13401
13415
  }
13402
- }, [onChange]);
13416
+ tryLoadNextPage(virtualizer);
13417
+ }, [onChange, tryLoadNextPage]);
13403
13418
  const handleEstimateSize = useCallback((index) => estimateSize?.(index) ?? DEFAULT_ROW_HEIGHT, [estimateSize]);
13404
13419
  // eslint-plugin-react-hooks hardcodes `useVirtualizer` as a known-incompatible
13405
13420
  // API (its returned functions can't be memoized), so this warning is emitted
@@ -13426,57 +13441,54 @@ const useBidirectionalScroll = ({ pagination, scrollElementRef, count, estimateS
13426
13441
  // after items are prepended, preventing an infinite backward-load loop.
13427
13442
  const prevCountRef = useRef(count);
13428
13443
  const isLoadingBackwardRef = useRef(false);
13444
+ const lastResetCountRef = useRef(pagination.resetCount);
13429
13445
  useEffect(() => {
13430
- if (isLoadingBackwardRef.current && !pagination.isLoading && count > prevCountRef.current) {
13431
- const prependedCount = count - prevCountRef.current;
13432
- const container = scrollElementRef.current;
13446
+ const container = scrollElementRef.current;
13447
+ const previousCount = prevCountRef.current;
13448
+ if (isLoadingBackwardRef.current && !pagination.isLoading && count > previousCount) {
13433
13449
  if (container) {
13434
13450
  const estimatedRowHeight = estimateSize?.(0) ?? DEFAULT_ROW_HEIGHT;
13435
- container.scrollTop += prependedCount * estimatedRowHeight;
13451
+ container.scrollTop += (count - previousCount) * estimatedRowHeight;
13436
13452
  }
13437
13453
  isLoadingBackwardRef.current = false;
13454
+ prevCountRef.current = count;
13455
+ return;
13438
13456
  }
13439
13457
  prevCountRef.current = count;
13440
13458
  }, [count, pagination.isLoading, scrollElementRef, estimateSize]);
13441
- // Forward loading: scroll reached bottom or insufficient content
13459
+ // Reset scroll to top when pagination is reset (e.g. new search).
13460
+ // Keyed on resetCount rather than pageInfo: a forward page without pageInfo
13461
+ // also clears endCursor, and must not move the user back to the top.
13442
13462
  useEffect(() => {
13443
- if (skip || pagination.pageInfo?.hasNextPage !== true || pagination.isLoading) {
13463
+ if (pagination.resetCount === lastResetCountRef.current) {
13444
13464
  return;
13445
13465
  }
13466
+ lastResetCountRef.current = pagination.resetCount;
13467
+ isLoadingBackwardRef.current = false;
13446
13468
  const container = scrollElementRef.current;
13447
- if (!container) {
13448
- return;
13469
+ if (container) {
13470
+ container.scrollTop = 0;
13449
13471
  }
13450
- const [lastItem] = [...virtualItems].reverse();
13451
- const shouldLoadFromScroll = lastItem !== undefined && lastItem.index >= count - 1;
13452
- const shouldLoadFromInsufficientContent = container.scrollHeight <= container.clientHeight;
13453
- if (shouldLoadFromScroll || shouldLoadFromInsufficientContent) {
13454
- pagination.nextPage();
13455
- }
13456
- }, [
13457
- skip,
13458
- pagination.pageInfo?.hasNextPage,
13459
- pagination.nextPage,
13460
- pagination.isLoading,
13461
- pagination,
13462
- scrollElementRef,
13463
- virtualItems,
13464
- count,
13465
- ]);
13472
+ }, [pagination.resetCount, scrollElementRef]);
13473
+ // Forward loading: scroll reached bottom or insufficient content
13474
+ useEffect(() => {
13475
+ tryLoadNextPage(rowVirtualizer);
13476
+ }, [tryLoadNextPage, rowVirtualizer, virtualItems, count, pagination.pageInfo?.hasNextPage, pagination.isLoading]);
13466
13477
  // Backward loading: fires when the scroll container is at the very top.
13467
13478
  // Uses scrollTop instead of virtualItems[0].index because after data
13468
13479
  // prepends the scroll-offset effect adjusts scrollTop away from 0,
13469
13480
  // which correctly prevents re-triggering. virtualItems[0].index would
13470
13481
  // still be 0 (overscan always renders from the start) causing a loop.
13471
13482
  useEffect(() => {
13472
- if (skip || pagination.pageInfo?.hasPreviousPage !== true || pagination.isLoading) {
13483
+ if (skip || !pagination.pageInfo?.hasPreviousPage || pagination.isLoading) {
13473
13484
  return;
13474
13485
  }
13475
13486
  const container = scrollElementRef.current;
13476
- if (container !== null && container.scrollTop === 0) {
13477
- isLoadingBackwardRef.current = true;
13478
- pagination.previousPage();
13487
+ if (!container || container.scrollTop !== 0) {
13488
+ return;
13479
13489
  }
13490
+ isLoadingBackwardRef.current = true;
13491
+ pagination.previousPage();
13480
13492
  }, [
13481
13493
  skip,
13482
13494
  pagination.pageInfo?.hasPreviousPage,
@@ -14304,35 +14316,38 @@ const useRelayPagination = ({ onReset, pageSize, initialCursor } = { pageSize: d
14304
14316
  }));
14305
14317
  const [pageInfo, setPageInfo] = useState(() => initialCursor !== undefined ? { hasPreviousPage: true } : null);
14306
14318
  const [isLoading, setIsLoading] = useState(true);
14319
+ const [resetCount, setResetCount] = useState(0);
14307
14320
  // Destructure pageInfo properties early to avoid depending on the entire object
14308
14321
  const { hasNextPage, endCursor, hasPreviousPage, startCursor } = pageInfo ?? {};
14309
14322
  const nextPage = useCallback(() => {
14310
- if (hasNextPage === true) {
14311
- const after = endCursor === null ? undefined : endCursor;
14312
- setVariables(prev => {
14313
- // Idempotent: when the resolved variables are unchanged (e.g. the
14314
- // backend keeps reporting `hasNextPage: true` without advancing the
14315
- // cursor), return the same reference so React skips the re-render.
14316
- // Without this bail-out the forward auto-load in `useBidirectionalScroll`
14317
- // re-runs every render and calls `nextPage` again, causing an infinite
14318
- // update loop.
14319
- if (prev.after === after && prev.first === pageSize && prev.before === undefined && prev.last === undefined) {
14320
- return prev;
14321
- }
14322
- return { after, first: pageSize };
14323
- });
14323
+ if (!hasNextPage) {
14324
+ return;
14324
14325
  }
14326
+ const after = endCursor === null ? undefined : endCursor;
14327
+ setVariables(prev => {
14328
+ // Idempotent: when the resolved variables are unchanged (e.g. the
14329
+ // backend keeps reporting `hasNextPage: true` without advancing the
14330
+ // cursor), return the same reference so React skips the re-render.
14331
+ // Without this bail-out the forward auto-load in `useBidirectionalScroll`
14332
+ // re-runs every render and calls `nextPage` again, causing an infinite
14333
+ // update loop.
14334
+ if (prev.after === after && prev.first === pageSize && prev.before === undefined && prev.last === undefined) {
14335
+ return prev;
14336
+ }
14337
+ return { after, first: pageSize };
14338
+ });
14325
14339
  }, [hasNextPage, endCursor, pageSize]);
14326
14340
  const previousPage = useCallback(() => {
14327
- if (hasPreviousPage === true) {
14328
- const before = startCursor === null ? undefined : startCursor;
14329
- setVariables(prev => {
14330
- if (prev.before === before && prev.last === pageSize && prev.after === undefined && prev.first === undefined) {
14331
- return prev;
14332
- }
14333
- return { before, last: pageSize };
14334
- });
14341
+ if (!hasPreviousPage) {
14342
+ return;
14335
14343
  }
14344
+ const before = startCursor === null ? undefined : startCursor;
14345
+ setVariables(prev => {
14346
+ if (prev.before === before && prev.last === pageSize && prev.after === undefined && prev.first === undefined) {
14347
+ return prev;
14348
+ }
14349
+ return { before, last: pageSize };
14350
+ });
14336
14351
  }, [hasPreviousPage, startCursor, pageSize]);
14337
14352
  const reset = useCallback(() => {
14338
14353
  setVariables({
@@ -14341,10 +14356,25 @@ const useRelayPagination = ({ onReset, pageSize, initialCursor } = { pageSize: d
14341
14356
  after: undefined,
14342
14357
  first: pageSize,
14343
14358
  });
14344
- if (onReset) {
14345
- onReset();
14346
- }
14347
- }, [onReset, pageSize, setVariables]);
14359
+ // Clear the cursors so a forward load cannot reuse the previous result's
14360
+ // endCursor. Keep count, isCountCapped and hasNextPage so the table footer
14361
+ // does not flash from "100+" to "100" while the new first page loads; with
14362
+ // endCursor gone, nextPage resolves to the variables written above and
14363
+ // bails out. hasPreviousPage is cleared because the scroll reset puts
14364
+ // scrollTop at 0, which would otherwise trigger a backward load.
14365
+ // usePaginationQuery clears pageInfo right after calling reset(), because
14366
+ // a skipped query never gets a new page to replace the kept values.
14367
+ setPageInfo(prev => ({
14368
+ count: prev?.count,
14369
+ isCountCapped: prev?.isCountCapped,
14370
+ endCursor: undefined,
14371
+ startCursor: undefined,
14372
+ hasNextPage: prev?.hasNextPage,
14373
+ hasPreviousPage: undefined,
14374
+ }));
14375
+ setResetCount(prev => prev + 1);
14376
+ onReset?.();
14377
+ }, [onReset, pageSize]);
14348
14378
  return useMemo(() => {
14349
14379
  return {
14350
14380
  variables,
@@ -14356,9 +14386,10 @@ const useRelayPagination = ({ onReset, pageSize, initialCursor } = { pageSize: d
14356
14386
  reset,
14357
14387
  pageInfo: pageInfo === null ? undefined : pageInfo,
14358
14388
  setPageInfo,
14389
+ resetCount,
14359
14390
  },
14360
14391
  };
14361
- }, [variables, nextPage, previousPage, isLoading, reset, pageInfo]);
14392
+ }, [variables, nextPage, previousPage, isLoading, reset, pageInfo, resetCount]);
14362
14393
  };
14363
14394
 
14364
14395
  /**
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@trackunit/react-router-components",
3
- "version": "1.3.40-alpha-b8d3d323d1a.0",
3
+ "version": "1.3.41",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
7
7
  "node": ">=24.x"
8
8
  },
9
9
  "dependencies": {
10
- "@trackunit/css-class-variance-utilities": "2.6.43-alpha-b8d3d323d1a.0",
11
- "@trackunit/i18n-library-translation": "2.14.35-alpha-b8d3d323d1a.0",
12
- "@trackunit/react-components": "6.0.37-alpha-b8d3d323d1a.0",
13
- "@trackunit/react-drawer": "2.17.38-alpha-b8d3d323d1a.0",
14
- "@trackunit/shared-utils": "1.22.43-alpha-b8d3d323d1a.0",
10
+ "@trackunit/css-class-variance-utilities": "2.6.43",
11
+ "@trackunit/i18n-library-translation": "2.14.35",
12
+ "@trackunit/react-components": "6.0.38",
13
+ "@trackunit/react-drawer": "2.17.39",
14
+ "@trackunit/shared-utils": "1.22.43",
15
15
  "dequal": "^2.0.3",
16
16
  "zod": "^3.25.76"
17
17
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-components",
3
- "version": "6.0.37-alpha-b8d3d323d1a.0",
3
+ "version": "6.0.38",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "migrations": "./migrations.json",
@@ -14,15 +14,15 @@
14
14
  "@floating-ui/react": "^0.26.25",
15
15
  "string-ts": "^2.0.0",
16
16
  "tailwind-merge": "^3.7.0",
17
- "@trackunit/ui-design-tokens": "1.21.41-alpha-b8d3d323d1a.0",
18
- "@trackunit/css-class-variance-utilities": "2.6.43-alpha-b8d3d323d1a.0",
19
- "@trackunit/shared-utils": "1.22.43-alpha-b8d3d323d1a.0",
20
- "@trackunit/ui-icons": "1.20.41-alpha-b8d3d323d1a.0",
17
+ "@trackunit/ui-design-tokens": "1.21.41",
18
+ "@trackunit/css-class-variance-utilities": "2.6.43",
19
+ "@trackunit/shared-utils": "1.22.43",
20
+ "@trackunit/ui-icons": "1.20.41",
21
21
  "es-toolkit": "^1.52.0",
22
22
  "@tanstack/react-virtual": "^3.14.13",
23
23
  "fflate": "^0.8.3",
24
24
  "zod": "^3.25.76",
25
- "@trackunit/i18n-library-translation": "2.14.35-alpha-b8d3d323d1a.0"
25
+ "@trackunit/i18n-library-translation": "2.14.35"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "react": "^19.0.0",
@@ -124,12 +124,6 @@ export declare const iconPalette: {
124
124
  readonly 500: "107 114 128";
125
125
  readonly 900: "17 24 39";
126
126
  };
127
- NO_DATA: {
128
- readonly 100: "243 244 246";
129
- readonly 300: "209 213 219";
130
- readonly 500: "107 114 128";
131
- readonly 900: "17 24 39";
132
- };
133
127
  MOVING: {
134
128
  readonly 100: "220 252 231";
135
129
  readonly 500: "34 197 94";
@@ -251,7 +245,7 @@ export declare const iconPalette: {
251
245
  readonly 900: "127 29 29";
252
246
  };
253
247
  };
254
- export declare const iconColorNames: ("black" | "white" | "active" | "primary" | "trackunit_branding" | "neutral" | "info" | "success" | "warning" | "danger" | "good" | "low" | "critical" | "working" | "idle" | "moving" | "excessive_usage" | "stopped" | "unknown" | "no_data" | "unused" | "utilized" | "heavily_utilized" | "unknown_utilization" | "site_area" | "site_classic_poi" | "site_classic_zone" | "site_depot" | "site_work_place" | "site_construction_site" | "site_unknown" | "on_rent" | "returned" | "available" | "pickup_ready" | "transfer" | "in_repair" | "other_rental_status")[];
248
+ export declare const iconColorNames: ("black" | "white" | "active" | "primary" | "trackunit_branding" | "neutral" | "info" | "success" | "warning" | "danger" | "good" | "low" | "critical" | "working" | "idle" | "moving" | "excessive_usage" | "stopped" | "unknown" | "unused" | "utilized" | "heavily_utilized" | "unknown_utilization" | "site_area" | "site_classic_poi" | "site_classic_zone" | "site_depot" | "site_work_place" | "site_construction_site" | "site_unknown" | "on_rent" | "returned" | "available" | "pickup_ready" | "transfer" | "in_repair" | "other_rental_status")[];
255
249
  type IconPropsSmall = {
256
250
  size?: "small";
257
251
  type?: "solid";
@@ -19,7 +19,6 @@ export declare const cvaIcon: import("cva").CVAComponent<Omit<{
19
19
  excessive_usage: string;
20
20
  stopped: string;
21
21
  unknown: string;
22
- no_data: string;
23
22
  default: string;
24
23
  black: string;
25
24
  white: string;
@@ -89,7 +88,6 @@ export declare const cvaIcon: import("cva").CVAComponent<Omit<{
89
88
  excessive_usage: string;
90
89
  stopped: string;
91
90
  unknown: string;
92
- no_data: string;
93
91
  default: string;
94
92
  black: string;
95
93
  white: string;
@@ -145,7 +143,6 @@ export declare const cvaIcon: import("cva").CVAComponent<Omit<{
145
143
  excessive_usage: string;
146
144
  stopped: string;
147
145
  unknown: string;
148
- no_data: string;
149
146
  default: string;
150
147
  black: string;
151
148
  white: string;
@@ -99,7 +99,6 @@ export declare const cvaIndicatorPing: import("cva").CVAComponent<Omit<{
99
99
  active: string;
100
100
  excessive_usage: string;
101
101
  unknown: string;
102
- no_data: string;
103
102
  unused: string;
104
103
  utilized: string;
105
104
  heavily_utilized: string;
@@ -142,7 +141,6 @@ export declare const cvaIndicatorPing: import("cva").CVAComponent<Omit<{
142
141
  active: string;
143
142
  excessive_usage: string;
144
143
  unknown: string;
145
- no_data: string;
146
144
  unused: string;
147
145
  utilized: string;
148
146
  heavily_utilized: string;
@@ -185,7 +183,6 @@ export declare const cvaIndicatorPing: import("cva").CVAComponent<Omit<{
185
183
  active: string;
186
184
  excessive_usage: string;
187
185
  unknown: string;
188
- no_data: string;
189
186
  unused: string;
190
187
  utilized: string;
191
188
  heavily_utilized: string;
@@ -229,7 +226,6 @@ export declare const cvaIndicatorIconBackground: import("cva").CVAComponent<Omit
229
226
  active: string;
230
227
  excessive_usage: string;
231
228
  unknown: string;
232
- no_data: string;
233
229
  unused: string;
234
230
  utilized: string;
235
231
  heavily_utilized: string;
@@ -280,7 +276,6 @@ export declare const cvaIndicatorIconBackground: import("cva").CVAComponent<Omit
280
276
  active: string;
281
277
  excessive_usage: string;
282
278
  unknown: string;
283
- no_data: string;
284
279
  unused: string;
285
280
  utilized: string;
286
281
  heavily_utilized: string;
@@ -330,7 +325,6 @@ export declare const cvaIndicatorIconBackground: import("cva").CVAComponent<Omit
330
325
  active: string;
331
326
  excessive_usage: string;
332
327
  unknown: string;
333
- no_data: string;
334
328
  unused: string;
335
329
  utilized: string;
336
330
  heavily_utilized: string;
@@ -31,7 +31,6 @@ export declare const cvaTag: import("cva").CVAComponent<Omit<{
31
31
  stopped: string[];
32
32
  idle: string[];
33
33
  unknown: string[];
34
- no_data: string[];
35
34
  moving: string[];
36
35
  active: string[];
37
36
  excessive_usage: string[];
@@ -73,7 +72,6 @@ export declare const cvaTag: import("cva").CVAComponent<Omit<{
73
72
  stopped: string[];
74
73
  idle: string[];
75
74
  unknown: string[];
76
- no_data: string[];
77
75
  moving: string[];
78
76
  active: string[];
79
77
  excessive_usage: string[];
@@ -114,7 +112,6 @@ export declare const cvaTag: import("cva").CVAComponent<Omit<{
114
112
  stopped: string[];
115
113
  idle: string[];
116
114
  unknown: string[];
117
- no_data: string[];
118
115
  moving: string[];
119
116
  active: string[];
120
117
  excessive_usage: string[];
@@ -23,6 +23,12 @@ export interface RelayPagination {
23
23
  previousPage: () => void;
24
24
  pageInfo?: RelayPageInfo;
25
25
  isLoading: boolean;
26
+ /**
27
+ * Increments every time `reset()` is called. Consumers such as `useBidirectionalScroll`
28
+ * use it to tell a deliberate reset (new search, filter or sort) apart from a page
29
+ * response that happens to clear `endCursor`.
30
+ */
31
+ resetCount?: number;
26
32
  }
27
33
  export interface RelayTableSupport extends RelayPagination {
28
34
  isLoading: boolean;