Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide edit details when you don't own the publisher/node/version. #8

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions components/nodes/NodeDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import nodesLogo from '../../public/images/nodesLogo.svg'
import NodeVDrawer from './NodeVDrawer'
import Link from 'next/link'
import { NodeEditModal } from './NodeEditModal'
import { NodeVersion, useGetNode, useListNodeVersions } from 'src/api/generated'
import {
NodeVersion,
useGetNode,
useGetPermissionOnPublisherNodes,
useListNodeVersions,
useListNodesForPublisher,
useListPublishersForUser,
} from 'src/api/generated'
import CopyableCodeBlock from '../CodeBlock/CodeBlock'

export function formatRelativeDate(dateString: string) {
Expand Down Expand Up @@ -40,6 +47,10 @@ const NodeDetails = () => {
const [selectedVersion, setSelectedVersion] = useState<NodeVersion | null>(
null
)
const { data: permissions } = useGetPermissionOnPublisherNodes(
publisherId as string,
nodeId as string
)
const [openEditModal, setIsEditModal] = useState(false)
const { data, isLoading, isError } = useGetNode(nodeId as string)
const {
Expand Down Expand Up @@ -245,7 +256,7 @@ const NodeDetails = () => {
</Link>
</Button>

{publisherId && (
{permissions?.canEdit && (
<Button
className="flex-shrink-0 px-4 flex items-center text-white bg-gray-700 rounded whitespace-nowrap text-[16px]"
onClick={handleOpenModal}
Expand Down Expand Up @@ -293,6 +304,7 @@ const NodeDetails = () => {
isDrawerOpen={isDrawerOpen}
nodeId={nodeId as string}
publisherId={publisherId as string}
canEdit={permissions?.canEdit}
/>
)}
</div>
Expand Down
12 changes: 11 additions & 1 deletion components/nodes/NodeVDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import React, { useState } from 'react'
import { NodeVersion, useUpdateNodeVersion } from 'src/api/generated'
import { formatRelativeDate } from './NodeDetails'
import { toast } from 'react-toastify'
import { Button } from 'flowbite-react'
type NodeVDrawerProps = {
version: NodeVersion
isDrawerOpen: boolean
toggleDrawer: () => void
publisherId?: string // Means don't deprecate version.
canEdit?: boolean
nodeId: string
}

Expand All @@ -16,6 +18,7 @@ const NodeVDrawer: React.FC<NodeVDrawerProps> = ({
version,
isDrawerOpen,
toggleDrawer,
canEdit = false,
}) => {
const [isVersionAvailable, setIsVersionAvailable] = useState(true)
const updateNodeVersionMutation = useUpdateNodeVersion()
Expand Down Expand Up @@ -103,6 +106,13 @@ const NodeVDrawer: React.FC<NodeVDrawerProps> = ({
Released {formatRelativeDate(version.createdAt)}
</p>
)}
{version.downloadUrl && (
<Button className="flex-shrink-0 px-4 text-white bg-blue-500 rounded whitespace-nowrap text-[16px] mt-5">
<a href={version.downloadUrl}>
Download Version {version.version}
</a>
</Button>
)}
<hr className="h-px my-8 bg-gray-700 border-0"></hr>

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

{publisherId && (
{canEdit && (
<div className="flex items-center py-4 rounded-lg">
<label className="inline-flex items-center mb-5 cursor-pointer">
<input
Expand Down
104 changes: 58 additions & 46 deletions components/publisher/PublisherDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CreateSecretKeyModal } from '../AccessTokens/CreateSecretKeyModal'
import {
Publisher,
useDeletePersonalAccessToken,
useGetPermissionOnPublisher,
useListNodesForPublisher,
useListPersonalAccessTokens,
useUpdatePublisher,
Expand All @@ -27,6 +28,9 @@ const PublisherDetail: React.FC<PublisherDetailProps> = ({ publisher }) => {
refetch: refetchTokens,
} = useListPersonalAccessTokens(publisher.id as string)
const { data: nodes } = useListNodesForPublisher(publisher.id as string)
const { data: permissions } = useGetPermissionOnPublisher(
publisher.id as string
)
const [openSecretKeyModal, setOpenSecretKeyModal] = useState(false)
const [openEditModal, setOpenEditModal] = useState(false)

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

if (error || publisher === undefined || publisher.id === undefined) {
return <div className="container p-6 mx-auto h-[90vh]">Not Found</div>
return (
<div className="container p-6 mx-auto h-[90vh] text-white">
Not Found
</div>
)
}

return (
Expand Down Expand Up @@ -104,31 +112,33 @@ const PublisherDetail: React.FC<PublisherDetailProps> = ({ publisher }) => {
<h1 className="mb-4 text-5xl font-bold text-white">
{publisher.name}
</h1>
<Button
size="xs"
className="h-8 p-2 px-4 font-bold text-white bg-blue-500 rounded hover:bg-blue-600"
color="blue"
onClick={handleEditButtonClick}
>
<svg
className="w-5 h-5 text-white"
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
fill="none"
viewBox="0 0 24 24"
{permissions?.canEdit && (
<Button
size="xs"
className="h-8 p-2 px-4 font-bold text-white bg-blue-500 rounded hover:bg-blue-600"
color="blue"
onClick={handleEditButtonClick}
>
<path
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
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"
/>
</svg>
<span className="text-[10px]">Edit details</span>
</Button>
<svg
className="w-5 h-5 text-white"
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
fill="none"
viewBox="0 0 24 24"
>
<path
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
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"
/>
</svg>
<span className="text-[10px]">Edit details</span>
</Button>
)}
</div>
<p className="text-gray-400">@{publisher.id}</p>
<div className="flex flex-col my-4 ">
Expand Down Expand Up @@ -175,28 +185,30 @@ const PublisherDetail: React.FC<PublisherDetailProps> = ({ publisher }) => {
</p>
)}
</div>
<PersonalAccessTokenTable
handleCreateButtonClick={handleCreateButtonClick}
accessTokens={personalAccessTokens || []}
isLoading={isLoadingAccessTokens}
deleteToken={(tokenId: string) =>
deleteTokenMutation.mutate(
{
publisherId: publisher.id as string,
tokenId: tokenId,
},
{
onError: (error) => {
toast.error('Failed to delete token')
{permissions?.canEdit && (
<PersonalAccessTokenTable
handleCreateButtonClick={handleCreateButtonClick}
accessTokens={personalAccessTokens || []}
isLoading={isLoadingAccessTokens}
deleteToken={(tokenId: string) =>
deleteTokenMutation.mutate(
{
publisherId: publisher.id as string,
tokenId: tokenId,
},
onSuccess: () => {
toast.success('Token deleted')
refetchTokens()
},
}
)
}
/>
{
onError: (error) => {
toast.error('Failed to delete token')
},
onSuccess: () => {
toast.success('Token deleted')
refetchTokens()
},
}
)
}
/>
)}
</div>
<CreateSecretKeyModal
publisherId={publisher.id}
Expand Down
Loading
Loading