@itaptec/datagrid 0.0.1-beta.8
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/README.md +29 -0
- package/dist/index.d.mts +104 -0
- package/dist/index.d.ts +104 -0
- package/dist/index.js +507 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +501 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +74 -0
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# README #
|
|
2
|
+
|
|
3
|
+
This README would normally document whatever steps are necessary to get your application up and running.
|
|
4
|
+
|
|
5
|
+
### What is this repository for? ###
|
|
6
|
+
|
|
7
|
+
* Quick summary
|
|
8
|
+
* Version
|
|
9
|
+
* [Learn Markdown](https://bitbucket.org/tutorials/markdowndemo)
|
|
10
|
+
|
|
11
|
+
### How do I get set up? ###
|
|
12
|
+
|
|
13
|
+
* Summary of set up
|
|
14
|
+
* Configuration
|
|
15
|
+
* Dependencies
|
|
16
|
+
* Database configuration
|
|
17
|
+
* How to run tests
|
|
18
|
+
* Deployment instructions
|
|
19
|
+
|
|
20
|
+
### Contribution guidelines ###
|
|
21
|
+
|
|
22
|
+
* Writing tests
|
|
23
|
+
* Code review
|
|
24
|
+
* Other guidelines
|
|
25
|
+
|
|
26
|
+
### Who do I talk to? ###
|
|
27
|
+
|
|
28
|
+
* Repo owner or admin
|
|
29
|
+
* Other community or team contact
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { GridValidRowModel, DataGridProps, GridActionsColDef, GridRowIdGetter } from '@mui/x-data-grid';
|
|
2
|
+
import { FieldValues, Path, UseFormReturn } from 'react-hook-form';
|
|
3
|
+
import { GridBaseColDef } from '@mui/x-data-grid/internals';
|
|
4
|
+
import { SelectProps, SelectionOption, MultiselectProps, ControlledDateRangePickerProps, TextFieldProps, ToggleButtonGroup, ToggleButtonGroupMultiple } from '@itaptec/form_components';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { UseQueryResult } from '@tanstack/react-query';
|
|
7
|
+
import { EntityListWithPagination, PaginationRequest } from '@itaptec/http_client';
|
|
8
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* MUI's DataGrid props that the user shouldn't see, as they are internally handled.
|
|
12
|
+
*/
|
|
13
|
+
type UnionOfDataGridPropsToOmit = keyof Pick<DataGridProps, "pagination" | "paginationMode" | "paginationModel" | "onPaginationModelChange" | "filterMode" | "filterModel" | "sortingMode" | "sortingOrder" | "rows" | "checkboxSelection" | "getRowId" | "rowSelectionModel" | "onRowSelectionModelChange">;
|
|
14
|
+
/**
|
|
15
|
+
* MUI's DataGrid props without the ones to omit.
|
|
16
|
+
*/
|
|
17
|
+
type DataGridPropsWithOmmited<TEntity extends GridValidRowModel> = Omit<DataGridProps<TEntity>, UnionOfDataGridPropsToOmit>;
|
|
18
|
+
/**
|
|
19
|
+
* ItecDataGrid columns definition.
|
|
20
|
+
*/
|
|
21
|
+
type ItecGridColsDef<TEntity extends GridValidRowModel> = (Omit<GridBaseColDef<TEntity>, "field"> & {
|
|
22
|
+
field: keyof TEntity | string;
|
|
23
|
+
}) | (Omit<GridActionsColDef<TEntity>, "field"> & {
|
|
24
|
+
field: keyof TEntity | string;
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* ItecDataGrid column's filter parameters.
|
|
28
|
+
*/
|
|
29
|
+
type ItecColFilters<TFilter extends FieldValues> = Record<string, // TODO: este tipo debería ser inferido de los posibles nombres de columnas.
|
|
30
|
+
ItecColFilterParams<TFilter>>;
|
|
31
|
+
type ItecColFilterParams<TFilter extends FieldValues> = {
|
|
32
|
+
name: Path<TFilter>;
|
|
33
|
+
} & ({
|
|
34
|
+
type: "select";
|
|
35
|
+
props: Omit<SelectProps<SelectionOption, TFilter>, "name" | "control">;
|
|
36
|
+
} | {
|
|
37
|
+
type: "multiselect";
|
|
38
|
+
props: Omit<MultiselectProps<SelectionOption, TFilter>, "name" | "control">;
|
|
39
|
+
} | {
|
|
40
|
+
type: "date-range";
|
|
41
|
+
props: Omit<ControlledDateRangePickerProps<TFilter>, "name" | "control">;
|
|
42
|
+
} | {
|
|
43
|
+
type: "text";
|
|
44
|
+
props: Omit<TextFieldProps<TFilter>, "name" | "control">;
|
|
45
|
+
} | {
|
|
46
|
+
type: "button-group";
|
|
47
|
+
props: Omit<React.ComponentProps<typeof ToggleButtonGroup>, "name" | "control">;
|
|
48
|
+
} | {
|
|
49
|
+
type: "multiple-button-group";
|
|
50
|
+
props: Omit<React.ComponentProps<typeof ToggleButtonGroupMultiple>, "name" | "control">;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
type UseItecDataGridProps<TEntity extends GridValidRowModel, TFilter extends FieldValues> = (DataGridPropsWithOmmited<TEntity> & {
|
|
54
|
+
columns: ItecGridColsDef<TEntity>[];
|
|
55
|
+
filters?: ItecColFilters<TFilter>;
|
|
56
|
+
pagination: false;
|
|
57
|
+
getEntities: (filter?: Partial<TFilter>) => Promise<TEntity[]>;
|
|
58
|
+
}) & ({
|
|
59
|
+
checkboxSelection: true;
|
|
60
|
+
getRowId: GridRowIdGetter<TEntity>;
|
|
61
|
+
} | {
|
|
62
|
+
checkboxSelection?: false;
|
|
63
|
+
getRowId?: never;
|
|
64
|
+
});
|
|
65
|
+
type UseItecDataGrid<TEntity extends GridValidRowModel, TFilter extends FieldValues> = {
|
|
66
|
+
datagridProps: DataGridProps<TEntity>;
|
|
67
|
+
control: {
|
|
68
|
+
query: UseQueryResult<TEntity[]>;
|
|
69
|
+
form: UseFormReturn<TFilter> | undefined;
|
|
70
|
+
selectedRows: TEntity[] | undefined;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Props to pass to the ItecDataGrid or useItecDataGrid for a paginated DataGrid.
|
|
76
|
+
*/
|
|
77
|
+
type UseItecDataGridPaginatedProps<TEntity extends GridValidRowModel, TFilter extends FieldValues> = (DataGridPropsWithOmmited<TEntity> & {
|
|
78
|
+
columns: ItecGridColsDef<TEntity>[];
|
|
79
|
+
filters?: ItecColFilters<TFilter>;
|
|
80
|
+
pagination: true;
|
|
81
|
+
getEntitiesPaginated: (pagination: PaginationRequest, filter?: Partial<TFilter>) => Promise<EntityListWithPagination<TEntity>>;
|
|
82
|
+
}) & ({
|
|
83
|
+
checkboxSelection: true;
|
|
84
|
+
getRowId: GridRowIdGetter<TEntity>;
|
|
85
|
+
} | {
|
|
86
|
+
checkboxSelection?: false;
|
|
87
|
+
getRowId?: never;
|
|
88
|
+
});
|
|
89
|
+
type UseItecDataGridPaginated<TEntity extends GridValidRowModel, TFilter extends FieldValues> = {
|
|
90
|
+
datagridProps: DataGridProps<TEntity>;
|
|
91
|
+
control: {
|
|
92
|
+
query: UseQueryResult<EntityListWithPagination<TEntity>>;
|
|
93
|
+
form: UseFormReturn<TFilter> | undefined;
|
|
94
|
+
selectedRows: TEntity[] | undefined;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
declare function useItecDataGrid<TEntity extends GridValidRowModel, TFilter extends FieldValues = {}>(props: UseItecDataGridPaginatedProps<TEntity, TFilter>): UseItecDataGrid<TEntity, TFilter>;
|
|
99
|
+
declare function useItecDataGrid<TEntity extends GridValidRowModel, TFilter extends FieldValues = {}>(props: UseItecDataGridProps<TEntity, TFilter>): UseItecDataGridPaginated<TEntity, TFilter>;
|
|
100
|
+
|
|
101
|
+
type ItecDataGridProps<TEntity extends GridValidRowModel> = Omit<DataGridProps<TEntity>, "paginationMode" | "filterMode">;
|
|
102
|
+
declare function ItecDataGrid<TEntity extends GridValidRowModel>(props: ItecDataGridProps<TEntity>): react_jsx_runtime.JSX.Element;
|
|
103
|
+
|
|
104
|
+
export { type DataGridPropsWithOmmited, type ItecColFilterParams, type ItecColFilters, ItecDataGrid, type ItecDataGridProps, type ItecGridColsDef, type UseItecDataGrid, type UseItecDataGridPaginated, type UseItecDataGridPaginatedProps, type UseItecDataGridProps, useItecDataGrid };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { GridValidRowModel, DataGridProps, GridActionsColDef, GridRowIdGetter } from '@mui/x-data-grid';
|
|
2
|
+
import { FieldValues, Path, UseFormReturn } from 'react-hook-form';
|
|
3
|
+
import { GridBaseColDef } from '@mui/x-data-grid/internals';
|
|
4
|
+
import { SelectProps, SelectionOption, MultiselectProps, ControlledDateRangePickerProps, TextFieldProps, ToggleButtonGroup, ToggleButtonGroupMultiple } from '@itaptec/form_components';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { UseQueryResult } from '@tanstack/react-query';
|
|
7
|
+
import { EntityListWithPagination, PaginationRequest } from '@itaptec/http_client';
|
|
8
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* MUI's DataGrid props that the user shouldn't see, as they are internally handled.
|
|
12
|
+
*/
|
|
13
|
+
type UnionOfDataGridPropsToOmit = keyof Pick<DataGridProps, "pagination" | "paginationMode" | "paginationModel" | "onPaginationModelChange" | "filterMode" | "filterModel" | "sortingMode" | "sortingOrder" | "rows" | "checkboxSelection" | "getRowId" | "rowSelectionModel" | "onRowSelectionModelChange">;
|
|
14
|
+
/**
|
|
15
|
+
* MUI's DataGrid props without the ones to omit.
|
|
16
|
+
*/
|
|
17
|
+
type DataGridPropsWithOmmited<TEntity extends GridValidRowModel> = Omit<DataGridProps<TEntity>, UnionOfDataGridPropsToOmit>;
|
|
18
|
+
/**
|
|
19
|
+
* ItecDataGrid columns definition.
|
|
20
|
+
*/
|
|
21
|
+
type ItecGridColsDef<TEntity extends GridValidRowModel> = (Omit<GridBaseColDef<TEntity>, "field"> & {
|
|
22
|
+
field: keyof TEntity | string;
|
|
23
|
+
}) | (Omit<GridActionsColDef<TEntity>, "field"> & {
|
|
24
|
+
field: keyof TEntity | string;
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* ItecDataGrid column's filter parameters.
|
|
28
|
+
*/
|
|
29
|
+
type ItecColFilters<TFilter extends FieldValues> = Record<string, // TODO: este tipo debería ser inferido de los posibles nombres de columnas.
|
|
30
|
+
ItecColFilterParams<TFilter>>;
|
|
31
|
+
type ItecColFilterParams<TFilter extends FieldValues> = {
|
|
32
|
+
name: Path<TFilter>;
|
|
33
|
+
} & ({
|
|
34
|
+
type: "select";
|
|
35
|
+
props: Omit<SelectProps<SelectionOption, TFilter>, "name" | "control">;
|
|
36
|
+
} | {
|
|
37
|
+
type: "multiselect";
|
|
38
|
+
props: Omit<MultiselectProps<SelectionOption, TFilter>, "name" | "control">;
|
|
39
|
+
} | {
|
|
40
|
+
type: "date-range";
|
|
41
|
+
props: Omit<ControlledDateRangePickerProps<TFilter>, "name" | "control">;
|
|
42
|
+
} | {
|
|
43
|
+
type: "text";
|
|
44
|
+
props: Omit<TextFieldProps<TFilter>, "name" | "control">;
|
|
45
|
+
} | {
|
|
46
|
+
type: "button-group";
|
|
47
|
+
props: Omit<React.ComponentProps<typeof ToggleButtonGroup>, "name" | "control">;
|
|
48
|
+
} | {
|
|
49
|
+
type: "multiple-button-group";
|
|
50
|
+
props: Omit<React.ComponentProps<typeof ToggleButtonGroupMultiple>, "name" | "control">;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
type UseItecDataGridProps<TEntity extends GridValidRowModel, TFilter extends FieldValues> = (DataGridPropsWithOmmited<TEntity> & {
|
|
54
|
+
columns: ItecGridColsDef<TEntity>[];
|
|
55
|
+
filters?: ItecColFilters<TFilter>;
|
|
56
|
+
pagination: false;
|
|
57
|
+
getEntities: (filter?: Partial<TFilter>) => Promise<TEntity[]>;
|
|
58
|
+
}) & ({
|
|
59
|
+
checkboxSelection: true;
|
|
60
|
+
getRowId: GridRowIdGetter<TEntity>;
|
|
61
|
+
} | {
|
|
62
|
+
checkboxSelection?: false;
|
|
63
|
+
getRowId?: never;
|
|
64
|
+
});
|
|
65
|
+
type UseItecDataGrid<TEntity extends GridValidRowModel, TFilter extends FieldValues> = {
|
|
66
|
+
datagridProps: DataGridProps<TEntity>;
|
|
67
|
+
control: {
|
|
68
|
+
query: UseQueryResult<TEntity[]>;
|
|
69
|
+
form: UseFormReturn<TFilter> | undefined;
|
|
70
|
+
selectedRows: TEntity[] | undefined;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Props to pass to the ItecDataGrid or useItecDataGrid for a paginated DataGrid.
|
|
76
|
+
*/
|
|
77
|
+
type UseItecDataGridPaginatedProps<TEntity extends GridValidRowModel, TFilter extends FieldValues> = (DataGridPropsWithOmmited<TEntity> & {
|
|
78
|
+
columns: ItecGridColsDef<TEntity>[];
|
|
79
|
+
filters?: ItecColFilters<TFilter>;
|
|
80
|
+
pagination: true;
|
|
81
|
+
getEntitiesPaginated: (pagination: PaginationRequest, filter?: Partial<TFilter>) => Promise<EntityListWithPagination<TEntity>>;
|
|
82
|
+
}) & ({
|
|
83
|
+
checkboxSelection: true;
|
|
84
|
+
getRowId: GridRowIdGetter<TEntity>;
|
|
85
|
+
} | {
|
|
86
|
+
checkboxSelection?: false;
|
|
87
|
+
getRowId?: never;
|
|
88
|
+
});
|
|
89
|
+
type UseItecDataGridPaginated<TEntity extends GridValidRowModel, TFilter extends FieldValues> = {
|
|
90
|
+
datagridProps: DataGridProps<TEntity>;
|
|
91
|
+
control: {
|
|
92
|
+
query: UseQueryResult<EntityListWithPagination<TEntity>>;
|
|
93
|
+
form: UseFormReturn<TFilter> | undefined;
|
|
94
|
+
selectedRows: TEntity[] | undefined;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
declare function useItecDataGrid<TEntity extends GridValidRowModel, TFilter extends FieldValues = {}>(props: UseItecDataGridPaginatedProps<TEntity, TFilter>): UseItecDataGrid<TEntity, TFilter>;
|
|
99
|
+
declare function useItecDataGrid<TEntity extends GridValidRowModel, TFilter extends FieldValues = {}>(props: UseItecDataGridProps<TEntity, TFilter>): UseItecDataGridPaginated<TEntity, TFilter>;
|
|
100
|
+
|
|
101
|
+
type ItecDataGridProps<TEntity extends GridValidRowModel> = Omit<DataGridProps<TEntity>, "paginationMode" | "filterMode">;
|
|
102
|
+
declare function ItecDataGrid<TEntity extends GridValidRowModel>(props: ItecDataGridProps<TEntity>): react_jsx_runtime.JSX.Element;
|
|
103
|
+
|
|
104
|
+
export { type DataGridPropsWithOmmited, type ItecColFilterParams, type ItecColFilters, ItecDataGrid, type ItecDataGridProps, type ItecGridColsDef, type UseItecDataGrid, type UseItecDataGridPaginated, type UseItecDataGridPaginatedProps, type UseItecDataGridProps, useItecDataGrid };
|