@@ -7,107 +7,111 @@ import { Tooltip, TOAST_TYPE, setToast } from "@plane/ui";
7
7
// helpers
8
8
import { calculateTimeAgo } from "@/helpers/date-time.helper" ;
9
9
// hooks
10
- import { useMember } from "@/hooks/store" ;
10
+ import { useMember , useModule } from "@/hooks/store" ;
11
11
import { usePlatformOS } from "@/hooks/use-platform-os" ;
12
12
// types
13
13
14
14
type Props = {
15
- links : ILinkDetails [ ] ;
15
+ moduleId : string ;
16
+
16
17
handleDeleteLink : ( linkId : string ) => void ;
17
18
handleEditLink : ( link : ILinkDetails ) => void ;
18
19
userAuth : UserAuth ;
19
20
disabled ?: boolean ;
20
21
} ;
21
22
22
- export const LinksList : React . FC < Props > = observer (
23
- ( { links, handleDeleteLink, handleEditLink, userAuth, disabled } ) => {
24
- const { getUserDetails } = useMember ( ) ;
25
- const { isMobile } = usePlatformOS ( ) ;
26
- const isNotAllowed = userAuth . isGuest || userAuth . isViewer || disabled ;
23
+ export const LinksList : React . FC < Props > = observer ( ( props ) => {
24
+ const { moduleId, handleDeleteLink, handleEditLink, userAuth, disabled } = props ;
25
+ // hooks
26
+ const { getUserDetails } = useMember ( ) ;
27
+ const { isMobile } = usePlatformOS ( ) ;
28
+ const { getModuleById } = useModule ( ) ;
29
+ // derived values
30
+ const currentModule = getModuleById ( moduleId ) ;
31
+ const moduleLinks = currentModule ?. link_module || undefined ;
32
+ const isNotAllowed = userAuth . isGuest || userAuth . isViewer || disabled ;
27
33
28
- const copyToClipboard = ( text : string ) => {
29
- navigator . clipboard . writeText ( text ) ;
30
- setToast ( {
31
- type : TOAST_TYPE . SUCCESS ,
32
- title : "Copied to clipboard" ,
33
- message : "The URL has been successfully copied to your clipboard" ,
34
- } ) ;
35
- } ;
34
+ const copyToClipboard = ( text : string ) => {
35
+ navigator . clipboard . writeText ( text ) ;
36
+ setToast ( {
37
+ type : TOAST_TYPE . SUCCESS ,
38
+ title : "Copied to clipboard" ,
39
+ message : "The URL has been successfully copied to your clipboard" ,
40
+ } ) ;
41
+ } ;
36
42
37
- return (
38
- < >
39
- { links . map ( ( link ) => {
40
- const createdByDetails = getUserDetails ( link . created_by ) ;
41
- return (
42
- < div key = { link . id } className = "relative flex flex-col rounded-md bg-custom-background-90 p-2.5" >
43
- < div className = "flex w-full items-start justify-between gap-2" >
44
- < div className = "flex items-start gap-2 truncate" >
45
- < span className = "py-1" >
46
- < LinkIcon className = "h-3 w-3 flex-shrink-0" />
43
+ if ( ! moduleLinks ) return < > </ > ;
44
+ return (
45
+ < >
46
+ { moduleLinks . map ( ( link ) => {
47
+ const createdByDetails = getUserDetails ( link . created_by ) ;
48
+ return (
49
+ < div key = { link . id } className = "relative flex flex-col rounded-md bg-custom-background-90 p-2.5" >
50
+ < div className = "flex w-full items-start justify-between gap-2" >
51
+ < div className = "flex items-start gap-2 truncate" >
52
+ < span className = "py-1" >
53
+ < LinkIcon className = "h-3 w-3 flex-shrink-0" />
54
+ </ span >
55
+ < Tooltip tooltipContent = { link . title && link . title !== "" ? link . title : link . url } isMobile = { isMobile } >
56
+ < span
57
+ className = "cursor-pointer truncate text-xs"
58
+ onClick = { ( ) => copyToClipboard ( link . title && link . title !== "" ? link . title : link . url ) }
59
+ >
60
+ { link . title && link . title !== "" ? link . title : link . url }
47
61
</ span >
48
- < Tooltip tooltipContent = { link . title && link . title !== "" ? link . title : link . url } isMobile = { isMobile } >
49
- < span
50
- className = "cursor-pointer truncate text-xs"
51
- onClick = { ( ) => copyToClipboard ( link . title && link . title !== "" ? link . title : link . url ) }
52
- >
53
- { link . title && link . title !== "" ? link . title : link . url }
54
- </ span >
55
- </ Tooltip >
56
- </ div >
62
+ </ Tooltip >
63
+ </ div >
57
64
58
- { ! isNotAllowed && (
59
- < div className = "z-[1] flex flex-shrink-0 items-center gap-2" >
60
- < button
61
- type = "button"
62
- className = "flex items-center justify-center p-1 hover:bg-custom-background-80"
63
- onClick = { ( e ) => {
64
- e . preventDefault ( ) ;
65
- e . stopPropagation ( ) ;
66
- handleEditLink ( link ) ;
67
- } }
68
- >
69
- < Pencil className = "h-3 w-3 stroke-[1.5] text-custom-text-200" />
70
- </ button >
71
- < a
72
- href = { link . url }
73
- target = "_blank"
74
- rel = "noopener noreferrer"
75
- className = "flex items-center justify-center p-1 hover:bg-custom-background-80"
76
- >
77
- < ExternalLink className = "h-3 w-3 stroke-[1.5] text-custom-text-200" />
78
- </ a >
79
- < button
80
- type = "button"
81
- className = "flex items-center justify-center p-1 hover:bg-custom-background-80"
82
- onClick = { ( e ) => {
83
- e . preventDefault ( ) ;
84
- e . stopPropagation ( ) ;
85
- handleDeleteLink ( link . id ) ;
86
- } }
87
- >
88
- < Trash2 className = "h-3 w-3" />
89
- </ button >
90
- </ div >
65
+ { ! isNotAllowed && (
66
+ < div className = "z-[1] flex flex-shrink-0 items-center gap-2" >
67
+ < button
68
+ type = "button"
69
+ className = "flex items-center justify-center p-1 hover:bg-custom-background-80"
70
+ onClick = { ( e ) => {
71
+ e . preventDefault ( ) ;
72
+ e . stopPropagation ( ) ;
73
+ handleEditLink ( link ) ;
74
+ } }
75
+ >
76
+ < Pencil className = "h-3 w-3 stroke-[1.5] text-custom-text-200" />
77
+ </ button >
78
+ < a
79
+ href = { link . url }
80
+ target = "_blank"
81
+ rel = "noopener noreferrer"
82
+ className = "flex items-center justify-center p-1 hover:bg-custom-background-80"
83
+ >
84
+ < ExternalLink className = "h-3 w-3 stroke-[1.5] text-custom-text-200" />
85
+ </ a >
86
+ < button
87
+ type = "button"
88
+ className = "flex items-center justify-center p-1 hover:bg-custom-background-80"
89
+ onClick = { ( e ) => {
90
+ e . preventDefault ( ) ;
91
+ e . stopPropagation ( ) ;
92
+ handleDeleteLink ( link . id ) ;
93
+ } }
94
+ >
95
+ < Trash2 className = "h-3 w-3" />
96
+ </ button >
97
+ </ div >
98
+ ) }
99
+ </ div >
100
+ < div className = "px-5" >
101
+ < p className = "mt-0.5 stroke-[1.5] text-xs text-custom-text-300" >
102
+ Added { calculateTimeAgo ( link . created_at ) }
103
+ < br />
104
+ { createdByDetails && (
105
+ < >
106
+ by{ " " }
107
+ { createdByDetails ?. is_bot ? createdByDetails ?. first_name + " Bot" : createdByDetails ?. display_name }
108
+ </ >
91
109
) }
92
- </ div >
93
- < div className = "px-5" >
94
- < p className = "mt-0.5 stroke-[1.5] text-xs text-custom-text-300" >
95
- Added { calculateTimeAgo ( link . created_at ) }
96
- < br />
97
- { createdByDetails && (
98
- < >
99
- by{ " " }
100
- { createdByDetails ?. is_bot
101
- ? createdByDetails ?. first_name + " Bot"
102
- : createdByDetails ?. display_name }
103
- </ >
104
- ) }
105
- </ p >
106
- </ div >
110
+ </ p >
107
111
</ div >
108
- ) ;
109
- } ) }
110
- </ >
111
- ) ;
112
- }
113
- ) ;
112
+ </ div >
113
+ ) ;
114
+ } ) }
115
+ </ >
116
+ ) ;
117
+ } ) ;
0 commit comments