Skip to content

Commit

Permalink
Note with same name refactoring across spaces fix (#442)
Browse files Browse the repository at this point in the history
#442

* Note with same name refactoring across spaces fix

* Version bump
  • Loading branch information
dineshsingh1 authored Nov 3, 2022
1 parent 0c994e5 commit d6038b5
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 65 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mex-alpha",
"productName": "Mex Alpha",
"version": "0.16.2-alpha.4",
"version": "0.16.2-alpha.5",
"description": "Mex it to flex it",
"main": "dist/main.cjs",
"scripts": {
Expand Down
20 changes: 10 additions & 10 deletions src/components/layouts/Modals.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import BlockModal from '../../editor/Components/Blocks/BlockModal'
import Delete from '../mex/Refactor/DeleteModal'
import HelpModal from '../mex/Help/HelpModal'
import Lookup from '../mex/Lookup'
import React from 'react'
import Refactor from '../mex/Refactor/Refactor'
import Rename from '../mex/Refactor/Rename'
import { useAuthStore } from '@services/auth/useAuth'
import CreateReminderModal from '../mex/Reminders/CreateReminderModal'

import FleetContainer from '@components/FleetContainer'
import ShareModal from '@components/mex/Mention/ShareModal'
import ReleaseNotesModal from '@components/mex/ReleaseNotes'
import TaskViewModal from '@components/mex/TaskViewModal'
import TemplateModal from '@components/mex/Template/TemplateModal'
import FleetContainer from '@components/FleetContainer'
import { useAuthStore } from '@services/auth/useAuth'

import BlockModal from '../../editor/Components/Blocks/BlockModal'
import HelpModal from '../mex/Help/HelpModal'
import Lookup from '../mex/Lookup'
import Delete from '../mex/Refactor/DeleteModal'
import Rename from '../mex/Refactor/Rename'
import CreateReminderModal from '../mex/Reminders/CreateReminderModal'

export interface ModalOpenAction {
type: 'share-invite-prefill'
Expand All @@ -26,7 +26,7 @@ const Modals = () => {
return (
<>
<Lookup />
<Refactor />
{/* <Refactor /> */}
<Rename />
<Delete />
<HelpModal />
Expand Down
3 changes: 2 additions & 1 deletion src/components/mex/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import quillPenLine from '@iconify/icons-ri/quill-pen-line'
import shareLine from '@iconify/icons-ri/share-line'
import { Icon } from '@iconify/react'
import { useSnippetStore } from '@store/useSnippetStore'
import { getInitialNode } from '@utils/initial'
import { mog } from '@utils/lib/mog'
import { convertContentToRawText } from '@utils/search/parseData'

Expand Down Expand Up @@ -46,7 +47,6 @@ import { Title, TitleText } from '../../../style/Typography'
import { NodeType } from '../../../types/Types'
import { GenericSearchResult, idxKey } from '../../../types/search'
import { SplitType } from '../../../ui/layout/splitView'
import { getInitialNode } from '@utils/initial'
import { NavigationType, ROUTE_PATHS, useRouting } from '../../../views/routes/urls'
import Backlinks from '../Backlinks'
import Metadata from '../Metadata/Metadata'
Expand Down Expand Up @@ -331,6 +331,7 @@ const Search = () => {
</SplitSearchPreviewWrapper>
)
}

if (item.index === 'node' || item.index === 'shared') {
const con = contents[item.id]
const content = con ? con.content : defaultContent.content
Expand Down
3 changes: 2 additions & 1 deletion src/data/Defaults/shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ export const defaultShortcuts = {
showRefactor: {
title: 'Refactor',
keystrokes: '$mod+Shift+KeyR',
category: 'Actions'
category: 'Actions',
disabled: true
},
showRename: {
title: 'Rename',
Expand Down
4 changes: 2 additions & 2 deletions src/editor/Actions/useEditorBlockSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ export const useEditorBlockSelection = () => {
insertNodes(editor, { type: ELEMENT_PARAGRAPH, id: generateTempId(), children: [{ text: '' }] }, { at: [0] })
}

const deleteSelectedBlock = (): any => {
const deleteSelectedBlock = (deleteBlock?: boolean): any => {
const editorBlocks = getEditorBlocks()
deleteContentBlocks(editorBlocks)
if (deleteBlock) deleteContentBlocks(editorBlocks)
return editorBlocks
}

Expand Down
9 changes: 7 additions & 2 deletions src/editor/Components/Blocks/Block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ const Block: React.FC<BlockProps> = ({ children, blockId, block }) => {
}

return (
<BlockElement contentEditable={false} id={blockId}>
<BlockSelectorInput type="checkbox" value={isSelected} onClick={handleBlockSelect} />
<BlockElement contentEditable={false} id={blockId} key={`is-selected-${blockId}-${isSelected}`}>
<BlockSelectorInput
type="checkbox"
checked={Boolean(isSelected)}
// key={`is-selected-${blockId}-${isSelected}`}
onClick={handleBlockSelect}
/>
{children}
</BlockElement>
)
Expand Down
21 changes: 12 additions & 9 deletions src/editor/Components/Blocks/BlockInfoBar.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import deleteBin6Line from '@iconify/icons-ri/delete-bin-6-line'
import React from 'react'
import styled, { useTheme } from 'styled-components'
import useBlockStore, { ContextMenuActionType } from '../../../store/useBlockStore'
import { ButtonWrapper } from '../../../style/Settings'
import xBold from '@iconify/icons-ph/x-bold'

import { useEditorBlockSelection } from '@editor/Actions/useEditorBlockSelection'
import sendToIcon from '@iconify/icons-ph/arrow-bend-up-right-bold'
import xBold from '@iconify/icons-ph/x-bold'
import moveToIcon from '@iconify/icons-ri/anticlockwise-2-fill'
import { MexIcon } from '../../../style/Layouts'
import { PrimaryText } from '../../../style/Integration'
import { useEditorBlockSelection } from '@editor/Actions/useEditorBlockSelection'
import deleteBin6Line from '@iconify/icons-ri/delete-bin-6-line'
import styled, { useTheme } from 'styled-components'

import { Button } from '@workduck-io/mex-components'

import useBlockStore, { ContextMenuActionType } from '../../../store/useBlockStore'
import { PrimaryText } from '../../../style/Integration'
import { MexIcon } from '../../../style/Layouts'
import { ButtonWrapper } from '../../../style/Settings'

const BlockMenu = styled.div`
display: flex;
align-items: center;
Expand All @@ -36,7 +39,7 @@ const BlockInfoBar = () => {
const blockHeading = length === 0 ? 'Select Blocks' : `Block${length > 1 ? 's' : ''} selected:`

const handleDelete = () => {
deleteSelectedBlock()
deleteSelectedBlock(true)
setIsModalOpen(undefined)
}

Expand Down
20 changes: 13 additions & 7 deletions src/editor/Components/Blocks/BlockModal.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { useEditorBlockSelection } from '@editor/Actions/useEditorBlockSelection'
import { useCreateNewNote } from '@hooks/useCreateNewNote'
import React from 'react'
import Modal from 'react-modal'

import { QuickLink, WrappedNodeSelect } from '@components/mex/NodeSelect/NodeSelect'
import { useEditorBlockSelection } from '@editor/Actions/useEditorBlockSelection'
import { useCreateNewNote } from '@hooks/useCreateNewNote'
import { useLinks } from '@hooks/useLinks'
import useBlockStore from '@store/useBlockStore'
import { useDataSaverFromContent } from '../Saver'
import { useNamespaces } from '@hooks/useNamespaces'
import useBlockStore, { ContextMenuActionType } from '@store/useBlockStore'
import Modal from 'react-modal'

import { useDataSaverFromContent } from '../Saver'

const BlockModal = () => {
const blocksFromStore = useBlockStore((store) => store.blocks)
Expand All @@ -25,15 +27,19 @@ const BlockModal = () => {
}

const onNodeCreate = (quickLink: QuickLink): void => {
const editorBlocks = deleteSelectedBlock()
const editorBlocks = deleteSelectedBlock(isDeleteBlock())
const blocksContent = getContentWithNewBlocks(quickLink.value, editorBlocks, false)
createNewNote({ path: quickLink.value, noteContent: blocksContent, namespace: quickLink.namespace })
setIsModalOpen(undefined)
}

const isDeleteBlock = () => {
return isModalOpen === ContextMenuActionType.move
}

const onNodeSelect = (quickLink: QuickLink) => {
const nodeid = getNodeidFromPath(quickLink.value, quickLink.namespace)
const editorBlocks = deleteSelectedBlock()
const editorBlocks = deleteSelectedBlock(isDeleteBlock())
const content = getContentWithNewBlocks(nodeid, editorBlocks)
const namespace = quickLink.namespace ?? getDefaultNamespaceId()

Expand Down
18 changes: 11 additions & 7 deletions src/editor/Components/Toolbar/NodeRename.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useEffect, useMemo, useRef, useState } from 'react'

import { getNameFromPath, getParentFromPath, SEPARATOR } from '@components/mex/Sidebar/treeUtils'
import { useNamespaces } from '@hooks/useNamespaces'
import { useNodes } from '@hooks/useNodes'
import { useKeyListener } from '@hooks/useShortcutListener'
import useDataStore from '@store/useDataStore'
Expand Down Expand Up @@ -33,11 +34,12 @@ const NodeRenameOnlyTitle = () => {
const { push } = useNavigation()
const setMockRefactored = useRenameStore((store) => store.setMockRefactored)
const modalReset = useRenameStore((store) => store.closeModal)
const node = useEditorStore((store) => store.node)
const { path: nodeFrom, namespace: nodeFromNS } = useMemo(() => {
const noteLink = ilinks.find((i) => i.nodeid === useEditorStore.getState()?.node?.nodeid)

return noteLink
}, [ilinks])
const noteLink = ilinks.find((i) => i.nodeid === node?.nodeid)
if (noteLink) return noteLink
return node
}, [ilinks, node])
const setFrom = useRenameStore((store) => store.setFrom)
const [editable, setEditable] = useState(false)
const [newTitle, setNewTitle] = useState(getNameFromPath(nodeFrom))
Expand All @@ -46,6 +48,7 @@ const NodeRenameOnlyTitle = () => {
//
//
//
const { getNodesOfNamespace } = useNamespaces()

const reset = () => {
if (editable) modalReset()
Expand All @@ -61,11 +64,12 @@ const NodeRenameOnlyTitle = () => {
}

const isClashed = useMemo(() => {
return isClash(
const checkClash = isClash(
getTo(newTitle),
ilinks.map((n) => n.path)
getNodesOfNamespace(nodeFromNS)?.map((l) => l.path)
)
}, [ilinks, newTitle])
return checkClash
}, [ilinks, newTitle, nodeFromNS])

const { shortcutHandler } = useKeyListener()
const shortcuts = useHelpStore((store) => store.shortcuts)
Expand Down
46 changes: 23 additions & 23 deletions src/editor/Plugins/plugins.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import { createActionPlugin } from '@editor/Components/Actions/createActionPlugin'
import { withBlockOptions } from '@editor/Components/Blocks'
import { createBlockModifierPlugin } from '@editor/Components/Blocks/createBlockModifierPlugin'
import { PlateFloatingLink } from '@editor/Components/Floating/FloatingLink'
// eslint-disable-next-line import/no-unresolved
import MediaIFrame, { parseRestMediaUrls } from '@editor/Components/media-embed-ui/src/MediaEmbedElement/MediaIFrame'
import { createMentionPlugin } from '@editor/Components/mentions/createMentionsPlugin'
import {
ELEMENT_DEFAULT,
ELEMENT_H1,
Expand Down Expand Up @@ -29,7 +36,6 @@ import {
createLinkPlugin,
createListPlugin,
createMediaEmbedPlugin,
createNodeIdPlugin,
createParagraphPlugin,
createPlugins,
createResetNodePlugin,
Expand All @@ -44,9 +50,24 @@ import {
parseTwitterUrl,
parseVideoUrl,
MediaEmbedVideo,
MediaEmbedTweet
MediaEmbedTweet,
createNodeIdPlugin
} from '@udecode/plate'
import { ELEMENT_EXCALIDRAW, createExcalidrawPlugin } from '@udecode/plate-excalidraw'

import { withStyledDraggables } from '../Actions/withDraggable'
import { withStyledPlaceHolders } from '../Actions/withPlaceholder'
import { ExcalidrawElement } from '../Components/Excalidraw'
import { createInlineBlockPlugin } from '../Components/InlineBlock/createInlineBlockPlugin'
import { createQAPlugin } from '../Components/QABlock/createQAPlugin'
import { createSyncBlockPlugin } from '../Components/SyncBlock/createSyncBlockPlugin'
import TableWrapper from '../Components/TableWrapper'
import createTodoPlugin from '../Components/Todo/createTodoPlugin'
import { createILinkPlugin } from '../Components/ilink/createILinkPlugin'
import { createTagPlugin } from '../Components/tag/createTagPlugin'
// import { TagCombobox } from '../Components/tag/components/TagCombobox';
import { createBlurSelectionPlugin } from './blurSelection'
import { createHighlightTextPlugin } from './highlightText'
import {
optionsAutoFormatRule,
optionsCreateNodeIdPlugin,
Expand All @@ -58,27 +79,6 @@ import {
autoformatMath
} from './pluginOptions'

import { ExcalidrawElement } from '../Components/Excalidraw'
import TableWrapper from '../Components/TableWrapper'
// import { TagCombobox } from '../Components/tag/components/TagCombobox';
import { createBlurSelectionPlugin } from './blurSelection'
import { createILinkPlugin } from '../Components/ilink/createILinkPlugin'
import { createInlineBlockPlugin } from '../Components/InlineBlock/createInlineBlockPlugin'
import { createSyncBlockPlugin } from '../Components/SyncBlock/createSyncBlockPlugin'
import { createTagPlugin } from '../Components/tag/createTagPlugin'
import { withStyledDraggables } from '../Actions/withDraggable'
import { withStyledPlaceHolders } from '../Actions/withPlaceholder'
import createTodoPlugin from '../Components/Todo/createTodoPlugin'
import { createQAPlugin } from '../Components/QABlock/createQAPlugin'
import { createHighlightTextPlugin } from './highlightText'
import { createActionPlugin } from '@editor/Components/Actions/createActionPlugin'
import { createMentionPlugin } from '@editor/Components/mentions/createMentionsPlugin'
import { withBlockOptions } from '@editor/Components/Blocks'
import { createBlockModifierPlugin } from '@editor/Components/Blocks/createBlockModifierPlugin'
// eslint-disable-next-line import/no-unresolved
import MediaIFrame, { parseRestMediaUrls } from '@editor/Components/media-embed-ui/src/MediaEmbedElement/MediaIFrame'
import { PlateFloatingLink } from '@editor/Components/Floating/FloatingLink'

export type PluginOptionType = {
exclude: {
dnd?: boolean
Expand Down
7 changes: 5 additions & 2 deletions src/hooks/useRefactor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,13 @@ export const useRefactor = () => {
const execRefactorAsync = async (from: RefactorPath, to: RefactorPath, clearBuffer = true) => {
mog('FROM < TO', { from, to })
const nodeId = getNodeidFromPath(from.path, from.namespaceID)
const uniquePath = useDataStore
.getState()
.checkValidILink({ notePath: to.path, namespace: to.namespaceID, showAlert: false })

const res = await refactorNotes(
{ path: from.path.split('.').join('#'), namespaceID: from.namespaceID },
{ path: to.path.split('.').join('#'), namespaceID: to.namespaceID ?? from.namespaceID },
{ path: uniquePath.split('.').join('#'), namespaceID: to.namespaceID ?? from.namespaceID },
nodeId
).then((response: RefactorResponse) => {
const addedILinks = []
Expand All @@ -138,7 +141,7 @@ export const useRefactor = () => {
// * Update search Index with new Title
// * TODO: Make search API more flexible (Update specific fields)
if (content && nodeId) {
const title = getTitleFromPath(to.path)
const title = getTitleFromPath(uniquePath)
mog('Updating search index', { title })
updateDocument('node', nodeId, content, title)
}
Expand Down

0 comments on commit d6038b5

Please sign in to comment.