drf-react-by-schema 0.17.8 → 0.17.9
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/dist/api.d.ts +2 -33
- package/dist/components/DataTotals.d.ts +1 -2
- package/dist/components/DataTotalsServer.d.ts +1 -1
- package/dist/components/DataTotalsServer.js +3 -5
- package/dist/components/GenericModelList.d.ts +1 -2
- package/dist/components/GenericRelatedModelList.d.ts +1 -2
- package/dist/context/APIWrapper.js +10 -0
- package/dist/context/APIWrapperContext.d.ts +4 -4
- package/dist/context/APIWrapperContext.js +1 -0
- package/dist/utils.d.ts +34 -1
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { AxiosError } from 'axios';
|
|
2
2
|
import { serverEndPointType } from './context/DRFReactBySchemaContext';
|
|
3
|
-
import { Item, SchemaType,
|
|
4
|
-
import { GridFilterModel, GridSortModel } from '@mui/x-data-grid';
|
|
5
|
-
import { AlertColor } from '@mui/material/Alert';
|
|
3
|
+
import { Item, SchemaType, DataSchemaColumnsType, ItemSchemaColumnsType, Id, TargetApiParams, TargetApiPostParams, GetGenericModelListProps } from './utils';
|
|
6
4
|
interface TargetApiParamsOptionalId {
|
|
7
5
|
path: string;
|
|
8
6
|
serverEndPoint: serverEndPointType | null;
|
|
@@ -20,7 +18,7 @@ export declare const getRawData: ({ path, serverEndPoint, }: {
|
|
|
20
18
|
*/
|
|
21
19
|
export declare const updateData: ({ path, serverEndPoint, data, id }: TargetApiParams) => Promise<Item>;
|
|
22
20
|
export declare const partialUpdateData: ({ path, serverEndPoint, data, id }: TargetApiParams) => Promise<Item>;
|
|
23
|
-
export declare const createData: ({ path, serverEndPoint, data }:
|
|
21
|
+
export declare const createData: ({ path, serverEndPoint, data }: TargetApiPostParams) => Promise<Item>;
|
|
24
22
|
export declare const deleteData: (path: string, serverEndPoint: serverEndPointType | null, id: Id) => Promise<true | AxiosError<unknown, any>>;
|
|
25
23
|
export declare const createOrUpdateData: ({ path, serverEndPoint, data, id, }: TargetApiParamsOptionalId) => Promise<Item>;
|
|
26
24
|
export declare const updateDataBySchema: ({ model, modelObjectId, serverEndPoint, data, schema, path, }: {
|
|
@@ -48,35 +46,6 @@ export declare const setAuthToken: (token: string | null) => void;
|
|
|
48
46
|
export declare const isLoggedIn: (serverEndPoint: serverEndPointType | null) => Promise<false | Item>;
|
|
49
47
|
export declare const getSignUpOptions: (serverEndPoint: serverEndPointType | null) => Promise<SchemaType | AxiosError<unknown, any>>;
|
|
50
48
|
export declare const signUp: (data: Item, serverEndPoint: serverEndPointType | null) => Promise<Item>;
|
|
51
|
-
export interface GetGenericModelListProps {
|
|
52
|
-
model: string;
|
|
53
|
-
serverEndPoint: serverEndPointType | null;
|
|
54
|
-
id?: Id;
|
|
55
|
-
relatedModel?: string;
|
|
56
|
-
relatedModelId?: Id;
|
|
57
|
-
columnFields: string[];
|
|
58
|
-
hiddenFields?: string[];
|
|
59
|
-
creatableFields?: string[];
|
|
60
|
-
disabledFields?: string[];
|
|
61
|
-
isInBatches?: boolean;
|
|
62
|
-
loadedSchema?: SchemaType | boolean;
|
|
63
|
-
loadedModelOptions?: modelOptionsType | boolean;
|
|
64
|
-
page?: number;
|
|
65
|
-
filter?: GridFilterModel;
|
|
66
|
-
queryParams?: string[];
|
|
67
|
-
sort?: GridSortModel;
|
|
68
|
-
sumRows?: SumRowsType;
|
|
69
|
-
}
|
|
70
|
-
export interface SumRowsType {
|
|
71
|
-
rows: SumRowsItem[];
|
|
72
|
-
severity?: AlertColor;
|
|
73
|
-
}
|
|
74
|
-
interface SumRowsItem {
|
|
75
|
-
field: string;
|
|
76
|
-
prefix?: string;
|
|
77
|
-
suffix?: string;
|
|
78
|
-
isCount?: boolean;
|
|
79
|
-
}
|
|
80
49
|
export declare const getGenericModelList: ({ model, serverEndPoint, id, relatedModel, relatedModelId, columnFields, hiddenFields, creatableFields, disabledFields, isInBatches, loadedSchema, loadedModelOptions, page, filter, queryParams, sort, sumRows, }: GetGenericModelListProps) => Promise<false | DataSchemaColumnsType>;
|
|
81
50
|
export declare const getGenericModel: ({ model, serverEndPoint, id, relatedModel, relatedModelId, }: {
|
|
82
51
|
model: string;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { GridRowId } from '@mui/x-data-grid';
|
|
3
|
-
import { Item } from '../utils';
|
|
4
|
-
import { SumRowsType } from '../api';
|
|
3
|
+
import { Item, SumRowsType } from '../utils';
|
|
5
4
|
interface DataTotalsProps {
|
|
6
5
|
data?: Item[];
|
|
7
6
|
sumRows?: SumRowsType;
|
|
@@ -8,11 +8,9 @@ const Alert_1 = __importDefault(require("@mui/material/Alert"));
|
|
|
8
8
|
const List_1 = __importDefault(require("@mui/material/List"));
|
|
9
9
|
const ListItem_1 = __importDefault(require("@mui/material/ListItem"));
|
|
10
10
|
const react_number_format_1 = require("react-number-format");
|
|
11
|
-
;
|
|
12
11
|
const DataTotalsServer = ({ sumRows, totals }) => {
|
|
13
|
-
return (react_1.default.createElement(react_1.default.Fragment, null, sumRows && sumRows.rows.length > 0 &&
|
|
14
|
-
react_1.default.createElement(
|
|
15
|
-
react_1.default.createElement(
|
|
16
|
-
react_1.default.createElement(react_number_format_1.NumericFormat, { value: totals ? totals[`${row.field}_total`] : 0, thousandSeparator: '.', decimalSeparator: ',', displayType: 'text', decimalScale: row.isCount ? 0 : 2, fixedDecimalScale: true, prefix: row.prefix, suffix: row.suffix }))))))));
|
|
12
|
+
return (react_1.default.createElement(react_1.default.Fragment, null, sumRows && sumRows.rows.length > 0 && (react_1.default.createElement(Alert_1.default, { severity: sumRows.severity || 'info' },
|
|
13
|
+
react_1.default.createElement(List_1.default, { dense: true }, sumRows.rows.map((row) => (react_1.default.createElement(ListItem_1.default, { key: `sumRows_${row.field}` },
|
|
14
|
+
react_1.default.createElement(react_number_format_1.NumericFormat, { value: totals ? totals[`${row.field}_total`] : 0, thousandSeparator: ".", decimalSeparator: ",", displayType: 'text', decimalScale: row.isCount ? 0 : 2, fixedDecimalScale: true, prefix: row.prefix, suffix: row.suffix })))))))));
|
|
17
15
|
};
|
|
18
16
|
exports.default = DataTotalsServer;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { GridFilterModel, GridRenderCellParams } from '@mui/x-data-grid';
|
|
3
|
-
import { GridEnrichedBySchemaColDef, ActionType, Item, OnSelectActions, OptionsAC, FormFieldLayout, CustomAction } from '../utils';
|
|
4
|
-
import { SumRowsType } from '../api';
|
|
3
|
+
import { GridEnrichedBySchemaColDef, ActionType, Item, OnSelectActions, OptionsAC, FormFieldLayout, CustomAction, SumRowsType } from '../utils';
|
|
5
4
|
interface GenericModelListProps {
|
|
6
5
|
model: string;
|
|
7
6
|
columnFields: string[];
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { GridFilterModel } from '@mui/x-data-grid';
|
|
3
|
-
import { ActionType, GridEnrichedBySchemaColDef, Id, Item, OnSelectActions, OptionsAC } from '../utils';
|
|
4
|
-
import { SumRowsType } from '../api';
|
|
3
|
+
import { ActionType, GridEnrichedBySchemaColDef, Id, Item, OnSelectActions, OptionsAC, SumRowsType } from '../utils';
|
|
5
4
|
interface GenericRelatedModelListProps {
|
|
6
5
|
model: string;
|
|
7
6
|
id: Id;
|
|
@@ -459,6 +459,15 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
|
459
459
|
return response;
|
|
460
460
|
});
|
|
461
461
|
}
|
|
462
|
+
function postData(params) {
|
|
463
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
464
|
+
const response = yield (0, api_1.createData)(Object.assign(Object.assign({}, params), { serverEndPoint }));
|
|
465
|
+
if ('isAxiosError' in response) {
|
|
466
|
+
return false;
|
|
467
|
+
}
|
|
468
|
+
return response;
|
|
469
|
+
});
|
|
470
|
+
}
|
|
462
471
|
return (react_1.default.createElement(APIWrapperContext_1.APIWrapperContext.Provider, { value: {
|
|
463
472
|
usuaria,
|
|
464
473
|
updateUsuaria,
|
|
@@ -483,6 +492,7 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
|
483
492
|
loginByPayload: localLoginByPayload,
|
|
484
493
|
getSignUpOptions: localGetSignupOptions,
|
|
485
494
|
signUp: localSignUp,
|
|
495
|
+
postData: postData,
|
|
486
496
|
// Remove after integrating new "onEditModel" to package:
|
|
487
497
|
serverEndPoint,
|
|
488
498
|
editModel,
|
|
@@ -2,8 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { FieldValues, SubmitHandler, UseFormGetValues, UseFormSetValue } from 'react-hook-form';
|
|
3
3
|
import { AlertColor, AlertPropsColorOverrides } from '@mui/material/Alert';
|
|
4
4
|
import { OverridableStringUnion } from '@mui/types';
|
|
5
|
-
import { ItemSchemaColumnsType, Id, Item, SchemaType, DataSchemaColumnsType, OnSuccessEvent, OptionsAC, GenericValue,
|
|
6
|
-
import { GetGenericModelListProps } from '../api';
|
|
5
|
+
import { ItemSchemaColumnsType, Id, Item, SchemaType, DataSchemaColumnsType, OnSuccessEvent, OptionsAC, GenericValue, FormFieldLayout, TargetApiParamsLocal, GetGenericModelListPropsLocal } from '../utils';
|
|
7
6
|
import { serverEndPointType } from './DRFReactBySchemaContext';
|
|
8
7
|
export interface LoadSinglePageDataProps {
|
|
9
8
|
model: string;
|
|
@@ -84,14 +83,15 @@ export interface APIWrapperContextType {
|
|
|
84
83
|
setDialog: (x: Partial<DialogType>) => void;
|
|
85
84
|
getRawData: (route: string) => Promise<GenericValue>;
|
|
86
85
|
getAutoComplete: (model: string) => Promise<false | Item[]>;
|
|
87
|
-
getGenericModelList: (x:
|
|
86
|
+
getGenericModelList: (x: GetGenericModelListPropsLocal) => Promise<false | DataSchemaColumnsType>;
|
|
88
87
|
getAllModels: () => Promise<Item[]>;
|
|
89
88
|
loginByPayload: (payload: Item) => Promise<boolean>;
|
|
90
89
|
getSignUpOptions: () => Promise<false | SchemaType>;
|
|
91
90
|
signUp: (data: Item) => Promise<false | Item>;
|
|
91
|
+
postData: (params: TargetApiParamsLocal) => Promise<false | Item>;
|
|
92
92
|
serverEndPoint: serverEndPointType;
|
|
93
93
|
editModel: React.MutableRefObject<Item>;
|
|
94
|
-
updateModel: (p:
|
|
94
|
+
updateModel: (p: TargetApiParamsLocal) => Promise<false | Item>;
|
|
95
95
|
populateOptionsAC: (optionsACModels: string[]) => void;
|
|
96
96
|
}
|
|
97
97
|
export declare const APIWrapperContext: React.Context<APIWrapperContextType>;
|
|
@@ -38,6 +38,7 @@ exports.APIWrapperContext = react_1.default.createContext({
|
|
|
38
38
|
loginByPayload: () => __awaiter(void 0, void 0, void 0, function* () { return false; }),
|
|
39
39
|
getSignUpOptions: () => __awaiter(void 0, void 0, void 0, function* () { return false; }),
|
|
40
40
|
signUp: () => __awaiter(void 0, void 0, void 0, function* () { return false; }),
|
|
41
|
+
postData: () => __awaiter(void 0, void 0, void 0, function* () { return false; }),
|
|
41
42
|
// Remove after integrating new "onEditModel" to package:
|
|
42
43
|
serverEndPoint: { url: '', apiTokenUrl: '' },
|
|
43
44
|
editModel: { current: {} },
|
package/dist/utils.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as Yup from 'yup';
|
|
|
2
2
|
import { ReactElement } from 'react';
|
|
3
3
|
import { GridActionsColDef, GridColDef, GridFilterModel, GridSortModel } from '@mui/x-data-grid';
|
|
4
4
|
import { Control, FieldValues, UseFormGetValues, UseFormSetValue } from 'react-hook-form';
|
|
5
|
-
import { AutocompleteRenderOptionState, SxProps } from '@mui/material';
|
|
5
|
+
import { AlertColor, AutocompleteRenderOptionState, SxProps } from '@mui/material';
|
|
6
6
|
import { OnEditModelType } from './context/APIWrapperContext';
|
|
7
7
|
import { serverEndPointType } from './context/DRFReactBySchemaContext';
|
|
8
8
|
import { DateView } from '@mui/x-date-pickers';
|
|
@@ -249,4 +249,37 @@ export interface TargetApiParams {
|
|
|
249
249
|
data: Item;
|
|
250
250
|
id: Id;
|
|
251
251
|
}
|
|
252
|
+
export type TargetApiParamsLocal = Omit<TargetApiParams, 'serverEndPoint'>;
|
|
253
|
+
export type TargetApiPostParams = Omit<TargetApiParams, 'id'>;
|
|
254
|
+
export type TargetApiPostParamsLocal = Omit<TargetApiPostParams, 'serverEndPoint'>;
|
|
255
|
+
export interface SumRowsType {
|
|
256
|
+
rows: SumRowsItem[];
|
|
257
|
+
severity?: AlertColor;
|
|
258
|
+
}
|
|
259
|
+
interface SumRowsItem {
|
|
260
|
+
field: string;
|
|
261
|
+
prefix?: string;
|
|
262
|
+
suffix?: string;
|
|
263
|
+
isCount?: boolean;
|
|
264
|
+
}
|
|
265
|
+
export interface GetGenericModelListProps {
|
|
266
|
+
model: string;
|
|
267
|
+
serverEndPoint: serverEndPointType | null;
|
|
268
|
+
id?: Id;
|
|
269
|
+
relatedModel?: string;
|
|
270
|
+
relatedModelId?: Id;
|
|
271
|
+
columnFields: string[];
|
|
272
|
+
hiddenFields?: string[];
|
|
273
|
+
creatableFields?: string[];
|
|
274
|
+
disabledFields?: string[];
|
|
275
|
+
isInBatches?: boolean;
|
|
276
|
+
loadedSchema?: SchemaType | boolean;
|
|
277
|
+
loadedModelOptions?: modelOptionsType | boolean;
|
|
278
|
+
page?: number;
|
|
279
|
+
filter?: GridFilterModel;
|
|
280
|
+
queryParams?: string[];
|
|
281
|
+
sort?: GridSortModel;
|
|
282
|
+
sumRows?: SumRowsType;
|
|
283
|
+
}
|
|
284
|
+
export type GetGenericModelListPropsLocal = Omit<GetGenericModelListProps, 'serverEndPoint'>;
|
|
252
285
|
export {};
|
package/package.json
CHANGED