Skip to content

Commit 64919a6

Browse files
authored
Fix Correct plugin initialization in extension, fix portal calls (#230)
#230
1 parent 9e07c78 commit 64919a6

File tree

14 files changed

+56
-26
lines changed

14 files changed

+56
-26
lines changed

.changeset/eleven-owls-greet.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'mexit': patch
3+
'mexit-webapp': patch
4+
---
5+
6+
Fix extension, portal calls

apps/extension/src/Components/Content/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ActionType, defaultContent, ELEMENT_TAG, mog, QuickLinkStatus, QuickLin
66
import { NodeEditorContent } from '@mexit/core'
77

88
import { CopyTag } from '../../Editor/components/Tags/CopyTag'
9-
import getPlugins from '../../Editor/plugins/index'
9+
import { generateEditorPluginsWithComponents } from '../../Editor/plugins/index'
1010
import { useEditorContext } from '../../Hooks/useEditorContext'
1111
import { useSnippets } from '../../Hooks/useSnippets'
1212
import { useSputlitContext } from '../../Hooks/useSputlitContext'
@@ -30,7 +30,7 @@ export default function Content() {
3030
useEffect(() => {
3131
if (selection?.range && selection?.url && previewMode) {
3232
const editor = createPlateEditor({
33-
plugins: getPlugins(
33+
plugins: generateEditorPluginsWithComponents(
3434
createPlateUI({
3535
[ELEMENT_TAG]: CopyTag as any
3636
}),

apps/extension/src/Components/Dibba/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { ActionTitle, ComboboxItemTitle, ComboboxShortcuts, ComboSeperator, Shor
2727

2828
import { ElementTypeBasedShortcut } from '../../Editor/components/ComboBox'
2929
import { CopyTag } from '../../Editor/components/Tags/CopyTag'
30-
import getPlugins from '../../Editor/plugins/index'
30+
import { generateEditorPluginsWithComponents } from '../../Editor/plugins/index'
3131
import { getPathFromNodeIdHookless } from '../../Hooks/useLinks'
3232
import usePointerMovedSinceMount from '../../Hooks/usePointerMovedSinceMount'
3333
import { useSnippets } from '../../Hooks/useSnippets'
@@ -162,7 +162,7 @@ export default function Dibba() {
162162
})
163163

164164
const tempEditor = createPlateEditor({
165-
plugins: getPlugins(
165+
plugins: generateEditorPluginsWithComponents(
166166
createPlateUI({
167167
[ELEMENT_TAG]: CopyTag as any
168168
}),

apps/extension/src/Components/Editor/EditorPreview.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from '@mexit/shared'
1616
import { Button } from '@mexit/shared'
1717

18-
import useMemoizedPlugins from '../../Editor/plugins'
18+
import { generateEditorPluginsWithComponents } from '../../Editor/plugins'
1919
// import useLoad from '../../../Hooks/useLoad'
2020
// import { useRouting, ROUTE_PATHS, NavigationType } from '../../../Hooks/useRouting'
2121
// import { useTags } from '../../Hooks/useTags'
@@ -95,7 +95,7 @@ const EditorPreview = ({
9595
// goTo(ROUTE_PATHS.node, NavigationType.push, nodeid)
9696
}
9797

98-
const plugins = useMemoizedPlugins(components, { exclude: { dnd: true } })
98+
const plugins = generateEditorPluginsWithComponents(components, { exclude: { dnd: true } })
9999

100100
if (cc) {
101101
return (

apps/extension/src/Components/EditorPreviewRenderer.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import styled from 'styled-components'
66
import { EditorStyles, FadeContainer, TodoContainer } from '@mexit/shared'
77
import { useEditorChange } from '@mexit/shared'
88

9-
import useMemoizedPlugins from '../Editor/plugins'
9+
import { useMemoizedPlugins } from '../Editor/plugins'
1010
import components from './Editor/Components'
1111

1212
interface EditorPreviewRendererProps {

apps/extension/src/Components/Sidebar/SnippetsInfoBar.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
import { SnippetCards, Input, SidebarListFilter, SidebarListFilterWrapper, SnippetSidebarHelp } from '@mexit/shared'
2121

2222
import { CopyTag } from '../../Editor/components/Tags/CopyTag'
23-
import getPlugins from '../../Editor/plugins/index'
23+
import { generateEditorPluginsWithComponents } from '../../Editor/plugins/index'
2424
import useRaju from '../../Hooks/useRaju'
2525
import { useSnippets } from '../../Hooks/useSnippets'
2626
import { useSnippetStore } from '../../Stores/useSnippetStore'
@@ -62,7 +62,7 @@ export const SnippetsInfoBar = () => {
6262
})
6363

6464
const tempEditor = createPlateEditor({
65-
plugins: getPlugins(
65+
plugins: generateEditorPluginsWithComponents(
6666
createPlateUI({
6767
[ELEMENT_TAG]: CopyTag as any
6868
}),

apps/extension/src/Editor/components/ComboBox/config.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { PlatePlugin, PlatePluginComponent } from '@udecode/plate'
2-
import useMemoizedPlugins, { generatePlugins } from '../../plugins'
2+
import { useMemoizedPlugins, generatePlugins } from '../../plugins'
33
import { QuickLinkComboboxItem } from '../../plugins/QuickLink/components/QuickLinkComboboxItem'
44
import { ELEMENT_ILINK, ELEMENT_TAG } from '@mexit/core'
55
import useMultiComboboxOnChange from '../MultiCombobox/useMultiComboboxChange'

apps/extension/src/Editor/plugins/index.tsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,17 @@ export const generatePlugins = (options: PluginOptionType) => {
195195

196196
return withPlugins
197197
}
198+
export const generateEditorPluginsWithComponents = (components: Record<string, any>, options?: PluginOptionType) => {
199+
const wrappedComponents = components
200+
201+
const plugins = createPlugins(generatePlugins(options), {
202+
components: wrappedComponents
203+
})
204+
205+
return plugins
206+
}
198207

199-
const useMemoizedPlugins = (components: Record<string, any>, options?: PluginOptionType) => {
208+
export const useMemoizedPlugins = (components: Record<string, any>, options?: PluginOptionType) => {
200209
const wrappedComponents = components
201210
// Raw uploader
202211
const { uploadImageToS3 } = useAuth()
@@ -215,5 +224,3 @@ const useMemoizedPlugins = (components: Record<string, any>, options?: PluginOpt
215224

216225
return plugins
217226
}
218-
219-
export default useMemoizedPlugins

apps/extension/src/Utils/pasteUtils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
} from '@mexit/core'
1414

1515
import { CopyTag } from '../Editor/components/Tags/CopyTag'
16-
import getPlugins from '../Editor/plugins/index'
16+
import { generateEditorPluginsWithComponents } from '../Editor/plugins/index'
1717

1818
// Also a better matching for the domains
1919
export const supportedDomains: Record<string, 'plain' | 'html'> = {
@@ -35,7 +35,7 @@ export const copySnippetToClipboard = async (item: Snippet) => {
3535
})
3636

3737
const tempEditor = createPlateEditor({
38-
plugins: getPlugins(
38+
plugins: generateEditorPluginsWithComponents(
3939
createPlateUI({
4040
[ELEMENT_TAG]: CopyTag as any
4141
}),

apps/webapp/src/Components/Portals/index.tsx

+15-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { QuickLink } from '../NodeSelect/NodeSelect'
1717
import CreateInput from '../createInput'
1818
import ServiceHeader from './ServiceHeader'
1919
import ServiceInfo from './ServiceInfo'
20+
import { useNamespaces } from '../../Hooks/useNamespaces'
2021

2122
const Portals = () => {
2223
const theme = useTheme()
@@ -36,6 +37,7 @@ const Portals = () => {
3637
const apps = usePortalStore((store) => store.apps)
3738
const connectedPortals = usePortalStore((store) => store.connectedPortals)
3839
const getIsPortalConnected = usePortalStore((store) => store.getIsPortalConnected)
40+
const { getNamespaceOfNodeid } = useNamespaces()
3941

4042
const actionGroup = apps[params.actionGroupId]
4143

@@ -44,9 +46,13 @@ const Portals = () => {
4446
const { connectedPortalInfo, parentNoteName } = useMemo(() => {
4547
const connectedPortalInfo = getIsPortalConnected(actionGroup.actionGroupId)
4648

47-
let parentNoteName = ''
49+
let parentNoteName = undefined
4850
if (connectedPortalInfo) {
49-
parentNoteName = getPathFromNodeid(connectedPortalInfo?.parentNodeId)
51+
const namespace = getNamespaceOfNodeid(connectedPortalInfo?.parentNodeId)
52+
parentNoteName = {
53+
path: getPathFromNodeid(connectedPortalInfo?.parentNodeId),
54+
namespace: namespace?.id
55+
}
5056
}
5157

5258
return {
@@ -79,10 +85,15 @@ const Portals = () => {
7985
const isUpdate = connectedPortalInfo && connectedPortalInfo.parentNodeId !== parentNote?.nodeid
8086

8187
if (isUpdate) {
82-
await updateParentNote(params.actionGroupId, connectedPortalInfo.serviceId, parentNote.nodeid)
88+
await updateParentNote(
89+
params.actionGroupId,
90+
connectedPortalInfo.serviceId,
91+
parentNote.nodeid,
92+
parentNote?.namespace
93+
)
8394
toast(`Updated Successfully! All new notes will be added under "${parentNote.text}"`)
8495
} else {
85-
await connectToPortal(params.actionGroupId, serviceId, parentNote?.nodeid)
96+
await connectToPortal(params.actionGroupId, serviceId, parentNote?.nodeid, parentNote?.namespace)
8697
toast(`Updated Successfully! All new notes will be added under "${parentNoteName}"`)
8798
}
8899
} catch (err) {

apps/webapp/src/Editor/Components/Combobox/config.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { PlatePluginComponent } from '@udecode/plate'
22
import { useContextMenu } from 'react-contexify'
33

4-
import useEditorPlugins, { PluginOptionType } from '../../Plugins/index'
4+
import { useEditorPlugins, PluginOptionType } from '../../Plugins/index'
55
import { ComboboxConfig } from '../../Types/MultiCombobox'
66
import { MENU_ID } from '../BlockContextMenu'
77
import useMultiComboboxOnChange from '../MultiCombobox/useMultiComboboxChange'

apps/webapp/src/Editor/Plugins/index.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ export const generateEditorPluginsWithComponents = (components: Record<string, a
225225
return plugins
226226
}
227227

228-
const useEditorPlugins = (components: Record<string, any>, options?: PluginOptionType) => {
228+
export const useEditorPlugins = (components: Record<string, any>, options?: PluginOptionType) => {
229229
const { uploadImageToS3 } = useAuth()
230230
const { uploadImageToWDCDN } = useUploadToCDN(uploadImageToS3)
231231

@@ -246,4 +246,3 @@ const useEditorPlugins = (components: Record<string, any>, options?: PluginOptio
246246
return plugins
247247
}
248248

249-
export default useEditorPlugins

apps/webapp/src/Hooks/usePortals.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ export const usePortals = () => {
3030
}
3131
}
3232

33-
const connectToPortal = async (actionGroupId: string, serviceId: string, parentNodeId: string) => {
33+
const connectToPortal = async (actionGroupId: string, serviceId: string, parentNodeId: string, namespaceId: string) => {
3434
const workspaceId = getWorkspaceId()
3535

36-
const portal: PortalType = { serviceId, parentNodeId, serviceType: actionGroupId, mexId: workspaceId }
36+
const portal: PortalType = { serviceId, parentNodeId, serviceType: actionGroupId, mexId: workspaceId, namespaceId }
3737

3838
try {
3939
const res = client.post(apiURLs.connectToLochService(), portal, {
@@ -49,11 +49,17 @@ export const usePortals = () => {
4949
}
5050
}
5151

52-
const updateParentNote = async (actionGroupId: string, serviceId: string, parentNodeId: string) => {
52+
const updateParentNote = async (
53+
actionGroupId: string,
54+
serviceId: string,
55+
parentNodeId: string,
56+
namespaceId: string
57+
) => {
5358
const reqBody = {
5459
serviceId,
5560
serviceType: actionGroupId,
56-
parentNodeId
61+
parentNodeId,
62+
namespaceId
5763
}
5864

5965
try {

apps/webapp/src/Types/Actions.ts

+1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ export type PortalType = {
1919
mexId?: string
2020
nodeId?: string
2121
parentNodeId?: string
22+
namespaceId?: string
2223
sessionStartTime?: number
2324
}

0 commit comments

Comments
 (0)