Jelajahi Sumber

fix array element rendering values seperately

AykutSarac 3 tahun lalu
induk
melakukan
8ea665a41b
1 mengubah file dengan 13 tambahan dan 2 penghapusan
  1. 13 2
      src/pages/editor/LiveEditor/Node.tsx

+ 13 - 2
src/pages/editor/LiveEditor/Node.tsx

@@ -2,12 +2,12 @@ import React from "react";
 import { Handle, Position } from "react-flow-renderer";
 import { Handle, Position } from "react-flow-renderer";
 import styled from "styled-components";
 import styled from "styled-components";
 
 
-const StyledWrapper = styled.div<{ isArray?: boolean }>`
+const StyledWrapper = styled.div<{ isArray?: boolean, isElement?: boolean }>`
   background: ${({ theme }) => theme.BLACK_PRIMARY};
   background: ${({ theme }) => theme.BLACK_PRIMARY};
   border: 1px solid ${({ theme }) => theme.BLACK};
   border: 1px solid ${({ theme }) => theme.BLACK};
   border-radius: 5px;
   border-radius: 5px;
   padding: 16px;
   padding: 16px;
-  color: ${({ theme, isArray }) => isArray && theme.SEAGREEN};
+  color: ${({ theme, isArray, isElement }) => isArray ? theme.SEAGREEN : isElement && theme.ORANGE};
   width: auto;
   width: auto;
   min-width: 100px;
   min-width: 100px;
   text-align: ${({ isArray }) => isArray && "center"};
   text-align: ${({ isArray }) => isArray && "center"};
@@ -36,6 +36,17 @@ export const CustomNodeComponent: React.FC<{ data: any; id: string }> = ({
   if (typeof json === "object") {
   if (typeof json === "object") {
     const keyPairs = Object.entries(json);
     const keyPairs = Object.entries(json);
 
 
+    // temporary solution for array items
+    if (Object.keys(json).every((val) => !isNaN(+val))) {
+      return (
+        <StyledWrapper isElement>
+          {Object.values(json).join('')}
+          <Handle type="source" position={Position.Left} />
+          <Handle type="target" position={Position.Right} />
+        </StyledWrapper>
+      );
+    }
+
     return (
     return (
       <StyledWrapper>
       <StyledWrapper>
         {keyPairs.map((entries) => {
         {keyPairs.map((entries) => {