Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Correct plugin initialization in extension, fix portal calls #230

Merged
merged 3 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/eleven-owls-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'mexit': patch
'mexit-webapp': patch
---

Fix extension, portal calls
4 changes: 2 additions & 2 deletions apps/extension/src/Components/Content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
}),
Expand Down
4 changes: 2 additions & 2 deletions apps/extension/src/Components/Dibba/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -162,7 +162,7 @@ export default function Dibba() {
})

const tempEditor = createPlateEditor({
plugins: getPlugins(
plugins: generateEditorPluginsWithComponents(
createPlateUI({
[ELEMENT_TAG]: CopyTag as any
}),
Expand Down
4 changes: 2 additions & 2 deletions apps/extension/src/Components/Editor/EditorPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion apps/extension/src/Components/EditorPreviewRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions apps/extension/src/Components/Sidebar/SnippetsInfoBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -62,7 +62,7 @@ export const SnippetsInfoBar = () => {
})

const tempEditor = createPlateEditor({
plugins: getPlugins(
plugins: generateEditorPluginsWithComponents(
createPlateUI({
[ELEMENT_TAG]: CopyTag as any
}),
Expand Down
2 changes: 1 addition & 1 deletion apps/extension/src/Editor/components/ComboBox/config.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
13 changes: 10 additions & 3 deletions apps/extension/src/Editor/plugins/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,17 @@ export const generatePlugins = (options: PluginOptionType) => {

return withPlugins
}
export const generateEditorPluginsWithComponents = (components: Record<string, any>, options?: PluginOptionType) => {
const wrappedComponents = components

const plugins = createPlugins(generatePlugins(options), {
components: wrappedComponents
})

return plugins
}

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

return plugins
}

export default useMemoizedPlugins
4 changes: 2 additions & 2 deletions apps/extension/src/Utils/pasteUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, 'plain' | 'html'> = {
Expand All @@ -35,7 +35,7 @@ export const copySnippetToClipboard = async (item: Snippet) => {
})

const tempEditor = createPlateEditor({
plugins: getPlugins(
plugins: generateEditorPluginsWithComponents(
createPlateUI({
[ELEMENT_TAG]: CopyTag as any
}),
Expand Down
19 changes: 15 additions & 4 deletions apps/webapp/src/Components/Portals/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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]

Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/Editor/Components/Combobox/config.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
3 changes: 1 addition & 2 deletions apps/webapp/src/Editor/Plugins/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export const generateEditorPluginsWithComponents = (components: Record<string, a
return plugins
}

const useEditorPlugins = (components: Record<string, any>, options?: PluginOptionType) => {
export const useEditorPlugins = (components: Record<string, any>, options?: PluginOptionType) => {
const { uploadImageToS3 } = useAuth()
const { uploadImageToWDCDN } = useUploadToCDN(uploadImageToS3)

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

export default useEditorPlugins
14 changes: 10 additions & 4 deletions apps/webapp/src/Hooks/usePortals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions apps/webapp/src/Types/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ export type PortalType = {
mexId?: string
nodeId?: string
parentNodeId?: string
namespaceId?: string
sessionStartTime?: number
}