@terreno/ui 57.3.0 → 57.4.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.
Files changed (212) hide show
  1. package/dist/AnnouncementBanner.d.ts +12 -0
  2. package/dist/AnnouncementBanner.js +61 -0
  3. package/dist/AnnouncementBanner.js.map +1 -0
  4. package/dist/AnnouncementNavigator.d.ts +11 -0
  5. package/dist/AnnouncementNavigator.js +189 -0
  6. package/dist/AnnouncementNavigator.js.map +1 -0
  7. package/dist/AnnouncementScreen.d.ts +12 -0
  8. package/dist/AnnouncementScreen.js +28 -0
  9. package/dist/AnnouncementScreen.js.map +1 -0
  10. package/dist/AreaChart.d.ts +5 -0
  11. package/dist/AreaChart.js +69 -0
  12. package/dist/AreaChart.js.map +1 -0
  13. package/dist/BarChart.d.ts +5 -0
  14. package/dist/BarChart.js +89 -0
  15. package/dist/BarChart.js.map +1 -0
  16. package/dist/Button.js +17 -3
  17. package/dist/Button.js.map +1 -1
  18. package/dist/Common.d.ts +96 -0
  19. package/dist/Common.js.map +1 -1
  20. package/dist/DashboardGrid.d.ts +4 -0
  21. package/dist/DashboardGrid.js +38 -0
  22. package/dist/DashboardGrid.js.map +1 -0
  23. package/dist/DataTable.js +83 -11
  24. package/dist/DataTable.js.map +1 -1
  25. package/dist/DonutChart.d.ts +5 -0
  26. package/dist/DonutChart.js +84 -0
  27. package/dist/DonutChart.js.map +1 -0
  28. package/dist/Filter.js +12 -2
  29. package/dist/Filter.js.map +1 -1
  30. package/dist/GPTChat.d.ts +7 -1
  31. package/dist/GPTChat.js +28 -15
  32. package/dist/GPTChat.js.map +1 -1
  33. package/dist/LineChart.d.ts +5 -0
  34. package/dist/LineChart.js +68 -0
  35. package/dist/LineChart.js.map +1 -0
  36. package/dist/MarkdownEmbed.d.ts +6 -0
  37. package/dist/MarkdownEmbed.js +17 -0
  38. package/dist/MarkdownEmbed.js.map +1 -0
  39. package/dist/MarkdownView.js +38 -3
  40. package/dist/MarkdownView.js.map +1 -1
  41. package/dist/Modal.js +12 -10
  42. package/dist/Modal.js.map +1 -1
  43. package/dist/ModalSheet.d.ts +5 -1
  44. package/dist/ModalSheet.js +31 -13
  45. package/dist/ModalSheet.js.map +1 -1
  46. package/dist/MultiselectField.js +4 -9
  47. package/dist/MultiselectField.js.map +1 -1
  48. package/dist/NotificationBell.d.ts +16 -0
  49. package/dist/NotificationBell.js +15 -0
  50. package/dist/NotificationBell.js.map +1 -0
  51. package/dist/NotificationInbox.d.ts +21 -0
  52. package/dist/NotificationInbox.js +41 -0
  53. package/dist/NotificationInbox.js.map +1 -0
  54. package/dist/NotificationPreferences.d.ts +14 -0
  55. package/dist/NotificationPreferences.js +32 -0
  56. package/dist/NotificationPreferences.js.map +1 -0
  57. package/dist/TextField.js +83 -6
  58. package/dist/TextField.js.map +1 -1
  59. package/dist/announcementBuildVersion.d.ts +6 -0
  60. package/dist/announcementBuildVersion.js +21 -0
  61. package/dist/announcementBuildVersion.js.map +1 -0
  62. package/dist/announcementFrequency.d.ts +42 -0
  63. package/dist/announcementFrequency.js +163 -0
  64. package/dist/announcementFrequency.js.map +1 -0
  65. package/dist/announcementPlatform.d.ts +2 -0
  66. package/dist/announcementPlatform.js +11 -0
  67. package/dist/announcementPlatform.js.map +1 -0
  68. package/dist/charts/ChartFrame.d.ts +12 -0
  69. package/dist/charts/ChartFrame.js +13 -0
  70. package/dist/charts/ChartFrame.js.map +1 -0
  71. package/dist/charts/bars.d.ts +18 -0
  72. package/dist/charts/bars.js +29 -0
  73. package/dist/charts/bars.js.map +1 -0
  74. package/dist/charts/layout.d.ts +47 -0
  75. package/dist/charts/layout.js +56 -0
  76. package/dist/charts/layout.js.map +1 -0
  77. package/dist/charts/paths.d.ts +31 -0
  78. package/dist/charts/paths.js +52 -0
  79. package/dist/charts/paths.js.map +1 -0
  80. package/dist/charts/scales.d.ts +6 -0
  81. package/dist/charts/scales.js +43 -0
  82. package/dist/charts/scales.js.map +1 -0
  83. package/dist/charts/theme.d.ts +9 -0
  84. package/dist/charts/theme.js +15 -0
  85. package/dist/charts/theme.js.map +1 -0
  86. package/dist/charts/types/chartTypes.d.ts +17 -0
  87. package/dist/charts/types/chartTypes.js +2 -0
  88. package/dist/charts/types/chartTypes.js.map +1 -0
  89. package/dist/dashboardGridLayout.d.ts +22 -0
  90. package/dist/dashboardGridLayout.js +33 -0
  91. package/dist/dashboardGridLayout.js.map +1 -0
  92. package/dist/dataTableFilters.d.ts +33 -0
  93. package/dist/dataTableFilters.js +221 -0
  94. package/dist/dataTableFilters.js.map +1 -0
  95. package/dist/dataTableListQuery.d.ts +42 -0
  96. package/dist/dataTableListQuery.js +161 -0
  97. package/dist/dataTableListQuery.js.map +1 -0
  98. package/dist/index.d.ts +18 -1
  99. package/dist/index.js +11 -1
  100. package/dist/index.js.map +1 -1
  101. package/dist/lazyBoundaries/heavyOptionalExports.d.ts +12 -0
  102. package/dist/lazyBoundaries/heavyOptionalExports.js +8 -0
  103. package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
  104. package/dist/markdownEmbeds.d.ts +6 -0
  105. package/dist/markdownEmbeds.js +59 -0
  106. package/dist/markdownEmbeds.js.map +1 -0
  107. package/dist/testing/resolveTestId.js +2 -1
  108. package/dist/testing/resolveTestId.js.map +1 -1
  109. package/dist/testing/types.d.ts +3 -0
  110. package/dist/textFieldOscillationGuard.d.ts +25 -0
  111. package/dist/textFieldOscillationGuard.js +41 -0
  112. package/dist/textFieldOscillationGuard.js.map +1 -0
  113. package/dist/useAcknowledgeAnnouncement.d.ts +71 -0
  114. package/dist/useAcknowledgeAnnouncement.js +94 -0
  115. package/dist/useAcknowledgeAnnouncement.js.map +1 -0
  116. package/dist/useAnnouncements.d.ts +73 -0
  117. package/dist/useAnnouncements.js +66 -0
  118. package/dist/useAnnouncements.js.map +1 -0
  119. package/package.json +7 -18
  120. package/src/AnnouncementBanner.test.tsx +267 -0
  121. package/src/AnnouncementBanner.tsx +128 -0
  122. package/src/AnnouncementNavigator.test.tsx +759 -0
  123. package/src/AnnouncementNavigator.tsx +287 -0
  124. package/src/AnnouncementScreen.test.tsx +97 -0
  125. package/src/AnnouncementScreen.tsx +70 -0
  126. package/src/AreaChart.test.tsx +68 -0
  127. package/src/AreaChart.tsx +194 -0
  128. package/src/BarChart.test.tsx +96 -0
  129. package/src/BarChart.tsx +208 -0
  130. package/src/Button.test.tsx +66 -0
  131. package/src/Button.tsx +17 -2
  132. package/src/Common.ts +95 -0
  133. package/src/ConsentNavigator.test.tsx +55 -0
  134. package/src/DashboardGrid.test.tsx +75 -0
  135. package/src/DashboardGrid.tsx +69 -0
  136. package/src/DataTable.test.tsx +296 -1
  137. package/src/DataTable.tsx +210 -18
  138. package/src/DonutChart.test.tsx +121 -0
  139. package/src/DonutChart.tsx +160 -0
  140. package/src/EmojiSelector.test.tsx +51 -0
  141. package/src/Field.test.tsx +18 -0
  142. package/src/Filter.test.tsx +25 -0
  143. package/src/Filter.tsx +38 -7
  144. package/src/GPTChat.test.tsx +107 -0
  145. package/src/GPTChat.tsx +176 -86
  146. package/src/LineChart.test.tsx +166 -0
  147. package/src/LineChart.tsx +190 -0
  148. package/src/MarkdownEmbed.test.tsx +34 -0
  149. package/src/MarkdownEmbed.tsx +43 -0
  150. package/src/MarkdownView.test.tsx +59 -2
  151. package/src/MarkdownView.tsx +51 -3
  152. package/src/Modal.test.tsx +107 -14
  153. package/src/Modal.tsx +20 -8
  154. package/src/ModalSheet.test.tsx +121 -9
  155. package/src/ModalSheet.tsx +46 -11
  156. package/src/MultiselectField.test.tsx +21 -0
  157. package/src/MultiselectField.tsx +11 -13
  158. package/src/NotificationBell.test.tsx +91 -0
  159. package/src/NotificationBell.tsx +77 -0
  160. package/src/NotificationInbox.test.tsx +130 -0
  161. package/src/NotificationInbox.tsx +144 -0
  162. package/src/NotificationPreferences.test.tsx +25 -0
  163. package/src/NotificationPreferences.tsx +75 -0
  164. package/src/RootImportRegression.test.tsx +20 -0
  165. package/src/TextField.test.tsx +421 -0
  166. package/src/TextField.tsx +121 -4
  167. package/src/__snapshots__/Field.test.tsx.snap +22 -0
  168. package/src/__snapshots__/ModalSheet.test.tsx.snap +4 -1
  169. package/src/__snapshots__/TextArea.test.tsx.snap +5 -5
  170. package/src/__snapshots__/TextField.test.tsx.snap +5 -5
  171. package/src/announcementBuildVersion.test.ts +43 -0
  172. package/src/announcementBuildVersion.ts +21 -0
  173. package/src/announcementFrequency.test.ts +245 -0
  174. package/src/announcementFrequency.ts +246 -0
  175. package/src/announcementPlatform.test.ts +27 -0
  176. package/src/announcementPlatform.ts +13 -0
  177. package/src/charts/ChartFrame.tsx +67 -0
  178. package/src/charts/bars.test.ts +56 -0
  179. package/src/charts/bars.ts +53 -0
  180. package/src/charts/layout.test.ts +80 -0
  181. package/src/charts/layout.ts +99 -0
  182. package/src/charts/paths.test.ts +79 -0
  183. package/src/charts/paths.ts +100 -0
  184. package/src/charts/scales.test.ts +59 -0
  185. package/src/charts/scales.ts +60 -0
  186. package/src/charts/theme.test.ts +22 -0
  187. package/src/charts/theme.ts +24 -0
  188. package/src/charts/types/chartTypes.ts +19 -0
  189. package/src/dashboardGridLayout.test.ts +90 -0
  190. package/src/dashboardGridLayout.ts +60 -0
  191. package/src/dataTableFilters.test.tsx +552 -0
  192. package/src/dataTableFilters.tsx +441 -0
  193. package/src/dataTableListQuery.test.ts +220 -0
  194. package/src/dataTableListQuery.ts +201 -0
  195. package/src/index.tsx +21 -1
  196. package/src/lazyBoundaries/heavyOptionalExports.tsx +28 -0
  197. package/src/login/__snapshots__/LoginScreen.test.tsx.snap +22 -0
  198. package/src/markdownEmbeds.test.ts +53 -0
  199. package/src/markdownEmbeds.ts +62 -0
  200. package/src/pdfHtmlTemplate.test.ts +119 -0
  201. package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +22 -0
  202. package/src/testing/resolveTestId.test.ts +3 -0
  203. package/src/testing/resolveTestId.ts +1 -0
  204. package/src/testing/types.ts +3 -0
  205. package/src/textFieldOscillationGuard.test.ts +63 -0
  206. package/src/textFieldOscillationGuard.ts +89 -0
  207. package/src/types/react-native-markdown-display.d.ts +6 -0
  208. package/src/types/react-native-swiper-flatlist.d.ts +5 -5
  209. package/src/useAcknowledgeAnnouncement.test.ts +223 -0
  210. package/src/useAcknowledgeAnnouncement.ts +166 -0
  211. package/src/useAnnouncements.test.ts +226 -0
  212. package/src/useAnnouncements.ts +150 -0
package/src/DataTable.tsx CHANGED
@@ -1,15 +1,26 @@
1
1
  import {FontAwesome6} from "@expo/vector-icons";
2
2
  import type React from "react";
3
- import {type FC, memo, useCallback, useLayoutEffect, useMemo, useRef, useState} from "react";
3
+ import {
4
+ type FC,
5
+ memo,
6
+ useCallback,
7
+ useEffect,
8
+ useLayoutEffect,
9
+ useMemo,
10
+ useRef,
11
+ useState,
12
+ } from "react";
4
13
  import {
5
14
  type NativeScrollEvent,
6
15
  type NativeSyntheticEvent,
16
+ Platform,
7
17
  Pressable,
8
18
  type FlatList as RNFlatList,
9
19
  ScrollView,
10
20
  View,
11
21
  } from "react-native";
12
22
  import {Box} from "./Box";
23
+ import {Button} from "./Button";
13
24
  import type {
14
25
  ColumnSortInterface,
15
26
  DataTableCellData,
@@ -20,12 +31,19 @@ import type {
20
31
  SurfaceColor,
21
32
  } from "./Common";
22
33
  import {DataTableHeaderInfoMarkdown} from "./DataTableHeaderInfoMarkdown";
34
+ import {
35
+ DataTableAdditionalFiltersWeb,
36
+ DataTableColumnFilterWeb,
37
+ DataTableFilterFields,
38
+ } from "./dataTableFilters";
39
+ import {buildDataTableListQuery, DATA_TABLE_SEARCH_DEBOUNCE_MS} from "./dataTableListQuery";
23
40
  import {FlatList} from "./FlatList";
24
41
  import {Icon} from "./Icon";
25
42
  import {InfoModalIcon} from "./InfoModalIcon";
26
43
  import {Modal} from "./Modal";
27
44
  import {Pagination} from "./Pagination";
28
45
  import {Text} from "./Text";
46
+ import {TextField} from "./TextField";
29
47
  import {useTheme} from "./Theme";
30
48
  import {TableTitle} from "./table/TableTitle";
31
49
  import {
@@ -267,12 +285,16 @@ interface DataTableHeaderCellProps {
267
285
  onSort: (index: number) => void;
268
286
  rowHeight: number;
269
287
  headerHeight?: number;
288
+ filterValues?: Record<string, unknown>;
289
+ onFilterValuesChange?: (next: Record<string, unknown>) => void;
270
290
  }
271
291
 
272
292
  const DataTableHeaderCell: FC<DataTableHeaderCellProps> = ({
273
293
  column,
294
+ filterValues,
274
295
  index,
275
296
  isPinnedHorizontal,
297
+ onFilterValuesChange,
276
298
  pinnedLeft,
277
299
  sortColumn,
278
300
  onSort,
@@ -306,6 +328,15 @@ const DataTableHeaderCell: FC<DataTableHeaderCellProps> = ({
306
328
  <TableTitle align="left" key="data-table-header-title" title={column.title!} />
307
329
  ) : null,
308
330
  <View key="data-table-header-tools" style={{alignItems: "center", flexDirection: "row"}}>
331
+ {column.filter && onFilterValuesChange && Platform.OS === "web" ? (
332
+ <DataTableColumnFilterWeb
333
+ appliedValues={filterValues ?? {}}
334
+ columnTitle={column.title}
335
+ filter={column.filter}
336
+ onApply={onFilterValuesChange}
337
+ testID={`data-table-filter-${column.filter.field}`}
338
+ />
339
+ ) : null}
309
340
  {column.infoModalText && (
310
341
  <InfoModalIcon
311
342
  infoModalChildren={
@@ -357,11 +388,15 @@ interface DataTableHeaderProps {
357
388
  rowHeight: number;
358
389
  headerHeight?: number;
359
390
  testID?: string;
391
+ filterValues?: Record<string, unknown>;
392
+ onFilterValuesChange?: (next: Record<string, unknown>) => void;
360
393
  }
361
394
 
362
395
  const DataTableHeader: FC<DataTableHeaderProps> = ({
363
396
  columns,
397
+ filterValues,
364
398
  hasMoreContent,
399
+ onFilterValuesChange,
365
400
  pinnedColumns,
366
401
  pinnedLeftOffsets,
367
402
  pinnedWidth,
@@ -405,10 +440,12 @@ const DataTableHeader: FC<DataTableHeaderProps> = ({
405
440
  {columns.slice(0, pinnedColumns).map((column, index) => (
406
441
  <DataTableHeaderCell
407
442
  column={column}
443
+ filterValues={filterValues}
408
444
  headerHeight={headerHeight}
409
445
  index={index}
410
446
  isPinnedHorizontal
411
447
  key={`pinned-header-${index}`}
448
+ onFilterValuesChange={onFilterValuesChange}
412
449
  onSort={onSort}
413
450
  pinnedLeft={pinnedLeftOffsets[index] ?? 0}
414
451
  rowHeight={rowHeight}
@@ -433,10 +470,12 @@ const DataTableHeader: FC<DataTableHeaderProps> = ({
433
470
  {columns.slice(pinnedColumns).map((column, index) => (
434
471
  <DataTableHeaderCell
435
472
  column={column}
473
+ filterValues={filterValues}
436
474
  headerHeight={headerHeight}
437
475
  index={index + pinnedColumns}
438
476
  isPinnedHorizontal={false}
439
477
  key={`scrollable-header-${index + pinnedColumns}`}
478
+ onFilterValuesChange={onFilterValuesChange}
440
479
  onSort={onSort}
441
480
  pinnedLeft={0}
442
481
  rowHeight={rowHeight}
@@ -853,11 +892,94 @@ const DataTableComponent: FC<DataTableProps> = ({
853
892
  testID,
854
893
  testIDs,
855
894
  getRowTestID,
895
+ emptyContent,
896
+ additionalFilters = [],
897
+ search = "",
898
+ searchFields,
899
+ onSearchChange,
900
+ filterValues,
901
+ onFilterValuesChange,
902
+ onQueryChange,
856
903
  }) => {
857
904
  const {theme} = useTheme();
858
905
  const tableTestIDs = resolveDataTableTestIDsFromProps({testID, testIDs});
859
906
  const headerScrollRef = useRef<ScrollView>(null);
860
907
  const bodyScrollRef = useRef<ScrollView>(null);
908
+ const lastEmittedQueryRef = useRef<string | undefined>(undefined);
909
+ const [debouncedSearch, setDebouncedSearch] = useState(search);
910
+ const [isNativeFiltersOpen, setIsNativeFiltersOpen] = useState(false);
911
+ const [nativeDraftValues, setNativeDraftValues] = useState<Record<string, unknown>>({});
912
+ const [nativeSearchDraft, setNativeSearchDraft] = useState(search);
913
+
914
+ const columnFilters = useMemo(() => {
915
+ const visibleColumnFilters = columns
916
+ .map((column) => column.filter)
917
+ .filter((filter): filter is NonNullable<typeof filter> => Boolean(filter));
918
+ return [...visibleColumnFilters, ...additionalFilters];
919
+ }, [additionalFilters, columns]);
920
+ const showSearch = Boolean(searchFields && searchFields.length > 0 && onSearchChange);
921
+ const showAdditionalFilters =
922
+ Platform.OS === "web" && additionalFilters.length > 0 && Boolean(onFilterValuesChange);
923
+ const showNativeFilters =
924
+ Platform.OS !== "web" &&
925
+ (columnFilters.length > 0 || showSearch) &&
926
+ Boolean(onFilterValuesChange || onSearchChange);
927
+
928
+ // Debounce toolbar search before emitting server query params.
929
+ useEffect(() => {
930
+ const timer = setTimeout(() => {
931
+ setDebouncedSearch(search);
932
+ }, DATA_TABLE_SEARCH_DEBOUNCE_MS);
933
+ return () => {
934
+ clearTimeout(timer);
935
+ };
936
+ }, [search]);
937
+
938
+ // Emit modelRouter-shaped query params when debounced search or filters change.
939
+ useEffect(() => {
940
+ if (!onQueryChange) {
941
+ return;
942
+ }
943
+ const query = buildDataTableListQuery({
944
+ columns,
945
+ filters: additionalFilters,
946
+ filterValues,
947
+ search: debouncedSearch,
948
+ searchFields,
949
+ });
950
+ const signature = JSON.stringify(query);
951
+ if (signature === lastEmittedQueryRef.current) {
952
+ return;
953
+ }
954
+ lastEmittedQueryRef.current = signature;
955
+ onQueryChange(query);
956
+ }, [additionalFilters, columns, debouncedSearch, filterValues, onQueryChange, searchFields]);
957
+
958
+ const handleOpenNativeFilters = useCallback((): void => {
959
+ setNativeDraftValues(filterValues ?? {});
960
+ setNativeSearchDraft(search);
961
+ setIsNativeFiltersOpen(true);
962
+ }, [filterValues, search]);
963
+
964
+ const handleApplyNativeFilters = useCallback((): void => {
965
+ onFilterValuesChange?.(nativeDraftValues);
966
+ onSearchChange?.(nativeSearchDraft);
967
+ setIsNativeFiltersOpen(false);
968
+ }, [nativeDraftValues, nativeSearchDraft, onFilterValuesChange, onSearchChange]);
969
+
970
+ const handleClearNativeFilters = useCallback((): void => {
971
+ const cleared: Record<string, unknown> = {};
972
+ for (const filter of columnFilters) {
973
+ if (filter.kind === "dateRange") {
974
+ cleared[`${filter.field}_gte`] = undefined;
975
+ cleared[`${filter.field}_lte`] = undefined;
976
+ } else {
977
+ cleared[filter.field] = undefined;
978
+ }
979
+ }
980
+ setNativeDraftValues(cleared);
981
+ setNativeSearchDraft("");
982
+ }, [columnFilters]);
861
983
 
862
984
  const columnWidths = useMemo(() => columns.map((col) => col.width), [columns]);
863
985
  const pinnedLeftOffsets = useMemo(() => {
@@ -915,6 +1037,45 @@ const DataTableComponent: FC<DataTableProps> = ({
915
1037
  style={{display: "flex", flexDirection: "column", height: "100%"}}
916
1038
  testID={tableTestIDs.root}
917
1039
  >
1040
+ {showSearch || showNativeFilters || showAdditionalFilters ? (
1041
+ <Box
1042
+ alignItems="center"
1043
+ direction="row"
1044
+ gap={2}
1045
+ marginBottom={2}
1046
+ paddingX={2}
1047
+ paddingY={2}
1048
+ wrap
1049
+ >
1050
+ {showSearch ? (
1051
+ <Box flex="grow" minWidth={200}>
1052
+ <TextField
1053
+ onChange={onSearchChange!}
1054
+ testID="data-table-search"
1055
+ title="Search"
1056
+ type="search"
1057
+ value={search}
1058
+ />
1059
+ </Box>
1060
+ ) : null}
1061
+ {showNativeFilters ? (
1062
+ <Button
1063
+ iconName="filter"
1064
+ onClick={handleOpenNativeFilters}
1065
+ testID="data-table-filters-trigger"
1066
+ text="Filters"
1067
+ variant="outline"
1068
+ />
1069
+ ) : null}
1070
+ {showAdditionalFilters && onFilterValuesChange ? (
1071
+ <DataTableAdditionalFiltersWeb
1072
+ appliedValues={filterValues ?? {}}
1073
+ filters={additionalFilters}
1074
+ onApply={onFilterValuesChange}
1075
+ />
1076
+ ) : null}
1077
+ </Box>
1078
+ ) : null}
918
1079
  <View
919
1080
  style={{
920
1081
  borderColor: theme.border.default,
@@ -927,9 +1088,11 @@ const DataTableComponent: FC<DataTableProps> = ({
927
1088
  >
928
1089
  <DataTableHeader
929
1090
  columns={columns}
1091
+ filterValues={filterValues}
930
1092
  hasMoreContent={Boolean(moreContentComponent)}
931
1093
  headerHeight={headerHeight}
932
1094
  headerScrollRef={headerScrollRef}
1095
+ onFilterValuesChange={onFilterValuesChange}
933
1096
  onScroll={handleScroll}
934
1097
  onSort={handleSort}
935
1098
  pinnedColumns={pinnedColumns}
@@ -941,23 +1104,27 @@ const DataTableComponent: FC<DataTableProps> = ({
941
1104
  />
942
1105
 
943
1106
  <View style={{flex: 1, minHeight: 0}}>
944
- <DataTableContent
945
- alternateRowBackground={alternateRowBackground}
946
- bodyScrollRef={bodyScrollRef}
947
- columns={columns}
948
- customColumnComponentMap={customColumnComponentMap}
949
- data={data}
950
- defaultTextSize={defaultTextSize}
951
- getRowTestID={getRowTestID}
952
- moreContentComponent={moreContentComponent}
953
- moreContentExtraData={moreContentExtraData}
954
- onScroll={handleScroll}
955
- pinnedColumns={pinnedColumns}
956
- pinnedLeftOffsets={pinnedLeftOffsets}
957
- pinnedWidth={pinnedWidth}
958
- rowHeight={rowHeight}
959
- rowTestIdBase={tableTestIDs.row}
960
- />
1107
+ {data.length === 0 && emptyContent ? (
1108
+ emptyContent
1109
+ ) : (
1110
+ <DataTableContent
1111
+ alternateRowBackground={alternateRowBackground}
1112
+ bodyScrollRef={bodyScrollRef}
1113
+ columns={columns}
1114
+ customColumnComponentMap={customColumnComponentMap}
1115
+ data={data}
1116
+ defaultTextSize={defaultTextSize}
1117
+ getRowTestID={getRowTestID}
1118
+ moreContentComponent={moreContentComponent}
1119
+ moreContentExtraData={moreContentExtraData}
1120
+ onScroll={handleScroll}
1121
+ pinnedColumns={pinnedColumns}
1122
+ pinnedLeftOffsets={pinnedLeftOffsets}
1123
+ pinnedWidth={pinnedWidth}
1124
+ rowHeight={rowHeight}
1125
+ rowTestIdBase={tableTestIDs.row}
1126
+ />
1127
+ )}
961
1128
  </View>
962
1129
  </View>
963
1130
 
@@ -977,6 +1144,31 @@ const DataTableComponent: FC<DataTableProps> = ({
977
1144
  />
978
1145
  </View>
979
1146
  )}
1147
+ {showNativeFilters ? (
1148
+ <Modal
1149
+ onDismiss={() => setIsNativeFiltersOpen(false)}
1150
+ primaryButtonOnClick={handleApplyNativeFilters}
1151
+ primaryButtonText="Apply"
1152
+ secondaryButtonOnClick={() => setIsNativeFiltersOpen(false)}
1153
+ secondaryButtonText="Cancel"
1154
+ testID="data-table-filters-sheet"
1155
+ title="Filters"
1156
+ visible={isNativeFiltersOpen}
1157
+ >
1158
+ <Box direction="column" gap={3}>
1159
+ <DataTableFilterFields
1160
+ draftValues={nativeDraftValues}
1161
+ filters={columnFilters}
1162
+ onDraftChange={setNativeDraftValues}
1163
+ onSearchDraftChange={setNativeSearchDraft}
1164
+ search={nativeSearchDraft}
1165
+ showFieldClear
1166
+ showSearch={showSearch}
1167
+ />
1168
+ <Button onClick={handleClearNativeFilters} text="Clear all" variant="ghost" />
1169
+ </Box>
1170
+ </Modal>
1171
+ ) : null}
980
1172
  </View>
981
1173
  );
982
1174
  };
@@ -0,0 +1,121 @@
1
+ import {describe, expect, it, spyOn} from "bun:test";
2
+ import {act, fireEvent} from "@testing-library/react-native";
3
+ import {Linking} from "react-native";
4
+
5
+ import {DonutChart} from "./DonutChart";
6
+ import {renderWithTheme} from "./test-utils";
7
+
8
+ const POINTS = [
9
+ {label: "A", value: 50},
10
+ {color: "#112233", label: "B", value: 50},
11
+ ];
12
+
13
+ describe("DonutChart", () => {
14
+ it("renders one mark testID per slice", () => {
15
+ const {getByTestId, queryByTestId} = renderWithTheme(
16
+ <DonutChart data={POINTS} testID="chart" />
17
+ );
18
+
19
+ expect(getByTestId("chart.point.0-clickable")).toBeTruthy();
20
+ expect(getByTestId("chart.point.1-clickable")).toBeTruthy();
21
+ expect(queryByTestId("chart.point.2-clickable")).toBeNull();
22
+ });
23
+
24
+ it("applies a per-slice color override on the legend swatch", () => {
25
+ const {getByTestId} = renderWithTheme(<DonutChart data={POINTS} testID="chart" />);
26
+ const swatchStyle = getByTestId("chart.swatch.1").props.style;
27
+ const styles = Array.isArray(swatchStyle) ? swatchStyle : [swatchStyle];
28
+
29
+ expect(styles).toEqual(
30
+ expect.arrayContaining([expect.objectContaining({backgroundColor: "#112233"})])
31
+ );
32
+ });
33
+
34
+ it("shows emptyText when data is empty", () => {
35
+ const {getByText} = renderWithTheme(<DonutChart data={[]} emptyText="Nothing yet" />);
36
+
37
+ expect(getByText("Nothing yet")).toBeTruthy();
38
+ });
39
+
40
+ it("renders a legend row per slice and ignores legendLabel", () => {
41
+ const {getByText, queryByText} = renderWithTheme(
42
+ <DonutChart data={POINTS} legendLabel="Should hide" />
43
+ );
44
+
45
+ expect(getByText("A")).toBeTruthy();
46
+ expect(getByText("B")).toBeTruthy();
47
+ expect(queryByText("Should hide")).toBeNull();
48
+ });
49
+
50
+ it("puts each quarter slice hit in the quadrant that slice paints", () => {
51
+ const quarters = [
52
+ {label: "A", value: 25},
53
+ {label: "B", value: 25},
54
+ {label: "C", value: 25},
55
+ {label: "D", value: 25},
56
+ ];
57
+ const {getByTestId} = renderWithTheme(
58
+ <DonutChart data={quarters} height={220} testID="chart" />
59
+ );
60
+ const positionOf = (index: number): {left: number; top: number} => {
61
+ const markStyle = getByTestId(`chart.point.${index}-clickable`).props.style;
62
+ const styles = Array.isArray(markStyle) ? markStyle : [markStyle];
63
+ return styles.find(
64
+ (entry: {left?: number; top?: number} | undefined) =>
65
+ typeof entry?.left === "number" && typeof entry?.top === "number"
66
+ ) as {left: number; top: number};
67
+ };
68
+
69
+ // The first quarter paints 12–3 o'clock, so its hit sits up and to the right of the third
70
+ // quarter, which paints 6–9 o'clock.
71
+ expect(positionOf(0).left).toBeGreaterThan(positionOf(2).left);
72
+ expect(positionOf(0).top).toBeLessThan(positionOf(2).top);
73
+ });
74
+
75
+ it("shows tooltip copy after pressing a slice mark", async () => {
76
+ const {getByTestId, getByText} = renderWithTheme(<DonutChart data={POINTS} testID="chart" />);
77
+
78
+ await act(async () => {
79
+ fireEvent.press(getByTestId("chart.point.1-clickable"));
80
+ });
81
+
82
+ expect(getByText("B: 50")).toBeTruthy();
83
+ });
84
+
85
+ it("updates or clears the active tooltip when data changes", async () => {
86
+ const {getByTestId, getByText, queryByTestId, rerender} = renderWithTheme(
87
+ <DonutChart data={POINTS} testID="chart" />
88
+ );
89
+
90
+ await act(async () => {
91
+ fireEvent.press(getByTestId("chart.point.1-clickable"));
92
+ });
93
+ rerender(
94
+ <DonutChart
95
+ data={[
96
+ {label: "A", value: 25},
97
+ {label: "B", value: 75},
98
+ ]}
99
+ testID="chart"
100
+ />
101
+ );
102
+ expect(getByText("B: 75")).toBeTruthy();
103
+
104
+ rerender(<DonutChart data={[{label: "A", value: 100}]} testID="chart" />);
105
+ expect(queryByTestId("chart.tooltip")).toBeNull();
106
+ });
107
+
108
+ it("does not open URLs from slice legend labels", async () => {
109
+ const openURLSpy = spyOn(Linking, "openURL").mockImplementation(() => Promise.resolve(true));
110
+ const {getByText} = renderWithTheme(
111
+ <DonutChart data={[{label: "https://evil.example", value: 10}]} />
112
+ );
113
+
114
+ await act(async () => {
115
+ fireEvent.press(getByText("https://evil.example"));
116
+ });
117
+
118
+ expect(openURLSpy).not.toHaveBeenCalled();
119
+ openURLSpy.mockRestore();
120
+ });
121
+ });
@@ -0,0 +1,160 @@
1
+ import type {FC} from "react";
2
+ import {useCallback, useState} from "react";
3
+ import {Path, Svg} from "react-native-svg";
4
+
5
+ import {Box} from "./Box";
6
+ import type {DonutChartProps, LayoutChangeEvent} from "./Common";
7
+ import {ChartFrame} from "./charts/ChartFrame";
8
+ import {getDonutSize} from "./charts/layout";
9
+ import {getDonutSliceAngles, getDonutSliceHitCenter, getDonutSlicePath} from "./charts/paths";
10
+ import {getChartPaint} from "./charts/theme";
11
+ import type {ChartPoint} from "./charts/types/chartTypes";
12
+ import {Text} from "./Text";
13
+ import {useTheme} from "./Theme";
14
+ import {resolveTestID} from "./testing/resolveTestId";
15
+
16
+ const DEFAULT_SIZE = 220;
17
+ const MARK_HIT_SIZE = 24;
18
+
19
+ const formatChartTooltip = ({
20
+ formatValue,
21
+ point,
22
+ }: {
23
+ formatValue: (value: number) => string;
24
+ point: ChartPoint;
25
+ }): string => {
26
+ return `${point.label}: ${formatValue(point.value)}`;
27
+ };
28
+
29
+ const getSliceAngles = (
30
+ data: ChartPoint[]
31
+ ): Array<{end: number; point: ChartPoint; start: number}> => {
32
+ const angles = getDonutSliceAngles(data);
33
+ return data.map((point, index) => {
34
+ const slice = angles[index];
35
+ return {end: slice?.end ?? 0, point, start: slice?.start ?? 0};
36
+ });
37
+ };
38
+
39
+ export const DonutChart: FC<DonutChartProps> = ({
40
+ accessibilityLabel,
41
+ data,
42
+ emptyText = "No data",
43
+ formatValue = String,
44
+ height = DEFAULT_SIZE,
45
+ loading = false,
46
+ testID,
47
+ }) => {
48
+ const {theme} = useTheme();
49
+ const paint = getChartPaint(theme);
50
+ const [chartWidth, setChartWidth] = useState(DEFAULT_SIZE);
51
+ const [activePointIndex, setActivePointIndex] = useState<number | undefined>(undefined);
52
+
53
+ const handleLayout = useCallback((event: LayoutChangeEvent): void => {
54
+ const nextWidth = event.nativeEvent.layout.width;
55
+ if (nextWidth > 0) {
56
+ setChartWidth(nextWidth);
57
+ }
58
+ }, []);
59
+
60
+ const handleMarkPress = useCallback((pointIndex: number): void => {
61
+ setActivePointIndex(pointIndex);
62
+ }, []);
63
+
64
+ const size = getDonutSize({chartWidth, height, legendRowCount: data.length});
65
+ const center = size / 2;
66
+ const outerRadius = Math.max(size / 2 - 8, 1);
67
+ const innerRadius = outerRadius * 0.55;
68
+ const slices = getSliceAngles(data);
69
+ const activePoint = activePointIndex === undefined ? undefined : data[activePointIndex];
70
+ const tooltipText = activePoint
71
+ ? formatChartTooltip({formatValue, point: activePoint})
72
+ : undefined;
73
+ const summaryLabel = accessibilityLabel ?? "Donut chart";
74
+
75
+ return (
76
+ <ChartFrame
77
+ accessibilityLabel={summaryLabel}
78
+ emptyText={emptyText}
79
+ isEmpty={data.length === 0}
80
+ loading={loading}
81
+ testID={testID}
82
+ tooltipText={tooltipText}
83
+ >
84
+ <Box
85
+ minWidth={0}
86
+ onLayout={handleLayout}
87
+ overflow="hidden"
88
+ testID={resolveTestID(testID, "plot")}
89
+ width="100%"
90
+ >
91
+ <Box height={size} width={size}>
92
+ <Svg height={size} width={size}>
93
+ {slices.map((slice, index) => (
94
+ <Path
95
+ d={getDonutSlicePath({
96
+ endAngle: slice.end,
97
+ innerRadius,
98
+ outerRadius,
99
+ startAngle: slice.start,
100
+ })}
101
+ fill={slice.point.color ?? paint.slices[index % paint.slices.length]}
102
+ key={`slice-${slice.point.label}`}
103
+ transform={`translate(${center}, ${center})`}
104
+ />
105
+ ))}
106
+ </Svg>
107
+ {slices.map((slice, index) => {
108
+ const onPress = (): void => {
109
+ handleMarkPress(index);
110
+ };
111
+ const mid = (slice.start + slice.end) / 2;
112
+ const hitRadius = (innerRadius + outerRadius) / 2;
113
+ const hitCenter = getDonutSliceHitCenter({center, hitRadius, midAngle: mid});
114
+ return (
115
+ <Box
116
+ accessibilityHint={`Show value for ${slice.point.label}`}
117
+ accessibilityLabel={`${slice.point.label}: ${formatValue(slice.point.value)}`}
118
+ dangerouslySetInlineStyle={{
119
+ __style: {
120
+ height: MARK_HIT_SIZE,
121
+ left: hitCenter.x - MARK_HIT_SIZE / 2,
122
+ position: "absolute",
123
+ top: hitCenter.y - MARK_HIT_SIZE / 2,
124
+ width: MARK_HIT_SIZE,
125
+ },
126
+ }}
127
+ key={`mark-${slice.point.label}`}
128
+ onClick={onPress}
129
+ onHoverStart={onPress}
130
+ testID={resolveTestID(testID, `point.${index}`)}
131
+ />
132
+ );
133
+ })}
134
+ </Box>
135
+ <Box direction="column" gap={1} padding={2}>
136
+ {data.map((point, index) => (
137
+ <Box direction="row" gap={2} key={`legend-${point.label}`}>
138
+ <Box
139
+ dangerouslySetInlineStyle={{
140
+ __style: {
141
+ backgroundColor: point.color ?? paint.slices[index % paint.slices.length],
142
+ height: 12,
143
+ width: 12,
144
+ },
145
+ }}
146
+ testID={resolveTestID(testID, `swatch.${index}`)}
147
+ />
148
+ <Text size="sm" skipLinking>
149
+ {point.label}
150
+ </Text>
151
+ </Box>
152
+ ))}
153
+ </Box>
154
+ </Box>
155
+ </ChartFrame>
156
+ );
157
+ };
158
+
159
+ export type {DonutChartProps} from "./Common";
160
+ export type {ChartPoint} from "./charts/types/chartTypes";
@@ -438,6 +438,57 @@ describe("EmojiSelector", () => {
438
438
  }
439
439
  });
440
440
 
441
+ it("re-renders the grid when layout changes after emoji data has loaded", async () => {
442
+ const {root, UNSAFE_getAllByType} = renderWithTheme(
443
+ <EmojiSelector
444
+ category={Categories.emotion}
445
+ columns={6}
446
+ onEmojiSelected={mock(() => {})}
447
+ placeholder="Search"
448
+ showHistory={false}
449
+ showSearchBar={false}
450
+ showSectionTitles
451
+ showTabs={false}
452
+ theme="#007AFF"
453
+ />
454
+ );
455
+ await waitForEmojiData(() => root as LayoutRoot);
456
+
457
+ // A second layout pass after the data resolved goes through the prerender branch directly.
458
+ await act(async () => {
459
+ (root as LayoutRoot).props.onLayout?.({
460
+ nativeEvent: {layout: {height: 600, width: 720, x: 0, y: 0}},
461
+ });
462
+ });
463
+
464
+ const {FlatList} = require("react-native");
465
+ const [list] = UNSAFE_getAllByType(FlatList);
466
+ expect(list.props.data.length).toBeGreaterThan(0);
467
+ const cell = list.props.renderItem({index: 0, item: list.props.data[0]});
468
+ expect(cell.props.colSize).toBe(120);
469
+ });
470
+
471
+ it("ignores emoji data that resolves after unmount", async () => {
472
+ const {unmount, toJSON} = renderWithTheme(
473
+ <EmojiSelector
474
+ category={Categories.emotion}
475
+ columns={6}
476
+ onEmojiSelected={mock(() => {})}
477
+ placeholder="Search"
478
+ showHistory={false}
479
+ showSearchBar={false}
480
+ showSectionTitles
481
+ showTabs={false}
482
+ theme="#007AFF"
483
+ />
484
+ );
485
+ unmount();
486
+ await act(async () => {
487
+ await new Promise((resolve) => setTimeout(resolve, 20));
488
+ });
489
+ expect(toJSON()).toBeNull();
490
+ });
491
+
441
492
  it("filters the emoji list when a search query is entered", async () => {
442
493
  const {getByPlaceholderText, UNSAFE_getAllByType, root} = renderWithTheme(
443
494
  <EmojiSelector