@boarteam/boar-pack-common-frontend 2.5.1-alpha.1 → 2.6.0-alpha.2
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/Comment/Comment.tsx +53 -0
- package/src/components/Comment/CommentAvatar.tsx +34 -0
- package/src/components/Comment/CommentForm.tsx +36 -0
- package/src/components/Comment/CommentFormModal.tsx +31 -0
- package/src/components/Comment/index.ts +5 -0
- package/src/components/Table/tableTools.ts +5 -1
- package/src/components/Table/tableTypes.ts +1 -1
- package/src/components/Table/useCreation.tsx +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@boarteam/boar-pack-common-frontend",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0-alpha.2",
|
|
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": "754f593790263282b28867173f587da6b142b306"
|
|
50
50
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import { createStyles } from "antd-style";
|
|
3
|
+
import CommentAvatar from "./CommentAvatar";
|
|
4
|
+
|
|
5
|
+
export interface AuthorProps {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface CommentProps {
|
|
11
|
+
key: string;
|
|
12
|
+
content: string;
|
|
13
|
+
author: AuthorProps;
|
|
14
|
+
date: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const useStyles = createStyles(() => {
|
|
18
|
+
return {
|
|
19
|
+
/**
|
|
20
|
+
* Styles for the ant-descriptions component to show edit icon on hover
|
|
21
|
+
*/
|
|
22
|
+
commentStyles: {
|
|
23
|
+
display: 'flex',
|
|
24
|
+
alignItems: 'flex-start',
|
|
25
|
+
gap: '10px'
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
const Comment: React.FC<CommentProps> = ({
|
|
31
|
+
content,
|
|
32
|
+
author,
|
|
33
|
+
date,
|
|
34
|
+
...rest
|
|
35
|
+
}) => {
|
|
36
|
+
const { styles } = useStyles();
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<div
|
|
40
|
+
className={styles.commentStyles}
|
|
41
|
+
{...rest}
|
|
42
|
+
>
|
|
43
|
+
<CommentAvatar author={author} />
|
|
44
|
+
<div>
|
|
45
|
+
<strong>{author.name}</strong>
|
|
46
|
+
<p>{content}</p>
|
|
47
|
+
<small style={{ color: '#888' }}>{dayjs(date).format('DD.MM.YYYY HH:mm')}</small>
|
|
48
|
+
</div>
|
|
49
|
+
</div>
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export default Comment;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Avatar } from "antd";
|
|
2
|
+
import { AuthorProps } from "./Comment";
|
|
3
|
+
import React from "react";
|
|
4
|
+
|
|
5
|
+
interface CommentProps {
|
|
6
|
+
author: AuthorProps;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const ColorList = [
|
|
10
|
+
'#f56a00',
|
|
11
|
+
'#7265e6',
|
|
12
|
+
'#ffbf00',
|
|
13
|
+
'#00a2ae',
|
|
14
|
+
'#b45d7e',
|
|
15
|
+
'#ace665',
|
|
16
|
+
'#6e3aaf',
|
|
17
|
+
'#54ae00'
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
const getColorByAuthor = (authorId: string) => {
|
|
21
|
+
return ColorList[parseInt(authorId, 36) % ColorList.length]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const CommentAvatar: React.FC<CommentProps> = ({
|
|
25
|
+
author,
|
|
26
|
+
}) => {
|
|
27
|
+
return (
|
|
28
|
+
<Avatar style={{ backgroundColor: getColorByAuthor(author.id), verticalAlign: 'middle', flexShrink: 0 }} size="large">
|
|
29
|
+
{author.name.slice(0, 1)}
|
|
30
|
+
</Avatar>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default CommentAvatar;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Form, Input, Button } from 'antd';
|
|
3
|
+
|
|
4
|
+
interface CommentFormProps {
|
|
5
|
+
onSubmit: (content: string) => void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const CommentForm: React.FC<CommentFormProps> = ({ onSubmit }) => {
|
|
9
|
+
const [content, setContent] = useState('');
|
|
10
|
+
|
|
11
|
+
const handleSubmit = () => {
|
|
12
|
+
if (content.trim()) {
|
|
13
|
+
onSubmit(content);
|
|
14
|
+
setContent('');
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<Form layout="vertical" onFinish={handleSubmit}>
|
|
20
|
+
<div>
|
|
21
|
+
<Form.Item label="Leave a comment:">
|
|
22
|
+
<Input.TextArea
|
|
23
|
+
value={content}
|
|
24
|
+
onChange={(e) => setContent(e.target.value)}
|
|
25
|
+
autoSize={{ minRows: 3, maxRows: 6 }}
|
|
26
|
+
/>
|
|
27
|
+
</Form.Item>
|
|
28
|
+
</div>
|
|
29
|
+
<Button type="primary" htmlType="submit" style={{ width: 100 }}>
|
|
30
|
+
Send
|
|
31
|
+
</Button>
|
|
32
|
+
</Form>
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export default CommentForm;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Modal } from 'antd';
|
|
3
|
+
import CommentForm from "./CommentForm";
|
|
4
|
+
|
|
5
|
+
interface CommentFormProps {
|
|
6
|
+
isOpen: boolean;
|
|
7
|
+
setIsOpen: (open: boolean) => void;
|
|
8
|
+
onSubmit: (content: string) => void;
|
|
9
|
+
children?: React.ReactNode;
|
|
10
|
+
title?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const CommentFormModal: React.FC<CommentFormProps> = ({ setIsOpen, isOpen, onSubmit, children, title = 'Add comment' }) => {
|
|
14
|
+
return (
|
|
15
|
+
<Modal
|
|
16
|
+
title={title}
|
|
17
|
+
open={isOpen}
|
|
18
|
+
width={800}
|
|
19
|
+
closeIcon={true}
|
|
20
|
+
footer={null}
|
|
21
|
+
onCancel={() => {
|
|
22
|
+
setIsOpen(false);
|
|
23
|
+
}}
|
|
24
|
+
>
|
|
25
|
+
{children}
|
|
26
|
+
<CommentForm onSubmit={onSubmit} />
|
|
27
|
+
</Modal>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default CommentFormModal;
|
|
@@ -172,7 +172,11 @@ export function buildFieldsFromColumns<T>(
|
|
|
172
172
|
// skip id column because it is always included by backend
|
|
173
173
|
// and join fields because they are included by join
|
|
174
174
|
|
|
175
|
-
const dataIndex =
|
|
175
|
+
const dataIndex = Array.isArray(col.dataIndex) ? col.dataIndex[0] : col.dataIndex;
|
|
176
|
+
if (typeof dataIndex !== 'string') {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
176
180
|
if (!dataIndex || (Array.isArray(idColumnName) ? idColumnName.includes(dataIndex) : dataIndex === idColumnName) || joinFields.has(dataIndex)) {
|
|
177
181
|
return;
|
|
178
182
|
}
|
|
@@ -53,7 +53,7 @@ export type TGetAllParams = {
|
|
|
53
53
|
cache?: number,
|
|
54
54
|
}
|
|
55
55
|
export type TFilters = {
|
|
56
|
-
[key: string]: number | string | boolean | (string | number)[] | null;
|
|
56
|
+
[key: string]: number | string | boolean | (string | number | boolean)[] | null;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
export type TGetRequestParams = {
|
|
@@ -33,7 +33,7 @@ export function useCreation<Entity, CreateDto, TPathParams = {}>({
|
|
|
33
33
|
}: {
|
|
34
34
|
actionRef?: MutableRefObject<ActionType | undefined>;
|
|
35
35
|
pathParams: TPathParams;
|
|
36
|
-
entityToCreateDto: (entity:
|
|
36
|
+
entityToCreateDto: (entity: Entity) => CreateDto;
|
|
37
37
|
onCreate?: ({}: { requestBody: CreateDto } & TPathParams) => Promise<Entity>;
|
|
38
38
|
createButtonSize: SizeType;
|
|
39
39
|
popupCreation?: boolean;
|
|
@@ -41,7 +41,7 @@ export function useCreation<Entity, CreateDto, TPathParams = {}>({
|
|
|
41
41
|
} & Omit<CreateEntityModalProps<Entity>, 'onSubmit' | 'onCancel' | 'entity'>) {
|
|
42
42
|
const [createPopupData, setCreatePopupData] = useState<Partial<Entity> | undefined>();
|
|
43
43
|
|
|
44
|
-
const onCreateSubmit = async (data:
|
|
44
|
+
const onCreateSubmit = async (data: Entity) => {
|
|
45
45
|
try {
|
|
46
46
|
await onCreate?.({
|
|
47
47
|
...pathParams,
|