drf-react-by-schema 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/dist/api.d.ts +83 -0
  2. package/dist/api.js +613 -0
  3. package/dist/components/DataGridBySchemaEditable/BooleanInputCell.d.ts +24 -0
  4. package/dist/components/DataGridBySchemaEditable/BooleanInputCell.js +42 -0
  5. package/dist/components/DataGridBySchemaEditable/ConfirmDialog.d.ts +8 -0
  6. package/dist/components/DataGridBySchemaEditable/ConfirmDialog.js +21 -0
  7. package/dist/components/DataGridBySchemaEditable/CustomToolbar.d.ts +17 -0
  8. package/dist/components/DataGridBySchemaEditable/CustomToolbar.js +77 -0
  9. package/dist/components/DataGridBySchemaEditable/FooterToolbar.d.ts +17 -0
  10. package/dist/components/DataGridBySchemaEditable/FooterToolbar.js +41 -0
  11. package/dist/components/DataGridBySchemaEditable/GridDecimalInput.d.ts +9 -0
  12. package/dist/components/DataGridBySchemaEditable/GridDecimalInput.js +32 -0
  13. package/dist/components/DataGridBySchemaEditable/GridPatternInput.d.ts +9 -0
  14. package/dist/components/DataGridBySchemaEditable/GridPatternInput.js +30 -0
  15. package/dist/components/DataGridBySchemaEditable/InputInterval.d.ts +4 -0
  16. package/dist/components/DataGridBySchemaEditable/InputInterval.js +105 -0
  17. package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.d.ts +33 -0
  18. package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.js +140 -0
  19. package/dist/components/DataGridBySchemaEditable/utils.d.ts +15 -0
  20. package/{src/components/DataGridBySchemaEditable/utils.ts → dist/components/DataGridBySchemaEditable/utils.js} +32 -50
  21. package/dist/components/DataGridBySchemaEditable.d.ts +34 -0
  22. package/dist/components/DataGridBySchemaEditable.js +565 -0
  23. package/dist/components/DataTotals.d.ts +15 -0
  24. package/dist/components/DataTotals.js +23 -0
  25. package/dist/components/DialogActions.d.ts +10 -0
  26. package/dist/components/DialogActions.js +17 -0
  27. package/dist/components/DialogJSONSchemaForm.d.ts +13 -0
  28. package/dist/components/DialogJSONSchemaForm.js +20 -0
  29. package/dist/components/FormButtons.d.ts +21 -0
  30. package/dist/components/FormButtons.js +43 -0
  31. package/dist/components/GenericModelList.d.ts +19 -0
  32. package/dist/components/GenericModelList.js +113 -0
  33. package/dist/components/GenericRelatedModelList.d.ts +25 -0
  34. package/dist/components/GenericRelatedModelList.js +111 -0
  35. package/dist/components/TextFieldBySchema.js +39 -0
  36. package/dist/context/APIWrapper.d.ts +12 -0
  37. package/dist/context/APIWrapper.js +341 -0
  38. package/{src/context/APIWrapperContext.tsx → dist/context/APIWrapperContext.d.ts} +22 -31
  39. package/dist/context/APIWrapperContext.js +15 -0
  40. package/{src/context/DRFReactBySchemaContext.tsx → dist/context/DRFReactBySchemaContext.d.ts} +4 -17
  41. package/dist/context/DRFReactBySchemaContext.js +19 -0
  42. package/dist/context/DRFReactBySchemaProvider.d.ts +13 -0
  43. package/dist/context/DRFReactBySchemaProvider.js +53 -0
  44. package/dist/context/Form.d.ts +21 -0
  45. package/dist/context/Form.js +99 -0
  46. package/dist/context/FormContext.d.ts +72 -0
  47. package/dist/context/FormContext.js +15 -0
  48. package/dist/context/Overlays.d.ts +4 -0
  49. package/dist/context/Overlays.js +87 -0
  50. package/dist/index.d.ts +12 -0
  51. package/dist/index.js +3 -1
  52. package/{src/styles/index.ts → dist/styles/index.d.ts} +0 -1
  53. package/dist/styles/index.js +28 -0
  54. package/dist/styles/layout.d.ts +107 -0
  55. package/dist/styles/layout.js +56 -0
  56. package/dist/styles/theme.d.ts +21 -0
  57. package/dist/styles/theme.js +139 -0
  58. package/dist/utils.d.ts +74 -0
  59. package/dist/utils.js +268 -0
  60. package/package.json +11 -2
  61. package/.eslintrc.js +0 -14
  62. package/.gitlab-ci.yml +0 -14
  63. package/src/api.ts +0 -727
  64. package/src/components/DataGridBySchemaEditable/ConfirmDialog.tsx +0 -41
  65. package/src/components/DataGridBySchemaEditable/CustomToolbar.tsx +0 -93
  66. package/src/components/DataGridBySchemaEditable/FooterToolbar.tsx +0 -77
  67. package/src/components/DataGridBySchemaEditable/GridDecimalInput.tsx +0 -41
  68. package/src/components/DataGridBySchemaEditable/GridPatternInput.tsx +0 -37
  69. package/src/components/DataGridBySchemaEditable/InputInterval.tsx +0 -194
  70. package/src/components/DataGridBySchemaEditable/SelectEditInputCell.tsx +0 -154
  71. package/src/components/DataGridBySchemaEditable.md +0 -50
  72. package/src/components/DataGridBySchemaEditable.tsx +0 -758
  73. package/src/components/DataTotals.tsx +0 -57
  74. package/src/components/DialogActions.tsx +0 -33
  75. package/src/components/DialogJSONSchemaForm.tsx +0 -40
  76. package/src/components/GenericModelList.tsx +0 -165
  77. package/src/components/GenericRelatedModelList.tsx +0 -168
  78. package/src/context/APIWrapper.tsx +0 -447
  79. package/src/context/DRFReactBySchemaProvider.md +0 -57
  80. package/src/context/DRFReactBySchemaProvider.tsx +0 -72
  81. package/src/context/Overlays.tsx +0 -94
  82. package/src/index.ts +0 -77
  83. package/src/styles/layout.ts +0 -104
  84. package/src/styles/theme.ts +0 -190
  85. package/src/utils.ts +0 -327
  86. package/styleguide.config.js +0 -13
  87. package/tsconfig.json +0 -104
  88. package/webpack.config.js +0 -24
package/src/index.ts DELETED
@@ -1,77 +0,0 @@
1
- // Methods:
2
- import {
3
- updateData,
4
- partialUpdateData,
5
- createData,
6
- deleteData,
7
- createOrUpdateData,
8
- updateDataBySchema,
9
- addExistingRelatedModel,
10
- getAutoComplete,
11
- getJSONSchema,
12
- createOrUpdateJSONSchema,
13
- loginByPayload,
14
- setAuthToken,
15
- isLoggedIn,
16
- getGenericModelList,
17
- getGenericModel
18
- } from './api';
19
- import {
20
- emptyByType,
21
- getChoiceByValue,
22
- populateValues,
23
- buildGenericYupValidationSchema,
24
- errorProps,
25
- getTmpId,
26
- isTmpId,
27
- getPatternFormat
28
- } from './utils';
29
-
30
- // Wrappers/Providers:
31
- import DRFReactBySchemaProvider from './context/DRFReactBySchemaProvider';
32
- import { DRFReactBySchemaContext, useTheme } from './context/DRFReactBySchemaContext';
33
- import { APIWrapperContext } from './context/APIWrapperContext';
34
- // Components
35
- import DataGridBySchemaEditable from './components/DataGridBySchemaEditable';
36
- import GenericModelList from './components/GenericModelList';
37
- import GenericRelatedModelList from './components/GenericRelatedModelList';
38
- import DataTotals from './components/DataTotals';
39
- import DialogActions from './components/DialogActions';
40
-
41
- export {
42
- // Wrappers/Providers:
43
- DRFReactBySchemaProvider,
44
- DRFReactBySchemaContext,
45
- APIWrapperContext,
46
- useTheme,
47
- // Components:
48
- DataGridBySchemaEditable,
49
- GenericModelList,
50
- GenericRelatedModelList,
51
- DataTotals,
52
- DialogActions,
53
- // Methods:
54
- updateData,
55
- partialUpdateData,
56
- createData,
57
- deleteData,
58
- createOrUpdateData,
59
- updateDataBySchema,
60
- addExistingRelatedModel,
61
- getAutoComplete,
62
- getJSONSchema,
63
- createOrUpdateJSONSchema,
64
- loginByPayload,
65
- setAuthToken,
66
- isLoggedIn,
67
- getGenericModelList,
68
- getGenericModel,
69
- emptyByType,
70
- getChoiceByValue,
71
- populateValues,
72
- buildGenericYupValidationSchema,
73
- errorProps,
74
- getTmpId,
75
- isTmpId,
76
- getPatternFormat
77
- };
@@ -1,104 +0,0 @@
1
- import theme from './theme';
2
-
3
- export const content = {
4
- flexGrow: 1,
5
- pr: 3,
6
- pl: 3,
7
- pt: 2,
8
- pb: 0
9
- };
10
-
11
- export const main = {
12
- ...content,
13
- ml: 4
14
- };
15
-
16
- export const flexRow = {
17
- display: 'flex',
18
- flexDirection: 'row',
19
- justifyContent: 'space-between',
20
- alignItems: 'center'
21
- };
22
-
23
- export const topBar = {
24
- ...flexRow,
25
- width: '100%',
26
- pl: 3,
27
- pr: 6
28
- };
29
-
30
- export const loadingBox = {
31
- ...flexRow,
32
- height: '100%',
33
- backgroundColor: '#ccc',
34
- justifyContent: 'center'
35
- };
36
-
37
- export const actionButtons = {
38
- ...flexRow,
39
- width: '100%',
40
- alignItems: 'flex-start'
41
- };
42
-
43
- export const inLineForm = {
44
- ...flexRow,
45
- width: '100%',
46
- justifyContent: 'flex-start'
47
- };
48
-
49
- export const flexColumn = {
50
- ...flexRow,
51
- flexDirection: 'column'
52
- };
53
-
54
- export const flexRowGrow = {
55
- ...flexRow,
56
- flexGrow: 1
57
- };
58
-
59
- export const topBarOverList = {
60
- ...flexRowGrow,
61
- mb: 2
62
- };
63
-
64
- export const dataGrid = {
65
- height: 'calc(100vh - 180px)',
66
- mt: 2
67
- };
68
-
69
- export const dataGridWithTabs = {
70
- ...dataGrid,
71
- mt: 0
72
- };
73
-
74
- export const dataGridFixedHeight = {
75
- ...dataGrid,
76
- height: 400
77
- };
78
-
79
- export const fullWidthButton = {
80
- mt: 3,
81
- width: '100%'
82
- };
83
-
84
- export const formCard = {
85
- width: '100%',
86
- backgroundColor: theme.palette.formCard.main,
87
- mt: 2,
88
- mb: 2
89
- };
90
-
91
- export const formCardContent = {
92
- maxHeight: 350,
93
- overflow: 'scroll'
94
- };
95
-
96
- export const metabaseAppEmbed = {
97
- height: 1700
98
- };
99
-
100
- export const geoPicker = {
101
- height: 350,
102
- width: '100%',
103
- mt: 0
104
- };
@@ -1,190 +0,0 @@
1
- import type {} from '@mui/x-data-grid/themeAugmentation';
2
- import { createTheme } from '@mui/material/styles';
3
- import { ptBR as corePtBR } from '@mui/material/locale';
4
- import { ptBR } from '@mui/x-data-grid';
5
- import { ptBR as pickersPtBR } from '@mui/x-date-pickers';
6
-
7
- declare module '@mui/material/styles' {
8
- // interface Theme {
9
- // status: {
10
- // danger: React.CSSProperties['color'];
11
- // };
12
- // }
13
- interface Palette {
14
- avatars: string[];
15
- avatarsMore: string[];
16
- topBarButton: Palette['primary'];
17
- producao: Palette['primary'];
18
- empreendimento: Palette['primary'];
19
- comercializacao: Palette['primary'];
20
- credito: Palette['primary'];
21
- certificacao: Palette['primary'];
22
- successButton: Palette['primary'];
23
- selectedItem: Palette['primary'];
24
- tableColumnHeader: Palette['primary'];
25
- formCard: Palette['primary'];
26
- }
27
- // interface PaletteOptions {
28
- // neutral: PaletteOptions['primary'];
29
- // }
30
- //
31
- interface PaletteColor {
32
- semaphoric?: string;
33
- }
34
- // interface SimplePaletteColorOptions {
35
- // darker?: string;
36
- // }
37
- // interface ThemeOptions {
38
- // status: {
39
- // danger: React.CSSProperties['color'];
40
- // };
41
- // }
42
- }
43
-
44
-
45
- ptBR.components.MuiDataGrid.defaultProps.localeText = {
46
- ...ptBR.components.MuiDataGrid.defaultProps.localeText,
47
- toolbarQuickFilterPlaceholder: 'Buscar...',
48
- toolbarQuickFilterLabel: 'Buscar',
49
- toolbarQuickFilterDeleteIconLabel: 'Limpar busca'
50
- };
51
-
52
- const palette = {
53
- avatars: ['#e60049', '#0bb4ff', '#50e991', '#e6d800', '#9b19f5', '#ffa300', '#dc0ab4', '#b3d4ff', '#00bfa0'],
54
- avatarsMore: ['#023fa5', '#8e063b', '#d33f6a', '#11c638', '#ef9708', '#0fcfc0', '#f79cd4', '#7d87b9', '#bb7784', '#4a6fe3', '#8595e1', '#b5bbe3', '#e6afb9', '#e07b91', '#8dd593', '#c6dec7', '#ead3c6', '#f0b98d', '#9cded6', '#d5eae7', '#f3e1eb', '#f6c4e1', '#bec1d4', '#d6bcc0'],
55
- topBarButton: {
56
- main: '#ffffff'
57
- },
58
- producao: {
59
- main: '#e60049',
60
- contrastText: '#fff'
61
- },
62
- empreendimento: {
63
- main: '#0bb4ff',
64
- contrastText: '#fff'
65
- },
66
- comercializacao: {
67
- main: '#ffa300',
68
- contrastText: '#fff'
69
- },
70
- credito: {
71
- main: '#dc0ab4',
72
- contrastText: '#fff'
73
- },
74
- certificacao: {
75
- main: '#9b19f5',
76
- contrastText: '#fff'
77
- },
78
- background: {
79
- default: '#D9D9D9'
80
- },
81
- primary: {
82
- main: '#3949AB'
83
- },
84
- secondary: {
85
- main: '#9ca4d5',
86
- contrastText: '#fff'
87
- },
88
- successButton: {
89
- main: '#CDDC39',
90
- contrastText: '#fff'
91
- },
92
- success: {
93
- main: '#0e0',
94
- contrastText: '#fff',
95
- semaphoric: '#0e0'
96
- },
97
- error: {
98
- main: '#d32f2f',
99
- semaphoric: '#f66'
100
- },
101
- warning: {
102
- main: '#ee0',
103
- semaphoric: '#ee0'
104
- },
105
- selectedItem: {
106
- main: '#2962FF'
107
- },
108
- tableColumnHeader: {
109
- main: '#ECEFF1'
110
- },
111
- formCard: {
112
- main: '#FFF'
113
- }
114
- };
115
-
116
- const defaultTheme = createTheme(
117
- {
118
- palette,
119
- components: {
120
- MuiButton: {
121
- styleOverrides: {
122
- contained: {
123
- // borderRadius: 50
124
- }
125
- }
126
- },
127
- MuiTextField: {
128
- styleOverrides: {
129
- root: {
130
- '&.Mui-required .MuiFormLabel-asterisk': {
131
- // color: '#F00'
132
- }
133
- }
134
- }
135
- },
136
- MuiListItemButton: {
137
- styleOverrides: {
138
- root: {
139
- '&.Mui-selected, :hover': {
140
- color: palette.selectedItem.main,
141
- '& .MuiListItemIcon-root': {
142
- color: palette.selectedItem.main
143
- }
144
- },
145
- '&.Mui-selected:hover': {
146
- color: palette.selectedItem.main,
147
- '& .MuiListItemIcon-root': {
148
- color: palette.selectedItem.main
149
- }
150
- },
151
- '&.disabled': {
152
- opacity: 0.5
153
- }
154
- }
155
- }
156
- },
157
- MuiDataGrid: {
158
- styleOverrides: {
159
- root: {
160
- backgroundColor: palette.formCard.main,
161
- '& .MuiDataGrid-columnHeaderTitle': {
162
- overflow: 'visible',
163
- lineHeight: '1.43rem',
164
- whiteSpace: 'normal'
165
- }
166
- },
167
- cell: {
168
- // backgroundColor: 'yellow'
169
- },
170
- columnHeader: {
171
- backgroundColor: palette.tableColumnHeader.main
172
- }
173
- }
174
- },
175
- MuiTabs: {
176
- styleOverrides: {
177
- root: {
178
- backgroundColor: palette.formCard.main,
179
- marginTop: 20
180
- }
181
- }
182
- }
183
- }
184
- },
185
- corePtBR,
186
- ptBR,
187
- pickersPtBR
188
- );
189
-
190
- export default defaultTheme;
package/src/utils.ts DELETED
@@ -1,327 +0,0 @@
1
- import * as Yup from 'yup';
2
- import { GridActionsColDef, GridColDef } from '@mui/x-data-grid';
3
-
4
- export type Id = string | number;
5
- export type Item = Record<string, any>;
6
- export type SchemaType = Record<string, Field>;
7
- export interface Choice {
8
- value: string | number,
9
- display_name: string
10
- };
11
- type FieldChild = Record<string, SchemaType>;
12
- export interface Field {
13
- type: string,
14
- child?: FieldChild,
15
- children?: SchemaType,
16
- model_default?: any,
17
- model_required?: boolean
18
- choices?: Choice[],
19
- max_length?: number | string,
20
- label: string,
21
- read_only?: boolean
22
- };
23
- interface GridBySchemaColDef extends GridColDef {
24
- isIndexField?: boolean,
25
- creatable?: boolean,
26
- orderable?: boolean,
27
- patternFormat?: string
28
- };
29
- interface GridActionsBySchemaColDef extends GridActionsColDef {
30
- isIndexField?: boolean,
31
- creatable?: boolean,
32
- orderable?: boolean,
33
- patternFormat?: string
34
- };
35
- export type GridEnrichedBySchemaColDef = GridBySchemaColDef | GridActionsBySchemaColDef;
36
- export interface DataSchemaColumnsType {
37
- data: Item[];
38
- schema: SchemaType;
39
- columns?: GridEnrichedBySchemaColDef[];
40
- }
41
- export interface ItemSchemaColumnsType {
42
- data: Item;
43
- schema: SchemaType;
44
- columns?: GridEnrichedBySchemaColDef[];
45
- }
46
-
47
- export const emptyByType: any = (field:Field, forDatabase:boolean = false) => {
48
- if (field.model_default) {
49
- return field.model_default;
50
- }
51
- switch (field.type) {
52
- case 'nested object':
53
- // emptyByType must be an empty object for the database, but must be null for the mui-autocomplete component. So I had to make this ugly hack here, when we're preparing to sendo to the database:
54
- return forDatabase ? {} : null;
55
- case 'field':
56
- if (field.child) {
57
- return [];
58
- }
59
- return (forDatabase)
60
- ? undefined
61
- : null;
62
- case 'string':
63
- case 'email':
64
- return '';
65
- case 'integer':
66
- return 0;
67
- case 'array':
68
- return [];
69
- default:
70
- return null;
71
- }
72
- };
73
-
74
- export const getChoiceByValue = (
75
- value:number | string,
76
- choices:Choice[] | undefined
77
- ) => {
78
- if (!choices) {
79
- return null;
80
- }
81
- for (const choice of choices) {
82
- if (choice.value === value) {
83
- return choice.display_name;
84
- }
85
- }
86
- };
87
-
88
- export const populateValues = ({
89
- data,
90
- schema
91
- }: {
92
- data:Item,
93
- schema:SchemaType
94
- }) => {
95
- const values:Record<string, any> = {};
96
- for (const entry of Object.entries(schema)) {
97
- const [key, field] = entry;
98
- if (key === 'id' && isTmpId(data[key])) {
99
- continue;
100
- }
101
-
102
- if (!data[key]) {
103
- values[key] = emptyByType(field);
104
- continue;
105
- }
106
-
107
- if (field.type === 'field' && field.child) {
108
- if (Array.isArray(data[key])) {
109
- const arValues = [];
110
- for (const row of data[key]) {
111
- const value = populateValues({
112
- data: row,
113
- schema: field.child.children
114
- });
115
- arValues.push(value);
116
- }
117
- values[key] = arValues;
118
- continue;
119
- }
120
-
121
- values[key] = populateValues({
122
- data: data[key],
123
- schema: field.child.children
124
- });
125
- continue;
126
- }
127
-
128
- if (field.type === 'choice') {
129
- values[key] = data[key]
130
- ? {
131
- value: data[key],
132
- display_name: getChoiceByValue(data[key], field.choices)
133
- }
134
- : emptyByType(field);
135
- continue;
136
- }
137
-
138
- values[key] = data[key];
139
- }
140
- // console.log(values);
141
- return values;
142
- };
143
-
144
- const getYupValidator = (type:string) => {
145
- let yupFunc;
146
- try {
147
- switch (type) {
148
- case 'slug':
149
- yupFunc = Yup.string();
150
- break;
151
- case 'email':
152
- yupFunc = Yup.string().email('Este campo deve ser um e-mail válido.');
153
- break;
154
- case 'integer':
155
- yupFunc = Yup.number().integer('Este campo deve ser um número inteiro');
156
- break;
157
- case 'choice':
158
- yupFunc = Yup.object();
159
- break;
160
- case 'field':
161
- yupFunc = Yup.mixed();
162
- break;
163
- case 'nested object':
164
- yupFunc = Yup.object();
165
- break;
166
- case 'date':
167
- yupFunc = Yup.date();
168
- break;
169
- case 'string':
170
- yupFunc = Yup.string();
171
- break;
172
- case 'number':
173
- yupFunc = Yup.number();
174
- break;
175
- case 'boolean':
176
- yupFunc = Yup.boolean();
177
- break;
178
- case 'array':
179
- yupFunc = Yup.array();
180
- break;
181
- case 'object':
182
- yupFunc = Yup.object();
183
- break;
184
- default:
185
- yupFunc = Yup.string();
186
- break;
187
- }
188
- } catch (e) {
189
- yupFunc = Yup.string();
190
- }
191
- return yupFunc.nullable();
192
- };
193
-
194
- export const buildGenericYupValidationSchema = ({
195
- data,
196
- schema,
197
- many = false,
198
- skipFields = [],
199
- extraValidators = {}
200
- }:{
201
- data:Item,
202
- schema:SchemaType,
203
- many?:boolean,
204
- skipFields?: string[],
205
- extraValidators?:Item
206
- }) => {
207
- const yupValidator:Record<string, any> = {};
208
- for (const entry of Object.entries(schema)) {
209
- const [key, field] = entry;
210
-
211
- if (!data || !(key in data) || key === 'id' || skipFields.includes(key)) {
212
- continue;
213
- }
214
-
215
- // console.log({ key, field, data: data[key] });
216
-
217
- // OneToMany or ManyToMany:
218
- if (field.type === 'field' && field.child) {
219
- yupValidator[key] = buildGenericYupValidationSchema({
220
- schema: field.child.children,
221
- many: true,
222
- data: data[key],
223
- extraValidators: Object.prototype.hasOwnProperty.call(extraValidators, key)
224
- ? extraValidators[key]
225
- : {}
226
- });
227
- continue;
228
- }
229
-
230
- // Nested Object:
231
- if (field.type === 'nested object' && field.children) {
232
- // yupValidator[key] = buildGenericYupValidationSchema({
233
- // schema: field.children,
234
- // many: false,
235
- // data: data[key],
236
- // extraValidators: Object.prototype.hasOwnProperty.call(extraValidators, key)
237
- // ? extraValidators[key]
238
- // : {}
239
- // });
240
- // if (!field.model_required) {
241
- // yupValidator[key] = yupValidator[key].nullable();
242
- // }
243
- // continue;
244
- }
245
-
246
- yupValidator[key] = Object.prototype.hasOwnProperty.call(extraValidators, key)
247
- ? extraValidators[key]
248
- : getYupValidator(field.type);
249
-
250
- if (field.model_required) {
251
- yupValidator[key] = yupValidator[key].required('Este campo é obrigatório');
252
- }
253
- if (field.max_length) {
254
- yupValidator[key] = yupValidator[key].max(parseInt(field.max_length as string), `Este campo só pode ter no máximo ${field.max_length} caracteres`);
255
- }
256
- }
257
- // console.log({ yupValidator });
258
- return (many)
259
- ? Yup.array().of(Yup.object().shape(yupValidator))
260
- : Yup.object().shape(yupValidator);
261
- };
262
-
263
- export const errorProps = ({
264
- type,
265
- errors,
266
- fieldKey,
267
- fieldKeyProp,
268
- index
269
- }: {
270
- type:string,
271
- errors:Item,
272
- fieldKey:string,
273
- fieldKeyProp:string,
274
- index?:number
275
- }) => {
276
- let error;
277
- let helperText;
278
- if (index) {
279
- const hasErrors = errors && errors[fieldKey] && errors[fieldKey][index] && Boolean(errors[fieldKey][index][fieldKeyProp]);
280
- error = hasErrors;
281
- helperText = hasErrors ? errors[fieldKey][index][fieldKeyProp].message : null;
282
- return { error, helperText };
283
- }
284
-
285
- const hasErrors = errors && errors[fieldKey] && Boolean(errors[fieldKey][fieldKeyProp]);
286
- error = hasErrors;
287
- helperText = hasErrors ? errors[fieldKey][fieldKeyProp].message : null;
288
- return { error, helperText };
289
- };
290
-
291
- export const getTmpId = () => {
292
- return 'tmp' + Math.floor(Math.random() * 1000000);
293
- };
294
-
295
- export const isTmpId = (id:string | number | undefined | null) => {
296
- if (!id) {
297
- return true;
298
- }
299
- return id.toString().substr(0, 3) === 'tmp';
300
- };
301
-
302
- export const reducer = (state:Record<string, any>, newState:Record<string, any>) => {
303
- return { ...state, ...newState };
304
- };
305
-
306
- export const getPatternFormat = (type:string) => {
307
- let format = '';
308
- switch (type) {
309
- case 'telefone':
310
- case 'fone':
311
- case 'phone':
312
- case 'contact':
313
- case 'contato':
314
- format = '(##)#####-####';
315
- break;
316
- case 'cpf':
317
- format = '###.###.###-##';
318
- break;
319
- case 'cnpj':
320
- format = '##.###.###/####-##';
321
- break;
322
- case 'cep':
323
- format = '##.###-###';
324
- break;
325
- }
326
- return format;
327
- };
@@ -1,13 +0,0 @@
1
- const path = require('path');
2
- const glob = require('glob');
3
-
4
- module.exports = {
5
- title: 'Styleguides for DRF React By Schema Package',
6
- styleguideDir: 'public',
7
- components: [
8
- 'src/components/*.tsx',
9
- 'src/context/*.tsx'
10
- ],
11
- resolver: require('react-docgen').resolver.findAllComponentDefinitions,
12
- propsParser: require('react-docgen-typescript').withDefaultConfig({ propFilter: { skipPropsWithoutDoc: false } }).parse
13
- };