Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

Commit 2354835

Browse files
committed
Do not altere tables once they are moved
1 parent 5d7fa29 commit 2354835

File tree

7 files changed

+64987
-3
lines changed

7 files changed

+64987
-3
lines changed

.idea/.gitignore

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/sql-scheme-diagram.iml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/App.js

+42-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react'
22
import ELK from 'elkjs/lib/elk.bundled.js'
33
import AceEditor from 'react-ace'
44
import uuid from 'uuid'
5+
import {debounce, keyBy} from 'lodash'
56
import {useDebouncedCallback} from 'use-debounce'
67
import ApolloClient, {gql} from 'apollo-boost'
78
import {
@@ -33,7 +34,7 @@ const client = new ApolloClient({
3334
uri:
3435
'https://k4emdgbstjgufjmo75arzjoxti.appsync-api.us-east-1.amazonaws.com/graphql',
3536
headers: {
36-
'x-api-key': 'da2-6hkc4wdow5et3hufzeq7nmuuye',
37+
'x-api-key': 'da2-3pw46cpomrgtnkzjmonjiec47i',
3738
},
3839
})
3940

@@ -79,6 +80,7 @@ const getSchemaData = (id) => {
7980
getSchema(id: $id) {
8081
id
8182
schema
83+
graph
8284
}
8385
}
8486
`,
@@ -88,6 +90,24 @@ const getSchemaData = (id) => {
8890
})
8991
}
9092

93+
const updateGraph = debounce((id, graph) => {
94+
client.mutate({
95+
mutation: gql`
96+
mutation updateSchema($input: UpdateSchemaInput!) {
97+
updateSchema(input: $input) {
98+
id
99+
}
100+
}
101+
`,
102+
variables: {
103+
input: {
104+
id: id,
105+
graph: graph,
106+
},
107+
},
108+
})
109+
}, 1000)
110+
91111
const parseInput = (text) => {
92112
const lexingResult = DBDefinitionLexer.tokenize(text)
93113
schemeParser.input = lexingResult.tokens
@@ -195,9 +215,25 @@ const tableDataReducer = (state, action) => {
195215
}
196216

197217
case 'set':
218+
const previusTables = keyBy(state.tables, 'id')
219+
220+
const tablesToSet = action.data.tables.map((table) => {
221+
if (previusTables[table.id]) {
222+
return {
223+
...table,
224+
x: previusTables[table.id].x,
225+
y: previusTables[table.id].y,
226+
}
227+
}
228+
229+
return table
230+
})
231+
232+
console.log(tablesToSet)
198233
return {
199234
...state,
200-
...action.data,
235+
refs: action.data.refs,
236+
tables: tablesToSet,
201237
}
202238

203239
case 'update':
@@ -209,6 +245,8 @@ const tableDataReducer = (state, action) => {
209245
return table
210246
})
211247

248+
updateGraph(state.globalId, JSON.stringify(updatedTables))
249+
212250
return {
213251
...state,
214252
tables: updatedTables,
@@ -232,7 +270,8 @@ function Home() {
232270
if (schema_id) {
233271
dispatch({type: 'setGlobalId', globalId: schema_id})
234272
getSchemaData(schema_id).then((response) => {
235-
const schema = response.data.getSchema.schema
273+
const {schema, graph} = response.data.getSchema
274+
236275
if (schema) {
237276
editorValue.current = schema
238277
aceComponent.current.editor.getSession().setValue(schema, -1)

0 commit comments

Comments
 (0)