Skip to content

Commit

Permalink
feat: refactor plugins (#161)
Browse files Browse the repository at this point in the history
* refactor: PluginProvider

* feat: refactor core plugins

* fix(pugin): add react deps

* fix(plugin): deps
  • Loading branch information
simonas-notcat authored Sep 26, 2023
1 parent 7196ba0 commit b8bcfa5
Show file tree
Hide file tree
Showing 35 changed files with 310 additions and 216 deletions.
150 changes: 0 additions & 150 deletions packages/agent-explorer/src/components/CredentialActionsDropdown.tsx

This file was deleted.

3 changes: 1 addition & 2 deletions packages/agent-explorer/src/components/CredentialSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import React from 'react'
import { Row, Avatar, Col, Typography, theme, Skeleton, Space, Popover, Tag } from 'antd'
import { useVeramo } from '@veramo-community/veramo-react'
import { useQuery } from 'react-query'
import { getIssuerDID, shortId } from '../utils/did'
import { getIssuerDID, shortId, CredentialActionsDropdown } from '@veramo-community/agent-explorer-plugin'
import { UniqueVerifiableCredential } from '@veramo/core'
import CredentialActionsDropdown from './CredentialActionsDropdown'
import { EllipsisOutlined } from '@ant-design/icons'
import { formatRelative } from 'date-fns'

Expand Down
3 changes: 1 addition & 2 deletions packages/agent-explorer/src/components/CredentialTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import { UniqueVerifiableCredential } from '@veramo/core'
import { VerifiableCredential } from '@veramo-community/react-components'
import CredentialInfo from './CredentialInfo'
import JsonBlock from './Json'
import { getIssuerDID } from '../utils/did'
import { getIssuerDID, CredentialActionsDropdown } from '@veramo-community/agent-explorer-plugin'
import IdentifierProfile from './IdentifierProfile'
import { EllipsisOutlined } from '@ant-design/icons'
import { formatRelative } from 'date-fns'
import CredentialActionsDropdown from './CredentialActionsDropdown'

interface CredentialTabsProps {
uniqueCredential: UniqueVerifiableCredential
Expand Down
2 changes: 1 addition & 1 deletion packages/agent-explorer/src/components/DIDDiscoveryBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useChat } from '../context/ChatProvider'
import { useVeramo } from '@veramo-community/veramo-react'
import { IDIDDiscovery } from '@veramo/did-discovery'
import { SelectProps } from 'antd/es/select'
import { shortId } from '../utils/did'
import { shortId } from '@veramo-community/agent-explorer-plugin'

interface DIDDiscoveryBarProps {
handleSelect: any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Row, Avatar, Col, Typography, theme, Skeleton } from 'antd'
import { useVeramo } from '@veramo-community/veramo-react'
import { useQuery } from 'react-query'
import { IIdentifierProfilePlugin } from '../context/plugins/IdentifierProfile'
import { shortId } from '../utils/did'
import { shortId } from '@veramo-community/agent-explorer-plugin'

interface IdentifierProfileProps {
did: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '@veramo/core'
import { IDataStoreORM } from '@veramo/data-store'
import parse from 'url-parse'
import { shortId } from '../../utils/did'
import { shortId } from '@veramo-community/agent-explorer-plugin'
import md5 from 'md5'

export interface IIdentifierProfile {
Expand Down
7 changes: 5 additions & 2 deletions packages/agent-explorer/src/layout/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@ import { ThemeProvider } from '../context/ThemeProvider'
import { QueryClientProvider, QueryClient } from 'react-query'
import { ChatProvider } from '../context/ChatProvider'
import { VeramoWeb3Provider } from '../context/web3/VeramoWeb3Provider'
import { PluginProvider } from '../context/PluginProvider'
import { PluginProvider } from '@veramo-community/agent-explorer-plugin'
import { getcorePlugins } from '../plugins'

declare global {
interface Window {
BASE_URL: string
}
}

const corePlugins = getcorePlugins()

const App = () => {
const queryClient = new QueryClient()

return (
<QueryClientProvider client={queryClient}>
<ThemeProvider>
<VeramoWeb3Provider>
<PluginProvider>
<PluginProvider corePlugins={corePlugins}>
<ChatProvider>
<BrowserRouter>
<Layout />
Expand Down
2 changes: 1 addition & 1 deletion packages/agent-explorer/src/layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Routes, Route, useLocation, Link } from 'react-router-dom'
import { useVeramo } from '@veramo-community/veramo-react'
import md5 from 'md5'
import AgentDropdown from '../components/AgentDropdown'
import { usePlugins } from '../context/PluginProvider'
import { usePlugins } from '@veramo-community/agent-explorer-plugin'
import { Landing } from '../pages/Landing'
import { Appearance } from '../pages/settings/Appearance'
import { Plugins } from '../pages/settings/Plugins'
Expand Down
8 changes: 4 additions & 4 deletions packages/agent-explorer/src/pages/settings/Plugins.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react'
import { Button, Input, List, Space, Switch, App, Drawer, Typography } from 'antd'
import { DeleteOutlined, MenuOutlined, PlusOutlined} from '@ant-design/icons'
import { usePlugins } from '../../context/PluginProvider'
import { usePlugins } from '@veramo-community/agent-explorer-plugin'
import { PageContainer } from '@ant-design/pro-components'
import { DndContext,
closestCenter,
Expand All @@ -13,9 +13,9 @@ import { DndContext,
} from '@dnd-kit/core';
import { SortableContext, useSortable, verticalListSortingStrategy, sortableKeyboardCoordinates } from '@dnd-kit/sortable';
import {CSS} from '@dnd-kit/utilities';
import { AgentPlugin } from '@veramo-community/agent-explorer-plugin'
import { IAgentExplorerPlugin } from '@veramo-community/agent-explorer-plugin'

const communityPlugins: AgentPlugin[] = [
const communityPlugins: IAgentExplorerPlugin[] = [
{
config: {
url: 'https://cdn.jsdelivr.net/gh/veramolabs/agent-explorer-plugin-social-feed/dist/plugin.js',
Expand Down Expand Up @@ -73,7 +73,7 @@ const communityPlugins: AgentPlugin[] = [
},
]

const SortableItem = ({ item }: { item: AgentPlugin}) => {
const SortableItem = ({ item }: { item: IAgentExplorerPlugin}) => {
const { notification } = App.useApp()
const { removePluginConfig, switchPlugin } = usePlugins()
const { attributes, listeners, setNodeRef, transform, transition } = useSortable({ id: item.config.url });
Expand Down
2 changes: 1 addition & 1 deletion packages/agent-explorer/src/plugins/audit-log/Messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useVeramo } from '@veramo-community/veramo-react'
import md5 from 'md5'
import { IMessage } from '@veramo/core'
import { PageContainer } from '@ant-design/pro-components'
import { shortId } from '../../utils/did'
import { shortId } from '@veramo-community/agent-explorer-plugin'

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

Expand Down
2 changes: 1 addition & 1 deletion packages/agent-explorer/src/plugins/chats/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useVeramo } from '@veramo-community/veramo-react'
import { useChat } from '../../context/ChatProvider'
import { v4 } from 'uuid'
import { useNavigate } from 'react-router-dom'
import { shortId } from '../../utils/did'
import { shortId } from '@veramo-community/agent-explorer-plugin'

const { TextArea } = Input

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { Row, Typography, Avatar, Col, theme } from 'antd'
import { shortId } from '../../utils/did'
import { shortId } from '@veramo-community/agent-explorer-plugin'
import { IMessage } from '@veramo/core'
import { useChat } from '../../context/ChatProvider'
import { IIdentifierProfile } from '../../context/plugins/IdentifierProfile'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useVeramo } from '@veramo-community/veramo-react'
import { IDIDDiscovery } from '@veramo/did-discovery'
import { QrScanner } from '@yudiel/react-qr-scanner'
import parse from 'url-parse'
import { shortId } from '../../utils/did'
import { shortId } from '@veramo-community/agent-explorer-plugin'
import { decodeBase64url } from '@veramo/utils'

interface NewChatThreadModalProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { IDIDManager, IResolver } from '@veramo/core'
import IdentifierReceivedCredentials from './IdentifierReceivedCredentials'
import IdentifierIssuedCredentials from './IdentifierIssuedCredentials'
import { PageContainer } from '@ant-design/pro-components'
import { shortId } from '../../utils/did'
import { shortId } from '@veramo-community/agent-explorer-plugin'
import { CopyOutlined } from '@ant-design/icons'
import { IIdentifierProfilePlugin } from '../../context/plugins/IdentifierProfile'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import { ProList } from '@ant-design/pro-components'
import { VerifiableCredential } from '@veramo-community/react-components'
import { Button } from 'antd'
import { formatRelative } from 'date-fns'
import { getIssuerDID } from '../../utils/did'
import IdentifierProfile from '../../components/IdentifierProfile'
import CredentialActionsDropdown from '../../components/CredentialActionsDropdown'
import { CredentialActionsDropdown, getIssuerDID } from '@veramo-community/agent-explorer-plugin'

interface IdentifierCredentialsProps {
identifier: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import { useVeramo } from '@veramo-community/veramo-react'
import { IDataStoreORM, UniqueVerifiableCredential } from '@veramo/core'
import { ProList } from '@ant-design/pro-components'
import { VerifiableCredential } from '@veramo-community/react-components'
import { getIssuerDID } from '../../utils/did'
import IdentifierProfile from '../../components/IdentifierProfile'
import CredentialActionsDropdown from '../../components/CredentialActionsDropdown'
import { CredentialActionsDropdown, getIssuerDID } from '@veramo-community/agent-explorer-plugin'

interface IdentifierCredentialsProps {
identifier: string
Expand Down
3 changes: 2 additions & 1 deletion packages/agent-explorer/src/plugins/contacts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IPlugin } from '@veramo-community/agent-explorer-plugin';

import { Contacts } from './Contacts';
import Identifier from './Identifier';
import { getCredentialContextMenuItems } from './menu';

const Plugin: IPlugin = {
//@ts-ignore
Expand Down Expand Up @@ -33,7 +34,7 @@ const Plugin: IPlugin = {
icon: <ContactsOutlined />,
},
],

getCredentialContextMenuItems
}
}
};
Expand Down
28 changes: 28 additions & 0 deletions packages/agent-explorer/src/plugins/contacts/menu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { InfoCircleOutlined } from "@ant-design/icons";
import { getIssuerDID } from "@veramo-community/agent-explorer-plugin";
import { UniqueVerifiableCredential } from "@veramo/core-types";
import { MenuProps } from "antd";
import { useNavigate } from "react-router";

export const getCredentialContextMenuItems = (credential: UniqueVerifiableCredential): MenuProps['items'] => {
const navigate = useNavigate()
const { verifiableCredential } = credential


return [ {
key: 'issuer',
label: 'Issuer',
icon: <InfoCircleOutlined />,
onClick: () => navigate('/contacts/' + getIssuerDID(verifiableCredential)),
},
{
key: 'subject',
label: 'Subject',
icon: <InfoCircleOutlined />,
onClick: () =>
navigate(
'/contacts/' +
encodeURIComponent(verifiableCredential.credentialSubject.id as string),
),
},
]}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { PageContainer } from '@ant-design/pro-components'
import CredentialTabs from '../../components/CredentialTabs'
import { IDataStore } from '@veramo/core'
import { computeEntryHash } from '@veramo/utils'
import CredentialActionsDropdown from '../../components/CredentialActionsDropdown'
import { CredentialActionsDropdown } from '@veramo-community/agent-explorer-plugin'
import { EllipsisOutlined } from '@ant-design/icons'

const Credential = () => {
Expand Down
Loading

0 comments on commit b8bcfa5

Please sign in to comment.