Skip to content

Commit aa4abef

Browse files
authored
Hide edit details when you don't own the publisher/node/version. (#8)
* Hide edit details when you don't own the publisher/node. * Add can edit for Node versions as well.
1 parent c122ffa commit aa4abef

File tree

4 files changed

+290
-112
lines changed

4 files changed

+290
-112
lines changed

components/nodes/NodeDetails.tsx

+14-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ import nodesLogo from '../../public/images/nodesLogo.svg'
66
import NodeVDrawer from './NodeVDrawer'
77
import Link from 'next/link'
88
import { NodeEditModal } from './NodeEditModal'
9-
import { NodeVersion, useGetNode, useListNodeVersions } from 'src/api/generated'
9+
import {
10+
NodeVersion,
11+
useGetNode,
12+
useGetPermissionOnPublisherNodes,
13+
useListNodeVersions,
14+
useListNodesForPublisher,
15+
useListPublishersForUser,
16+
} from 'src/api/generated'
1017
import CopyableCodeBlock from '../CodeBlock/CodeBlock'
1118

1219
export function formatRelativeDate(dateString: string) {
@@ -40,6 +47,10 @@ const NodeDetails = () => {
4047
const [selectedVersion, setSelectedVersion] = useState<NodeVersion | null>(
4148
null
4249
)
50+
const { data: permissions } = useGetPermissionOnPublisherNodes(
51+
publisherId as string,
52+
nodeId as string
53+
)
4354
const [openEditModal, setIsEditModal] = useState(false)
4455
const { data, isLoading, isError } = useGetNode(nodeId as string)
4556
const {
@@ -245,7 +256,7 @@ const NodeDetails = () => {
245256
</Link>
246257
</Button>
247258

248-
{publisherId && (
259+
{permissions?.canEdit && (
249260
<Button
250261
className="flex-shrink-0 px-4 flex items-center text-white bg-gray-700 rounded whitespace-nowrap text-[16px]"
251262
onClick={handleOpenModal}
@@ -293,6 +304,7 @@ const NodeDetails = () => {
293304
isDrawerOpen={isDrawerOpen}
294305
nodeId={nodeId as string}
295306
publisherId={publisherId as string}
307+
canEdit={permissions?.canEdit}
296308
/>
297309
)}
298310
</div>

components/nodes/NodeVDrawer.tsx

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import React, { useState } from 'react'
22
import { NodeVersion, useUpdateNodeVersion } from 'src/api/generated'
33
import { formatRelativeDate } from './NodeDetails'
44
import { toast } from 'react-toastify'
5+
import { Button } from 'flowbite-react'
56
type NodeVDrawerProps = {
67
version: NodeVersion
78
isDrawerOpen: boolean
89
toggleDrawer: () => void
910
publisherId?: string // Means don't deprecate version.
11+
canEdit?: boolean
1012
nodeId: string
1113
}
1214

@@ -16,6 +18,7 @@ const NodeVDrawer: React.FC<NodeVDrawerProps> = ({
1618
version,
1719
isDrawerOpen,
1820
toggleDrawer,
21+
canEdit = false,
1922
}) => {
2023
const [isVersionAvailable, setIsVersionAvailable] = useState(true)
2124
const updateNodeVersionMutation = useUpdateNodeVersion()
@@ -103,6 +106,13 @@ const NodeVDrawer: React.FC<NodeVDrawerProps> = ({
103106
Released {formatRelativeDate(version.createdAt)}
104107
</p>
105108
)}
109+
{version.downloadUrl && (
110+
<Button className="flex-shrink-0 px-4 text-white bg-blue-500 rounded whitespace-nowrap text-[16px] mt-5">
111+
<a href={version.downloadUrl}>
112+
Download Version {version.version}
113+
</a>
114+
</Button>
115+
)}
106116
<hr className="h-px my-8 bg-gray-700 border-0"></hr>
107117

108118
<div className="space-y-4">
@@ -116,7 +126,7 @@ const NodeVDrawer: React.FC<NodeVDrawerProps> = ({
116126
<hr className="h-px my-8 bg-gray-700 border-0"></hr>
117127
</div>
118128

119-
{publisherId && (
129+
{canEdit && (
120130
<div className="flex items-center py-4 rounded-lg">
121131
<label className="inline-flex items-center mb-5 cursor-pointer">
122132
<input

components/publisher/PublisherDetail.tsx

+58-46
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { CreateSecretKeyModal } from '../AccessTokens/CreateSecretKeyModal'
55
import {
66
Publisher,
77
useDeletePersonalAccessToken,
8+
useGetPermissionOnPublisher,
89
useListNodesForPublisher,
910
useListPersonalAccessTokens,
1011
useUpdatePublisher,
@@ -27,6 +28,9 @@ const PublisherDetail: React.FC<PublisherDetailProps> = ({ publisher }) => {
2728
refetch: refetchTokens,
2829
} = useListPersonalAccessTokens(publisher.id as string)
2930
const { data: nodes } = useListNodesForPublisher(publisher.id as string)
31+
const { data: permissions } = useGetPermissionOnPublisher(
32+
publisher.id as string
33+
)
3034
const [openSecretKeyModal, setOpenSecretKeyModal] = useState(false)
3135
const [openEditModal, setOpenEditModal] = useState(false)
3236

@@ -68,7 +72,11 @@ const PublisherDetail: React.FC<PublisherDetailProps> = ({ publisher }) => {
6872
const oneMemberOfPublisher = getFirstMemberName(publisher)
6973

7074
if (error || publisher === undefined || publisher.id === undefined) {
71-
return <div className="container p-6 mx-auto h-[90vh]">Not Found</div>
75+
return (
76+
<div className="container p-6 mx-auto h-[90vh] text-white">
77+
Not Found
78+
</div>
79+
)
7280
}
7381

7482
return (
@@ -104,31 +112,33 @@ const PublisherDetail: React.FC<PublisherDetailProps> = ({ publisher }) => {
104112
<h1 className="mb-4 text-5xl font-bold text-white">
105113
{publisher.name}
106114
</h1>
107-
<Button
108-
size="xs"
109-
className="h-8 p-2 px-4 font-bold text-white bg-blue-500 rounded hover:bg-blue-600"
110-
color="blue"
111-
onClick={handleEditButtonClick}
112-
>
113-
<svg
114-
className="w-5 h-5 text-white"
115-
aria-hidden="true"
116-
xmlns="http://www.w3.org/2000/svg"
117-
width="24"
118-
height="24"
119-
fill="none"
120-
viewBox="0 0 24 24"
115+
{permissions?.canEdit && (
116+
<Button
117+
size="xs"
118+
className="h-8 p-2 px-4 font-bold text-white bg-blue-500 rounded hover:bg-blue-600"
119+
color="blue"
120+
onClick={handleEditButtonClick}
121121
>
122-
<path
123-
stroke="currentColor"
124-
stroke-linecap="round"
125-
stroke-linejoin="round"
126-
stroke-width="2"
127-
d="m14.304 4.844 2.852 2.852M7 7H4a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h11a1 1 0 0 0 1-1v-4.5m2.409-9.91a2.017 2.017 0 0 1 0 2.853l-6.844 6.844L8 14l.713-3.565 6.844-6.844a2.015 2.015 0 0 1 2.852 0Z"
128-
/>
129-
</svg>
130-
<span className="text-[10px]">Edit details</span>
131-
</Button>
122+
<svg
123+
className="w-5 h-5 text-white"
124+
aria-hidden="true"
125+
xmlns="http://www.w3.org/2000/svg"
126+
width="24"
127+
height="24"
128+
fill="none"
129+
viewBox="0 0 24 24"
130+
>
131+
<path
132+
stroke="currentColor"
133+
stroke-linecap="round"
134+
stroke-linejoin="round"
135+
stroke-width="2"
136+
d="m14.304 4.844 2.852 2.852M7 7H4a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h11a1 1 0 0 0 1-1v-4.5m2.409-9.91a2.017 2.017 0 0 1 0 2.853l-6.844 6.844L8 14l.713-3.565 6.844-6.844a2.015 2.015 0 0 1 2.852 0Z"
137+
/>
138+
</svg>
139+
<span className="text-[10px]">Edit details</span>
140+
</Button>
141+
)}
132142
</div>
133143
<p className="text-gray-400">@{publisher.id}</p>
134144
<div className="flex flex-col my-4 ">
@@ -175,28 +185,30 @@ const PublisherDetail: React.FC<PublisherDetailProps> = ({ publisher }) => {
175185
</p>
176186
)}
177187
</div>
178-
<PersonalAccessTokenTable
179-
handleCreateButtonClick={handleCreateButtonClick}
180-
accessTokens={personalAccessTokens || []}
181-
isLoading={isLoadingAccessTokens}
182-
deleteToken={(tokenId: string) =>
183-
deleteTokenMutation.mutate(
184-
{
185-
publisherId: publisher.id as string,
186-
tokenId: tokenId,
187-
},
188-
{
189-
onError: (error) => {
190-
toast.error('Failed to delete token')
188+
{permissions?.canEdit && (
189+
<PersonalAccessTokenTable
190+
handleCreateButtonClick={handleCreateButtonClick}
191+
accessTokens={personalAccessTokens || []}
192+
isLoading={isLoadingAccessTokens}
193+
deleteToken={(tokenId: string) =>
194+
deleteTokenMutation.mutate(
195+
{
196+
publisherId: publisher.id as string,
197+
tokenId: tokenId,
191198
},
192-
onSuccess: () => {
193-
toast.success('Token deleted')
194-
refetchTokens()
195-
},
196-
}
197-
)
198-
}
199-
/>
199+
{
200+
onError: (error) => {
201+
toast.error('Failed to delete token')
202+
},
203+
onSuccess: () => {
204+
toast.success('Token deleted')
205+
refetchTokens()
206+
},
207+
}
208+
)
209+
}
210+
/>
211+
)}
200212
</div>
201213
<CreateSecretKeyModal
202214
publisherId={publisher.id}

0 commit comments

Comments
 (0)