@ssplib/react-components 0.0.50 → 0.0.52
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.
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
export default function FileUpload({ name, tipoArquivo, title, required, multiple, apiURL, xs, sm, md, }: {
|
|
2
|
+
export default function FileUpload({ name, tipoArquivo, title, required, multiple, apiURL, xs, sm, md, clientDelete, }: {
|
|
3
3
|
name: string;
|
|
4
4
|
tipoArquivo: string;
|
|
5
|
+
clientDelete: boolean;
|
|
5
6
|
title: string;
|
|
6
7
|
apiURL: string;
|
|
7
8
|
required?: boolean;
|
|
@@ -38,7 +38,7 @@ const lodash_get_1 = __importDefault(require("lodash.get"));
|
|
|
38
38
|
const react_1 = __importStar(require("react"));
|
|
39
39
|
const auth_1 = require("../../../context/auth");
|
|
40
40
|
const form_1 = require("../../../context/form");
|
|
41
|
-
function FileUpload({ name, tipoArquivo, title, required = false, multiple = false, apiURL, xs = 12, sm, md, }) {
|
|
41
|
+
function FileUpload({ name, tipoArquivo, title, required = false, multiple = false, apiURL, xs = 12, sm, md, clientDelete = false, }) {
|
|
42
42
|
const context = (0, react_1.useContext)(form_1.FormContext);
|
|
43
43
|
const { user } = (0, react_1.useContext)(auth_1.AuthContext);
|
|
44
44
|
const [files, setFiles] = (0, react_1.useState)([]);
|
|
@@ -63,6 +63,8 @@ function FileUpload({ name, tipoArquivo, title, required = false, multiple = fal
|
|
|
63
63
|
Authorization: `Bearer ${user ? user.token : ''}`,
|
|
64
64
|
},
|
|
65
65
|
}).then((res) => {
|
|
66
|
+
if (!res.ok)
|
|
67
|
+
setFilesError((fl) => [...fl, id]);
|
|
66
68
|
res.json().then((j) => {
|
|
67
69
|
if (j.status.status === 200) {
|
|
68
70
|
const fileIdFromApi = j.data[0];
|
|
@@ -87,6 +89,12 @@ function FileUpload({ name, tipoArquivo, title, required = false, multiple = fal
|
|
|
87
89
|
]);
|
|
88
90
|
}, [files, context]);
|
|
89
91
|
const deleteFile = (0, react_1.useCallback)((e, id) => {
|
|
92
|
+
if (clientDelete) {
|
|
93
|
+
console.log('aa');
|
|
94
|
+
setFiles(files.filter((x) => x.id !== id));
|
|
95
|
+
context.setFilesUid((fId) => fId.filter((idd) => idd.CO_SEQ_ARQUIVO !== id));
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
90
98
|
if (Object.keys(fileIds).includes(id.toString())) {
|
|
91
99
|
fetch(`${apiURL}/files/${fileIds[id]}`, {
|
|
92
100
|
method: 'DELETE',
|
|
@@ -96,6 +104,7 @@ function FileUpload({ name, tipoArquivo, title, required = false, multiple = fal
|
|
|
96
104
|
}).then((res) => {
|
|
97
105
|
if (res.status === 200) {
|
|
98
106
|
setFiles(files.filter((x) => x.id !== id));
|
|
107
|
+
context.setFilesUid((fId) => fId.filter((idd) => idd.CO_SEQ_ARQUIVO !== id));
|
|
99
108
|
}
|
|
100
109
|
});
|
|
101
110
|
}
|
|
@@ -146,6 +155,7 @@ function FileUpload({ name, tipoArquivo, title, required = false, multiple = fal
|
|
|
146
155
|
filesLoaded.includes(x.id) ? (react_1.default.createElement(Done_1.default, { sx: { fill: '#06d6a0' } })) : filesError.includes(x.id) ? (react_1.default.createElement(Clear_1.default, { sx: { fill: 'red' } })) : (react_1.default.createElement(material_1.CircularProgress, { size: 22, sx: { color: 'black' } })),
|
|
147
156
|
react_1.default.createElement(PictureAsPdf_1.default, { color: 'error' }),
|
|
148
157
|
react_1.default.createElement(material_1.Typography, { fontWeight: 600 }, x.name))),
|
|
149
|
-
react_1.default.createElement(material_1.Box, null, filesLoaded.includes(x.id)
|
|
158
|
+
react_1.default.createElement(material_1.Box, null, filesLoaded.includes(x.id) ||
|
|
159
|
+
(filesError.includes(x.id) && (react_1.default.createElement(material_1.Button, { variant: 'contained', size: 'small', sx: { textTransform: 'none', backgroundColor: '#d1495b', '&:hover': { backgroundColor: '#c1121f' } }, onClick: (e) => deleteFile(e, x.id), startIcon: react_1.default.createElement(Delete_1.default, null) }, "Remover")))))))))))));
|
|
150
160
|
}
|
|
151
161
|
exports.default = FileUpload;
|
|
@@ -3,9 +3,12 @@ interface ColumnData {
|
|
|
3
3
|
title: string;
|
|
4
4
|
keyName: string;
|
|
5
5
|
}
|
|
6
|
-
export declare function Table({ columns, fetchFunc, emptyMsg, dataPath, tableName, csv, columnSize, action, isPublic, filters, statusKeyName, csvExcludeKeys, }: {
|
|
6
|
+
export declare function Table({ columns, fetchFunc, emptyMsg, dataPath, tableName, csv, columnSize, action, isPublic, filters, statusKeyName, csvExcludeKeys, csvCustomKeyNames, }: {
|
|
7
7
|
columns: ColumnData[];
|
|
8
8
|
tableName: string;
|
|
9
|
+
csvCustomKeyNames?: {
|
|
10
|
+
[key: string]: string;
|
|
11
|
+
};
|
|
9
12
|
csvExcludeKeys?: string[];
|
|
10
13
|
statusKeyName?: string;
|
|
11
14
|
action: (prop: any) => JSX.Element;
|
|
@@ -40,7 +40,7 @@ const auth_1 = require("../../../context/auth");
|
|
|
40
40
|
function Table({ columns, fetchFunc, emptyMsg = {
|
|
41
41
|
user: 'Nenhum dado encontrado',
|
|
42
42
|
public: 'Nenhum dado encontrado',
|
|
43
|
-
}, dataPath = '', tableName, csv, columnSize, action, isPublic = false, filters, statusKeyName = '', csvExcludeKeys = [], }) {
|
|
43
|
+
}, dataPath = '', tableName, csv, columnSize, action, isPublic = false, filters, statusKeyName = '', csvExcludeKeys = [], csvCustomKeyNames = {}, }) {
|
|
44
44
|
const [isLoading, setIsLoading] = (0, react_1.useState)(true);
|
|
45
45
|
const [error, setError] = (0, react_1.useState)(null);
|
|
46
46
|
const [data, setData] = (0, react_1.useState)(null);
|
|
@@ -168,7 +168,7 @@ function Table({ columns, fetchFunc, emptyMsg = {
|
|
|
168
168
|
if (list.length <= 0)
|
|
169
169
|
return;
|
|
170
170
|
const keys = Object.keys(list[0]).filter((k) => !csvExcludeKeys.includes(k));
|
|
171
|
-
const header = keys.join(',') + '\n';
|
|
171
|
+
const header = keys.map((k) => (csvCustomKeyNames[k] ? csvCustomKeyNames[k] : k)).join(',') + '\n';
|
|
172
172
|
const values = list
|
|
173
173
|
.map((x) => {
|
|
174
174
|
return keys
|