@inventreedb/ui 0.10.1 → 0.11.1

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 (178) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/.vite/manifest.json +421 -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 +84 -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/@sentry/browser/build/npm/esm/prod/debug-build.js +5 -0
  53. package/dist/node_modules/@sentry/browser/build/npm/esm/prod/debug-build.js.map +1 -0
  54. package/dist/node_modules/@sentry/browser/build/npm/esm/prod/helpers.js +6 -0
  55. package/dist/node_modules/@sentry/browser/build/npm/esm/prod/helpers.js.map +1 -0
  56. package/dist/node_modules/@sentry/browser/build/npm/esm/prod/report-dialog.js +54 -0
  57. package/dist/node_modules/@sentry/browser/build/npm/esm/prod/report-dialog.js.map +1 -0
  58. package/dist/node_modules/@sentry/core/build/esm/api.js +41 -0
  59. package/dist/node_modules/@sentry/core/build/esm/api.js.map +1 -0
  60. package/dist/node_modules/@sentry/core/build/esm/asyncContext/index.js +13 -0
  61. package/dist/node_modules/@sentry/core/build/esm/asyncContext/index.js.map +1 -0
  62. package/dist/node_modules/@sentry/core/build/esm/asyncContext/stackStrategy.js +124 -0
  63. package/dist/node_modules/@sentry/core/build/esm/asyncContext/stackStrategy.js.map +1 -0
  64. package/dist/node_modules/@sentry/core/build/esm/carrier.js +22 -0
  65. package/dist/node_modules/@sentry/core/build/esm/carrier.js.map +1 -0
  66. package/dist/node_modules/@sentry/core/build/esm/currentScopes.js +34 -0
  67. package/dist/node_modules/@sentry/core/build/esm/currentScopes.js.map +1 -0
  68. package/dist/node_modules/@sentry/core/build/esm/debug-build.js +5 -0
  69. package/dist/node_modules/@sentry/core/build/esm/debug-build.js.map +1 -0
  70. package/dist/node_modules/@sentry/core/build/esm/defaultScopes.js +13 -0
  71. package/dist/node_modules/@sentry/core/build/esm/defaultScopes.js.map +1 -0
  72. package/dist/node_modules/@sentry/core/build/esm/exports.js +13 -0
  73. package/dist/node_modules/@sentry/core/build/esm/exports.js.map +1 -0
  74. package/dist/node_modules/@sentry/core/build/esm/scope.js +577 -0
  75. package/dist/node_modules/@sentry/core/build/esm/scope.js.map +1 -0
  76. package/dist/node_modules/@sentry/core/build/esm/session.js +61 -0
  77. package/dist/node_modules/@sentry/core/build/esm/session.js.map +1 -0
  78. package/dist/node_modules/@sentry/core/build/esm/utils/chain-and-copy-promiselike.js +39 -0
  79. package/dist/node_modules/@sentry/core/build/esm/utils/chain-and-copy-promiselike.js.map +1 -0
  80. package/dist/node_modules/@sentry/core/build/esm/utils/debug-logger.js +79 -0
  81. package/dist/node_modules/@sentry/core/build/esm/utils/debug-logger.js.map +1 -0
  82. package/dist/node_modules/@sentry/core/build/esm/utils/dsn.js +88 -0
  83. package/dist/node_modules/@sentry/core/build/esm/utils/dsn.js.map +1 -0
  84. package/dist/node_modules/@sentry/core/build/esm/utils/is.js +35 -0
  85. package/dist/node_modules/@sentry/core/build/esm/utils/is.js.map +1 -0
  86. package/dist/node_modules/@sentry/core/build/esm/utils/merge.js +19 -0
  87. package/dist/node_modules/@sentry/core/build/esm/utils/merge.js.map +1 -0
  88. package/dist/node_modules/@sentry/core/build/esm/utils/misc.js +32 -0
  89. package/dist/node_modules/@sentry/core/build/esm/utils/misc.js.map +1 -0
  90. package/dist/node_modules/@sentry/core/build/esm/utils/object.js +18 -0
  91. package/dist/node_modules/@sentry/core/build/esm/utils/object.js.map +1 -0
  92. package/dist/node_modules/@sentry/core/build/esm/utils/prepareEvent.js +34 -0
  93. package/dist/node_modules/@sentry/core/build/esm/utils/prepareEvent.js.map +1 -0
  94. package/dist/node_modules/@sentry/core/build/esm/utils/propagationContext.js +8 -0
  95. package/dist/node_modules/@sentry/core/build/esm/utils/propagationContext.js.map +1 -0
  96. package/dist/node_modules/@sentry/core/build/esm/utils/randomSafeContext.js +27 -0
  97. package/dist/node_modules/@sentry/core/build/esm/utils/randomSafeContext.js.map +1 -0
  98. package/dist/node_modules/@sentry/core/build/esm/utils/spanOnScope.js +17 -0
  99. package/dist/node_modules/@sentry/core/build/esm/utils/spanOnScope.js.map +1 -0
  100. package/dist/node_modules/@sentry/core/build/esm/utils/string.js +10 -0
  101. package/dist/node_modules/@sentry/core/build/esm/utils/string.js.map +1 -0
  102. package/dist/node_modules/@sentry/core/build/esm/utils/time.js +26 -0
  103. package/dist/node_modules/@sentry/core/build/esm/utils/time.js.map +1 -0
  104. package/dist/node_modules/@sentry/core/build/esm/utils/version.js +5 -0
  105. package/dist/node_modules/@sentry/core/build/esm/utils/version.js.map +1 -0
  106. package/dist/node_modules/@sentry/core/build/esm/utils/worldwide.js +5 -0
  107. package/dist/node_modules/@sentry/core/build/esm/utils/worldwide.js.map +1 -0
  108. package/dist/node_modules/@sentry/react/build/esm/debug-build.js +5 -0
  109. package/dist/node_modules/@sentry/react/build/esm/debug-build.js.map +1 -0
  110. package/dist/node_modules/@sentry/react/build/esm/error.js +40 -0
  111. package/dist/node_modules/@sentry/react/build/esm/error.js.map +1 -0
  112. package/dist/node_modules/@sentry/react/build/esm/errorboundary.js +103 -0
  113. package/dist/node_modules/@sentry/react/build/esm/errorboundary.js.map +1 -0
  114. package/dist/node_modules/@tabler/icons-react/dist/esm/createReactComponent.js +0 -6
  115. package/dist/node_modules/@tabler/icons-react/dist/esm/createReactComponent.js.map +1 -1
  116. package/dist/node_modules/@tabler/icons-react/dist/esm/defaultAttributes.js +0 -6
  117. package/dist/node_modules/@tabler/icons-react/dist/esm/defaultAttributes.js.map +1 -1
  118. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconAdjustments.js +8 -0
  119. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconAdjustments.js.map +1 -0
  120. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconArrowRight.js +0 -6
  121. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconArrowRight.js.map +1 -1
  122. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconCheck.js +8 -0
  123. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconCheck.js.map +1 -0
  124. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconCircleCheck.js +0 -6
  125. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconCircleCheck.js.map +1 -1
  126. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconCircleX.js +0 -6
  127. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconCircleX.js.map +1 -1
  128. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconCopy.js +0 -6
  129. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconCopy.js.map +1 -1
  130. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconDots.js +0 -6
  131. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconDots.js.map +1 -1
  132. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconEdit.js +0 -6
  133. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconEdit.js.map +1 -1
  134. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconExclamationCircle.js +0 -6
  135. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconExclamationCircle.js.map +1 -1
  136. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconPlus.js +0 -6
  137. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconPlus.js.map +1 -1
  138. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconSearch.js +0 -6
  139. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconSearch.js.map +1 -1
  140. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconTrash.js +0 -6
  141. package/dist/node_modules/@tabler/icons-react/dist/esm/icons/IconTrash.js.map +1 -1
  142. package/dist/node_modules/react/cjs/react-jsx-runtime.development.js +1 -10
  143. package/dist/node_modules/react/cjs/react-jsx-runtime.development.js.map +1 -1
  144. package/dist/node_modules/react/cjs/react-jsx-runtime.production.js +1 -10
  145. package/dist/node_modules/react/cjs/react-jsx-runtime.production.js.map +1 -1
  146. package/dist/node_modules/zustand/esm/middleware.js +202 -0
  147. package/dist/node_modules/zustand/esm/middleware.js.map +1 -0
  148. package/dist/node_modules/zustand/esm/react.js +24 -0
  149. package/dist/node_modules/zustand/esm/react.js.map +1 -0
  150. package/dist/node_modules/zustand/esm/vanilla.js +26 -0
  151. package/dist/node_modules/zustand/esm/vanilla.js.map +1 -0
  152. package/dist/states/StoredTableState.d.ts +37 -0
  153. package/dist/states/StoredTableState.js +58 -0
  154. package/dist/states/StoredTableState.js.map +1 -0
  155. package/dist/types/Forms.d.ts +2 -0
  156. package/dist/types/Plugins.d.ts +14 -7
  157. package/dist/types/Plugins.js +1 -1
  158. package/dist/types/Plugins.js.map +1 -1
  159. package/dist/types/Tables.d.ts +11 -4
  160. package/lib/components/Boundary.tsx +46 -0
  161. package/lib/components/CopyButton.tsx +76 -0
  162. package/lib/components/CopyableCell.tsx +51 -0
  163. package/lib/components/InvenTreeTable.tsx +63 -0
  164. package/lib/components/TableColumnSelect.tsx +40 -0
  165. package/lib/enums/ApiEndpoints.tsx +1 -1
  166. package/lib/enums/ModelInformation.tsx +7 -0
  167. package/lib/enums/ModelType.tsx +1 -0
  168. package/lib/functions/Forms.tsx +47 -0
  169. package/lib/functions/Notification.tsx +50 -0
  170. package/lib/functions/String.tsx +38 -0
  171. package/lib/hooks/UseFilterSet.tsx +47 -0
  172. package/lib/hooks/UseTable.tsx +149 -0
  173. package/lib/index.ts +49 -1
  174. package/lib/states/StoredTableState.tsx +91 -0
  175. package/lib/types/Forms.tsx +2 -0
  176. package/lib/types/Plugins.tsx +15 -7
  177. package/lib/types/Tables.tsx +12 -7
  178. package/package.json +2 -2
@@ -0,0 +1,149 @@
1
+ import { randomId } from '@mantine/hooks';
2
+ import { useCallback, useMemo, useState } from 'react';
3
+
4
+ import type { FilterSetState, TableFilter } from '../types/Filters';
5
+ import type { TableState } from '../types/Tables';
6
+ import useFilterSet from './UseFilterSet';
7
+
8
+ export type TableStateExtraProps = {
9
+ idAccessor?: string;
10
+ initialFilters?: TableFilter[];
11
+ };
12
+
13
+ /**
14
+ * A custom hook for managing the state of an <InvenTreeTable> component.
15
+ *
16
+ * Refer to the TableState type definition for more information.
17
+ */
18
+
19
+ export default function useTable(
20
+ tableName: string,
21
+ tableProps: TableStateExtraProps = {
22
+ idAccessor: 'pk',
23
+ initialFilters: []
24
+ }
25
+ ): TableState {
26
+ // Function to generate a new ID (to refresh the table)
27
+ function generateTableName() {
28
+ return `${tableName.replaceAll('-', '')}-${randomId()}`;
29
+ }
30
+
31
+ const [tableKey, setTableKey] = useState<string>(generateTableName());
32
+
33
+ // Callback used to refresh (reload) the table
34
+ const refreshTable = useCallback(
35
+ (clearSelection?: boolean) => {
36
+ setTableKey(generateTableName());
37
+ if (clearSelection) {
38
+ clearSelectedRecords();
39
+ }
40
+ },
41
+ [generateTableName]
42
+ );
43
+
44
+ const filterSet: FilterSetState = useFilterSet(
45
+ `table-${tableName}`,
46
+ tableProps.initialFilters
47
+ );
48
+
49
+ // Array of expanded records
50
+ const [expandedRecords, setExpandedRecords] = useState<any[]>([]);
51
+
52
+ // Function to determine if a record is expanded
53
+ const isRowExpanded = useCallback(
54
+ (pk: number) => {
55
+ return expandedRecords.includes(pk);
56
+ },
57
+ [expandedRecords]
58
+ );
59
+
60
+ // Array of columns which are hidden
61
+ const [hiddenColumns, setHiddenColumns] = useState<string[]>([]);
62
+
63
+ // Array of selected records
64
+ const [selectedRecords, setSelectedRecords] = useState<any[]>([]);
65
+
66
+ // Array of selected primary key values
67
+ const selectedIds = useMemo(
68
+ () => selectedRecords.map((r) => r[tableProps.idAccessor || 'pk']),
69
+ [selectedRecords]
70
+ );
71
+
72
+ const clearSelectedRecords = useCallback(() => {
73
+ setSelectedRecords([]);
74
+ }, []);
75
+
76
+ const hasSelectedRecords = useMemo(() => {
77
+ return selectedRecords.length > 0;
78
+ }, [selectedRecords]);
79
+
80
+ // Total record count
81
+ const [recordCount, setRecordCount] = useState<number>(0);
82
+
83
+ const [page, setPage] = useState<number>(1);
84
+
85
+ // Search term
86
+ const [searchTerm, setSearchTerm] = useState<string>('');
87
+
88
+ // Table records
89
+ const [records, setRecords] = useState<any[]>([]);
90
+
91
+ // Update a single record in the table, by primary key value
92
+ const updateRecord = useCallback(
93
+ (record: any) => {
94
+ const _records = [...records];
95
+
96
+ // Find the matching record in the table
97
+ const index = _records.findIndex(
98
+ (r) => r[tableProps.idAccessor || 'pk'] === record.pk
99
+ );
100
+
101
+ if (index >= 0) {
102
+ _records[index] = {
103
+ ..._records[index],
104
+ ...record
105
+ };
106
+ } else {
107
+ _records.push(record);
108
+ }
109
+
110
+ setRecords(_records);
111
+ },
112
+ [records]
113
+ );
114
+
115
+ const idAccessor = useMemo(
116
+ () => tableProps.idAccessor || 'pk',
117
+ [tableProps.idAccessor]
118
+ );
119
+
120
+ const [isLoading, setIsLoading] = useState<boolean>(false);
121
+
122
+ return {
123
+ tableKey,
124
+ refreshTable,
125
+ isLoading,
126
+ setIsLoading,
127
+ filterSet,
128
+ expandedRecords,
129
+ setExpandedRecords,
130
+ isRowExpanded,
131
+ selectedRecords,
132
+ selectedIds,
133
+ setSelectedRecords,
134
+ clearSelectedRecords,
135
+ hasSelectedRecords,
136
+ searchTerm,
137
+ setSearchTerm,
138
+ recordCount,
139
+ setRecordCount,
140
+ hiddenColumns,
141
+ setHiddenColumns,
142
+ page,
143
+ setPage,
144
+ records,
145
+ setRecords,
146
+ updateRecord,
147
+ idAccessor
148
+ };
149
+ }
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,10 +1,11 @@
1
1
  import type { MantineStyleProp } from '@mantine/core';
2
+ import type { AxiosInstance } from 'axios';
2
3
  import type {
3
4
  DataTableCellClickHandler,
4
5
  DataTableRowExpansionProps
5
6
  } from 'mantine-datatable';
6
7
  import type { ReactNode } from 'react';
7
- import type { NavigateFunction, SetURLSearchParams } from 'react-router-dom';
8
+ import type { NavigateFunction } from 'react-router-dom';
8
9
  import type { ModelType } from '../enums/ModelType';
9
10
  import type { FilterSetState, TableFilter } from './Filters';
10
11
  import type { ApiFormFieldType } from './Forms';
@@ -17,9 +18,6 @@ import type { ApiFormFieldType } from './Forms';
17
18
  * isLoading: A boolean flag to indicate if the table is currently loading data
18
19
  * setIsLoading: A function to set the isLoading flag
19
20
  * filterSet: A group of active filters
20
- * queryFilters: A map of query filters (e.g. ?active=true&overdue=false) passed in the URL
21
- * setQueryFilters: A function to set the query filters
22
- * clearQueryFilters: A function to clear all query filters
23
21
  * expandedRecords: An array of expanded records (rows) in the table
24
22
  * setExpandedRecords: A function to set the expanded records
25
23
  * isRowExpanded: A function to determine if a record is expanded
@@ -49,9 +47,6 @@ export type TableState = {
49
47
  isLoading: boolean;
50
48
  setIsLoading: (value: boolean) => void;
51
49
  filterSet: FilterSetState;
52
- queryFilters: URLSearchParams;
53
- setQueryFilters: SetURLSearchParams;
54
- clearQueryFilters: () => void;
55
50
  expandedRecords: any[];
56
51
  setExpandedRecords: (records: any[]) => void;
57
52
  isRowExpanded: (pk: number) => boolean;
@@ -219,3 +214,13 @@ export type InvenTreeTableProps<T = any> = {
219
214
  minHeight?: number;
220
215
  noHeader?: boolean;
221
216
  };
217
+
218
+ export type InvenTreeTableRenderProps<T extends Record<string, any>> = {
219
+ url?: string;
220
+ tableState: TableState;
221
+ tableData?: T[];
222
+ columns: TableColumn<T>[];
223
+ props: InvenTreeTableProps<T>;
224
+ api: AxiosInstance;
225
+ navigate: NavigateFunction;
226
+ };
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.1",
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",