Skip to content

Commit

Permalink
feat: agent management refactor & layout changes (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat authored Aug 24, 2023
1 parent b695c6f commit c7d0214
Show file tree
Hide file tree
Showing 16 changed files with 539 additions and 559 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
},
"devDependencies": {
"@ant-design/icons": "^5.1.4",
"@ant-design/pro-components": "^2.5.3",
"@ant-design/pro-components": "^2.6.13",
"@babel/plugin-syntax-import-assertions": "^7.20.0",
"@babel/preset-react": "^7.22.5",
"@commitlint/cli": "^17.6.5",
Expand Down Expand Up @@ -169,7 +169,7 @@
"@web3-react/types": "^8.2.0",
"@web3-react/walletconnect": "^8.2.0",
"@yudiel/react-qr-scanner": "^1.1.8",
"antd": "~5.5.2",
"antd": "~5.8.4",
"assert": "npm:assert-browserify@^2.0.0",
"browserify-zlib": "^0.2.0",
"buffer": "^6.0.3",
Expand Down
698 changes: 367 additions & 331 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

23 changes: 5 additions & 18 deletions src/components/AgentDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,22 @@ import { Dropdown } from 'antd'
import React from 'react'
import { useVeramo } from '@veramo-community/veramo-react'
import { useNavigate } from 'react-router-dom'
import { CheckCircleOutlined } from '@ant-design/icons'

const AgentDropdown: React.FC<{ children: React.ReactNode }> = ({
children,
}) => {
const { agents, setActiveAgentId, activeAgentId } = useVeramo()
const navigate = useNavigate()

return (
<Dropdown

menu={{
selectedKeys: activeAgentId ? [activeAgentId] : [],
items: [
...agents.map((_agent: any, index: number) => {
...agents.map((_agent: any) => {
return {
key: index,
key: _agent.context?.id,
onClick: () => setActiveAgentId(_agent.context?.id),
icon: (
<CheckCircleOutlined
style={{
fontSize: '17px',
opacity: _agent.context?.id === activeAgentId ? 1 : 0.1,
}}
/>
),
label: _agent.context?.name,
}
}),
Expand All @@ -34,12 +26,7 @@ const AgentDropdown: React.FC<{ children: React.ReactNode }> = ({
{
key: 'manage',
label: 'Magage',
onClick: () => navigate('/agents'),
},
{
key: 'connect',
label: 'Connect',
onClick: () => navigate('/connect'),
onClick: () => navigate('/settings/agents'),
},
],
],
Expand Down
8 changes: 4 additions & 4 deletions src/components/CreateRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { CaretDownOutlined, CaretRightOutlined } from '@ant-design/icons'
import { v4 as uuidv4 } from 'uuid'
import DIDDiscoveryBar from './DIDDiscoveryBar'

interface CreateRequestProps {}


interface SDRArgs {
issuer: string
Expand All @@ -24,7 +24,7 @@ interface AddClaimArgs {
reason?: string
}

const CreateRequest: React.FC<CreateRequestProps> = () => {
const CreateRequest: React.FC = () => {
const { agent } = useVeramo()
const query = useQueryClient()
const [subject, setSubject] = useState<string>('')
Expand Down Expand Up @@ -208,7 +208,7 @@ const CreateRequest: React.FC<CreateRequestProps> = () => {
</Form.Item>
</Row>
<Button
type="ghost"

disabled={!requiredIssuer}
onClick={() =>
addRequiredIssuer(requiredIssuer, requiredIssuerUrl)
Expand All @@ -218,7 +218,7 @@ const CreateRequest: React.FC<CreateRequestProps> = () => {
</Button>
</Card>
<Button
type="ghost"

disabled={!claimType}
onClick={() =>
addClaim({
Expand Down
3 changes: 2 additions & 1 deletion src/components/CredentialActionsDropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dropdown, notification } from 'antd'
import { Dropdown, App } from 'antd'
import React from 'react'
import { useVeramo } from '@veramo-community/veramo-react'
import { useNavigate } from 'react-router-dom'
Expand All @@ -12,6 +12,7 @@ const CredentialActionsDropdown: React.FC<{
}> = ({ children, credential }) => {
const { agents, getAgent } = useVeramo<IDataStore>()
const navigate = useNavigate()
const { notification } = App.useApp()

const agentsToCopyTo = agents.filter((agent) =>
agent.availableMethods().includes('dataStoreSaveVerifiableCredential'),
Expand Down
3 changes: 2 additions & 1 deletion src/components/NewChatThreadModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Row,
Button,
Col,
notification,
App,
} from 'antd'
import { QrcodeOutlined } from '@ant-design/icons'
import { useVeramo } from '@veramo-community/veramo-react'
Expand All @@ -28,6 +28,7 @@ const NewChatThreadModal: React.FC<NewChatThreadModalProps> = ({
onCreate,
onCancel,
}) => {
const { notification } = App.useApp()
const { agent } = useVeramo<IDIDDiscovery>()
const [options, setOptions] = useState<SelectProps<object>['options']>([])
const [did, setDid] = useState<string>('')
Expand Down
32 changes: 20 additions & 12 deletions src/context/ThemeProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ConfigProvider, theme as antdTheme } from 'antd'
import { ConfigProvider, theme as antdTheme, App } from 'antd'
import { ProConfigProvider } from '@ant-design/pro-components'
import React, { createContext, useState, useEffect, useContext } from 'react'
import en_US from 'antd/es/locale/en_US'

Expand Down Expand Up @@ -78,18 +79,25 @@ const ThemeProvider = (props: any) => {
<ThemeContext.Provider
value={{ theme, switchTheme, isCompact, setIsCompact }}
>
<ConfigProvider
locale={en_US}
theme={{
token: {
colorPrimary: '#1DA57A',
borderRadius: 3,
},
algorithm,
}}
<ProConfigProvider
hashed={false}

>
{props.children}
</ConfigProvider>
<ConfigProvider
locale={en_US}
theme={{
token: {
colorPrimary: '#1DA57A',
borderRadius: 3,
},
algorithm,
}}
>
<App>
{props.children}
</App>
</ConfigProvider>
</ProConfigProvider>
</ThemeContext.Provider>
)
}
Expand Down
28 changes: 13 additions & 15 deletions src/layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ import {
FileProtectOutlined,
} from '@ant-design/icons'
import { Routes, Route, useLocation, Link, Navigate } from 'react-router-dom'
import Connect from '../pages/Connect'

import Identifier from '../pages/Identifier'
import Credentials from '../pages/Credentials'
import Credential from '../pages/Credential'
import Activity from '../pages/Messages'
import Requests from '../pages/Requests'
import Agents from '../pages/Agents'
import Agent from '../pages/Agent'
import Chats from '../pages/Chats'
import { useVeramo } from '@veramo-community/veramo-react'
import CreateResponse from '../components/CreateResponse'
Expand All @@ -33,6 +31,7 @@ import { Appearance } from '../pages/settings/Appearance'
import { Plugins } from '../pages/settings/Plugins'
import { Web3 } from '../pages/settings/Web3'
import { Version } from '../pages/settings/Version'
import { Agents } from '../pages/settings/Agents'

const GRAVATAR_URI = 'https://www.gravatar.com/avatar/'

Expand All @@ -42,7 +41,7 @@ const Layout = () => {
const location = useLocation()

const availableMethods = agent?.availableMethods() || []
const currentAgentName = agent?.context?.name || 'No Agent Connected'


const uri =
agent?.context?.name &&
Expand Down Expand Up @@ -126,6 +125,10 @@ const Layout = () => {
name: 'Settings',
icon: <SettingOutlined />,
routes: [
{
name: 'Agents',
path: '/settings/agents',
},
{
name: 'Appearance',
path: '/settings/appearance',
Expand All @@ -145,8 +148,6 @@ const Layout = () => {
]
})



return (
<div
style={{
Expand All @@ -157,8 +158,7 @@ const Layout = () => {
locale="en-US"
contentWidth="Fixed"
title="Agent explorer"
logo={require('../assets/icon.png')}

logo={false}
menuItemRender={(menuItemProps, defaultDom) => {
if (menuItemProps.isUrl || menuItemProps.children) {
return defaultDom
Expand All @@ -169,6 +169,7 @@ const Layout = () => {
<Link
to={menuItemProps.path.replace('/*', '')}
target={menuItemProps.target}
state={menuItemProps.state}
>
{defaultDom}
</Link>
Expand All @@ -183,22 +184,18 @@ const Layout = () => {
avatarProps={{
src: uri,
size: 'small',
title: currentAgentName,
render: (props, children) => (
<AgentDropdown>{children}</AgentDropdown>
),
}}
token={{
pageContainer: {
paddingBlockPageContainerContent: 15,
paddingInlinePageContainerContent: 15,
paddingBlockPageContainerContent: 20,
paddingInlinePageContainerContent: 20,
},
}}
>
<Routes>
<Route path="/connect" element={<Connect />} />
<Route path="/agents" element={<Agents />} />
<Route path="/agent/:id" element={<Agent />} />
<Route path="/chats/threads/:threadId" element={<Chats />} />
<Route path="/chats/threads" element={<Chats />} />
<Route path="/statistics" element={<Statistics />} />
Expand All @@ -212,12 +209,13 @@ const Layout = () => {
<Route path="/requests" element={<Requests />} />
<Route path="/requests/sdr/:messageId" element={<CreateResponse />} />

<Route path="/settings/agents" element={<Agents />} />
<Route path="/settings/appearance" element={<Appearance />} />
<Route path="/settings/plugins" element={<Plugins />} />
<Route path="/settings/web3" element={<Web3 />} />
<Route path="/settings/version" element={<Version />} />
{!agent && (
<Route path="/" element={<Navigate replace to="/connect" />} />
<Route path="/" element={<Navigate replace to="/statistics" />} />
)}
{plugins.map((plugin) => {
if (plugin.config.enabled && plugin.routes) {
Expand Down
63 changes: 0 additions & 63 deletions src/pages/Agent.tsx

This file was deleted.

Loading

0 comments on commit c7d0214

Please sign in to comment.