Improve preservation of column widths in sheets when making schema changes
This commit is contained in:
parent
31f6f9db7b
commit
eeda58822c
|
@ -10,9 +10,8 @@
|
||||||
import { createScrollStores } from "./stores/scroll"
|
import { createScrollStores } from "./stores/scroll"
|
||||||
import { createBoundsStores } from "./stores/bounds"
|
import { createBoundsStores } from "./stores/bounds"
|
||||||
import { createUIStores } from "./stores/ui"
|
import { createUIStores } from "./stores/ui"
|
||||||
export { createUserStores } from "./stores/users"
|
|
||||||
import { createWebsocket } from "./websocket"
|
|
||||||
import { createUserStores } from "./stores/users"
|
import { createUserStores } from "./stores/users"
|
||||||
|
import { createWebsocket } from "./websocket"
|
||||||
import { createResizeStores } from "./stores/resize"
|
import { createResizeStores } from "./stores/resize"
|
||||||
import { createMenuStores } from "./stores/menu"
|
import { createMenuStores } from "./stores/menu"
|
||||||
import { createMaxScrollStores } from "./stores/max-scroll"
|
import { createMaxScrollStores } from "./stores/max-scroll"
|
||||||
|
|
|
@ -18,6 +18,9 @@
|
||||||
dispatch,
|
dispatch,
|
||||||
config,
|
config,
|
||||||
ui,
|
ui,
|
||||||
|
table,
|
||||||
|
rows,
|
||||||
|
API,
|
||||||
} = getContext("sheet")
|
} = getContext("sheet")
|
||||||
|
|
||||||
let anchor
|
let anchor
|
||||||
|
@ -79,7 +82,18 @@
|
||||||
open = false
|
open = false
|
||||||
}
|
}
|
||||||
|
|
||||||
const makeDisplayColumn = () => {}
|
const makeDisplayColumn = async () => {
|
||||||
|
const tableDefinition = $table
|
||||||
|
if (!tableDefinition) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await API.saveTable({
|
||||||
|
...tableDefinition,
|
||||||
|
primaryDisplay: column.name,
|
||||||
|
})
|
||||||
|
await rows.actions.refreshSchema()
|
||||||
|
open = false
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
|
|
@ -38,11 +38,13 @@ export const createColumnsStores = context => {
|
||||||
|
|
||||||
// Merge new schema fields with existing schema in order to preserve widths
|
// Merge new schema fields with existing schema in order to preserve widths
|
||||||
schema.subscribe($schema => {
|
schema.subscribe($schema => {
|
||||||
const currentColumns = get(columns)
|
|
||||||
if (!$schema) {
|
if (!$schema) {
|
||||||
columns.set([])
|
columns.set([])
|
||||||
|
stickyColumn.set(null)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
const currentColumns = get(columns)
|
||||||
|
const currentStickyColumn = get(stickyColumn)
|
||||||
|
|
||||||
// Get field list
|
// Get field list
|
||||||
let fields = []
|
let fields = []
|
||||||
|
@ -55,7 +57,12 @@ export const createColumnsStores = context => {
|
||||||
// Update columns, removing extraneous columns and adding missing ones
|
// Update columns, removing extraneous columns and adding missing ones
|
||||||
columns.set(
|
columns.set(
|
||||||
fields.map(field => {
|
fields.map(field => {
|
||||||
const existing = currentColumns.find(x => x.name === field)
|
// Check if there is an existing column with this name so we can keep
|
||||||
|
// the width setting
|
||||||
|
let existing = currentColumns.find(x => x.name === field)
|
||||||
|
if (!existing && currentStickyColumn?.name === field) {
|
||||||
|
existing = currentStickyColumn
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
name: field,
|
name: field,
|
||||||
width: existing?.width || DefaultColumnWidth,
|
width: existing?.width || DefaultColumnWidth,
|
||||||
|
@ -64,21 +71,24 @@ export const createColumnsStores = context => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
|
||||||
|
|
||||||
schema.subscribe($schema => {
|
// Update sticky column
|
||||||
const primaryDisplay = Object.entries($schema).find(entry => {
|
const primaryDisplay = Object.entries($schema).find(entry => {
|
||||||
return entry[1].primaryDisplay
|
return entry[1].primaryDisplay
|
||||||
})
|
})
|
||||||
if (!primaryDisplay) {
|
if (!primaryDisplay) {
|
||||||
stickyColumn.set(null)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const existingWidth = get(stickyColumn)?.width
|
|
||||||
const same = primaryDisplay[0] === get(stickyColumn)?.name
|
// Check if there is an existing column with this name so we can keep
|
||||||
|
// the width setting
|
||||||
|
let existing = currentColumns.find(x => x.name === primaryDisplay[0])
|
||||||
|
if (!existing && currentStickyColumn?.name === primaryDisplay[0]) {
|
||||||
|
existing = currentStickyColumn
|
||||||
|
}
|
||||||
stickyColumn.set({
|
stickyColumn.set({
|
||||||
name: primaryDisplay[0],
|
name: primaryDisplay[0],
|
||||||
width: same ? existingWidth : DefaultColumnWidth,
|
width: existing?.width || DefaultColumnWidth,
|
||||||
left: 40,
|
left: 40,
|
||||||
schema: primaryDisplay[1],
|
schema: primaryDisplay[1],
|
||||||
idx: "sticky",
|
idx: "sticky",
|
||||||
|
|
Loading…
Reference in New Issue