@visns-studio/visns-components 3.1.1 → 3.1.3

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.
@@ -6,80 +6,89 @@ const DragHandle = sortableHandle(() => (
6
6
  <ChevronVertical strokeWidth={1} size={26} />
7
7
  ));
8
8
 
9
+ // Utility function to truncate text
10
+ const truncateText = (text, maxLength) => {
11
+ if (text && text.length > maxLength) {
12
+ return `${text.substring(0, maxLength)}...`;
13
+ }
14
+ return text;
15
+ };
16
+
9
17
  const SortableItem = ({
10
18
  containerIndex,
11
19
  handleClick,
12
20
  handleEdit,
13
21
  handleDelete,
14
- showImage = true,
22
+ showImage,
15
23
  value,
16
24
  }) => {
17
25
  const renderImage = (d) => {
18
26
  let htmlContainer = '';
19
27
 
20
28
  if (showImage) {
21
- if (d.hasOwnProperty('image_url') && d.image_url !== '') {
22
- htmlContainer = (
23
- <div className="sortimg">
24
- <img src={d.image_url} />
25
- </div>
26
- );
27
- }
29
+ const imageUrl = d.image_url || d.file_url;
30
+ htmlContainer = imageUrl ? (
31
+ <div className="sortimg">
32
+ <img src={imageUrl} alt="" />
33
+ </div>
34
+ ) : (
35
+ <div className="sortimg">
36
+ {/* Placeholder image */}
37
+ <img src="data:image/png;base64,..." />
38
+ </div>
39
+ );
40
+ }
28
41
 
29
- if (d.hasOwnProperty('file_url') && d.file_url !== '') {
30
- htmlContainer = (
31
- <div className="sortimg">
32
- <img src={d.file_url} />
33
- </div>
34
- );
35
- }
42
+ return htmlContainer;
43
+ };
44
+
45
+ const renderEditButton = () => {
46
+ if (!handleEdit) return null;
36
47
 
37
- if (htmlContainer === '') {
38
- htmlContainer = (
39
- <div className="sortimg">
40
- <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEsAAABLCAYAAAA4TnrqAAACoUlEQVR4Xu3cO47CMBAAUNMhGiQ6qDkv5+Ac1BwBUUKHRIOgYteg7AaS+Ds/O0OFSPyZp/FEQZYn+/3+uVgszHQ6NfrpF7jf7+ZyuZjJ8Xh82i/r9drM53P1+hK4Xq/mcDgYm1CT0+n0nM1mrx8U7FOqgbIut9vtjbVcLk37gmaY6Xicz+d/LGuqYO/M6nPoYCnYcML0Yo0ZzLWyBrHGCOYrQU6sMYH5oKyFF2sMYCFQwVg1g4VCRWHVCBYDFY1VE1gsVBJWDWApUMlYJYOlQmVhlQiWA5WNVRJYLhQIVglgEFBgWJLBoKBAsSSCQUKBY0kCg4ZCwZIAhgGFhsUJhgWFisUBhgmFjkUJhg1FgkUBRgFFhoUJRgVFioUBRglFjgUJRg3FggUBxgHFhpUDxgXFipUCxgnFjhUDxg0lAisETAKUGCwXmBQoUVh9YJKgxGG1wezmOru3QNJOxKC9DjYIys/vTsQXlAVbrVaUQzvHEofVLD3NLE+OfNcorVkDYEMwksBELEMfiO86VVFjxwqFCL0PE44VKxYg9n5oODas1MBT20HAsWDlBpzbPhWOHAsqUKh+YuBIsaADhO7PB0eGhRUYVr99cCRY2AFh99/AoWNRBUIxDioWRQDt5YI9HhoW9sSHijHmuChYmBP2PbFC/tMP6YOkwHNDNUFizAM0szAmmJoFGBkGhiUNCiPDQLCkQkGDZWNJh4IEy8IqBQoKLBmrNCgIsCSsUqFywaKxSofKAYvCqgUqFSwYqzaoFLAgrFqhYsG8WLVDxYDpWTStl09fYgxi+RrmvOBKbuuKuxdrrFC+JdnBGjuUC+wDS6E+C8S3xx+WnibZraTb7dY8Hg+z2+3MZrN5nyap55S6HzlNhr3OKdUTcP3P5+YE3B/mgEymnzCGDgAAAABJRU5ErkJggg==" />
41
- </div>
42
- );
48
+ if (showImage) {
49
+ if (
50
+ value.hasOwnProperty('file_title') &&
51
+ value.hasOwnProperty('file_description')
52
+ ) {
53
+ return <EditButton />;
43
54
  }
55
+ return null;
44
56
  }
45
57
 
46
- return htmlContainer;
58
+ return <EditButton />;
47
59
  };
48
60
 
61
+ const EditButton = () => (
62
+ <Pencil
63
+ className="delete pencil-edit"
64
+ strokeWidth={1}
65
+ size={26}
66
+ onClick={(e) => {
67
+ e.preventDefault();
68
+ e.stopPropagation();
69
+ handleEdit(value);
70
+ }}
71
+ />
72
+ );
73
+
49
74
  return (
50
75
  <li
51
76
  onClick={(e) => {
52
77
  e.preventDefault();
53
-
54
78
  if (handleClick) {
55
79
  handleClick(containerIndex);
56
80
  }
57
81
  }}
58
82
  >
59
83
  <DragHandle />
60
- {value.label
61
- ? value.label
62
- : value.file_title
63
- ? value.file_title
64
- : value.file_name}
84
+ {truncateText(
85
+ value.label || value.file_title || value.file_name,
86
+ 50
87
+ )}
65
88
 
66
89
  {renderImage(value)}
67
90
 
68
- {handleEdit &&
69
- value.hasOwnProperty('file_title') &&
70
- value.hasOwnProperty('file_description') && (
71
- <Pencil
72
- className="delete pencil-edit"
73
- strokeWidth={1}
74
- size={26}
75
- onClick={(e) => {
76
- e.preventDefault();
77
- e.stopPropagation();
78
-
79
- handleEdit(value);
80
- }}
81
- />
82
- )}
91
+ {renderEditButton()}
83
92
 
84
93
  {handleDelete && (
85
94
  <TrashCan
@@ -89,10 +98,9 @@ const SortableItem = ({
89
98
  onClick={(e) => {
90
99
  e.preventDefault();
91
100
  e.stopPropagation();
92
-
93
101
  handleDelete(
94
- value.id ? value.id : containerIndex,
95
- value.label ? value.label : value.file_name
102
+ value.id || containerIndex,
103
+ value.label || value.file_name
96
104
  );
97
105
  }}
98
106
  />
package/package.json CHANGED
@@ -46,7 +46,7 @@
46
46
  "react-dom": "^17.0.1"
47
47
  },
48
48
  "name": "@visns-studio/visns-components",
49
- "version": "3.1.1",
49
+ "version": "3.1.3",
50
50
  "description": "Various packages to assist in the development of our Custom Applications.",
51
51
  "main": "index.js",
52
52
  "scripts": {