Skip to content

Commit

Permalink
MindMap: Fix findNodeDifferences bug
Browse files Browse the repository at this point in the history
This bug occurred when styled was used.
findNodeDifferences could no longer find a usable key.
  • Loading branch information
norentkhy committed Jul 1, 2021
1 parent 3f0e63d commit 3a49cbb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/apps/MindMap/MainView/MainView.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useContext, useEffect, useRef, useState } from 'react'
import styled from 'styled-components'
import { ProjectContext } from '../Contexts/ProjectContext'

export function MainView({ theProjectContext = ProjectContext }) {
Expand Down Expand Up @@ -61,15 +62,15 @@ function Node({ node: { editing, id, text }, theProjectContext }) {

if (!editing)
return (
<button
<Button
onKeyUp={({ key }) => {
key === 'Enter' && initiateEditNode(id)
key === 'c' && createChildNode(id)
key === 'f' && foldNode(id)
}}
>
{text}
</button>
</Button>
)
else
return (
Expand All @@ -85,3 +86,5 @@ function Node({ node: { editing, id, text }, theProjectContext }) {
/>
)
}

const Button = styled.button``
8 changes: 7 additions & 1 deletion src/apps/MindMap/MindMapTestUtilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@ export async function findNodeDifferences(callback) {
function getKey(Element) {
const objectKeys = Object.keys(Element)
const fiberSomething = Element[objectKeys[0]]
return fiberSomething?.return?.key
return getMeaningfulKey(fiberSomething)

function getMeaningfulKey(obj) {
if (obj?.key) return obj.key
if (obj.return) return getMeaningfulKey(obj.return)
return null
}
}
}

Expand Down

0 comments on commit 3a49cbb

Please sign in to comment.