From f1c106a94365546086c7fb3279bf1dbf83f110a1 Mon Sep 17 00:00:00 2001 From: Shoaibdev7 Date: Wed, 3 Jul 2024 20:14:16 +0500 Subject: [PATCH 1/3] fix(blue-print): render schema attributes if attributes object --- .../BlueprintModal/Body/index.tsx | 28 +++++++++++++++++-- .../BlueprintModal/types/index.ts | 3 ++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/components/ModalsContainer/BlueprintModal/Body/index.tsx b/src/components/ModalsContainer/BlueprintModal/Body/index.tsx index e61393df1..b3333a11c 100644 --- a/src/components/ModalsContainer/BlueprintModal/Body/index.tsx +++ b/src/components/ModalsContainer/BlueprintModal/Body/index.tsx @@ -1,6 +1,7 @@ import { useEffect, useState } from 'react' import { ClipLoader } from 'react-spinners' import styled from 'styled-components' +import { AddEdgeNode } from '~/components/ModalsContainer/BlueprintModal/Body/AddEdgeNode' import { Flex } from '~/components/common/Flex' import { Schema, getSchemaAll } from '~/network/fetchSourcesData' import { useSchemaStore } from '~/stores/useSchemaStore' @@ -9,7 +10,6 @@ import { SchemaWithChildren } from '../types' import { Editor } from './Editor' import { Graph } from './Graph' import { Toolbar } from './Toolbar' -import { AddEdgeNode } from '~/components/ModalsContainer/BlueprintModal/Body/AddEdgeNode' export type FormData = { type: string @@ -43,7 +43,18 @@ export const Body = () => { const filteredSchemas = response.schemas.filter((i) => i.ref_id && !i.is_deleted) - setSchemaAll(filteredSchemas.length > 0 ? filteredSchemas : response.schemas) + const processedSchemas = filteredSchemas.map((schema) => { + if (schema.attributes) { + return { + ...schema, + ...schema.attributes, + } + } + + return schema + }) + + setSchemaAll(processedSchemas.length > 0 ? processedSchemas : response.schemas) setSchemaLinks(response.edges.length > 0 ? response.edges : []) @@ -88,7 +99,18 @@ export const Body = () => { const onSchemaUpdate = async () => { const response = await getSchemaAll() - setSchemaAll(response.schemas.filter((i) => i.ref_id && !i.is_deleted && i.ref_id)) + const processedSchemas = response.schemas.map((schema) => { + if (schema.attributes) { + return { + ...schema, + ...schema.attributes, + } + } + + return schema + }) + + setSchemaAll(processedSchemas.filter((i) => i.ref_id && !i.is_deleted && i.ref_id)) setSchemaLinks(response.edges) } diff --git a/src/components/ModalsContainer/BlueprintModal/types/index.ts b/src/components/ModalsContainer/BlueprintModal/types/index.ts index f694aafc1..b7b17b0b7 100644 --- a/src/components/ModalsContainer/BlueprintModal/types/index.ts +++ b/src/components/ModalsContainer/BlueprintModal/types/index.ts @@ -14,6 +14,9 @@ export type SchemaExtended = SchemaWithChildren & { vx?: number vy?: number vz?: number + attributes?: { + [k: string]: string | boolean + } } export type SchemaLinkExtended = SchemaLink & { From 0c640af6720e8fda84d511802f938b339f23f3d9 Mon Sep 17 00:00:00 2001 From: Shoaibdev7 Date: Sun, 7 Jul 2024 05:07:31 +0500 Subject: [PATCH 2/3] fix(blue-print): render schema attributes if attributes object --- .../AddItemModal/SetAttributesStep/index.tsx | 3 ++- .../CustomAttributesStep/FormInput/index.tsx | 6 ++++- .../BlueprintModal/Body/index.tsx | 26 ++----------------- 3 files changed, 9 insertions(+), 26 deletions(-) diff --git a/src/components/AddItemModal/SetAttributesStep/index.tsx b/src/components/AddItemModal/SetAttributesStep/index.tsx index 1cb4e4150..ea4a63020 100644 --- a/src/components/AddItemModal/SetAttributesStep/index.tsx +++ b/src/components/AddItemModal/SetAttributesStep/index.tsx @@ -35,7 +35,8 @@ export const SetAttributesStep: FC = ({ handleSelectType, skipToStep, nod const data = await getNodeType(nodeType) - const parsedData = parseJson(data) + const parsedData = + data.attributes && typeof data.attributes === 'object' ? parseJson(data.attributes) : parseJson(data) const filteredAttributes = parsedData.filter((attr) => attr.key !== 'node_key') diff --git a/src/components/ModalsContainer/BlueprintModal/Body/Editor/CustomAttributesStep/FormInput/index.tsx b/src/components/ModalsContainer/BlueprintModal/Body/Editor/CustomAttributesStep/FormInput/index.tsx index 2ab61e04f..d5c4ef927 100644 --- a/src/components/ModalsContainer/BlueprintModal/Body/Editor/CustomAttributesStep/FormInput/index.tsx +++ b/src/components/ModalsContainer/BlueprintModal/Body/Editor/CustomAttributesStep/FormInput/index.tsx @@ -48,7 +48,11 @@ export const FormInput = ({ const data = await getNodeType(parentParam as string) - parsedDataDefault = parseJson(data) + if (data.attributes && typeof data.attributes === 'object') { + parsedDataDefault = parseJson(data.attributes) + } else { + parsedDataDefault = parseJson(data) + } } parsedDataDefault = parsedDataDefault.filter((x) => x.key !== 'node_key') diff --git a/src/components/ModalsContainer/BlueprintModal/Body/index.tsx b/src/components/ModalsContainer/BlueprintModal/Body/index.tsx index b3333a11c..dd53065dd 100644 --- a/src/components/ModalsContainer/BlueprintModal/Body/index.tsx +++ b/src/components/ModalsContainer/BlueprintModal/Body/index.tsx @@ -43,18 +43,7 @@ export const Body = () => { const filteredSchemas = response.schemas.filter((i) => i.ref_id && !i.is_deleted) - const processedSchemas = filteredSchemas.map((schema) => { - if (schema.attributes) { - return { - ...schema, - ...schema.attributes, - } - } - - return schema - }) - - setSchemaAll(processedSchemas.length > 0 ? processedSchemas : response.schemas) + setSchemaAll(filteredSchemas.length > 0 ? filteredSchemas : response.schemas) setSchemaLinks(response.edges.length > 0 ? response.edges : []) @@ -99,18 +88,7 @@ export const Body = () => { const onSchemaUpdate = async () => { const response = await getSchemaAll() - const processedSchemas = response.schemas.map((schema) => { - if (schema.attributes) { - return { - ...schema, - ...schema.attributes, - } - } - - return schema - }) - - setSchemaAll(processedSchemas.filter((i) => i.ref_id && !i.is_deleted && i.ref_id)) + setSchemaAll(response.schemas.filter((i) => i.ref_id && !i.is_deleted && i.ref_id)) setSchemaLinks(response.edges) } From 452c640259ac65721ca304eb7075ac986dbdfa38 Mon Sep 17 00:00:00 2001 From: Shoaibdev7 Date: Sun, 7 Jul 2024 05:10:51 +0500 Subject: [PATCH 3/3] fix(blue-print): remove unrelated changes --- src/components/ModalsContainer/BlueprintModal/types/index.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/components/ModalsContainer/BlueprintModal/types/index.ts b/src/components/ModalsContainer/BlueprintModal/types/index.ts index b7b17b0b7..f694aafc1 100644 --- a/src/components/ModalsContainer/BlueprintModal/types/index.ts +++ b/src/components/ModalsContainer/BlueprintModal/types/index.ts @@ -14,9 +14,6 @@ export type SchemaExtended = SchemaWithChildren & { vx?: number vy?: number vz?: number - attributes?: { - [k: string]: string | boolean - } } export type SchemaLinkExtended = SchemaLink & {