Skip to content

Commit ee8c6bc

Browse files
committed
fix table header color shuffling
1 parent 4ff5fbd commit ee8c6bc

File tree

4 files changed

+96
-27
lines changed

4 files changed

+96
-27
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ An Open Source alternative to dbdiagram.io, aiming to have the same basic featur
3333
+ 19. Added diagram fit function
3434
+ 20. Fix key icon positioning
3535
+ 21. Show key icon for columns in composite PK
36+
+ 22. Fix table header color reshuffle when changing the code
3637

3738
## Architecture - Solution
3839

web/src/components/VDbChart/VDbChart.vue

+1
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@
372372
y: p.y - (s.height / 2)
373373
}
374374
z = Math.min(zWidth, zHeight) - cor;
375+
console.log('sizes', s, 'start pan ', props.startpan, 'zooms', z,zWidth,zHeight)
375376
store.$patch({
376377
pan: pan,
377378
zoom: z

web/src/components/VDbChart/VDbTable.vue

+6
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,12 @@
106106
const tableNameWidth = root.value.querySelectorAll('.db-table-header__name')[0].getComputedTextLength()*(0.08*16);
107107
const maxWidth = Math.max(maxFieldWidth, tableNameWidth);
108108
state.value.width = snap(Math.max(200, maxWidth), gridSnap)+20;
109+
109110
}
110111
111112
const updateHeight = () => {
112113
state.value.height = 35 + (30 * props.fields.length);
114+
113115
}
114116
115117
const checkIndexPK = (field) => {
@@ -118,20 +120,24 @@
118120
119121
watch(() => props.useSchema, value => {
120122
updateWidth();
123+
store.updateTable(props.id,state.value)
121124
});
122125
123126
watch(() => props.name, value => {
124127
updateWidth();
128+
store.updateTable(props.id,state.value)
125129
});
126130
127131
watch(() => props.fields, value => {
128132
updateHeight();
129133
updateWidth();
134+
store.updateTable(props.id,state.value)
130135
});
131136
132137
onMounted(() => {
133138
updateHeight();
134139
updateWidth();
140+
store.updateTable(props.id,state.value)
135141
})
136142
137143
const emit = defineEmits([

web/src/store/chart.js

+88-27
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
import { defineStore } from "pinia";
23
import { markRaw } from "vue";
34

@@ -10,6 +11,7 @@ export const useChartStore = defineStore("chart", {
1011
tableGroups: {},
1112
tables: {},
1213
tablesColors:{},
14+
actualTables:{},
1315
refs: {},
1416
grid: {
1517
size: 100,
@@ -91,21 +93,62 @@ export const useChartStore = defineStore("chart", {
9193
getTableColor(state) {
9294
return (tablename, tableId, schema) => {
9395
let tfn = `${schema}.${tablename}`;
94-
if (!(tfn in state.tablesColors)) {
95-
state.tablesColors[tfn] = {
96-
color:null
97-
}
98-
}
99-
if (tablename in state.tablesColors) {
100-
state.tablesColors[tfn] = state.tablesColors[tablename];
101-
delete state.tablesColors[tablename];
102-
}
96+
10397
if (tableId in state.tablesColors) {
104-
state.tablesColors[tfn] = state.tablesColors[tableId];
105-
delete state.tablesColors[tableId];
106-
}
10798

108-
return state.tablesColors[tfn];
99+
if (Object.keys(state.tablesColors[tableId]).includes('color')){
100+
const c = state.tablesColors[tableId].color;
101+
state.tablesColors[tableId][tfn] = {color:c}
102+
delete state.tablesColors[tableId].color
103+
}
104+
105+
if (!(tfn in state.tablesColors[tableId])){
106+
let founded = false;
107+
for (const obj in state.tablesColors){
108+
if (tfn in state.tablesColors[obj] && obj != tableId){
109+
state.tablesColors[tableId][tfn] = state.tablesColors[obj][tfn]
110+
delete state.tablesColors[obj][tfn]
111+
founded = true
112+
}
113+
}
114+
if (!founded) {
115+
if (Object.keys(state.tablesColors[tableId]).length > 0) {
116+
if (!(tfn in state.tablesColors[tableId])){
117+
const k = Object.keys(state.tablesColors[tableId])[0]
118+
state.tablesColors[tableId][tfn] = state.tablesColors[tableId][k]
119+
delete state.tablesColors[tableId][k]
120+
}
121+
} else {
122+
state.tablesColors[tableId] = {};
123+
state.tablesColors[tableId][tfn] = {color:null}
124+
}
125+
}
126+
}
127+
} else {
128+
129+
state.tablesColors[tableId] = {};
130+
state.tablesColors[tableId][tfn] = {color:null}
131+
132+
if (tablename in state.tablesColors) {
133+
state.tablesColors[tableId] = {};
134+
state.tablesColors[tableId][tfn] = state.tablesColors[tablename];
135+
delete state.tablesColors[tablename];
136+
} else {
137+
state.tablesColors[tableId] = {};
138+
state.tablesColors[tableId][tfn] = {color:null}
139+
}
140+
141+
if (tfn in state.tablesColors) {
142+
state.tablesColors[tableId] = {};
143+
state.tablesColors[tableId][tfn] = state.tablesColors[tfn]
144+
delete state.tablesColors[tfn];
145+
} else {
146+
state.tablesColors[tableId] = {};
147+
state.tablesColors[tableId][tfn] = {color:null}
148+
}
149+
150+
}
151+
return state.tablesColors[tableId][tfn];
109152
};
110153
},
111154
getTableGroup(state) {
@@ -210,22 +253,40 @@ export const useChartStore = defineStore("chart", {
210253
};
211254
},
212255
loadDatabase(database) {
213-
for(const tableGroup of database.schemas[0].tableGroups)
214-
{
215-
this.getTableGroup(tableGroup.id);
216-
}
217-
for(const table of database.schemas[0].tables)
218-
{
219-
this.getTable(table.id);
220-
}
221-
for(const ref of database.schemas[0].refs)
222-
{
223-
this.getRef(ref.id);
256+
let tablesList = [];
257+
for (const schema of database.schemas){
258+
for(const tableGroup of schema.tableGroups)
259+
{
260+
this.getTableGroup(tableGroup.id);
261+
}
262+
263+
for(const table of schema.tables)
264+
{
265+
this.getTable(table.id);
266+
this.getTableColor(table.name,table.id,schema.name)
267+
}
268+
tablesList.push(...schema.tables.map((x)=> x.id));
269+
270+
for(const ref of schema.refs)
271+
{
272+
this.getRef(ref.id);
273+
}
274+
console.log(schema);
224275
}
225-
console.log(database.schemas[0]);
276+
277+
278+
this.$patch({
279+
actualTables:tablesList
280+
})
226281
this.loaded = true;
227282
},
228-
load(state) {
283+
load(state) {
284+
console.log(Object.values(this.actualTables))
285+
for (const tbl in state.tables) {
286+
if (!(Object.values(this.actualTables).includes(Number(tbl)))){
287+
delete state.tables[tbl]
288+
}
289+
}
229290
this.$reset();
230291
this.$patch({
231292
...state,
@@ -257,7 +318,7 @@ export const useChartStore = defineStore("chart", {
257318
updateTableColor(tablename,id, color,schema) {
258319
let tfn = `${schema}.${tablename}`;
259320
this.$patch({
260-
tablesColors:{[tfn]: {'color': color }}
321+
tablesColors:{[id]: { [tfn]: {'color': color }}}
261322
});
262323
},
263324
updateTable(tableId, newTable) {

0 commit comments

Comments
 (0)