From bdd44e0e7458c77eb5d476f1be36361e966b7ac6 Mon Sep 17 00:00:00 2001 From: xypnox Date: Wed, 26 Oct 2022 23:32:21 +0530 Subject: [PATCH 1/3] Fix Correct plugin initialization in extension, remove default export --- apps/extension/src/Components/Content/index.tsx | 4 ++-- apps/extension/src/Components/Dibba/index.tsx | 4 ++-- .../src/Components/Editor/EditorPreview.tsx | 4 ++-- .../src/Components/EditorPreviewRenderer.tsx | 2 +- .../src/Components/Sidebar/SnippetsInfoBar.tsx | 4 ++-- .../src/Editor/components/ComboBox/config.tsx | 2 +- apps/extension/src/Editor/plugins/index.tsx | 13 ++++++++++--- apps/extension/src/Utils/pasteUtils.ts | 4 ++-- .../src/Editor/Components/Combobox/config.tsx | 2 +- apps/webapp/src/Editor/Plugins/index.tsx | 3 +-- 10 files changed, 24 insertions(+), 18 deletions(-) diff --git a/apps/extension/src/Components/Content/index.tsx b/apps/extension/src/Components/Content/index.tsx index 7c74d1d9d..bc62e8263 100644 --- a/apps/extension/src/Components/Content/index.tsx +++ b/apps/extension/src/Components/Content/index.tsx @@ -6,7 +6,7 @@ import { ActionType, defaultContent, ELEMENT_TAG, mog, QuickLinkStatus, QuickLin import { NodeEditorContent } from '@mexit/core' import { CopyTag } from '../../Editor/components/Tags/CopyTag' -import getPlugins from '../../Editor/plugins/index' +import { generateEditorPluginsWithComponents } from '../../Editor/plugins/index' import { useEditorContext } from '../../Hooks/useEditorContext' import { useSnippets } from '../../Hooks/useSnippets' import { useSputlitContext } from '../../Hooks/useSputlitContext' @@ -30,7 +30,7 @@ export default function Content() { useEffect(() => { if (selection?.range && selection?.url && previewMode) { const editor = createPlateEditor({ - plugins: getPlugins( + plugins: generateEditorPluginsWithComponents( createPlateUI({ [ELEMENT_TAG]: CopyTag as any }), diff --git a/apps/extension/src/Components/Dibba/index.tsx b/apps/extension/src/Components/Dibba/index.tsx index 2444c29e6..6318e8c46 100644 --- a/apps/extension/src/Components/Dibba/index.tsx +++ b/apps/extension/src/Components/Dibba/index.tsx @@ -27,7 +27,7 @@ import { ActionTitle, ComboboxItemTitle, ComboboxShortcuts, ComboSeperator, Shor import { ElementTypeBasedShortcut } from '../../Editor/components/ComboBox' import { CopyTag } from '../../Editor/components/Tags/CopyTag' -import getPlugins from '../../Editor/plugins/index' +import { generateEditorPluginsWithComponents } from '../../Editor/plugins/index' import { getPathFromNodeIdHookless } from '../../Hooks/useLinks' import usePointerMovedSinceMount from '../../Hooks/usePointerMovedSinceMount' import { useSnippets } from '../../Hooks/useSnippets' @@ -162,7 +162,7 @@ export default function Dibba() { }) const tempEditor = createPlateEditor({ - plugins: getPlugins( + plugins: generateEditorPluginsWithComponents( createPlateUI({ [ELEMENT_TAG]: CopyTag as any }), diff --git a/apps/extension/src/Components/Editor/EditorPreview.tsx b/apps/extension/src/Components/Editor/EditorPreview.tsx index 2ff0c604d..8714d92c4 100644 --- a/apps/extension/src/Components/Editor/EditorPreview.tsx +++ b/apps/extension/src/Components/Editor/EditorPreview.tsx @@ -15,7 +15,7 @@ import { } from '@mexit/shared' import { Button } from '@mexit/shared' -import useMemoizedPlugins from '../../Editor/plugins' +import { generateEditorPluginsWithComponents } from '../../Editor/plugins' // import useLoad from '../../../Hooks/useLoad' // import { useRouting, ROUTE_PATHS, NavigationType } from '../../../Hooks/useRouting' // import { useTags } from '../../Hooks/useTags' @@ -95,7 +95,7 @@ const EditorPreview = ({ // goTo(ROUTE_PATHS.node, NavigationType.push, nodeid) } - const plugins = useMemoizedPlugins(components, { exclude: { dnd: true } }) + const plugins = generateEditorPluginsWithComponents(components, { exclude: { dnd: true } }) if (cc) { return ( diff --git a/apps/extension/src/Components/EditorPreviewRenderer.tsx b/apps/extension/src/Components/EditorPreviewRenderer.tsx index 9a43b6993..51602f4c6 100644 --- a/apps/extension/src/Components/EditorPreviewRenderer.tsx +++ b/apps/extension/src/Components/EditorPreviewRenderer.tsx @@ -6,7 +6,7 @@ import styled from 'styled-components' import { EditorStyles, FadeContainer, TodoContainer } from '@mexit/shared' import { useEditorChange } from '@mexit/shared' -import useMemoizedPlugins from '../Editor/plugins' +import { useMemoizedPlugins } from '../Editor/plugins' import components from './Editor/Components' interface EditorPreviewRendererProps { diff --git a/apps/extension/src/Components/Sidebar/SnippetsInfoBar.tsx b/apps/extension/src/Components/Sidebar/SnippetsInfoBar.tsx index bc604084b..e441432ac 100644 --- a/apps/extension/src/Components/Sidebar/SnippetsInfoBar.tsx +++ b/apps/extension/src/Components/Sidebar/SnippetsInfoBar.tsx @@ -20,7 +20,7 @@ import { import { SnippetCards, Input, SidebarListFilter, SidebarListFilterWrapper, SnippetSidebarHelp } from '@mexit/shared' import { CopyTag } from '../../Editor/components/Tags/CopyTag' -import getPlugins from '../../Editor/plugins/index' +import { generateEditorPluginsWithComponents } from '../../Editor/plugins/index' import useRaju from '../../Hooks/useRaju' import { useSnippets } from '../../Hooks/useSnippets' import { useSnippetStore } from '../../Stores/useSnippetStore' @@ -62,7 +62,7 @@ export const SnippetsInfoBar = () => { }) const tempEditor = createPlateEditor({ - plugins: getPlugins( + plugins: generateEditorPluginsWithComponents( createPlateUI({ [ELEMENT_TAG]: CopyTag as any }), diff --git a/apps/extension/src/Editor/components/ComboBox/config.tsx b/apps/extension/src/Editor/components/ComboBox/config.tsx index 5cfb2d008..6552200a7 100644 --- a/apps/extension/src/Editor/components/ComboBox/config.tsx +++ b/apps/extension/src/Editor/components/ComboBox/config.tsx @@ -1,5 +1,5 @@ import { PlatePlugin, PlatePluginComponent } from '@udecode/plate' -import useMemoizedPlugins, { generatePlugins } from '../../plugins' +import { useMemoizedPlugins, generatePlugins } from '../../plugins' import { QuickLinkComboboxItem } from '../../plugins/QuickLink/components/QuickLinkComboboxItem' import { ELEMENT_ILINK, ELEMENT_TAG } from '@mexit/core' import useMultiComboboxOnChange from '../MultiCombobox/useMultiComboboxChange' diff --git a/apps/extension/src/Editor/plugins/index.tsx b/apps/extension/src/Editor/plugins/index.tsx index ee18590c5..4a28c8c29 100644 --- a/apps/extension/src/Editor/plugins/index.tsx +++ b/apps/extension/src/Editor/plugins/index.tsx @@ -195,8 +195,17 @@ export const generatePlugins = (options: PluginOptionType) => { return withPlugins } +export const generateEditorPluginsWithComponents = (components: Record, options?: PluginOptionType) => { + const wrappedComponents = components + + const plugins = createPlugins(generatePlugins(options), { + components: wrappedComponents + }) + + return plugins +} -const useMemoizedPlugins = (components: Record, options?: PluginOptionType) => { +export const useMemoizedPlugins = (components: Record, options?: PluginOptionType) => { const wrappedComponents = components // Raw uploader const { uploadImageToS3 } = useAuth() @@ -215,5 +224,3 @@ const useMemoizedPlugins = (components: Record, options?: PluginOpt return plugins } - -export default useMemoizedPlugins diff --git a/apps/extension/src/Utils/pasteUtils.ts b/apps/extension/src/Utils/pasteUtils.ts index 66049cecb..233a84a1e 100644 --- a/apps/extension/src/Utils/pasteUtils.ts +++ b/apps/extension/src/Utils/pasteUtils.ts @@ -13,7 +13,7 @@ import { } from '@mexit/core' import { CopyTag } from '../Editor/components/Tags/CopyTag' -import getPlugins from '../Editor/plugins/index' +import { generateEditorPluginsWithComponents } from '../Editor/plugins/index' // Also a better matching for the domains export const supportedDomains: Record = { @@ -35,7 +35,7 @@ export const copySnippetToClipboard = async (item: Snippet) => { }) const tempEditor = createPlateEditor({ - plugins: getPlugins( + plugins: generateEditorPluginsWithComponents( createPlateUI({ [ELEMENT_TAG]: CopyTag as any }), diff --git a/apps/webapp/src/Editor/Components/Combobox/config.tsx b/apps/webapp/src/Editor/Components/Combobox/config.tsx index fe3a1facb..e1e536ed3 100644 --- a/apps/webapp/src/Editor/Components/Combobox/config.tsx +++ b/apps/webapp/src/Editor/Components/Combobox/config.tsx @@ -1,7 +1,7 @@ import { PlatePluginComponent } from '@udecode/plate' import { useContextMenu } from 'react-contexify' -import useEditorPlugins, { PluginOptionType } from '../../Plugins/index' +import { useEditorPlugins, PluginOptionType } from '../../Plugins/index' import { ComboboxConfig } from '../../Types/MultiCombobox' import { MENU_ID } from '../BlockContextMenu' import useMultiComboboxOnChange from '../MultiCombobox/useMultiComboboxChange' diff --git a/apps/webapp/src/Editor/Plugins/index.tsx b/apps/webapp/src/Editor/Plugins/index.tsx index 9b9e9e7f0..78f484a9a 100644 --- a/apps/webapp/src/Editor/Plugins/index.tsx +++ b/apps/webapp/src/Editor/Plugins/index.tsx @@ -225,7 +225,7 @@ export const generateEditorPluginsWithComponents = (components: Record, options?: PluginOptionType) => { +export const useEditorPlugins = (components: Record, options?: PluginOptionType) => { const { uploadImageToS3 } = useAuth() const { uploadImageToWDCDN } = useUploadToCDN(uploadImageToS3) @@ -246,4 +246,3 @@ const useEditorPlugins = (components: Record, options?: PluginOptio return plugins } -export default useEditorPlugins From 618e2df0b3d71d3d0792e19f696cb3ad2a3d9388 Mon Sep 17 00:00:00 2001 From: xypnox Date: Wed, 26 Oct 2022 23:51:30 +0530 Subject: [PATCH 2/3] Send namespace as well as parentNoteId for portal calls --- apps/webapp/src/Components/Portals/index.tsx | 19 +++++++++++++++---- apps/webapp/src/Hooks/usePortals.ts | 14 ++++++++++---- apps/webapp/src/Types/Actions.ts | 1 + 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/apps/webapp/src/Components/Portals/index.tsx b/apps/webapp/src/Components/Portals/index.tsx index ae080f2af..49ab58156 100644 --- a/apps/webapp/src/Components/Portals/index.tsx +++ b/apps/webapp/src/Components/Portals/index.tsx @@ -17,6 +17,7 @@ import { QuickLink } from '../NodeSelect/NodeSelect' import CreateInput from '../createInput' import ServiceHeader from './ServiceHeader' import ServiceInfo from './ServiceInfo' +import { useNamespaces } from '../../Hooks/useNamespaces' const Portals = () => { const theme = useTheme() @@ -36,6 +37,7 @@ const Portals = () => { const apps = usePortalStore((store) => store.apps) const connectedPortals = usePortalStore((store) => store.connectedPortals) const getIsPortalConnected = usePortalStore((store) => store.getIsPortalConnected) + const { getNamespaceOfNodeid } = useNamespaces() const actionGroup = apps[params.actionGroupId] @@ -44,9 +46,13 @@ const Portals = () => { const { connectedPortalInfo, parentNoteName } = useMemo(() => { const connectedPortalInfo = getIsPortalConnected(actionGroup.actionGroupId) - let parentNoteName = '' + let parentNoteName = undefined if (connectedPortalInfo) { - parentNoteName = getPathFromNodeid(connectedPortalInfo?.parentNodeId) + const namespace = getNamespaceOfNodeid(connectedPortalInfo?.parentNodeId) + parentNoteName = { + path: getPathFromNodeid(connectedPortalInfo?.parentNodeId), + namespace: namespace?.id + } } return { @@ -79,10 +85,15 @@ const Portals = () => { const isUpdate = connectedPortalInfo && connectedPortalInfo.parentNodeId !== parentNote?.nodeid if (isUpdate) { - await updateParentNote(params.actionGroupId, connectedPortalInfo.serviceId, parentNote.nodeid) + await updateParentNote( + params.actionGroupId, + connectedPortalInfo.serviceId, + parentNote.nodeid, + parentNote?.namespace + ) toast(`Updated Successfully! All new notes will be added under "${parentNote.text}"`) } else { - await connectToPortal(params.actionGroupId, serviceId, parentNote?.nodeid) + await connectToPortal(params.actionGroupId, serviceId, parentNote?.nodeid, parentNote?.namespace) toast(`Updated Successfully! All new notes will be added under "${parentNoteName}"`) } } catch (err) { diff --git a/apps/webapp/src/Hooks/usePortals.ts b/apps/webapp/src/Hooks/usePortals.ts index 067085be4..480d5997c 100644 --- a/apps/webapp/src/Hooks/usePortals.ts +++ b/apps/webapp/src/Hooks/usePortals.ts @@ -30,10 +30,10 @@ export const usePortals = () => { } } - const connectToPortal = async (actionGroupId: string, serviceId: string, parentNodeId: string) => { + const connectToPortal = async (actionGroupId: string, serviceId: string, parentNodeId: string, namespaceId: string) => { const workspaceId = getWorkspaceId() - const portal: PortalType = { serviceId, parentNodeId, serviceType: actionGroupId, mexId: workspaceId } + const portal: PortalType = { serviceId, parentNodeId, serviceType: actionGroupId, mexId: workspaceId, namespaceId } try { const res = client.post(apiURLs.connectToLochService(), portal, { @@ -49,11 +49,17 @@ export const usePortals = () => { } } - const updateParentNote = async (actionGroupId: string, serviceId: string, parentNodeId: string) => { + const updateParentNote = async ( + actionGroupId: string, + serviceId: string, + parentNodeId: string, + namespaceId: string + ) => { const reqBody = { serviceId, serviceType: actionGroupId, - parentNodeId + parentNodeId, + namespaceId } try { diff --git a/apps/webapp/src/Types/Actions.ts b/apps/webapp/src/Types/Actions.ts index 66329c4ae..4a597a5b2 100644 --- a/apps/webapp/src/Types/Actions.ts +++ b/apps/webapp/src/Types/Actions.ts @@ -19,5 +19,6 @@ export type PortalType = { mexId?: string nodeId?: string parentNodeId?: string + namespaceId?: string sessionStartTime?: number } From e1af33beea8341bd19503288f0e5700282daec6c Mon Sep 17 00:00:00 2001 From: xypnox Date: Wed, 26 Oct 2022 23:52:47 +0530 Subject: [PATCH 3/3] Add changeset --- .changeset/eleven-owls-greet.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/eleven-owls-greet.md diff --git a/.changeset/eleven-owls-greet.md b/.changeset/eleven-owls-greet.md new file mode 100644 index 000000000..587fcf1c7 --- /dev/null +++ b/.changeset/eleven-owls-greet.md @@ -0,0 +1,6 @@ +--- +'mexit': patch +'mexit-webapp': patch +--- + +Fix extension, portal calls