drf-react-by-schema 0.3.0 → 0.3.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 (83) hide show
  1. package/dist/api.d.ts +84 -0
  2. package/dist/api.js +613 -0
  3. package/dist/components/DataGridBySchemaEditable/ConfirmDialog.d.ts +8 -0
  4. package/dist/components/DataGridBySchemaEditable/ConfirmDialog.js +21 -0
  5. package/dist/components/DataGridBySchemaEditable/CustomToolbar.d.ts +16 -0
  6. package/dist/components/DataGridBySchemaEditable/CustomToolbar.js +77 -0
  7. package/dist/components/DataGridBySchemaEditable/FooterToolbar.d.ts +16 -0
  8. package/dist/components/DataGridBySchemaEditable/FooterToolbar.js +41 -0
  9. package/dist/components/DataGridBySchemaEditable/GridDecimalInput.d.ts +8 -0
  10. package/dist/components/DataGridBySchemaEditable/GridDecimalInput.js +32 -0
  11. package/dist/components/DataGridBySchemaEditable/GridPatternInput.d.ts +8 -0
  12. package/dist/components/DataGridBySchemaEditable/GridPatternInput.js +30 -0
  13. package/dist/components/DataGridBySchemaEditable/InputInterval.d.ts +3 -0
  14. package/dist/components/DataGridBySchemaEditable/InputInterval.js +105 -0
  15. package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.d.ts +33 -0
  16. package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.js +140 -0
  17. package/dist/components/DataGridBySchemaEditable/utils.d.ts +15 -0
  18. package/{src/components/DataGridBySchemaEditable/utils.ts → dist/components/DataGridBySchemaEditable/utils.js} +32 -50
  19. package/dist/components/DataGridBySchemaEditable.d.ts +34 -0
  20. package/dist/components/DataGridBySchemaEditable.js +549 -0
  21. package/dist/components/DataTotals.d.ts +14 -0
  22. package/dist/components/DataTotals.js +23 -0
  23. package/dist/components/DialogActions.d.ts +10 -0
  24. package/dist/components/DialogActions.js +17 -0
  25. package/dist/components/DialogJSONSchemaForm.d.ts +12 -0
  26. package/dist/components/DialogJSONSchemaForm.js +20 -0
  27. package/dist/components/FormButtons.d.ts +14 -0
  28. package/dist/components/FormButtons.js +39 -0
  29. package/dist/components/GenericModelList.d.ts +19 -0
  30. package/dist/components/GenericModelList.js +113 -0
  31. package/dist/components/GenericRelatedModelList.d.ts +25 -0
  32. package/dist/components/GenericRelatedModelList.js +111 -0
  33. package/dist/components/TextFieldBySchema.js +39 -0
  34. package/dist/context/APIWrapper.d.ts +12 -0
  35. package/dist/context/APIWrapper.js +341 -0
  36. package/{src/context/APIWrapperContext.tsx → dist/context/APIWrapperContext.d.ts} +22 -31
  37. package/dist/context/APIWrapperContext.js +15 -0
  38. package/{src/context/DRFReactBySchemaContext.tsx → dist/context/DRFReactBySchemaContext.d.ts} +4 -17
  39. package/dist/context/DRFReactBySchemaContext.js +19 -0
  40. package/dist/context/DRFReactBySchemaProvider.d.ts +13 -0
  41. package/dist/context/DRFReactBySchemaProvider.js +53 -0
  42. package/dist/context/Form.d.ts +11 -0
  43. package/dist/context/Form.js +82 -0
  44. package/dist/context/Overlays.d.ts +4 -0
  45. package/dist/context/Overlays.js +87 -0
  46. package/dist/index.d.ts +11 -0
  47. package/{src/styles/index.ts → dist/styles/index.d.ts} +0 -1
  48. package/dist/styles/index.js +28 -0
  49. package/dist/styles/layout.d.ts +107 -0
  50. package/dist/styles/layout.js +56 -0
  51. package/dist/styles/theme.d.ts +21 -0
  52. package/dist/styles/theme.js +139 -0
  53. package/dist/utils.d.ts +75 -0
  54. package/dist/utils.js +268 -0
  55. package/package.json +11 -2
  56. package/.eslintrc.js +0 -14
  57. package/.gitlab-ci.yml +0 -14
  58. package/src/api.ts +0 -727
  59. package/src/components/DataGridBySchemaEditable/ConfirmDialog.tsx +0 -41
  60. package/src/components/DataGridBySchemaEditable/CustomToolbar.tsx +0 -93
  61. package/src/components/DataGridBySchemaEditable/FooterToolbar.tsx +0 -77
  62. package/src/components/DataGridBySchemaEditable/GridDecimalInput.tsx +0 -41
  63. package/src/components/DataGridBySchemaEditable/GridPatternInput.tsx +0 -37
  64. package/src/components/DataGridBySchemaEditable/InputInterval.tsx +0 -194
  65. package/src/components/DataGridBySchemaEditable/SelectEditInputCell.tsx +0 -154
  66. package/src/components/DataGridBySchemaEditable.md +0 -50
  67. package/src/components/DataGridBySchemaEditable.tsx +0 -758
  68. package/src/components/DataTotals.tsx +0 -57
  69. package/src/components/DialogActions.tsx +0 -33
  70. package/src/components/DialogJSONSchemaForm.tsx +0 -40
  71. package/src/components/GenericModelList.tsx +0 -165
  72. package/src/components/GenericRelatedModelList.tsx +0 -168
  73. package/src/context/APIWrapper.tsx +0 -447
  74. package/src/context/DRFReactBySchemaProvider.md +0 -57
  75. package/src/context/DRFReactBySchemaProvider.tsx +0 -72
  76. package/src/context/Overlays.tsx +0 -94
  77. package/src/index.ts +0 -77
  78. package/src/styles/layout.ts +0 -104
  79. package/src/styles/theme.ts +0 -190
  80. package/src/utils.ts +0 -327
  81. package/styleguide.config.js +0 -13
  82. package/tsconfig.json +0 -104
  83. package/webpack.config.js +0 -24
@@ -1,57 +0,0 @@
1
- import React from 'react';
2
- import Alert, { AlertColor } from '@mui/material/Alert';
3
- import List from '@mui/material/List';
4
- import ListItem from '@mui/material/ListItem';
5
- import { NumericFormat } from 'react-number-format';
6
- import { GridRowId } from '@mui/x-data-grid';
7
-
8
- import { Item } from '../utils';
9
-
10
- export interface SumRowsType {
11
- rows: Item[],
12
- severity?: AlertColor;
13
- }
14
-
15
- interface DataTotalsProps {
16
- data?: Item[];
17
- sumRows?: SumRowsType;
18
- visibleRows: GridRowId[];
19
- };
20
-
21
- const DataTotals = ({
22
- data,
23
- sumRows,
24
- visibleRows
25
- }: DataTotalsProps) => {
26
- return (
27
- <>
28
- {data && sumRows && sumRows.rows.length > 0 &&
29
- <Alert severity={sumRows.severity || 'info'}>
30
- <List dense={true}>
31
- {sumRows.rows.map(row => (
32
- <ListItem key={`sumRows_${row.field}`}>
33
- <NumericFormat
34
- value={data.reduce((total, item) => {
35
- if (parseFloat(item[row.field]) && visibleRows.includes(`${item.id}`)) {
36
- return total + parseFloat(item[row.field]);
37
- }
38
- return total;
39
- }, 0)}
40
- thousandSeparator='.'
41
- decimalSeparator=','
42
- displayType={'text'}
43
- decimalScale={row.isCount ? 0 : 2}
44
- fixedDecimalScale={true}
45
- prefix={row.prefix}
46
- suffix={row.suffix}
47
- />
48
- </ListItem>
49
- ))}
50
- </List>
51
- </Alert>
52
- }
53
- </>
54
- );
55
- };
56
-
57
- export default DataTotals;
@@ -1,33 +0,0 @@
1
- import React from 'react';
2
- import Button from '@mui/material/Button';
3
- import { DialogType } from '../context/APIWrapperContext';
4
-
5
- interface DialogActionsProps {
6
- setDialog: React.Dispatch<React.SetStateAction<DialogType>>;
7
- handleSave: (p: any) => Promise<boolean | undefined>;
8
- btnCancel?: string;
9
- btnConfirm?: string;
10
- };
11
- export default function DialogActions ({
12
- setDialog,
13
- handleSave,
14
- btnCancel = 'Cancelar',
15
- btnConfirm = 'Salvar'
16
- }: DialogActionsProps) {
17
- return (
18
- <>
19
- <Button
20
- onClick={() => {
21
- setDialog({ open: false });
22
- }}
23
- >
24
- {btnCancel}
25
- </Button>
26
- <Button
27
- onClick={handleSave}
28
- >
29
- {btnConfirm}
30
- </Button>
31
- </>
32
- );
33
- };
@@ -1,40 +0,0 @@
1
- import React from 'react';
2
- import Button from '@mui/material/Button';
3
- import validator from '@rjsf/validator-ajv8';
4
- import Form from '@rjsf/mui';
5
- import { Item, SchemaType } from '../utils';
6
-
7
- interface DialogJSONSchemaFormProps {
8
- jsonSchemaFormRef: any;
9
- schema: SchemaType;
10
- uiSchema: SchemaType;
11
- formData: Item;
12
- onSubmit: ({ formData }:{ formData: Item }) => void;
13
- };
14
-
15
- export default function DialogJSONSchemaForm ({
16
- jsonSchemaFormRef,
17
- schema,
18
- uiSchema,
19
- formData,
20
- onSubmit
21
- }:DialogJSONSchemaFormProps) {
22
- return (
23
- <Form
24
- // @ts-ignore
25
- ref={jsonSchemaFormRef}
26
- schema={schema}
27
- uiSchema={uiSchema}
28
- validator={validator}
29
- formData={formData}
30
- onSubmit={onSubmit}
31
- >
32
- <Button
33
- type="submit"
34
- sx={{ display: 'none' }}
35
- >
36
- Salvar
37
- </Button>
38
- </Form>
39
- );
40
- };
@@ -1,165 +0,0 @@
1
- import React, { useState, useEffect } from 'react';
2
- import Box from '@mui/material/Box';
3
- import { GridRowId } from '@mui/x-data-grid';
4
-
5
- import DataGridBySchemaEditable from './DataGridBySchemaEditable';
6
- import DataTotals, { SumRowsType } from './DataTotals';
7
- import { Layout } from '../styles';
8
- import { GridEnrichedBySchemaColDef, Item, SchemaType, DataSchemaColumnsType } from '../utils';
9
- import { getGenericModelList, getGenericModelListProps } from '../api';
10
- import { DRFReactBySchemaContext } from '../context/DRFReactBySchemaContext';
11
- import { APIWrapperContext } from '../context/APIWrapperContext';
12
-
13
- interface GenericModelListProps {
14
- columnFields: string[];
15
- hiddenFields?: string[];
16
- minWidthFields?: Record<string, number>;
17
- indexFieldBasePath: string;
18
- indexField: string;
19
- customColumnOperations?: (column: GridEnrichedBySchemaColDef) => GridEnrichedBySchemaColDef;
20
- customLinkDestination?: (p: any) => string;
21
- sumRows?: SumRowsType;
22
- isAutoHeight?: boolean;
23
- model: string;
24
- forceReload: boolean;
25
- LinkComponent?: React.ReactNode;
26
- }
27
-
28
- const GenericModelList = ({
29
- columnFields,
30
- hiddenFields = [],
31
- minWidthFields,
32
- indexFieldBasePath,
33
- indexField,
34
- customColumnOperations,
35
- customLinkDestination,
36
- sumRows,
37
- isAutoHeight = true,
38
- model,
39
- forceReload = false,
40
- LinkComponent = null
41
- }: GenericModelListProps) => {
42
- const context = React.useContext(DRFReactBySchemaContext);
43
- const apiContext = React.useContext(APIWrapperContext);
44
- if (!context.serverEndPoint || !apiContext) {
45
- console.error('Error: There is no endpoint defined in DRFReactBySchemaProvider!');
46
- return (<></>);
47
- }
48
- const {
49
- serverEndPoint,
50
- isInBatches,
51
- firstBatchLength
52
- } = context;
53
- const {
54
- handleLoading
55
- } = apiContext;
56
- interface dataProps {
57
- data: Item[];
58
- schema: SchemaType;
59
- columns: GridEnrichedBySchemaColDef[]
60
- };
61
- const [data, setData] = useState<DataSchemaColumnsType | boolean>(false);
62
- const [visibleRows, setVisibleRows] = useState<GridRowId[]>([]);
63
- const [hideFooterPagination, setHideFooterPagination] = useState(false);
64
-
65
- const finalCustomColumnOperations = (column: GridEnrichedBySchemaColDef) => {
66
- if (minWidthFields) {
67
- if (Object.prototype.hasOwnProperty.call(minWidthFields, column.field)) {
68
- column.minWidth = minWidthFields[column.field];
69
- }
70
- }
71
-
72
- if (customColumnOperations) {
73
- return customColumnOperations(column);
74
- }
75
-
76
- return column;
77
- };
78
-
79
- const loadObjectList = async () => {
80
- const loadParams:getGenericModelListProps = {
81
- model,
82
- serverEndPoint,
83
- columnFields,
84
- hiddenFields,
85
- isInBatches
86
- };
87
- handleLoading(true);
88
- const loadedData = await getGenericModelList(loadParams);
89
- if (loadedData && typeof loadedData !== 'boolean') {
90
- setData(loadedData);
91
- handleLoading(false);
92
- if (isInBatches && loadedData.data.length === firstBatchLength) {
93
- setHideFooterPagination(true);
94
- getGenericModelList({
95
- ...loadParams,
96
- loadedSchema: loadedData.schema
97
- }).then(lastBatchData => {
98
- if (lastBatchData && typeof lastBatchData !== 'boolean') {
99
- setData({
100
- ...loadedData,
101
- data: [
102
- ...loadedData.data,
103
- ...lastBatchData.data
104
- ]
105
- });
106
- }
107
- setHideFooterPagination(false);
108
- });
109
- }
110
- return;
111
- }
112
- console.log('error retrieving data!');
113
- };
114
-
115
- if (forceReload) {
116
- loadObjectList();
117
- }
118
-
119
- useEffect(() => {
120
- loadObjectList();
121
- }, []);
122
-
123
- return (
124
- <>
125
- {typeof data !== 'boolean' && data.columns &&
126
- <>
127
- <Box sx={Layout.dataGridWithTabs}>
128
- <DataGridBySchemaEditable
129
- data={data.data}
130
- columns={data.columns}
131
- schema={data.schema || {}}
132
- model={model}
133
- indexField={indexField}
134
- indexFieldBasePath={indexFieldBasePath}
135
- isEditable={false}
136
- isAutoHeight={isAutoHeight}
137
- hideFooterPagination={hideFooterPagination}
138
- customColumnOperations={finalCustomColumnOperations}
139
- customLinkDestination={customLinkDestination}
140
- setVisibleRows={(newVisibleRows:GridRowId[]) => {
141
- if (JSON.stringify(newVisibleRows) !== JSON.stringify(visibleRows)) {
142
- setVisibleRows(newVisibleRows);
143
- }
144
- }}
145
- onDataChange={newData => {
146
- setData({
147
- ...data,
148
- data: newData
149
- });
150
- }}
151
- LinkComponent={LinkComponent}
152
- />
153
- </Box>
154
- <DataTotals
155
- data={data.data}
156
- sumRows={sumRows}
157
- visibleRows={visibleRows}
158
- />
159
- </>
160
- }
161
- </>
162
- );
163
- };
164
-
165
- export default GenericModelList;
@@ -1,168 +0,0 @@
1
- import React, { useState, useEffect } from 'react';
2
- import Box from '@mui/material/Box';
3
- import { GridRowId } from '@mui/x-data-grid';
4
-
5
- import DataGridBySchemaEditable from './DataGridBySchemaEditable';
6
- import DataTotals from './DataTotals';
7
- import { DRFReactBySchemaContext } from '../context/DRFReactBySchemaContext';
8
- import { APIWrapperContext } from '../context/APIWrapperContext';
9
- import { DataSchemaColumnsType, GridEnrichedBySchemaColDef, Id, Item } from '../utils';
10
- import { getGenericModelList } from '../api';
11
- import { SumRowsType } from './DataTotals';
12
- import { Layout } from '../styles';
13
-
14
- interface GenericRelatedModelListProps {
15
- model: string;
16
- id: Id;
17
- relatedModel: string;
18
- columnFields: string[];
19
- creatableFields: string[];
20
- hiddenFields: string[];
21
- usuaria?: Item | null;
22
- minWidthFields?: Record<string, number>;
23
- indexField?: string;
24
- addExistingModel?: string;
25
- onProcessRow?: (p: any) => void;
26
- sumRows?: SumRowsType;
27
- customColumnOperations?: (column: GridEnrichedBySchemaColDef) => GridEnrichedBySchemaColDef;
28
- isEditable?: boolean;
29
- isAutoHeight?: boolean;
30
- isInBatches?: boolean;
31
- indexFieldBasePath?: string;
32
- LinkComponent?: React.ReactNode;
33
- };
34
-
35
- export default function GenericRelatedModelList ({
36
- model,
37
- id,
38
- relatedModel,
39
- columnFields,
40
- creatableFields,
41
- hiddenFields,
42
- usuaria,
43
- minWidthFields,
44
- indexField = '',
45
- addExistingModel = '',
46
- onProcessRow,
47
- sumRows,
48
- customColumnOperations,
49
- isEditable = true,
50
- isAutoHeight = false,
51
- indexFieldBasePath,
52
- LinkComponent
53
- }:GenericRelatedModelListProps) {
54
- const context = React.useContext(DRFReactBySchemaContext);
55
- const apiContext = React.useContext(APIWrapperContext);
56
- if (!context.serverEndPoint || !apiContext) {
57
- console.error('Error: There is no endpoint defined in DRFReactBySchemaProvider!');
58
- return (<></>);
59
- }
60
- const {
61
- serverEndPoint,
62
- isInBatches,
63
- firstBatchLength,
64
- } = context;
65
- const {
66
- onEditRelatedModelSave,
67
- onDeleteRelatedModel
68
- } = apiContext;
69
-
70
- const [data, setData] = useState<DataSchemaColumnsType | boolean>(false);
71
- const [visibleRows, setVisibleRows] = useState<GridRowId[]>([]);
72
- const [hideFooterPagination, setHideFooterPagination] = useState(false);
73
-
74
- const finalCustomColumnOperations = (column:GridEnrichedBySchemaColDef) => {
75
- if (minWidthFields) {
76
- if (Object.prototype.hasOwnProperty.call(minWidthFields, column.field)) {
77
- column.minWidth = minWidthFields[column.field];
78
- }
79
- }
80
-
81
- if (customColumnOperations) {
82
- return customColumnOperations(column);
83
- }
84
-
85
- return column;
86
- };
87
-
88
- const loadObjectList = async () => {
89
- const loadParams = {
90
- model,
91
- serverEndPoint,
92
- id,
93
- relatedModel,
94
- columnFields,
95
- hiddenFields,
96
- creatableFields,
97
- isInBatches
98
- };
99
- const loadedData = await getGenericModelList(loadParams);
100
- if (loadedData) {
101
- setData(loadedData);
102
- if (isInBatches && loadedData.data.length === firstBatchLength) {
103
- setHideFooterPagination(true);
104
- getGenericModelList({
105
- ...loadParams,
106
- loadedSchema: loadedData.schema
107
- }).then(lastBatchData => {
108
- if (lastBatchData) {
109
- setData({
110
- ...loadedData,
111
- data: [
112
- ...loadedData.data,
113
- ...lastBatchData.data
114
- ]
115
- });
116
- }
117
- setHideFooterPagination(false);
118
- });
119
- }
120
- return;
121
- }
122
- console.log('error retrieving data!');
123
- };
124
-
125
- useEffect(() => {
126
- loadObjectList();
127
- }, []);
128
-
129
- return (
130
- <>
131
- {typeof data !== 'boolean' && data.columns &&
132
- <>
133
- <Box sx={Layout.dataGridFixedHeight}>
134
- <DataGridBySchemaEditable
135
- data={data.data}
136
- columns={data.columns}
137
- schema={data.schema}
138
- model={relatedModel}
139
- indexField={indexField}
140
- indexFieldBasePath={indexFieldBasePath}
141
- addExistingModel={addExistingModel}
142
- isEditable={isEditable}
143
- modelParent={model}
144
- modelParentId={id}
145
- customColumnOperations={finalCustomColumnOperations}
146
- setVisibleRows={setVisibleRows}
147
- isAutoHeight={isAutoHeight}
148
- hideFooterPagination={hideFooterPagination}
149
- onProcessRow={onProcessRow}
150
- onDataChange={newData => {
151
- setData({
152
- ...data,
153
- data: newData
154
- });
155
- }}
156
- LinkComponent={LinkComponent}
157
- />
158
- </Box>
159
- <DataTotals
160
- data={data.data}
161
- sumRows={sumRows}
162
- visibleRows={visibleRows}
163
- />
164
- </>
165
- }
166
- </>
167
- );
168
- }