@boarteam/boar-pack-common-frontend 2.5.1-alpha.0 → 2.6.0-alpha.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boarteam/boar-pack-common-frontend",
3
- "version": "2.5.1-alpha.0",
3
+ "version": "2.6.0-alpha.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": "fe24b636ace6e71cc60a3f65126f8520f926aba1"
49
+ "gitHead": "38ccd74e5ec92322ac4efaf3482b131d51fca296"
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;
@@ -0,0 +1,5 @@
1
+ export * from './Comment';
2
+ export * from './CommentAvatar';
3
+ export * from './CommentForm';
4
+ export * from './CommentFormModal';
5
+ export { default as Comment } from './Comment';
@@ -129,6 +129,7 @@ export function applyKeywordToSearch(
129
129
  export type TIndexableRecord = {
130
130
  dataIndex?: Key | Key[];
131
131
  children?: TIndexableRecord[] | React.ReactNode;
132
+ editable?: false;
132
133
  };
133
134
 
134
135
  export function collectFieldsFromColumns<T>(
@@ -149,7 +150,9 @@ export function buildFieldsFromColumnsForDescriptionsDisplay<T>(
149
150
  if ('children' in col && Array.isArray(col.children)) {
150
151
  buildFieldsFromColumnsForDescriptionsDisplay(col.children, idColumnName, fields);
151
152
  }
152
- fields.add(String(Array.isArray(col.dataIndex) ? col.dataIndex[0] : col.dataIndex));
153
+ if (col.editable !== false) {
154
+ fields.add(String(Array.isArray(col.dataIndex) ? col.dataIndex[0] : col.dataIndex));
155
+ }
153
156
  });
154
157
 
155
158
  return fields;
@@ -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: Partial<Entity>) => CreateDto;
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: Partial<Entity>) => {
44
+ const onCreateSubmit = async (data: Entity) => {
45
45
  try {
46
46
  await onCreate?.({
47
47
  ...pathParams,