@inventreedb/ui 0.11.0 → 0.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  This file contains historical changelog information for the InvenTree UI components library.
4
4
 
5
+ ### 0.11.2 - April 2026
6
+
7
+ Exposes additional type definitions related to tables and filters:
8
+
9
+ - TableFilterChoice
10
+ - TableFilterType
11
+ - TableFilter
12
+ - FilterSetState
13
+
14
+ ### 0.11.1 - April 2026
15
+
16
+ Fixes dependency issues for the `InvenTreeTable` component, which were introduced in `0.11.0`. This ensures that the component works correctly and does not cause issues with plugin builds.
17
+
5
18
  ### 0.11.0 - April 2026
6
19
 
7
20
  Adds the `InvenTreeTable` component, which provides plugins with a method of implementing an API-driven data table which is consistent with the rest of the InvenTree UI. This component supports features such as pagination, sorting, and filtering, and can be used to display data from the InvenTree API in a tabular format.
@@ -261,7 +261,6 @@
261
261
  "name": "hooks/UseTable",
262
262
  "src": "lib/hooks/UseTable.tsx",
263
263
  "imports": [
264
- "node_modules/react-router-dom/dist/index.js",
265
264
  "lib/hooks/UseFilterSet.tsx",
266
265
  "node_modules/@mantine/hooks/esm/utils/random-id/random-id.mjs"
267
266
  ]
@@ -352,11 +351,6 @@
352
351
  "name": "node_modules/@mantine/hooks/esm/utils/random-id/random-id",
353
352
  "src": "node_modules/@mantine/hooks/esm/utils/random-id/random-id.mjs"
354
353
  },
355
- "node_modules/@remix-run/router/dist/router.js": {
356
- "file": "node_modules/@remix-run/router/dist/router.js",
357
- "name": "node_modules/@remix-run/router/dist/router",
358
- "src": "node_modules/@remix-run/router/dist/router.js"
359
- },
360
354
  "node_modules/@sentry/browser/build/npm/esm/prod/debug-build.js": {
361
355
  "file": "node_modules/@sentry/browser/build/npm/esm/prod/debug-build.js",
362
356
  "name": "node_modules/@sentry/browser/build/npm/esm/prod/debug-build",
@@ -865,23 +859,6 @@
865
859
  "node_modules/@tanstack/react-query/build/modern/useBaseQuery.js"
866
860
  ]
867
861
  },
868
- "node_modules/react-router-dom/dist/index.js": {
869
- "file": "node_modules/react-router-dom/dist/index.js",
870
- "name": "node_modules/react-router-dom/dist/index",
871
- "src": "node_modules/react-router-dom/dist/index.js",
872
- "imports": [
873
- "node_modules/react-router/dist/index.js",
874
- "node_modules/@remix-run/router/dist/router.js"
875
- ]
876
- },
877
- "node_modules/react-router/dist/index.js": {
878
- "file": "node_modules/react-router/dist/index.js",
879
- "name": "node_modules/react-router/dist/index",
880
- "src": "node_modules/react-router/dist/index.js",
881
- "imports": [
882
- "node_modules/@remix-run/router/dist/router.js"
883
- ]
884
- },
885
862
  "node_modules/react/cjs/react-jsx-runtime.development.js": {
886
863
  "file": "node_modules/react/cjs/react-jsx-runtime.development.js",
887
864
  "name": "node_modules/react/cjs/react-jsx-runtime.development",
@@ -1,4 +1,3 @@
1
- import { useSearchParams } from "../node_modules/react-router-dom/dist/index.js";
2
1
  import useFilterSet from "./UseFilterSet.js";
3
2
  import { randomId } from "../node_modules/@mantine/hooks/esm/utils/random-id/random-id.js";
4
3
  const useCallback = window["React"].useCallback;
@@ -11,10 +10,6 @@ function useTable(tableName, tableProps = {
11
10
  function generateTableName() {
12
11
  return `${tableName.replaceAll("-", "")}-${randomId()}`;
13
12
  }
14
- const [queryFilters, setQueryFilters] = useSearchParams();
15
- const clearQueryFilters = useCallback(() => {
16
- setQueryFilters({});
17
- }, []);
18
13
  const [tableKey, setTableKey] = useState(generateTableName());
19
14
  const refreshTable = useCallback((clearSelection) => {
20
15
  setTableKey(generateTableName());
@@ -61,9 +56,6 @@ function useTable(tableName, tableProps = {
61
56
  isLoading,
62
57
  setIsLoading,
63
58
  filterSet,
64
- queryFilters,
65
- setQueryFilters,
66
- clearQueryFilters,
67
59
  expandedRecords,
68
60
  setExpandedRecords,
69
61
  isRowExpanded,
@@ -1 +1 @@
1
- {"version":3,"file":"UseTable.js","sources":["../../lib/hooks/UseTable.tsx"],"sourcesContent":["import { randomId } from '@mantine/hooks';\nimport { useCallback, useMemo, useState } from 'react';\nimport { useSearchParams } from 'react-router-dom';\n\nimport type { FilterSetState, TableFilter } from '../types/Filters';\nimport type { TableState } from '../types/Tables';\nimport useFilterSet from './UseFilterSet';\n\nexport type TableStateExtraProps = {\n idAccessor?: string;\n initialFilters?: TableFilter[];\n};\n\n/**\n * A custom hook for managing the state of an <InvenTreeTable> component.\n *\n * Refer to the TableState type definition for more information.\n */\n\nexport default function useTable(\n tableName: string,\n tableProps: TableStateExtraProps = {\n idAccessor: 'pk',\n initialFilters: []\n }\n): TableState {\n // Function to generate a new ID (to refresh the table)\n function generateTableName() {\n return `${tableName.replaceAll('-', '')}-${randomId()}`;\n }\n\n // Extract URL query parameters (e.g. ?active=true&overdue=false)\n const [queryFilters, setQueryFilters] = useSearchParams();\n\n const clearQueryFilters = useCallback(() => {\n setQueryFilters({});\n }, []);\n\n const [tableKey, setTableKey] = useState<string>(generateTableName());\n\n // Callback used to refresh (reload) the table\n const refreshTable = useCallback(\n (clearSelection?: boolean) => {\n setTableKey(generateTableName());\n if (clearSelection) {\n clearSelectedRecords();\n }\n },\n [generateTableName]\n );\n\n const filterSet: FilterSetState = useFilterSet(\n `table-${tableName}`,\n tableProps.initialFilters\n );\n\n // Array of expanded records\n const [expandedRecords, setExpandedRecords] = useState<any[]>([]);\n\n // Function to determine if a record is expanded\n const isRowExpanded = useCallback(\n (pk: number) => {\n return expandedRecords.includes(pk);\n },\n [expandedRecords]\n );\n\n // Array of columns which are hidden\n const [hiddenColumns, setHiddenColumns] = useState<string[]>([]);\n\n // Array of selected records\n const [selectedRecords, setSelectedRecords] = useState<any[]>([]);\n\n // Array of selected primary key values\n const selectedIds = useMemo(\n () => selectedRecords.map((r) => r[tableProps.idAccessor || 'pk']),\n [selectedRecords]\n );\n\n const clearSelectedRecords = useCallback(() => {\n setSelectedRecords([]);\n }, []);\n\n const hasSelectedRecords = useMemo(() => {\n return selectedRecords.length > 0;\n }, [selectedRecords]);\n\n // Total record count\n const [recordCount, setRecordCount] = useState<number>(0);\n\n const [page, setPage] = useState<number>(1);\n\n // Search term\n const [searchTerm, setSearchTerm] = useState<string>('');\n\n // Table records\n const [records, setRecords] = useState<any[]>([]);\n\n // Update a single record in the table, by primary key value\n const updateRecord = useCallback(\n (record: any) => {\n const _records = [...records];\n\n // Find the matching record in the table\n const index = _records.findIndex(\n (r) => r[tableProps.idAccessor || 'pk'] === record.pk\n );\n\n if (index >= 0) {\n _records[index] = {\n ..._records[index],\n ...record\n };\n } else {\n _records.push(record);\n }\n\n setRecords(_records);\n },\n [records]\n );\n\n const idAccessor = useMemo(\n () => tableProps.idAccessor || 'pk',\n [tableProps.idAccessor]\n );\n\n const [isLoading, setIsLoading] = useState<boolean>(false);\n\n return {\n tableKey,\n refreshTable,\n isLoading,\n setIsLoading,\n filterSet,\n queryFilters,\n setQueryFilters,\n clearQueryFilters,\n expandedRecords,\n setExpandedRecords,\n isRowExpanded,\n selectedRecords,\n selectedIds,\n setSelectedRecords,\n clearSelectedRecords,\n hasSelectedRecords,\n searchTerm,\n setSearchTerm,\n recordCount,\n setRecordCount,\n hiddenColumns,\n setHiddenColumns,\n page,\n setPage,\n records,\n setRecords,\n updateRecord,\n idAccessor\n };\n}\n"],"names":["useTable","tableName","tableProps","idAccessor","initialFilters","generateTableName","replaceAll","randomId","queryFilters","setQueryFilters","useSearchParams","clearQueryFilters","useCallback","tableKey","setTableKey","useState","refreshTable","clearSelection","clearSelectedRecords","filterSet","useFilterSet","expandedRecords","setExpandedRecords","isRowExpanded","pk","includes","hiddenColumns","setHiddenColumns","selectedRecords","setSelectedRecords","selectedIds","useMemo","map","r","hasSelectedRecords","length","recordCount","setRecordCount","page","setPage","searchTerm","setSearchTerm","records","setRecords","updateRecord","record","_records","index","findIndex","push","isLoading","setIsLoading"],"mappings":";;;AACA,MAAA,cAAA,OAAA,OAAA,EAAA;;;AAkBA,SAAwBA,SACtBC,WACAC,aAAmC;AAAA,EACjCC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AExD,QAAM,CAACuB,MAAMC,OAAO,IAAIxB,SAAiB,CAAC;AAG1C,QAAM,CAACyB,YAAYC,aAAa,IAAI1B,SAAiB,EAAE;AAGvD,QAAM,CAAC2B,SAASC,UAAU,IAAI5B,SAAgB,CAAA,CAAE;AAGhD,QAAM6B,eAAehC,YACnB,CAACiC,WAAgB;AACf,UAAMC,WAAW,CAAC,GAAGJ,OAAO;AAG5B,UAAMK,QAAQD,SAASE,UACpBf,CAAAA,MAAMA,EAAE/B,WAAWC,cAAc,IAAI,MAAM0C,OAAOrB,EACrD;AAEA,QAAIuB,SAAS,GAAG;AACdD,eAASC,KAAK,IAAI;AAAA,QAChB,GAAGD,SAASC,KAAK;AAAA,QACjB,GAAGF;AAAAA,MAAAA;AAAAA,IAEP,OAAO;AACLC,eAASG,KAAKJ,MAAM;AAAA,IACtB;AAEAF,eAAWG,QAAQ;AAAA,EACrB,GACA,CAACJ,OAAO,CACV;AAEA,QAAMvC,aAAa4B,QACjB,MAAM7B,WAAWC,cAAc,MAC/B,CAACD,WAAWC,UAAU,CACxB;AAEA,QAAM,CAAC+C,WAAWC,YAAY,IAAIpC,SAAkB,KAAK;AAEzD,SAAO;AAAA,IACLF;AAAAA,IACAG;AAAAA,IACAkC;AAAAA,IACAC;AAAAA,IACAhC;AAAAA,IACAX;AAAAA,IACAC;AAAAA,IACAE;AAAAA,IACAU;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAK;AAAAA,IACAE;AAAAA,IACAD;AAAAA,IACAX;AAAAA,IACAgB;AAAAA,IACAM;AAAAA,IACAC;AAAAA,IACAL;AAAAA,IACAC;AAAAA,IACAX;AAAAA,IACAC;AAAAA,IACAW;AAAAA,IACAC;AAAAA,IACAG;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAzC;AAAAA,EAAAA;AAEJ;"}
1
+ {"version":3,"file":"UseTable.js","sources":["../../lib/hooks/UseTable.tsx"],"sourcesContent":["import { randomId } from '@mantine/hooks';\nimport { useCallback, useMemo, useState } from 'react';\n\nimport type { FilterSetState, TableFilter } from '../types/Filters';\nimport type { TableState } from '../types/Tables';\nimport useFilterSet from './UseFilterSet';\n\nexport type TableStateExtraProps = {\n idAccessor?: string;\n initialFilters?: TableFilter[];\n};\n\n/**\n * A custom hook for managing the state of an <InvenTreeTable> component.\n *\n * Refer to the TableState type definition for more information.\n */\n\nexport default function useTable(\n tableName: string,\n tableProps: TableStateExtraProps = {\n idAccessor: 'pk',\n initialFilters: []\n }\n): TableState {\n // Function to generate a new ID (to refresh the table)\n function generateTableName() {\n return `${tableName.replaceAll('-', '')}-${randomId()}`;\n }\n\n const [tableKey, setTableKey] = useState<string>(generateTableName());\n\n // Callback used to refresh (reload) the table\n const refreshTable = useCallback(\n (clearSelection?: boolean) => {\n setTableKey(generateTableName());\n if (clearSelection) {\n clearSelectedRecords();\n }\n },\n [generateTableName]\n );\n\n const filterSet: FilterSetState = useFilterSet(\n `table-${tableName}`,\n tableProps.initialFilters\n );\n\n // Array of expanded records\n const [expandedRecords, setExpandedRecords] = useState<any[]>([]);\n\n // Function to determine if a record is expanded\n const isRowExpanded = useCallback(\n (pk: number) => {\n return expandedRecords.includes(pk);\n },\n [expandedRecords]\n );\n\n // Array of columns which are hidden\n const [hiddenColumns, setHiddenColumns] = useState<string[]>([]);\n\n // Array of selected records\n const [selectedRecords, setSelectedRecords] = useState<any[]>([]);\n\n // Array of selected primary key values\n const selectedIds = useMemo(\n () => selectedRecords.map((r) => r[tableProps.idAccessor || 'pk']),\n [selectedRecords]\n );\n\n const clearSelectedRecords = useCallback(() => {\n setSelectedRecords([]);\n }, []);\n\n const hasSelectedRecords = useMemo(() => {\n return selectedRecords.length > 0;\n }, [selectedRecords]);\n\n // Total record count\n const [recordCount, setRecordCount] = useState<number>(0);\n\n const [page, setPage] = useState<number>(1);\n\n // Search term\n const [searchTerm, setSearchTerm] = useState<string>('');\n\n // Table records\n const [records, setRecords] = useState<any[]>([]);\n\n // Update a single record in the table, by primary key value\n const updateRecord = useCallback(\n (record: any) => {\n const _records = [...records];\n\n // Find the matching record in the table\n const index = _records.findIndex(\n (r) => r[tableProps.idAccessor || 'pk'] === record.pk\n );\n\n if (index >= 0) {\n _records[index] = {\n ..._records[index],\n ...record\n };\n } else {\n _records.push(record);\n }\n\n setRecords(_records);\n },\n [records]\n );\n\n const idAccessor = useMemo(\n () => tableProps.idAccessor || 'pk',\n [tableProps.idAccessor]\n );\n\n const [isLoading, setIsLoading] = useState<boolean>(false);\n\n return {\n tableKey,\n refreshTable,\n isLoading,\n setIsLoading,\n filterSet,\n expandedRecords,\n setExpandedRecords,\n isRowExpanded,\n selectedRecords,\n selectedIds,\n setSelectedRecords,\n clearSelectedRecords,\n hasSelectedRecords,\n searchTerm,\n setSearchTerm,\n recordCount,\n setRecordCount,\n hiddenColumns,\n setHiddenColumns,\n page,\n setPage,\n records,\n setRecords,\n updateRecord,\n idAccessor\n };\n}\n"],"names":["useTable","tableName","tableProps","idAccessor","initialFilters","generateTableName","replaceAll","randomId","tableKey","setTableKey","useState","refreshTable","useCallback","clearSelection","clearSelectedRecords","filterSet","useFilterSet","expandedRecords","setExpandedRecords","isRowExpanded","pk","includes","hiddenColumns","setHiddenColumns","selectedRecords","setSelectedRecords","selectedIds","useMemo","map","r","hasSelectedRecords","length","recordCount","setRecordCount","page","setPage","searchTerm","setSearchTerm","records","setRecords","updateRecord","record","_records","index","findIndex","push","isLoading","setIsLoading"],"mappings":";;AACA,MAAA,cAAA,OAAA,OAAA,EAAA;;;AAiBA,SAAwBA,SACtBC,WACAC,aAAmC;AAAA,EACjCC,YAAY;AAAA,EACZC,gBAAgB,CAAA;AAClB,GACY;AAEZ,WAASC,oBAAoB;AAC3B,WAAO,GAAGJ,UAAUK,WAAW,KAAK,EAAE,CAAC,IAAIC,UAAU;AAAA,EACvD;AAEA,QAAM,CAACC,UAAUC,WAAW,IAAIC,SAAiBL,mBAAmB;AAGpE,QAAMM,eAAeC,YACnB,CAACC,mBAA6B;AAC5BJ,gBAAY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AK,IAAI;AAAA,QAChB,GAAGD,SAASC,KAAK;AAAA,QACjB,GAAGF;AAAAA,MAAAA;AAAAA,IAEP,OAAO;AACLC,eAASG,KAAKJ,MAAM;AAAA,IACtB;AAEAF,eAAWG,QAAQ;AAAA,EACrB,GACA,CAACJ,OAAO,CACV;AAEA,QAAMnC,aAAawB,QACjB,MAAMzB,WAAWC,cAAc,MAC/B,CAACD,WAAWC,UAAU,CACxB;AAEA,QAAM,CAAC2C,WAAWC,YAAY,IAAIrC,SAAkB,KAAK;AAEzD,SAAO;AAAA,IACLF;AAAAA,IACAG;AAAAA,IACAmC;AAAAA,IACAC;AAAAA,IACAhC;AAAAA,IACAE;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACAK;AAAAA,IACAE;AAAAA,IACAD;AAAAA,IACAX;AAAAA,IACAgB;AAAAA,IACAM;AAAAA,IACAC;AAAAA,IACAL;AAAAA,IACAC;AAAAA,IACAX;AAAAA,IACAC;AAAAA,IACAW;AAAAA,IACAC;AAAAA,IACAG;AAAAA,IACAC;AAAAA,IACAC;AAAAA,IACArC;AAAAA,EAAAA;AAEJ;"}
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export type { ModelDict } from './enums/ModelInformation';
5
5
  export { UserRoles, UserPermissions } from './enums/Roles';
6
6
  export type { InvenTreePluginContext, InvenTreeFormsContext, InvenTreeTablesContext, ImporterDrawerContext, PluginVersion, StockAdjustmentFormsContext } from './types/Plugins';
7
7
  export type { RowAction, RowViewProps, TableColumn, TableColumnProps, InvenTreeTableProps, InvenTreeTableRenderProps } from './types/Tables';
8
+ export type { TableFilterChoice, TableFilterType, TableFilter, FilterSetState } from './types/Filters';
8
9
  export type { ApiFormFieldChoice, ApiFormFieldHeader, ApiFormFieldType, ApiFormFieldSet, ApiFormProps, ApiFormModalProps, BulkEditApiFormModalProps } from './types/Forms';
9
10
  export type { UseModalProps, UseModalReturn } from './types/Modals';
10
11
  export { apiUrl } from './functions/Api';
@@ -1,4 +1,4 @@
1
- const INVENTREE_PLUGIN_VERSION = "0.11.0";
1
+ const INVENTREE_PLUGIN_VERSION = "0.11.2";
2
2
  const INVENTREE_REACT_VERSION = "19.2.4";
3
3
  const INVENTREE_REACT_DOM_VERSION = (
4
4
  // @ts-ignore
@@ -1,8 +1,9 @@
1
1
  import { MantineStyleProp } from '@mantine/core';
2
2
  import { AxiosInstance } from 'axios';
3
+ import { ShowContextMenuFunction } from 'mantine-contextmenu';
3
4
  import { DataTableCellClickHandler, DataTableRowExpansionProps } from 'mantine-datatable';
4
5
  import { ReactNode } from 'react';
5
- import { NavigateFunction, SetURLSearchParams } from 'react-router-dom';
6
+ import { NavigateFunction } from 'react-router-dom';
6
7
  import { ModelType } from '../enums/ModelType';
7
8
  import { FilterSetState, TableFilter } from './Filters';
8
9
  import { ApiFormFieldType } from './Forms';
@@ -12,9 +13,6 @@ export type TableState = {
12
13
  isLoading: boolean;
13
14
  setIsLoading: (value: boolean) => void;
14
15
  filterSet: FilterSetState;
15
- queryFilters: URLSearchParams;
16
- setQueryFilters: SetURLSearchParams;
17
- clearQueryFilters: () => void;
18
16
  expandedRecords: any[];
19
17
  setExpandedRecords: (records: any[]) => void;
20
18
  isRowExpanded: (pk: number) => boolean;
@@ -183,5 +181,8 @@ export type InvenTreeTableRenderProps<T extends Record<string, any>> = {
183
181
  props: InvenTreeTableProps<T>;
184
182
  api: AxiosInstance;
185
183
  navigate: NavigateFunction;
184
+ showContextMenu?: ShowContextMenuFunction;
185
+ searchParams?: URLSearchParams;
186
+ setSearchParams?: (params: URLSearchParams) => void;
186
187
  };
187
188
  export {};
@@ -1,6 +1,5 @@
1
1
  import { randomId } from '@mantine/hooks';
2
2
  import { useCallback, useMemo, useState } from 'react';
3
- import { useSearchParams } from 'react-router-dom';
4
3
 
5
4
  import type { FilterSetState, TableFilter } from '../types/Filters';
6
5
  import type { TableState } from '../types/Tables';
@@ -29,13 +28,6 @@ export default function useTable(
29
28
  return `${tableName.replaceAll('-', '')}-${randomId()}`;
30
29
  }
31
30
 
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
31
  const [tableKey, setTableKey] = useState<string>(generateTableName());
40
32
 
41
33
  // Callback used to refresh (reload) the table
@@ -133,9 +125,6 @@ export default function useTable(
133
125
  isLoading,
134
126
  setIsLoading,
135
127
  filterSet,
136
- queryFilters,
137
- setQueryFilters,
138
- clearQueryFilters,
139
128
  expandedRecords,
140
129
  setExpandedRecords,
141
130
  isRowExpanded,
package/lib/index.ts CHANGED
@@ -30,6 +30,13 @@ export type {
30
30
  InvenTreeTableRenderProps
31
31
  } from './types/Tables';
32
32
 
33
+ export type {
34
+ TableFilterChoice,
35
+ TableFilterType,
36
+ TableFilter,
37
+ FilterSetState
38
+ } from './types/Filters';
39
+
33
40
  export type {
34
41
  ApiFormFieldChoice,
35
42
  ApiFormFieldHeader,
@@ -1,11 +1,12 @@
1
1
  import type { MantineStyleProp } from '@mantine/core';
2
2
  import type { AxiosInstance } from 'axios';
3
+ import type { ShowContextMenuFunction } from 'mantine-contextmenu';
3
4
  import type {
4
5
  DataTableCellClickHandler,
5
6
  DataTableRowExpansionProps
6
7
  } from 'mantine-datatable';
7
8
  import type { ReactNode } from 'react';
8
- import type { NavigateFunction, SetURLSearchParams } from 'react-router-dom';
9
+ import type { NavigateFunction } from 'react-router-dom';
9
10
  import type { ModelType } from '../enums/ModelType';
10
11
  import type { FilterSetState, TableFilter } from './Filters';
11
12
  import type { ApiFormFieldType } from './Forms';
@@ -18,9 +19,6 @@ import type { ApiFormFieldType } from './Forms';
18
19
  * isLoading: A boolean flag to indicate if the table is currently loading data
19
20
  * setIsLoading: A function to set the isLoading flag
20
21
  * filterSet: A group of active filters
21
- * queryFilters: A map of query filters (e.g. ?active=true&overdue=false) passed in the URL
22
- * setQueryFilters: A function to set the query filters
23
- * clearQueryFilters: A function to clear all query filters
24
22
  * expandedRecords: An array of expanded records (rows) in the table
25
23
  * setExpandedRecords: A function to set the expanded records
26
24
  * isRowExpanded: A function to determine if a record is expanded
@@ -50,9 +48,6 @@ export type TableState = {
50
48
  isLoading: boolean;
51
49
  setIsLoading: (value: boolean) => void;
52
50
  filterSet: FilterSetState;
53
- queryFilters: URLSearchParams;
54
- setQueryFilters: SetURLSearchParams;
55
- clearQueryFilters: () => void;
56
51
  expandedRecords: any[];
57
52
  setExpandedRecords: (records: any[]) => void;
58
53
  isRowExpanded: (pk: number) => boolean;
@@ -229,4 +224,9 @@ export type InvenTreeTableRenderProps<T extends Record<string, any>> = {
229
224
  props: InvenTreeTableProps<T>;
230
225
  api: AxiosInstance;
231
226
  navigate: NavigateFunction;
227
+
228
+ // The following attributes are for internal use only (plugins should not use these directly)
229
+ showContextMenu?: ShowContextMenuFunction;
230
+ searchParams?: URLSearchParams;
231
+ setSearchParams?: (params: URLSearchParams) => void;
232
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.11.0",
4
+ "version": "0.11.2",
5
5
  "private": false,
6
6
  "type": "module",
7
7
  "license": "MIT",
@@ -1,272 +0,0 @@
1
- function _extends() {
2
- _extends = Object.assign ? Object.assign.bind() : function(target) {
3
- for (var i = 1; i < arguments.length; i++) {
4
- var source = arguments[i];
5
- for (var key in source) {
6
- if (Object.prototype.hasOwnProperty.call(source, key)) {
7
- target[key] = source[key];
8
- }
9
- }
10
- }
11
- return target;
12
- };
13
- return _extends.apply(this, arguments);
14
- }
15
- var Action;
16
- (function(Action2) {
17
- Action2["Pop"] = "POP";
18
- Action2["Push"] = "PUSH";
19
- Action2["Replace"] = "REPLACE";
20
- })(Action || (Action = {}));
21
- function invariant(value, message) {
22
- if (value === false || value === null || typeof value === "undefined") {
23
- throw new Error(message);
24
- }
25
- }
26
- function warning(cond, message) {
27
- if (!cond) {
28
- if (typeof console !== "undefined") console.warn(message);
29
- try {
30
- throw new Error(message);
31
- } catch (e) {
32
- }
33
- }
34
- }
35
- function createPath(_ref) {
36
- let {
37
- pathname = "/",
38
- search = "",
39
- hash = ""
40
- } = _ref;
41
- if (search && search !== "?") pathname += search.charAt(0) === "?" ? search : "?" + search;
42
- if (hash && hash !== "#") pathname += hash.charAt(0) === "#" ? hash : "#" + hash;
43
- return pathname;
44
- }
45
- function parsePath(path) {
46
- let parsedPath = {};
47
- if (path) {
48
- let hashIndex = path.indexOf("#");
49
- if (hashIndex >= 0) {
50
- parsedPath.hash = path.substr(hashIndex);
51
- path = path.substr(0, hashIndex);
52
- }
53
- let searchIndex = path.indexOf("?");
54
- if (searchIndex >= 0) {
55
- parsedPath.search = path.substr(searchIndex);
56
- path = path.substr(0, searchIndex);
57
- }
58
- if (path) {
59
- parsedPath.pathname = path;
60
- }
61
- }
62
- return parsedPath;
63
- }
64
- var ResultType;
65
- (function(ResultType2) {
66
- ResultType2["data"] = "data";
67
- ResultType2["deferred"] = "deferred";
68
- ResultType2["redirect"] = "redirect";
69
- ResultType2["error"] = "error";
70
- })(ResultType || (ResultType = {}));
71
- function matchPath(pattern, pathname) {
72
- if (typeof pattern === "string") {
73
- pattern = {
74
- path: pattern,
75
- caseSensitive: false,
76
- end: true
77
- };
78
- }
79
- let [matcher, compiledParams] = compilePath(pattern.path, pattern.caseSensitive, pattern.end);
80
- let match = pathname.match(matcher);
81
- if (!match) return null;
82
- let matchedPathname = match[0];
83
- let pathnameBase = matchedPathname.replace(/(.)\/+$/, "$1");
84
- let captureGroups = match.slice(1);
85
- let params = compiledParams.reduce((memo, _ref, index) => {
86
- let {
87
- paramName,
88
- isOptional
89
- } = _ref;
90
- if (paramName === "*") {
91
- let splatValue = captureGroups[index] || "";
92
- pathnameBase = matchedPathname.slice(0, matchedPathname.length - splatValue.length).replace(/(.)\/+$/, "$1");
93
- }
94
- const value = captureGroups[index];
95
- if (isOptional && !value) {
96
- memo[paramName] = void 0;
97
- } else {
98
- memo[paramName] = (value || "").replace(/%2F/g, "/");
99
- }
100
- return memo;
101
- }, {});
102
- return {
103
- params,
104
- pathname: matchedPathname,
105
- pathnameBase,
106
- pattern
107
- };
108
- }
109
- function compilePath(path, caseSensitive, end) {
110
- if (caseSensitive === void 0) {
111
- caseSensitive = false;
112
- }
113
- if (end === void 0) {
114
- end = true;
115
- }
116
- warning(path === "*" || !path.endsWith("*") || path.endsWith("/*"), 'Route path "' + path + '" will be treated as if it were ' + ('"' + path.replace(/\*$/, "/*") + '" because the `*` character must ') + "always follow a `/` in the pattern. To get rid of this warning, " + ('please change the route path to "' + path.replace(/\*$/, "/*") + '".'));
117
- let params = [];
118
- let regexpSource = "^" + path.replace(/\/*\*?$/, "").replace(/^\/*/, "/").replace(/[\\.*+^${}|()[\]]/g, "\\$&").replace(/\/:([\w-]+)(\?)?/g, (_, paramName, isOptional) => {
119
- params.push({
120
- paramName,
121
- isOptional: isOptional != null
122
- });
123
- return isOptional ? "/?([^\\/]+)?" : "/([^\\/]+)";
124
- });
125
- if (path.endsWith("*")) {
126
- params.push({
127
- paramName: "*"
128
- });
129
- regexpSource += path === "*" || path === "/*" ? "(.*)$" : "(?:\\/(.+)|\\/*)$";
130
- } else if (end) {
131
- regexpSource += "\\/*$";
132
- } else if (path !== "" && path !== "/") {
133
- regexpSource += "(?:(?=\\/|$))";
134
- } else ;
135
- let matcher = new RegExp(regexpSource, caseSensitive ? void 0 : "i");
136
- return [matcher, params];
137
- }
138
- function stripBasename(pathname, basename) {
139
- if (basename === "/") return pathname;
140
- if (!pathname.toLowerCase().startsWith(basename.toLowerCase())) {
141
- return null;
142
- }
143
- let startIndex = basename.endsWith("/") ? basename.length - 1 : basename.length;
144
- let nextChar = pathname.charAt(startIndex);
145
- if (nextChar && nextChar !== "/") {
146
- return null;
147
- }
148
- return pathname.slice(startIndex) || "/";
149
- }
150
- const ABSOLUTE_URL_REGEX$1 = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
151
- const isAbsoluteUrl = (url) => ABSOLUTE_URL_REGEX$1.test(url);
152
- function resolvePath(to, fromPathname) {
153
- if (fromPathname === void 0) {
154
- fromPathname = "/";
155
- }
156
- let {
157
- pathname: toPathname,
158
- search = "",
159
- hash = ""
160
- } = typeof to === "string" ? parsePath(to) : to;
161
- let pathname;
162
- if (toPathname) {
163
- if (isAbsoluteUrl(toPathname)) {
164
- pathname = toPathname;
165
- } else {
166
- if (toPathname.includes("//")) {
167
- let oldPathname = toPathname;
168
- toPathname = toPathname.replace(/\/\/+/g, "/");
169
- warning(false, "Pathnames cannot have embedded double slashes - normalizing " + (oldPathname + " -> " + toPathname));
170
- }
171
- if (toPathname.startsWith("/")) {
172
- pathname = resolvePathname(toPathname.substring(1), "/");
173
- } else {
174
- pathname = resolvePathname(toPathname, fromPathname);
175
- }
176
- }
177
- } else {
178
- pathname = fromPathname;
179
- }
180
- return {
181
- pathname,
182
- search: normalizeSearch(search),
183
- hash: normalizeHash(hash)
184
- };
185
- }
186
- function resolvePathname(relativePath, fromPathname) {
187
- let segments = fromPathname.replace(/\/+$/, "").split("/");
188
- let relativeSegments = relativePath.split("/");
189
- relativeSegments.forEach((segment) => {
190
- if (segment === "..") {
191
- if (segments.length > 1) segments.pop();
192
- } else if (segment !== ".") {
193
- segments.push(segment);
194
- }
195
- });
196
- return segments.length > 1 ? segments.join("/") : "/";
197
- }
198
- function getInvalidPathError(char, field, dest, path) {
199
- return "Cannot include a '" + char + "' character in a manually specified " + ("`to." + field + "` field [" + JSON.stringify(path) + "]. Please separate it out to the ") + ("`to." + dest + "` field. Alternatively you may provide the full path as ") + 'a string in <Link to="..."> and the router will parse it for you.';
200
- }
201
- function getPathContributingMatches(matches) {
202
- return matches.filter((match, index) => index === 0 || match.route.path && match.route.path.length > 0);
203
- }
204
- function getResolveToMatches(matches, v7_relativeSplatPath) {
205
- let pathMatches = getPathContributingMatches(matches);
206
- if (v7_relativeSplatPath) {
207
- return pathMatches.map((match, idx) => idx === pathMatches.length - 1 ? match.pathname : match.pathnameBase);
208
- }
209
- return pathMatches.map((match) => match.pathnameBase);
210
- }
211
- function resolveTo(toArg, routePathnames, locationPathname, isPathRelative) {
212
- if (isPathRelative === void 0) {
213
- isPathRelative = false;
214
- }
215
- let to;
216
- if (typeof toArg === "string") {
217
- to = parsePath(toArg);
218
- } else {
219
- to = _extends({}, toArg);
220
- invariant(!to.pathname || !to.pathname.includes("?"), getInvalidPathError("?", "pathname", "search", to));
221
- invariant(!to.pathname || !to.pathname.includes("#"), getInvalidPathError("#", "pathname", "hash", to));
222
- invariant(!to.search || !to.search.includes("#"), getInvalidPathError("#", "search", "hash", to));
223
- }
224
- let isEmptyPath = toArg === "" || to.pathname === "";
225
- let toPathname = isEmptyPath ? "/" : to.pathname;
226
- let from;
227
- if (toPathname == null) {
228
- from = locationPathname;
229
- } else {
230
- let routePathnameIndex = routePathnames.length - 1;
231
- if (!isPathRelative && toPathname.startsWith("..")) {
232
- let toSegments = toPathname.split("/");
233
- while (toSegments[0] === "..") {
234
- toSegments.shift();
235
- routePathnameIndex -= 1;
236
- }
237
- to.pathname = toSegments.join("/");
238
- }
239
- from = routePathnameIndex >= 0 ? routePathnames[routePathnameIndex] : "/";
240
- }
241
- let path = resolvePath(to, from);
242
- let hasExplicitTrailingSlash = toPathname && toPathname !== "/" && toPathname.endsWith("/");
243
- let hasCurrentTrailingSlash = (isEmptyPath || toPathname === ".") && locationPathname.endsWith("/");
244
- if (!path.pathname.endsWith("/") && (hasExplicitTrailingSlash || hasCurrentTrailingSlash)) {
245
- path.pathname += "/";
246
- }
247
- return path;
248
- }
249
- const joinPaths = (paths) => paths.join("/").replace(/\/\/+/g, "/");
250
- const normalizeSearch = (search) => !search || search === "?" ? "" : search.startsWith("?") ? search : "?" + search;
251
- const normalizeHash = (hash) => !hash || hash === "#" ? "" : hash.startsWith("#") ? hash : "#" + hash;
252
- class AbortedDeferredError extends Error {
253
- }
254
- const validMutationMethodsArr = ["post", "put", "patch", "delete"];
255
- new Set(validMutationMethodsArr);
256
- const validRequestMethodsArr = ["get", ...validMutationMethodsArr];
257
- new Set(validRequestMethodsArr);
258
- export {
259
- AbortedDeferredError,
260
- Action,
261
- getResolveToMatches as UNSAFE_getResolveToMatches,
262
- invariant as UNSAFE_invariant,
263
- warning as UNSAFE_warning,
264
- createPath,
265
- joinPaths,
266
- matchPath,
267
- parsePath,
268
- resolvePath,
269
- resolveTo,
270
- stripBasename
271
- };
272
- //# sourceMappingURL=router.js.map