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

Enhance codebase with improved formatting, logic, and error handling #643

Merged
merged 1 commit into from
Feb 13, 2025
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
1 change: 1 addition & 0 deletions webapp/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/test/*
12 changes: 7 additions & 5 deletions webapp/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"parser": "@typescript-eslint/parser",
"ignorePatterns": [
"*.config.js",
"*.config.ts",
Expand All @@ -8,21 +9,22 @@
],
"extends": [
// "next/core-web-vitals",
"plugin:prettier/recommended"
// "plugin:prettier/recommended"
],
"parserOptions": {
"ecmaVersion": "latest"
"ecmaVersion": "latest",
"sourceType": "module",
"project": "./tsconfig.json"
},
"plugins": [
"simple-import-sort"
],
"rules": {
"simple-import-sort/imports": "error",
// "simple-import-sort/imports": "error",
"react-hooks/exhaustive-deps": "off",
"@next/next/no-img-element": "off",
"import/no-anonymous-default-export": "off",
"jsx-a11y/alt-text": "off",
"prettier/prettier": ["error", { "bracketSameLine": true }]
"jsx-a11y/alt-text": "off"

}
}
3 changes: 2 additions & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"dev:email": "email dev --dir ./src/emails",
"test:unit": "jest --verbose --testPathIgnorePatterns=./test/ --coverage",
"test:coverage": "jest --verbose --testPathIgnorePatterns=./test/ --collectCoverage --coverageReporters cobertura",
"test:integration": "jest --detectOpenHandles --testPathPattern=./test/"
"test:integration": "jest --detectOpenHandles --testPathPattern=./test/",
"format:tsx": "prettier --write \"src/**/*.tsx\""
},
"keywords": [],
"author": "RNA DIGITAL PTY LTD",
Expand Down
7 changes: 6 additions & 1 deletion webapp/src/components/AgentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,12 @@ export default function AgentForm({
Avatar
</label>
<div className='mt-2'>
<AvatarUploader existingAvatar={icon} callback={iconCallback} />
<AvatarUploader
existingAvatar={icon}
callback={iconCallback}
isDialogOpen={false}
setIsDialogOpen={() => {}}
/>
</div>
</div>
</div>
Expand Down
33 changes: 21 additions & 12 deletions webapp/src/components/AgentList2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ const DeleteDialog = ({
onDelete: () => void;
}) => {
return (
<Dialog
open={openDeleteDialog}
onOpenChange={(open) => {
<Dialog
open={openDeleteDialog}
onOpenChange={open => {
setOpenDeleteDialog(open);
if (!open) {
// Reset focus and state when dialog closes
document.body.style.pointerEvents = 'auto';
}
}}
>
<DialogContent
<DialogContent
onPointerDownOutside={() => {
setOpenDeleteDialog(false);
document.body.style.pointerEvents = 'auto';
Expand Down Expand Up @@ -91,7 +91,7 @@ const DeleteDialog = ({
</DialogDescription>
</DialogHeader>
<DialogFooter className='flex items-center justify-center gap-6 mx-auto mt-4'>
<Button
<Button
onClick={() => {
setOpenDeleteDialog(false);
document.body.style.pointerEvents = 'auto';
Expand All @@ -100,7 +100,7 @@ const DeleteDialog = ({
>
Cancel
</Button>
<Button
<Button
onClick={() => {
onDelete();
setOpenDeleteDialog(false);
Expand Down Expand Up @@ -143,7 +143,7 @@ export default function AgentList2({ agents, fetchAgents }) {

async function deleteAgent(agentId) {
if (!agentId) return;

API.deleteAgent(
{
_csrf: csrf,
Expand All @@ -155,7 +155,7 @@ export default function AgentList2({ agents, fetchAgents }) {
toast.success('Agent deleted successfully');
setSelectedAgentId(null);
},
(error) => {
error => {
toast.error(error || 'Error deleting agent');
setSelectedAgentId(null);
},
Expand All @@ -165,7 +165,11 @@ export default function AgentList2({ agents, fetchAgents }) {

return (
<>
<DeleteDialog openDeleteDialog={openDeleteDialog} setOpenDeleteDialog={setOpenDeleteDialog} onDelete={() => deleteAgent(selectedAgentId)} />
<DeleteDialog
openDeleteDialog={openDeleteDialog}
setOpenDeleteDialog={setOpenDeleteDialog}
onDelete={() => deleteAgent(selectedAgentId)}
/>
<main className='text-foreground flex flex-col gap-2'>
<section className='flex items-center justify-between mb-4'>
<h4 className='text-gray-900 font-semibold text-2xl'>Agents</h4>
Expand All @@ -182,7 +186,8 @@ export default function AgentList2({ agents, fetchAgents }) {
<Button
onClick={() => setOpenNewAgentSheet(true)}
asChild
className='flex items-center gap-2 bg-gradient-to-r from-[#4F46E5] to-[#612D89] text-white py-2.5 px-4 rounded-lg cursor-pointer'>
className='flex items-center gap-2 bg-gradient-to-r from-[#4F46E5] to-[#612D89] text-white py-2.5 px-4 rounded-lg cursor-pointer'
>
<div>
<CirclePlus width={10.5} />
<p className='font-semibold text-sm'>New Agent</p>
Expand All @@ -192,6 +197,7 @@ export default function AgentList2({ agents, fetchAgents }) {
</section>
{agents.length <= 0 ? (
<CreateAgentSheet
//@ts-ignore
setAgentDisplay={setAgentDisplay}
openEditSheet={openEditSheet}
setOpenEditSheet={setOpenEditSheet}
Expand All @@ -206,7 +212,8 @@ export default function AgentList2({ agents, fetchAgents }) {
return (
<Card
key={agent.id}
className='rounded-2xl gap-[21px] flex flex-col border-0 shadow-none lg:border lg:border-gray-200 max-h-80 overflow-auto'>
className='rounded-2xl gap-[21px] flex flex-col border-0 shadow-none lg:border lg:border-gray-200 max-h-80 overflow-auto'
>
<CardHeader>
<CardTitle>
<div className='flex flex-col gap-2'>
Expand All @@ -222,7 +229,8 @@ export default function AgentList2({ agents, fetchAgents }) {
onClick={() => {
setSelectedAgentId(agent._id);
setOpenDeleteDialog(true);
}}>
}}
>
Delete
</DropdownMenuItem>
<DropdownMenuItem onClick={() => alert('Pin action triggered')}>
Expand Down Expand Up @@ -305,6 +313,7 @@ export default function AgentList2({ agents, fetchAgents }) {
</main>

<NewAgentSheet
//@ts-ignore
setAgentDisplay={setAgentDisplay}
openEditSheet={openNewAgentSheet}
setOpenEditSheet={setOpenNewAgentSheet}
Expand Down
27 changes: 18 additions & 9 deletions webapp/src/components/ApiKeyList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,31 +121,36 @@ export default function ApiKeyList({ keys, fetchKeys }: { keys: any[]; fetchKeys
<tr>
<th
scope='col'
className='w-min px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider dark:text-gray-50'>
className='w-min px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider dark:text-gray-50'
>
Name
</th>
<th
scope='col'
className='w-min px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider dark:text-gray-50'>
className='w-min px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider dark:text-gray-50'
>
Description
</th>

<th
scope='col'
className='w-min px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider dark:text-gray-50'>
className='w-min px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider dark:text-gray-50'
>
Token
</th>
<th
scope='col'
className='w-min px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider dark:text-gray-50'>
className='w-min px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider dark:text-gray-50'
>
Expiry
</th>

{/* Add more columns as necessary */}

<th
scope='col'
className='w-min px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider dark:text-gray-50'>
className='w-min px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider dark:text-gray-50'
>
Actions
</th>
</tr>
Expand All @@ -167,7 +172,8 @@ export default function ApiKeyList({ keys, fetchKeys }: { keys: any[]; fetchKeys
? 'bg-red-400'
: 'hover:bg-gray-50 dark:hover:bg-gray-500 dark:text-gray-50'
)}
style={{ borderColor: deletingMap[key._id] ? 'red' : '' }}>
style={{ borderColor: deletingMap[key._id] ? 'red' : '' }}
>
<td className={'px-6 py-4 whitespace-nowrap'} onClick={() => router.push(``)}>
<div className='text-sm text-gray-900 dark:text-white'>{key.name}</div>
</td>
Expand All @@ -178,7 +184,8 @@ export default function ApiKeyList({ keys, fetchKeys }: { keys: any[]; fetchKeys
</td>
<td
className='px-6 py-4 whitespace-nowrap'
onClick={() => handleCopyClick(key?.token)}>
onClick={() => handleCopyClick(key?.token)}
>
<div className='text-sm max-w-36 text-gray-900 dark:text-white truncate hover:text-blue-600 hover:underline cursor-pointer'>
{key?.token}
</div>
Expand All @@ -195,7 +202,8 @@ export default function ApiKeyList({ keys, fetchKeys }: { keys: any[]; fetchKeys
setRegeneratingKey(key);
setRegenerateOpen(true);
}}
className='text-gray-900 hover:text-gray-400'>
className='text-gray-900 hover:text-gray-400'
>
<ArrowPathIcon className='h-5 w-5' aria-hidden='true' />
</button>

Expand All @@ -208,7 +216,8 @@ export default function ApiKeyList({ keys, fetchKeys }: { keys: any[]; fetchKeys
setDeleteOpen(true);
}}
className='text-red-500 hover:text-red-700'
data-tooltip-target='delete-tooltip'>
data-tooltip-target='delete-tooltip'
>
<TrashIcon className='h-5 w-5' aria-hidden='true' />
</button>
</>
Expand Down
12 changes: 9 additions & 3 deletions webapp/src/components/AvatarUploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import React, { useCallback, useEffect, useRef, useState } from 'react';
import { useDropzone } from 'react-dropzone';
import { toast } from 'react-toastify';

export default function AvatarUploader({ callback, existingAvatar, isDialogOpen, setIsDialogOpen }) { // add isOpen prop
export default function AvatarUploader({
callback,
existingAvatar,
isDialogOpen,
setIsDialogOpen
}) {
// add isOpen prop
const [files, setFiles] = useState([]);
const [uploading, setUploading] = useState(false);
const [error, setError] = useState(null);
Expand Down Expand Up @@ -115,8 +121,8 @@ export default function AvatarUploader({ callback, existingAvatar, isDialogOpen,
) : files?.length > 0 ? (
<img
src={files[0].preview}
className="h-full w-full object-cover"
alt="Avatar preview"
className='h-full w-full object-cover'
alt='Avatar preview'
/>
) : files?.length === 0 ? (
<CameraIcon className='h-full transition-all hover:stroke-gray-600 stroke-gray-400 w-8 inline-flex align-center justify-center' />
Expand Down
Loading
Loading