From cece18e3cb900cbe2fe7d77c0c329a2c430e2539 Mon Sep 17 00:00:00 2001 From: Guillermo Puente Date: Tue, 20 Feb 2024 18:13:04 -0300 Subject: [PATCH 1/3] feat: enabled switchboard link in RWA editor --- src/components/editors.tsx | 3 +++ src/components/file-item/file-item.tsx | 20 ++++--------------- src/hooks/useOpenSwitchboardLink.ts | 27 ++++++++++++++++++++++++++ src/pages/content.tsx | 17 ++++++++++++++++ 4 files changed, 51 insertions(+), 16 deletions(-) create mode 100644 src/hooks/useOpenSwitchboardLink.ts diff --git a/src/components/editors.tsx b/src/components/editors.tsx index 4225dd0c..a457f3b1 100644 --- a/src/components/editors.tsx +++ b/src/components/editors.tsx @@ -33,6 +33,7 @@ export interface IProps extends EditorProps { onClose: () => void; onExport: () => void; onAddOperation: (operation: Operation) => void; + onOpenSwitchboardLink?: () => Promise; } export const DocumentEditor: React.FC = ({ @@ -41,6 +42,7 @@ export const DocumentEditor: React.FC = ({ onClose, onExport, onAddOperation, + onOpenSwitchboardLink, }) => { const documentModel = useDocumentModel(initialDocument.documentType); const editor = useEditor(initialDocument.documentType); @@ -124,6 +126,7 @@ export const DocumentEditor: React.FC = ({ dispatch={dispatch} onClose={onClose} onExport={onExport} + onSwitchboardLinkClick={onOpenSwitchboardLink} /> ); diff --git a/src/components/file-item/file-item.tsx b/src/components/file-item/file-item.tsx index 08707837..6d4ac37d 100644 --- a/src/components/file-item/file-item.tsx +++ b/src/components/file-item/file-item.tsx @@ -13,8 +13,7 @@ import { useDocumentDriveById } from 'src/hooks/useDocumentDriveById'; import { useDrivesContainer } from 'src/hooks/useDrivesContainer'; import { useGetDocumentById } from 'src/hooks/useGetDocumentById'; import { useGetReadableItemPath } from 'src/hooks/useGetReadableItemPath'; -import { getSwitchboardUrl } from 'src/utils/getSwitchboardUrl'; -import { openUrl } from 'src/utils/openUrl'; +import { useOpenSwitchboardLink } from 'src/hooks/useOpenSwitchboardLink'; const allowedItemOptions = ['delete', 'rename']; @@ -42,7 +41,8 @@ export const FileItem: React.FC = ({ const { updateNodeName } = useDrivesContainer(); const decodedDriveID = decodeID(drive); - const { isRemoteDrive, remoteUrl } = useDocumentDriveById(decodedDriveID); + const openSwitchboardLink = useOpenSwitchboardLink(decodedDriveID); + const { isRemoteDrive } = useDocumentDriveById(decodedDriveID); const onFileOptionsClick = async (optionId: string, fileNode: TreeItem) => { if (optionId === 'delete') { @@ -54,23 +54,11 @@ export const FileItem: React.FC = ({ } if (optionId === 'switchboard-link') { - if (!remoteUrl) return; - const url = new URL(remoteUrl); - const baseUrl = url.origin; const document = getDocumentById(decodedDriveID, fileNode.id) as | FileNode | undefined; - if (document) { - const url = getSwitchboardUrl( - baseUrl, - decodedDriveID, - document.documentType, - document.id, - ); - - await openUrl(url); - } + await openSwitchboardLink(document); } }; diff --git a/src/hooks/useOpenSwitchboardLink.ts b/src/hooks/useOpenSwitchboardLink.ts new file mode 100644 index 00000000..55330ab8 --- /dev/null +++ b/src/hooks/useOpenSwitchboardLink.ts @@ -0,0 +1,27 @@ +import { FileNode } from 'document-model-libs/document-drive'; +import { getSwitchboardUrl } from 'src/utils/getSwitchboardUrl'; +import { openUrl } from 'src/utils/openUrl'; +import { useDocumentDriveById } from './useDocumentDriveById'; + +export const useOpenSwitchboardLink = (driveId: string) => { + const { isRemoteDrive, remoteUrl } = useDocumentDriveById(driveId); + + return async (document?: FileNode) => { + if (!remoteUrl) return; + if (!isRemoteDrive) return; + + const url = new URL(remoteUrl); + const baseUrl = url.origin; + + if (document) { + const url = getSwitchboardUrl( + baseUrl, + driveId, + document.documentType, + document.id, + ); + + await openUrl(url); + } + }; +}; diff --git a/src/pages/content.tsx b/src/pages/content.tsx index 813676db..ab85fcdf 100644 --- a/src/pages/content.tsx +++ b/src/pages/content.tsx @@ -8,6 +8,7 @@ import { useItemActions, useItemsContext, } from '@powerhousedao/design-system'; +import { FileNode } from 'document-model-libs/document-drive'; import { Document, DocumentModel, Operation } from 'document-model/document'; import path from 'path'; import { useEffect, useState } from 'react'; @@ -16,8 +17,11 @@ import { DocumentEditor } from 'src/components/editors'; import FolderView from 'src/components/folder-view'; import { useModal } from 'src/components/modal'; import { SearchBar } from 'src/components/search-bar'; +import { useDocumentDriveById } from 'src/hooks/useDocumentDriveById'; import { useDocumentDriveServer } from 'src/hooks/useDocumentDriveServer'; import { useDrivesContainer } from 'src/hooks/useDrivesContainer'; +import { useGetDocumentById } from 'src/hooks/useGetDocumentById'; +import { useOpenSwitchboardLink } from 'src/hooks/useOpenSwitchboardLink'; import { preloadTabs, useFileNodeDocument, useSelectedPath } from 'src/store'; import { useFilteredDocumentModels, @@ -37,6 +41,9 @@ const Content = () => { const driveID = getRootPath(selectedFolder?.path ?? ''); const decodedDriveID = decodeID(driveID); const { showModal } = useModal(); + const getDocumentById = useGetDocumentById(); + const { isRemoteDrive } = useDocumentDriveById(decodedDriveID); + const openSwitchboardLink = useOpenSwitchboardLink(decodedDriveID); const { addFile, deleteNode, documentDrives, renameNode } = useDocumentDriveServer(); @@ -149,6 +156,15 @@ const Content = () => { } }; + const onOpenSwitchboardLink = async () => { + const doc = getDocumentById( + decodedDriveID, + selectedFileNode?.id || '', + ) as FileNode | undefined; + + await openSwitchboardLink(doc); + }; + return (
{selectedFileNode && selectedDocument ? ( @@ -159,6 +175,7 @@ const Content = () => { onChange={onDocumentChangeHandler} onExport={() => exportDocument(selectedDocument)} onAddOperation={handleAddOperation} + {...(isRemoteDrive && { onOpenSwitchboardLink })} />
) : ( From d4ab8f881d0e04d5bf68e0748205cf25fcce90e1 Mon Sep 17 00:00:00 2001 From: Guillermo Puente Date: Wed, 21 Feb 2024 10:48:24 -0300 Subject: [PATCH 2/3] feat: updated document-model-libs and design-system ver --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index e3659ff7..8313d9f6 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "@typescript-eslint/parser": "^6.18.1", "@vitejs/plugin-react": "^3.1.0", "autoprefixer": "^10.4.14", - "document-model-libs": "^1.1.51", + "document-model-libs": "^1.1.52", "electron": "28.2.3", "eslint": "^8.56.0", "eslint-config-prettier": "^8.8.0", diff --git a/yarn.lock b/yarn.lock index 261b4fe8..eb7f29ff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5280,10 +5280,10 @@ document-drive@^1.0.0-alpha.9: nanoevents "^9.0.0" sanitize-filename "^1.6.3" -document-model-libs@^1.1.51: - version "1.1.51" - resolved "https://registry.yarnpkg.com/document-model-libs/-/document-model-libs-1.1.51.tgz#7b7869fa8d6bb08aa83469189b339cadd06c30f7" - integrity sha512-58SYxLfSklaImunLD/kcfXLpKrlNz1yIbIHYtBFto2SQmAhEoBpr8d1bMDbqX03Q7HrPHzRf0qnUfwlS5y22wA== +document-model-libs@^1.1.52: + version "1.1.52" + resolved "https://registry.yarnpkg.com/document-model-libs/-/document-model-libs-1.1.52.tgz#85859770fae18ef56b4287a7eebcc488415217e2" + integrity sha512-cZmFhk6tWY3NABqFQFtto6Woz3EIsJmA+voqNEhyuxAIsLRKzn2seLLPxy0DFUVttntumEsEfCgR8c92aOXK+g== dependencies: "@acaldas/graphql-codegen-typescript-validation-schema" "^0.12.3" "@graphql-codegen/core" "^4.0.2" From 05dfd0781038523b86437ebe1164e20a848c65b2 Mon Sep 17 00:00:00 2001 From: Guillermo Puente Date: Wed, 21 Feb 2024 10:59:24 -0300 Subject: [PATCH 3/3] feat: added RWA doc name fix for demo --- src/pages/content.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/pages/content.tsx b/src/pages/content.tsx index ab85fcdf..b6274270 100644 --- a/src/pages/content.tsx +++ b/src/pages/content.tsx @@ -30,6 +30,14 @@ import { import { exportFile } from 'src/utils'; import { v4 as uuid } from 'uuid'; +const getDocumentModelName = (name: string) => { + if (name === 'RealWorldAssets') { + return 'RWA Portfolio'; + } + + return name; +}; + const Content = () => { const { items } = useItemsContext(); const [selectedPath, setSelectedPath] = useSelectedPath(); @@ -222,7 +230,9 @@ const Content = () => { onClick={() => createDocument(doc)} > - {doc.documentModel.name} + {getDocumentModelName( + doc.documentModel.name, + )} ))}