From f2ff3dfd155d105a371c7b8df38bb57604b33b37 Mon Sep 17 00:00:00 2001 From: Michael Behrisch <m.behrisch@uu.nl> Date: Mon, 14 Mar 2022 18:00:40 +0100 Subject: [PATCH] fix(vis-schema): :bug: regression fix for unmerged files somehow the merge from feat/schema-refactor did get a regression. --- .../src/components/schema/schema.stories.tsx | 4 +++- .../src/components/schema/schema.tsx | 22 +++++++++++-------- .../data-access/store/src/lib/schemaSlice.ts | 6 ++--- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/apps/web-graphpolaris/src/components/schema/schema.stories.tsx b/apps/web-graphpolaris/src/components/schema/schema.stories.tsx index c1367b96c..a05129048 100644 --- a/apps/web-graphpolaris/src/components/schema/schema.stories.tsx +++ b/apps/web-graphpolaris/src/components/schema/schema.stories.tsx @@ -2,6 +2,7 @@ import { SchemaUtils } from '@graphpolaris/schema-utils'; import { colorPaletteConfigSlice, schemaSlice, + setSchema, store, } from '@graphpolaris/shared/data-access/store'; import { GraphPolarisThemeProvider } from '@graphpolaris/shared/data-access/theme'; @@ -144,6 +145,7 @@ TestWithSchema.play = async () => { ], }); - //dispatch(setSchema(schema)); + console.info('dispatch dummy schema', schema.order); + dispatch(setSchema(schema.export())); // handleSchemaLayout(schema); }; diff --git a/apps/web-graphpolaris/src/components/schema/schema.tsx b/apps/web-graphpolaris/src/components/schema/schema.tsx index 0bc264d47..7eb3be96d 100644 --- a/apps/web-graphpolaris/src/components/schema/schema.tsx +++ b/apps/web-graphpolaris/src/components/schema/schema.tsx @@ -3,7 +3,7 @@ import { useSchema, useSchemaLayout, } from '@graphpolaris/shared/data-access/store'; -import { LayoutFactory } from '@graphpolaris/graph-layout'; +import { AllLayoutAlgorithms, LayoutFactory } from '@graphpolaris/graph-layout'; import { useEffect, useState } from 'react'; import ReactFlow, { FlowElement, ReactFlowProvider } from 'react-flow-renderer'; @@ -19,22 +19,26 @@ const Schema = (props: Props) => { const [elements, setElements] = useState([] as FlowElement[]); // In case the schema is updated const dbschema = useSchema(); - const schemaLayout = useSchemaLayout(); + // const [dbschema, setSchema] = useState(useSchema()); + const [schemaLayout, setSchemaLayout] = useState(useSchemaLayout()); useEffect(() => { + if (dbschema == undefined || dbschema.order == 0) { + return; + } const layoutFactory = new LayoutFactory(); - // console.log('schema Layout', schemaLayout); + console.log('schema Layout', schemaLayout, 'order', dbschema.order); const layout = layoutFactory.createLayout( - // schemaLayout as AllLayoutAlgorithms - 'Graphology_noverlap' + schemaLayout as AllLayoutAlgorithms + // schemaLayout ); layout?.layout(dbschema); - // dbschema.forEachNode((node, attr) => { - // console.log('x', dbschema.getNodeAttribute(node, 'x')); - // console.log('y', dbschema.getNodeAttribute(node, 'y')); - // }); + dbschema.forEachNode((node, attr) => { + console.log('x', dbschema.getNodeAttribute(node, 'x')); + console.log('y', dbschema.getNodeAttribute(node, 'y')); + }); const flowElements = createReactFlowElements(dbschema); setElements(flowElements); diff --git a/libs/shared/data-access/store/src/lib/schemaSlice.ts b/libs/shared/data-access/store/src/lib/schemaSlice.ts index 3bc30b6da..1769c7b90 100644 --- a/libs/shared/data-access/store/src/lib/schemaSlice.ts +++ b/libs/shared/data-access/store/src/lib/schemaSlice.ts @@ -1,5 +1,6 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit'; import Graph, { MultiGraph } from 'graphology'; +import { SerializedGraph } from 'graphology-types'; import { SchemaFromBackend } from 'libs/shared/models/src'; import type { RootState } from './store'; @@ -16,10 +17,9 @@ export const schemaSlice = createSlice({ // `createSlice` will infer the state type from the `initialState` argument initialState, reducers: { - setSchema: (state, action: PayloadAction<Graph>) => { + setSchema: (state, action: PayloadAction<SerializedGraph>) => { console.log('setSchema', action); - - state.graphologySerialized = action.payload.export(); + state.graphologySerialized = action.payload; }, setSchemaLayout: (state, action: PayloadAction<string>) => { -- GitLab