@boarteam/boar-pack-common-frontend 2.6.0 → 2.7.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.
- package/package.json +2 -2
- package/src/components/Descriptions/Descriptions.tsx +14 -17
- package/src/components/Descriptions/descriptionTypes.ts +1 -1
- package/src/components/Table/Table.tsx +14 -0
- package/src/components/Table/tableTypes.ts +2 -0
- package/src/components/Table/useImportExport.tsx +58 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@boarteam/boar-pack-common-frontend",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "Common frontend package for Boar Pack",
|
|
5
5
|
"repository": "git@github.com:boarteam/boar-pack.git",
|
|
6
6
|
"author": "Andrew Balakirev <balakirev.andrey@gmail.com>",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"scripts": {
|
|
47
47
|
"yalc:push": "yalc push"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "fd26e1cd23414aaf4b2aed44640f2eeb2f84b611"
|
|
50
50
|
}
|
|
@@ -16,25 +16,22 @@ import { createStyles } from "antd-style";
|
|
|
16
16
|
import { debounce } from "lodash";
|
|
17
17
|
import { NamePath } from "antd/lib/form/interface";
|
|
18
18
|
|
|
19
|
-
const useStyles = createStyles(() => {
|
|
19
|
+
const useStyles = createStyles(({css}) => {
|
|
20
20
|
return {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
'.anticon-edit': {
|
|
34
|
-
opacity: 1
|
|
35
|
-
},
|
|
21
|
+
antDescriptionsStyles: css`
|
|
22
|
+
.ant-descriptions-item-content {
|
|
23
|
+
.anticon-edit {
|
|
24
|
+
opacity: 0;
|
|
25
|
+
transition: opacity 200ms;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
&:hover {
|
|
29
|
+
.anticon-edit {
|
|
30
|
+
opacity: 1;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
36
33
|
}
|
|
37
|
-
|
|
34
|
+
`
|
|
38
35
|
}
|
|
39
36
|
})
|
|
40
37
|
|
|
@@ -36,7 +36,7 @@ export type TDescriptionsProps<Entity, CreateDto, UpdateDto, TPathParams = objec
|
|
|
36
36
|
requestBody: UpdateDto,
|
|
37
37
|
index?: number,
|
|
38
38
|
} & TPathParams) => Promise<Entity>,
|
|
39
|
-
onCreate
|
|
39
|
+
onCreate?: (data: Partial<Entity>) => Promise<void>;
|
|
40
40
|
onDelete?: ({}: Partial<Entity> & TPathParams) => Promise<void>,
|
|
41
41
|
pathParams?: TPathParams,
|
|
42
42
|
idColumnName?: string & keyof Entity,
|
|
@@ -9,6 +9,7 @@ import { KEY_SYMBOL, useCreation } from "./useCreation";
|
|
|
9
9
|
import { getTableDataQueryParams } from "./getTableDataQueryParams";
|
|
10
10
|
import { useEditableTable } from "./useEditableTable";
|
|
11
11
|
import { useBulkEditing } from "./useBulkEditing";
|
|
12
|
+
import { useImportExport } from "./useImportExport";
|
|
12
13
|
|
|
13
14
|
const useStyles = createStyles(() => {
|
|
14
15
|
return {
|
|
@@ -34,6 +35,8 @@ const Table = <Entity extends Record<string | symbol, any>,
|
|
|
34
35
|
onUpdateMany,
|
|
35
36
|
onDelete,
|
|
36
37
|
onDeleteMany,
|
|
38
|
+
exportUrl,
|
|
39
|
+
onImport,
|
|
37
40
|
pathParams,
|
|
38
41
|
idColumnName = 'id',
|
|
39
42
|
entityToCreateDto,
|
|
@@ -118,6 +121,11 @@ const Table = <Entity extends Record<string | symbol, any>,
|
|
|
118
121
|
createNewDefaultParams,
|
|
119
122
|
});
|
|
120
123
|
|
|
124
|
+
const { exportButton, importButton, setLastQueryParams } = useImportExport<TPathParams>({
|
|
125
|
+
exportUrl,
|
|
126
|
+
onImport,
|
|
127
|
+
})
|
|
128
|
+
|
|
121
129
|
useEffect(() => {
|
|
122
130
|
setUpdatePopupData(editableRecord);
|
|
123
131
|
actionRef?.current?.reload();
|
|
@@ -158,6 +166,7 @@ const Table = <Entity extends Record<string | symbol, any>,
|
|
|
158
166
|
queryParams,
|
|
159
167
|
result,
|
|
160
168
|
]);
|
|
169
|
+
setLastQueryParams(queryParams);
|
|
161
170
|
return result;
|
|
162
171
|
}
|
|
163
172
|
|
|
@@ -181,6 +190,9 @@ const Table = <Entity extends Record<string | symbol, any>,
|
|
|
181
190
|
listsHeight: 500,
|
|
182
191
|
},
|
|
183
192
|
}}
|
|
193
|
+
scroll={{
|
|
194
|
+
x: 'max-content',
|
|
195
|
+
}}
|
|
184
196
|
bordered
|
|
185
197
|
search={false}
|
|
186
198
|
editable={editableConfig}
|
|
@@ -193,6 +205,8 @@ const Table = <Entity extends Record<string | symbol, any>,
|
|
|
193
205
|
? bulkDeleteButton
|
|
194
206
|
: null,
|
|
195
207
|
!viewOnly && createButton || null,
|
|
208
|
+
!viewOnly && importButton || null,
|
|
209
|
+
exportUrl && exportButton || null,
|
|
196
210
|
...toolBarRender && toolBarRender(...args) || [],
|
|
197
211
|
]}
|
|
198
212
|
columns={columns}
|
|
@@ -107,6 +107,8 @@ export interface EditableProps<Entity, CreateDto, UpdateDto, TPathParams = {}> {
|
|
|
107
107
|
editable?: RowEditableConfig<Entity>;
|
|
108
108
|
afterSave?: (record: Entity) => Promise<void>;
|
|
109
109
|
onCreate?: ({}: { requestBody: CreateDto } & TPathParams) => Promise<Entity>;
|
|
110
|
+
exportUrl?: string;
|
|
111
|
+
onImport?: (event: React.ChangeEvent<HTMLInputElement>) => Promise<any>;
|
|
110
112
|
onUpdate: ({}: Partial<Entity> & {
|
|
111
113
|
requestBody: UpdateDto,
|
|
112
114
|
index?: number,
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Button, Tooltip } from 'antd';
|
|
2
|
+
import { DownloadOutlined, UploadOutlined } from "@ant-design/icons";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { TGetAllParams } from "./tableTypes";
|
|
5
|
+
import { Link } from "react-router-dom";
|
|
6
|
+
|
|
7
|
+
export function useImportExport<TPathParams = {}>({
|
|
8
|
+
exportUrl,
|
|
9
|
+
onImport
|
|
10
|
+
}: {
|
|
11
|
+
exportUrl?: string;
|
|
12
|
+
onImport?: (event: React.ChangeEvent<HTMLInputElement>) => Promise<any>;
|
|
13
|
+
}) {
|
|
14
|
+
const [isLoadingImport, setIsLoadingImport] = useState(false);
|
|
15
|
+
const [lastQueryParams, setLastQueryParams] = useState<TGetAllParams & TPathParams>();
|
|
16
|
+
|
|
17
|
+
const onImportChange = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
18
|
+
setIsLoadingImport(true);
|
|
19
|
+
await onImport?.(event)
|
|
20
|
+
.then((response) => {
|
|
21
|
+
console.log(response);
|
|
22
|
+
})
|
|
23
|
+
.finally(() => {
|
|
24
|
+
setIsLoadingImport(false);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const url = exportUrl + (lastQueryParams ? '?' + new URLSearchParams({
|
|
29
|
+
s: lastQueryParams.s,
|
|
30
|
+
sort: lastQueryParams.sort?.[0],
|
|
31
|
+
}).toString() : '');
|
|
32
|
+
const exportButton = <Tooltip title="Export">
|
|
33
|
+
<Link to={url} target={'_blank'}>
|
|
34
|
+
<Button icon={<DownloadOutlined />}/>
|
|
35
|
+
</Link>
|
|
36
|
+
</Tooltip>;
|
|
37
|
+
|
|
38
|
+
const importButton = <>
|
|
39
|
+
<Tooltip title="Import">
|
|
40
|
+
<label htmlFor="import-input">
|
|
41
|
+
<Button loading={isLoadingImport} icon={<UploadOutlined />} />
|
|
42
|
+
</label>
|
|
43
|
+
</Tooltip>
|
|
44
|
+
<input
|
|
45
|
+
type="file"
|
|
46
|
+
id="import-input"
|
|
47
|
+
style={{ display: "none" }}
|
|
48
|
+
accept=".xlsx, .xls"
|
|
49
|
+
onChange={onImportChange}
|
|
50
|
+
/>
|
|
51
|
+
</>
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
exportButton,
|
|
55
|
+
importButton,
|
|
56
|
+
setLastQueryParams
|
|
57
|
+
};
|
|
58
|
+
}
|