@inventreedb/ui 0.10.1 → 0.11.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 (184) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/.vite/manifest.json +444 -1
  3. package/dist/components/Boundary.d.ts +10 -0
  4. package/dist/components/Boundary.js +37 -0
  5. package/dist/components/Boundary.js.map +1 -0
  6. package/dist/components/CopyButton.d.ts +13 -0
  7. package/dist/components/CopyButton.js +51 -0
  8. package/dist/components/CopyButton.js.map +1 -0
  9. package/dist/components/CopyableCell.d.ts +11 -0
  10. package/dist/components/CopyableCell.js +24 -0
  11. package/dist/components/CopyableCell.js.map +1 -0
  12. package/dist/components/InvenTreeTable.d.ts +17 -0
  13. package/dist/components/InvenTreeTable.js +41 -0
  14. package/dist/components/InvenTreeTable.js.map +1 -0
  15. package/dist/components/TableColumnSelect.d.ts +4 -0
  16. package/dist/components/TableColumnSelect.js +38 -0
  17. package/dist/components/TableColumnSelect.js.map +1 -0
  18. package/dist/enums/ApiEndpoints.d.ts +1 -1
  19. package/dist/enums/ApiEndpoints.js +1 -1
  20. package/dist/enums/ApiEndpoints.js.map +1 -1
  21. package/dist/enums/ModelInformation.js +17 -0
  22. package/dist/enums/ModelInformation.js.map +1 -1
  23. package/dist/enums/ModelType.d.ts +1 -0
  24. package/dist/enums/ModelType.js +1 -0
  25. package/dist/enums/ModelType.js.map +1 -1
  26. package/dist/functions/Forms.d.ts +11 -0
  27. package/dist/functions/Forms.js +27 -0
  28. package/dist/functions/Forms.js.map +1 -0
  29. package/dist/functions/Notification.d.ts +16 -0
  30. package/dist/functions/Notification.js +82 -0
  31. package/dist/functions/Notification.js.map +1 -0
  32. package/dist/functions/String.d.ts +13 -0
  33. package/dist/functions/String.js +25 -0
  34. package/dist/functions/String.js.map +1 -0
  35. package/dist/hooks/UseFilterSet.d.ts +2 -0
  36. package/dist/hooks/UseFilterSet.js +35 -0
  37. package/dist/hooks/UseFilterSet.js.map +1 -0
  38. package/dist/hooks/UseTable.d.ts +12 -0
  39. package/dist/hooks/UseTable.js +92 -0
  40. package/dist/hooks/UseTable.js.map +1 -0
  41. package/dist/index.d.ts +13 -2
  42. package/dist/index.js +32 -4
  43. package/dist/index.js.map +1 -1
  44. package/dist/node_modules/@mantine/hooks/esm/use-local-storage/create-storage.js +129 -0
  45. package/dist/node_modules/@mantine/hooks/esm/use-local-storage/create-storage.js.map +1 -0
  46. package/dist/node_modules/@mantine/hooks/esm/use-local-storage/use-local-storage.js +8 -0
  47. package/dist/node_modules/@mantine/hooks/esm/use-local-storage/use-local-storage.js.map +1 -0
  48. package/dist/node_modules/@mantine/hooks/esm/use-window-event/use-window-event.js +11 -0
  49. package/dist/node_modules/@mantine/hooks/esm/use-window-event/use-window-event.js.map +1 -0
  50. package/dist/node_modules/@mantine/hooks/esm/utils/random-id/random-id.js +7 -0
  51. package/dist/node_modules/@mantine/hooks/esm/utils/random-id/random-id.js.map +1 -0
  52. package/dist/node_modules/@remix-run/router/dist/router.js +272 -0
  53. package/dist/node_modules/@remix-run/router/dist/router.js.map +1 -0
  54. package/dist/node_modules/@sentry/browser/build/npm/esm/prod/debug-build.js +5 -0
  55. package/dist/node_modules/@sentry/browser/build/npm/esm/prod/debug-build.js.map +1 -0
  56. package/dist/node_modules/@sentry/browser/build/npm/esm/prod/helpers.js +6 -0
  57. package/dist/node_modules/@sentry/browser/build/npm/esm/prod/helpers.js.map +1 -0
  58. package/dist/node_modules/@sentry/browser/build/npm/esm/prod/report-dialog.js +54 -0
  59. package/dist/node_modules/@sentry/browser/build/npm/esm/prod/report-dialog.js.map +1 -0
  60. package/dist/node_modules/@sentry/core/build/esm/api.js +41 -0
  61. package/dist/node_modules/@sentry/core/build/esm/api.js.map +1 -0
  62. package/dist/node_modules/@sentry/core/build/esm/asyncContext/index.js +13 -0
  63. package/dist/node_modules/@sentry/core/build/esm/asyncContext/index.js.map +1 -0
  64. package/dist/node_modules/@sentry/core/build/esm/asyncContext/stackStrategy.js +124 -0
  65. package/dist/node_modules/@sentry/core/build/esm/asyncContext/stackStrategy.js.map +1 -0
  66. package/dist/node_modules/@sentry/core/build/esm/carrier.js +22 -0
  67. package/dist/node_modules/@sentry/core/build/esm/carrier.js.map +1 -0
  68. package/dist/node_modules/@sentry/core/build/esm/currentScopes.js +34 -0
  69. package/dist/node_modules/@sentry/core/build/esm/currentScopes.js.map +1 -0
  70. package/dist/node_modules/@sentry/core/build/esm/debug-build.js +5 -0
  71. package/dist/node_modules/@sentry/core/build/esm/debug-build.js.map +1 -0
  72. package/dist/node_modules/@sentry/core/build/esm/defaultScopes.js +13 -0
  73. package/dist/node_modules/@sentry/core/build/esm/defaultScopes.js.map +1 -0
  74. package/dist/node_modules/@sentry/core/build/esm/exports.js +13 -0
  75. package/dist/node_modules/@sentry/core/build/esm/exports.js.map +1 -0
  76. package/dist/node_modules/@sentry/core/build/esm/scope.js +577 -0
  77. package/dist/node_modules/@sentry/core/build/esm/scope.js.map +1 -0
  78. package/dist/node_modules/@sentry/core/build/esm/session.js +61 -0
  79. package/dist/node_modules/@sentry/core/build/esm/session.js.map +1 -0
  80. package/dist/node_modules/@sentry/core/build/esm/utils/chain-and-copy-promiselike.js +39 -0
  81. package/dist/node_modules/@sentry/core/build/esm/utils/chain-and-copy-promiselike.js.map +1 -0
  82. package/dist/node_modules/@sentry/core/build/esm/utils/debug-logger.js +79 -0
  83. package/dist/node_modules/@sentry/core/build/esm/utils/debug-logger.js.map +1 -0
  84. package/dist/node_modules/@sentry/core/build/esm/utils/dsn.js +88 -0
  85. package/dist/node_modules/@sentry/core/build/esm/utils/dsn.js.map +1 -0
  86. package/dist/node_modules/@sentry/core/build/esm/utils/is.js +35 -0
  87. package/dist/node_modules/@sentry/core/build/esm/utils/is.js.map +1 -0
  88. package/dist/node_modules/@sentry/core/build/esm/utils/merge.js +19 -0
  89. package/dist/node_modules/@sentry/core/build/esm/utils/merge.js.map +1 -0
  90. package/dist/node_modules/@sentry/core/build/esm/utils/misc.js +32 -0
  91. package/dist/node_modules/@sentry/core/build/esm/utils/misc.js.map +1 -0
  92. package/dist/node_modules/@sentry/core/build/esm/utils/object.js +18 -0
  93. package/dist/node_modules/@sentry/core/build/esm/utils/object.js.map +1 -0
  94. package/dist/node_modules/@sentry/core/build/esm/utils/prepareEvent.js +34 -0
  95. package/dist/node_modules/@sentry/core/build/esm/utils/prepareEvent.js.map +1 -0
  96. package/dist/node_modules/@sentry/core/build/esm/utils/propagationContext.js +8 -0
  97. package/dist/node_modules/@sentry/core/build/esm/utils/propagationContext.js.map +1 -0
  98. package/dist/node_modules/@sentry/core/build/esm/utils/randomSafeContext.js +27 -0
  99. package/dist/node_modules/@sentry/core/build/esm/utils/randomSafeContext.js.map +1 -0
  100. package/dist/node_modules/@sentry/core/build/esm/utils/spanOnScope.js +17 -0
  101. package/dist/node_modules/@sentry/core/build/esm/utils/spanOnScope.js.map +1 -0
  102. package/dist/node_modules/@sentry/core/build/esm/utils/string.js +10 -0
  103. package/dist/node_modules/@sentry/core/build/esm/utils/string.js.map +1 -0
  104. package/dist/node_modules/@sentry/core/build/esm/utils/time.js +26 -0
  105. package/dist/node_modules/@sentry/core/build/esm/utils/time.js.map +1 -0
  106. package/dist/node_modules/@sentry/core/build/esm/utils/version.js +5 -0
  107. package/dist/node_modules/@sentry/core/build/esm/utils/version.js.map +1 -0
  108. package/dist/node_modules/@sentry/core/build/esm/utils/worldwide.js +5 -0
  109. package/dist/node_modules/@sentry/core/build/esm/utils/worldwide.js.map +1 -0
  110. package/dist/node_modules/@sentry/react/build/esm/debug-build.js +5 -0
  111. package/dist/node_modules/@sentry/react/build/esm/debug-build.js.map +1 -0
  112. package/dist/node_modules/@sentry/react/build/esm/error.js +40 -0
  113. package/dist/node_modules/@sentry/react/build/esm/error.js.map +1 -0
  114. package/dist/node_modules/@sentry/react/build/esm/errorboundary.js +103 -0
  115. package/dist/node_modules/@sentry/react/build/esm/errorboundary.js.map +1 -0
  116. package/dist/node_modules/@tabler/icons-react/dist/esm/createReactComponent.js +0 -6
  117. package/dist/node_modules/@tabler/icons-react/dist/esm/createReactComponent.js.map +1 -1
  118. package/dist/node_modules/@tabler/icons-react/dist/esm/defaultAttributes.js +0 -6
  119. package/dist/node_modules/@tabler/icons-react/dist/esm/defaultAttributes.js.map +1 -1
  120. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconAdjustments.js +8 -0
  121. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconAdjustments.js.map +1 -0
  122. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconArrowRight.js +0 -6
  123. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconArrowRight.js.map +1 -1
  124. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconCheck.js +8 -0
  125. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconCheck.js.map +1 -0
  126. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconCircleCheck.js +0 -6
  127. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconCircleCheck.js.map +1 -1
  128. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconCircleX.js +0 -6
  129. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconCircleX.js.map +1 -1
  130. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconCopy.js +0 -6
  131. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconCopy.js.map +1 -1
  132. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconDots.js +0 -6
  133. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconDots.js.map +1 -1
  134. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconEdit.js +0 -6
  135. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconEdit.js.map +1 -1
  136. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconExclamationCircle.js +0 -6
  137. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconExclamationCircle.js.map +1 -1
  138. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconPlus.js +0 -6
  139. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconPlus.js.map +1 -1
  140. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconSearch.js +0 -6
  141. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconSearch.js.map +1 -1
  142. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconTrash.js +0 -6
  143. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconTrash.js.map +1 -1
  144. package/dist/node_modules/react/cjs/react-jsx-runtime.development.js +1 -10
  145. package/dist/node_modules/react/cjs/react-jsx-runtime.development.js.map +1 -1
  146. package/dist/node_modules/react/cjs/react-jsx-runtime.production.js +1 -10
  147. package/dist/node_modules/react/cjs/react-jsx-runtime.production.js.map +1 -1
  148. package/dist/node_modules/react-router/dist/index.js +377 -0
  149. package/dist/node_modules/react-router/dist/index.js.map +1 -0
  150. package/dist/node_modules/react-router-dom/dist/index.js +560 -0
  151. package/dist/node_modules/react-router-dom/dist/index.js.map +1 -0
  152. package/dist/node_modules/zustand/esm/middleware.js +202 -0
  153. package/dist/node_modules/zustand/esm/middleware.js.map +1 -0
  154. package/dist/node_modules/zustand/esm/react.js +24 -0
  155. package/dist/node_modules/zustand/esm/react.js.map +1 -0
  156. package/dist/node_modules/zustand/esm/vanilla.js +26 -0
  157. package/dist/node_modules/zustand/esm/vanilla.js.map +1 -0
  158. package/dist/states/StoredTableState.d.ts +37 -0
  159. package/dist/states/StoredTableState.js +58 -0
  160. package/dist/states/StoredTableState.js.map +1 -0
  161. package/dist/types/Forms.d.ts +2 -0
  162. package/dist/types/Plugins.d.ts +14 -7
  163. package/dist/types/Plugins.js +1 -1
  164. package/dist/types/Plugins.js.map +1 -1
  165. package/dist/types/Tables.d.ts +10 -0
  166. package/lib/components/Boundary.tsx +46 -0
  167. package/lib/components/CopyButton.tsx +76 -0
  168. package/lib/components/CopyableCell.tsx +51 -0
  169. package/lib/components/InvenTreeTable.tsx +63 -0
  170. package/lib/components/TableColumnSelect.tsx +40 -0
  171. package/lib/enums/ApiEndpoints.tsx +1 -1
  172. package/lib/enums/ModelInformation.tsx +7 -0
  173. package/lib/enums/ModelType.tsx +1 -0
  174. package/lib/functions/Forms.tsx +47 -0
  175. package/lib/functions/Notification.tsx +50 -0
  176. package/lib/functions/String.tsx +38 -0
  177. package/lib/hooks/UseFilterSet.tsx +47 -0
  178. package/lib/hooks/UseTable.tsx +160 -0
  179. package/lib/index.ts +49 -1
  180. package/lib/states/StoredTableState.tsx +91 -0
  181. package/lib/types/Forms.tsx +2 -0
  182. package/lib/types/Plugins.tsx +15 -7
  183. package/lib/types/Tables.tsx +11 -0
  184. package/package.json +2 -2
@@ -0,0 +1,160 @@
1
+ import { randomId } from '@mantine/hooks';
2
+ import { useCallback, useMemo, useState } from 'react';
3
+ import { useSearchParams } from 'react-router-dom';
4
+
5
+ import type { FilterSetState, TableFilter } from '../types/Filters';
6
+ import type { TableState } from '../types/Tables';
7
+ import useFilterSet from './UseFilterSet';
8
+
9
+ export type TableStateExtraProps = {
10
+ idAccessor?: string;
11
+ initialFilters?: TableFilter[];
12
+ };
13
+
14
+ /**
15
+ * A custom hook for managing the state of an <InvenTreeTable> component.
16
+ *
17
+ * Refer to the TableState type definition for more information.
18
+ */
19
+
20
+ export default function useTable(
21
+ tableName: string,
22
+ tableProps: TableStateExtraProps = {
23
+ idAccessor: 'pk',
24
+ initialFilters: []
25
+ }
26
+ ): TableState {
27
+ // Function to generate a new ID (to refresh the table)
28
+ function generateTableName() {
29
+ return `${tableName.replaceAll('-', '')}-${randomId()}`;
30
+ }
31
+
32
+ // Extract URL query parameters (e.g. ?active=true&overdue=false)
33
+ const [queryFilters, setQueryFilters] = useSearchParams();
34
+
35
+ const clearQueryFilters = useCallback(() => {
36
+ setQueryFilters({});
37
+ }, []);
38
+
39
+ const [tableKey, setTableKey] = useState<string>(generateTableName());
40
+
41
+ // Callback used to refresh (reload) the table
42
+ const refreshTable = useCallback(
43
+ (clearSelection?: boolean) => {
44
+ setTableKey(generateTableName());
45
+ if (clearSelection) {
46
+ clearSelectedRecords();
47
+ }
48
+ },
49
+ [generateTableName]
50
+ );
51
+
52
+ const filterSet: FilterSetState = useFilterSet(
53
+ `table-${tableName}`,
54
+ tableProps.initialFilters
55
+ );
56
+
57
+ // Array of expanded records
58
+ const [expandedRecords, setExpandedRecords] = useState<any[]>([]);
59
+
60
+ // Function to determine if a record is expanded
61
+ const isRowExpanded = useCallback(
62
+ (pk: number) => {
63
+ return expandedRecords.includes(pk);
64
+ },
65
+ [expandedRecords]
66
+ );
67
+
68
+ // Array of columns which are hidden
69
+ const [hiddenColumns, setHiddenColumns] = useState<string[]>([]);
70
+
71
+ // Array of selected records
72
+ const [selectedRecords, setSelectedRecords] = useState<any[]>([]);
73
+
74
+ // Array of selected primary key values
75
+ const selectedIds = useMemo(
76
+ () => selectedRecords.map((r) => r[tableProps.idAccessor || 'pk']),
77
+ [selectedRecords]
78
+ );
79
+
80
+ const clearSelectedRecords = useCallback(() => {
81
+ setSelectedRecords([]);
82
+ }, []);
83
+
84
+ const hasSelectedRecords = useMemo(() => {
85
+ return selectedRecords.length > 0;
86
+ }, [selectedRecords]);
87
+
88
+ // Total record count
89
+ const [recordCount, setRecordCount] = useState<number>(0);
90
+
91
+ const [page, setPage] = useState<number>(1);
92
+
93
+ // Search term
94
+ const [searchTerm, setSearchTerm] = useState<string>('');
95
+
96
+ // Table records
97
+ const [records, setRecords] = useState<any[]>([]);
98
+
99
+ // Update a single record in the table, by primary key value
100
+ const updateRecord = useCallback(
101
+ (record: any) => {
102
+ const _records = [...records];
103
+
104
+ // Find the matching record in the table
105
+ const index = _records.findIndex(
106
+ (r) => r[tableProps.idAccessor || 'pk'] === record.pk
107
+ );
108
+
109
+ if (index >= 0) {
110
+ _records[index] = {
111
+ ..._records[index],
112
+ ...record
113
+ };
114
+ } else {
115
+ _records.push(record);
116
+ }
117
+
118
+ setRecords(_records);
119
+ },
120
+ [records]
121
+ );
122
+
123
+ const idAccessor = useMemo(
124
+ () => tableProps.idAccessor || 'pk',
125
+ [tableProps.idAccessor]
126
+ );
127
+
128
+ const [isLoading, setIsLoading] = useState<boolean>(false);
129
+
130
+ return {
131
+ tableKey,
132
+ refreshTable,
133
+ isLoading,
134
+ setIsLoading,
135
+ filterSet,
136
+ queryFilters,
137
+ setQueryFilters,
138
+ clearQueryFilters,
139
+ expandedRecords,
140
+ setExpandedRecords,
141
+ isRowExpanded,
142
+ selectedRecords,
143
+ selectedIds,
144
+ setSelectedRecords,
145
+ clearSelectedRecords,
146
+ hasSelectedRecords,
147
+ searchTerm,
148
+ setSearchTerm,
149
+ recordCount,
150
+ setRecordCount,
151
+ hiddenColumns,
152
+ setHiddenColumns,
153
+ page,
154
+ setPage,
155
+ records,
156
+ setRecords,
157
+ updateRecord,
158
+ idAccessor
159
+ };
160
+ }
package/lib/index.ts CHANGED
@@ -15,10 +15,20 @@ export { UserRoles, UserPermissions } from './enums/Roles';
15
15
  export type {
16
16
  InvenTreePluginContext,
17
17
  InvenTreeFormsContext,
18
+ InvenTreeTablesContext,
19
+ ImporterDrawerContext,
18
20
  PluginVersion,
19
21
  StockAdjustmentFormsContext
20
22
  } from './types/Plugins';
21
- export type { RowAction, RowViewProps } from './types/Tables';
23
+
24
+ export type {
25
+ RowAction,
26
+ RowViewProps,
27
+ TableColumn,
28
+ TableColumnProps,
29
+ InvenTreeTableProps,
30
+ InvenTreeTableRenderProps
31
+ } from './types/Tables';
22
32
 
23
33
  export type {
24
34
  ApiFormFieldChoice,
@@ -42,6 +52,14 @@ export {
42
52
  getDetailUrl,
43
53
  navigateToLink
44
54
  } from './functions/Navigation';
55
+
56
+ export {
57
+ notYetImplemented,
58
+ permissionDenied,
59
+ invalidResponse,
60
+ showTimeoutNotification
61
+ } from './functions/Notification';
62
+
45
63
  export {
46
64
  checkPluginVersion,
47
65
  initPlugin
@@ -53,16 +71,32 @@ export {
53
71
  formatFileSize
54
72
  } from './functions/Formatting';
55
73
 
74
+ export {
75
+ constructFormUrl,
76
+ mapFields,
77
+ type NestedDict
78
+ } from './functions/Forms';
79
+
80
+ export {
81
+ shortenString,
82
+ hashString
83
+ } from './functions/String';
84
+
56
85
  // Common UI components
57
86
  export {
58
87
  ActionButton,
59
88
  type ActionButtonProps
60
89
  } from './components/ActionButton';
61
90
  export { AddItemButton } from './components/AddItemButton';
91
+ export { Boundary, DefaultFallback } from './components/Boundary';
62
92
  export { ButtonMenu } from './components/ButtonMenu';
93
+ export { CopyButton } from './components/CopyButton';
94
+ export { CopyableCell } from './components/CopyableCell';
63
95
  export { ProgressBar } from './components/ProgressBar';
64
96
  export { PassFailButton, YesNoButton } from './components/YesNoButton';
65
97
  export { SearchInput } from './components/SearchInput';
98
+ export { TableColumnSelect } from './components/TableColumnSelect';
99
+ export { default as InvenTreeTable } from './components/InvenTreeTable';
66
100
  export {
67
101
  RowViewAction,
68
102
  RowDuplicateAction,
@@ -77,7 +111,21 @@ export {
77
111
  default as useMonitorDataOutput,
78
112
  type MonitorDataOutputProps
79
113
  } from './hooks/MonitorDataOutput';
114
+
80
115
  export {
81
116
  default as useMonitorBackgroundTask,
82
117
  type MonitorBackgroundTaskProps
83
118
  } from './hooks/MonitorBackgroundTask';
119
+
120
+ export { default as useFilterSet } from './hooks/UseFilterSet';
121
+
122
+ export {
123
+ default as useTable,
124
+ type TableStateExtraProps
125
+ } from './hooks/UseTable';
126
+
127
+ // State management
128
+ export {
129
+ type StoredTableStateProps,
130
+ useStoredTableState
131
+ } from './states/StoredTableState';
@@ -0,0 +1,91 @@
1
+ import type { DataTableSortStatus } from 'mantine-datatable';
2
+ import { create } from 'zustand';
3
+ import { persist } from 'zustand/middleware';
4
+
5
+ const DEFAULT_PAGE_SIZE: number = 25;
6
+
7
+ /**
8
+ * Interfacing for storing persistent table state in the browser.
9
+ *
10
+ * The following properties are stored:
11
+ * - pageSize: The number of rows to display per page in the table.
12
+ * - hiddenColumns: An array of column names that are hidden in a given table.
13
+ * - columnNames: An object mapping table keys to arrays of column names.
14
+ * - sorting: An object mapping table keys to sorting configurations.
15
+ */
16
+ export interface StoredTableStateProps {
17
+ pageSize: number;
18
+ setPageSize: (size: number) => void;
19
+ tableSorting: Record<string, any>;
20
+ getTableSorting: (tableKey: string) => DataTableSortStatus;
21
+ setTableSorting: (
22
+ tableKey: string
23
+ ) => (sorting: DataTableSortStatus<any>) => void;
24
+ tableColumnNames: Record<string, Record<string, string>>;
25
+ getTableColumnNames: (tableKey: string) => Record<string, string>;
26
+ setTableColumnNames: (
27
+ tableKey: string
28
+ ) => (names: Record<string, string>) => void;
29
+ clearTableColumnNames: () => void;
30
+ hiddenColumns: Record<string, string[]>;
31
+ getHiddenColumns: (tableKey: string) => string[] | null;
32
+ setHiddenColumns: (tableKey: string) => (columns: string[]) => void;
33
+ }
34
+
35
+ export const useStoredTableState = create<StoredTableStateProps>()(
36
+ persist(
37
+ (set, get) => ({
38
+ pageSize: DEFAULT_PAGE_SIZE,
39
+ setPageSize: (size: number) => {
40
+ set((state) => ({
41
+ pageSize: size
42
+ }));
43
+ },
44
+ tableSorting: {},
45
+ getTableSorting: (tableKey) => {
46
+ return get().tableSorting[tableKey] || {};
47
+ },
48
+ setTableSorting: (tableKey) => (sorting) => {
49
+ // Update the table sorting for the given table
50
+ set({
51
+ tableSorting: {
52
+ ...get().tableSorting,
53
+ [tableKey]: sorting
54
+ }
55
+ });
56
+ },
57
+ tableColumnNames: {},
58
+ getTableColumnNames: (tableKey) => {
59
+ return get().tableColumnNames[tableKey] || null;
60
+ },
61
+ setTableColumnNames: (tableKey) => (names) => {
62
+ // Update the table column names for the given table
63
+ set({
64
+ tableColumnNames: {
65
+ ...get().tableColumnNames,
66
+ [tableKey]: names
67
+ }
68
+ });
69
+ },
70
+ clearTableColumnNames: () => {
71
+ set({ tableColumnNames: {} });
72
+ },
73
+ hiddenColumns: {},
74
+ getHiddenColumns: (tableKey) => {
75
+ return get().hiddenColumns?.[tableKey] ?? null;
76
+ },
77
+ setHiddenColumns: (tableKey) => (columns) => {
78
+ // Update the hidden columns for the given table
79
+ set({
80
+ hiddenColumns: {
81
+ ...get().hiddenColumns,
82
+ [tableKey]: columns
83
+ }
84
+ });
85
+ }
86
+ }),
87
+ {
88
+ name: 'inventree-table-state'
89
+ }
90
+ )
91
+ );
@@ -68,6 +68,7 @@ export type ApiFormFieldHeader = {
68
68
  * @param adjustValue : Callback function to adjust the value of the field before it is sent to the API
69
69
  * @param addRow : Callback function to add a new row to a table field
70
70
  * @param onKeyDown : Callback function to get which key was pressed in the form to handle submission on enter
71
+ * @param singleFetchFunction : Optional function to fetch a single value for this field (used for fetching the initial value when editing an existing object)
71
72
  */
72
73
  export type ApiFormFieldType = {
73
74
  label?: string;
@@ -126,6 +127,7 @@ export type ApiFormFieldType = {
126
127
  addRow?: () => any;
127
128
  headers?: ApiFormFieldHeader[];
128
129
  depends_on?: string[];
130
+ singleFetchFunction?: (value: any) => Promise<any> | null;
129
131
  };
130
132
 
131
133
  export type ApiFormFieldSet = Record<string, ApiFormFieldType>;
@@ -13,6 +13,7 @@ import type {
13
13
  import type { UseModalReturn } from './Modals';
14
14
  import type { RenderInstanceProps } from './Rendering';
15
15
  import type { SettingsStateProps } from './Settings';
16
+ import type { InvenTreeTableRenderProps } from './Tables';
16
17
  import type { UserStateProps } from './User';
17
18
 
18
19
  export interface PluginProps {
@@ -48,6 +49,10 @@ export type InvenTreeFormsContext = {
48
49
  stockActions: StockAdjustmentFormsContext;
49
50
  };
50
51
 
52
+ export type InvenTreeTablesContext<T extends Record<string, any>> = {
53
+ renderTable: (props: InvenTreeTableRenderProps<T>) => React.ReactNode;
54
+ };
55
+
51
56
  export type ImporterDrawerContext = {
52
57
  open: (sessionId: number, options?: { onClose?: () => void }) => void;
53
58
  close: () => void;
@@ -61,20 +66,22 @@ export type ImporterDrawerContext = {
61
66
  *
62
67
  * @param version - The version of the running InvenTree software stack
63
68
  * @param api - The Axios API instance (see ../states/ApiState.tsx)
69
+ * @param queryClient - The Tanstack QueryClient instance (see ../states/QueryState.tsx)
64
70
  * @param user - The current user instance (see ../states/UserState.tsx)
65
71
  * @param userSettings - The current user settings (see ../states/SettingsState.tsx)
66
72
  * @param globalSettings - The global settings (see ../states/SettingsState.tsx)
73
+ * @param modelInformation - A dictionary of available model information
74
+ * @param renderInstance - A component function for rendering a model instance
75
+ * @param host - The current host URL
76
+ * @param i18n - The i18n instance for translations (from @lingui/core)
77
+ * @param locale - The current locale string (e.g. 'en' / 'de')
67
78
  * @param navigate - The navigation function (see react-router-dom)
68
79
  * @param theme - The current Mantine theme
80
+ * @param colorScheme - The current Mantine color scheme (e.g. 'light' / 'dark')
69
81
  * @param forms - A set of functions for opening various API forms (see ../components/Forms.tsx)
82
+ * @param tables - A set of functions for rendering API tables
70
83
  * @param importer - A set of functions for controlling the global importer drawer (see ../components/importer/GlobalImporterDrawer.tsx)
71
- * @param colorScheme - The current Mantine color scheme (e.g. 'light' / 'dark')
72
- * @param host - The current host URL
73
- * @param i18n - The i18n instance for translations (from @lingui/core)
74
- * @param locale - The current locale string (e.g. 'en' / 'de')
75
84
  * @param model - The model type associated with the rendered component (if applicable)
76
- * @param modelInformation - A dictionary of available model information
77
- * @param renderInstance - A component function for rendering a model instance
78
85
  * @param id - The ID (primary key) of the model instance for the plugin (if applicable)
79
86
  * @param instance - The model instance data (if available)
80
87
  * @param reloadContent - A function which can be called to reload the plugin content
@@ -95,9 +102,10 @@ export type InvenTreePluginContext = {
95
102
  locale: string;
96
103
  navigate: NavigateFunction;
97
104
  theme: MantineTheme;
105
+ colorScheme: MantineColorScheme;
98
106
  forms: InvenTreeFormsContext;
107
+ tables: InvenTreeTablesContext<any>;
99
108
  importer: ImporterDrawerContext;
100
- colorScheme: MantineColorScheme;
101
109
  model?: ModelType | string;
102
110
  id?: string | number | null;
103
111
  instance?: any;
@@ -1,4 +1,5 @@
1
1
  import type { MantineStyleProp } from '@mantine/core';
2
+ import type { AxiosInstance } from 'axios';
2
3
  import type {
3
4
  DataTableCellClickHandler,
4
5
  DataTableRowExpansionProps
@@ -219,3 +220,13 @@ export type InvenTreeTableProps<T = any> = {
219
220
  minHeight?: number;
220
221
  noHeader?: boolean;
221
222
  };
223
+
224
+ export type InvenTreeTableRenderProps<T extends Record<string, any>> = {
225
+ url?: string;
226
+ tableState: TableState;
227
+ tableData?: T[];
228
+ columns: TableColumn<T>[];
229
+ props: InvenTreeTableProps<T>;
230
+ api: AxiosInstance;
231
+ navigate: NavigateFunction;
232
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@inventreedb/ui",
3
3
  "description": "UI components for the InvenTree project",
4
- "version": "0.10.1",
4
+ "version": "0.11.0",
5
5
  "private": false,
6
6
  "type": "module",
7
7
  "license": "MIT",
@@ -130,7 +130,7 @@
130
130
  "rollup": "^4.59.0",
131
131
  "rollup-plugin-license": "^3.7.0",
132
132
  "typescript": "^5.9.3",
133
- "vite": "7.1.11",
133
+ "vite": "7.3.2",
134
134
  "vite-plugin-babel-macros": "^1.0.6",
135
135
  "vite-plugin-dts": "^4.5.4",
136
136
  "vite-plugin-externals": "^0.6.2",