@antelopejs/dms-database 0.2.3 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/frontend-module.d.ts +2 -0
- package/dist/frontend-module.js +17 -0
- package/dist/frontend-module.js.map +1 -0
- package/dist/index.js +2 -11
- package/dist/index.js.map +1 -1
- package/dist/pages/overview.d.ts +0 -1
- package/dist/pages/overview.js +0 -14
- package/dist/pages/overview.js.map +1 -1
- package/dist/pages/schemas.js +3 -0
- package/dist/pages/schemas.js.map +1 -1
- package/frontend-vue/app/build/composables/useDatabaseHealth.ts +11 -7
- package/frontend-vue/app/build/composables/useDatabaseSchemas.ts +8 -1
- package/frontend-vue/app/build/data/cellValues.ts +50 -0
- package/frontend-vue/app/build/diagram/graph.ts +211 -47
- package/frontend-vue/app/build/diagram/packing.ts +283 -0
- package/frontend-vue/app/build/utils/fieldTypes.ts +16 -1
- package/frontend-vue/app/components/ConnectionStatus.vue +5 -1
- package/frontend-vue/app/components/DataBrowser.vue +2 -2
- package/frontend-vue/app/components/DataBrowserSidebar.vue +1 -1
- package/frontend-vue/app/components/DataGrid.vue +44 -34
- package/frontend-vue/app/components/DiagramTableNode.vue +25 -1
- package/frontend-vue/app/components/DrawerTabs.vue +57 -0
- package/frontend-vue/app/components/JsonCellPanel.vue +81 -85
- package/frontend-vue/app/components/QueryConsole.vue +6 -1
- package/frontend-vue/app/components/RowDrawer.vue +98 -124
- package/frontend-vue/app/components/SchemaDiagram.vue +134 -17
- package/frontend-vue/app/components/TableInspector.vue +122 -149
- package/frontend-vue/i18n/locales/database-en-GB.json +8 -12
- package/frontend-vue/i18n/locales/database-fr-FR.json +8 -12
- package/frontend-vue/package.json +2 -2
- package/frontend-vue/pnpm-lock.yaml +5 -5
- package/frontend-vue/tests/clientNavigation.test.ts +93 -0
- package/frontend-vue/tests/dataBrowser.test.ts +91 -1
- package/frontend-vue/tests/diagramLayout.test.ts +383 -0
- package/frontend-vue/tests/fixtures/serverRender.ts +114 -0
- package/frontend-vue/tests/locales.test.ts +48 -0
- package/frontend-vue/tests/onDemandReads.test.ts +81 -0
- package/frontend-vue/tests/serverRender.test.ts +83 -1
- package/frontend-vue/vitest.config.ts +8 -1
- package/package.json +9 -8
- package/skills/dms-database/SKILL.md +2 -1
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import type { SchemaSummary } from '../app/build/composables/useDatabaseSchemas'
|
|
3
|
+
import {
|
|
4
|
+
buildGraph,
|
|
5
|
+
expandForSearch,
|
|
6
|
+
FOLDED_COLUMNS,
|
|
7
|
+
type GraphInput,
|
|
8
|
+
layOutSchema,
|
|
9
|
+
NODE_WIDTH,
|
|
10
|
+
nodeHeight,
|
|
11
|
+
type SchemaLayout,
|
|
12
|
+
shownColumns,
|
|
13
|
+
STUB_NODE_WIDTH,
|
|
14
|
+
TABLE_NODE_TYPE,
|
|
15
|
+
type TableNodeData,
|
|
16
|
+
tableNodeId,
|
|
17
|
+
} from '../app/build/diagram/graph'
|
|
18
|
+
import {
|
|
19
|
+
boundsOf,
|
|
20
|
+
DEFAULT_ASPECT,
|
|
21
|
+
fitZoom,
|
|
22
|
+
linkedGroups,
|
|
23
|
+
overlaps,
|
|
24
|
+
PACK_GAP,
|
|
25
|
+
packBlocks,
|
|
26
|
+
prefixOrder,
|
|
27
|
+
type Rect,
|
|
28
|
+
shelfRows,
|
|
29
|
+
startViewport,
|
|
30
|
+
} from '../app/build/diagram/packing'
|
|
31
|
+
|
|
32
|
+
// A schema shaped like a real MongoDB one: about forty tables on their own,
|
|
33
|
+
// most named `<module>__<table>`, a few groups linked by relations, a
|
|
34
|
+
// relation to another schema, and one very tall table (60 columns) whose
|
|
35
|
+
// relation column and the column pointed at sit far below the fold.
|
|
36
|
+
|
|
37
|
+
type Relation = {
|
|
38
|
+
fromField: string
|
|
39
|
+
toSchema: string
|
|
40
|
+
toTable: string
|
|
41
|
+
toField: string
|
|
42
|
+
many: boolean
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function table(name: string, columns: number, relations: Relation[] = []) {
|
|
46
|
+
const fields: Record<string, { kind: string }> = { _id: { kind: 'string' } }
|
|
47
|
+
for (let i = 1; i < columns; i++) fields[`field_${i}`] = { kind: 'string' }
|
|
48
|
+
for (const relation of relations)
|
|
49
|
+
fields[relation.fromField] = { kind: 'string' }
|
|
50
|
+
return { name, fields, indexes: {}, relations }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function to(fromField: string, toTable: string, toField = '_id'): Relation {
|
|
54
|
+
return { fromField, toSchema: 'app', toTable, toField, many: false }
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const ISOLATED = [
|
|
58
|
+
...Array.from({ length: 12 }, (_, i) =>
|
|
59
|
+
table(`dms-core__t${String(i).padStart(2, '0')}`, 3 + (i % 6)),
|
|
60
|
+
),
|
|
61
|
+
...Array.from({ length: 10 }, (_, i) =>
|
|
62
|
+
table(`dms-tenant__t${String(i).padStart(2, '0')}`, 4 + (i % 5)),
|
|
63
|
+
),
|
|
64
|
+
...Array.from({ length: 8 }, (_, i) =>
|
|
65
|
+
table(`dms-files__t${String(i).padStart(2, '0')}`, 2 + (i % 7)),
|
|
66
|
+
),
|
|
67
|
+
...Array.from({ length: 10 }, (_, i) =>
|
|
68
|
+
table(`plain_${String(i).padStart(2, '0')}`, 5 + (i % 4)),
|
|
69
|
+
),
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
// audit (60 columns) -> users by `user_id`, its 46th column; sessions point
|
|
73
|
+
// at audit's `code`, its 31st column.
|
|
74
|
+
const audit = table('dms-core__audit', 60)
|
|
75
|
+
audit.fields.user_id = { kind: 'string' }
|
|
76
|
+
audit.relations = [to('user_id', 'dms-core__users')]
|
|
77
|
+
|
|
78
|
+
const APP = {
|
|
79
|
+
id: 'app',
|
|
80
|
+
tables: [
|
|
81
|
+
...ISOLATED,
|
|
82
|
+
audit,
|
|
83
|
+
table('dms-core__users', 6),
|
|
84
|
+
table('dms-core__sessions', 4, [
|
|
85
|
+
to('audit_code', 'dms-core__audit', 'field_30'),
|
|
86
|
+
]),
|
|
87
|
+
table('shop__orders', 5, [to('customer_id', 'shop__customers')]),
|
|
88
|
+
table('shop__customers', 4),
|
|
89
|
+
table('shop__items', 4, [
|
|
90
|
+
to('order_id', 'shop__orders'),
|
|
91
|
+
to('product_id', 'shop__products'),
|
|
92
|
+
]),
|
|
93
|
+
table('shop__products', 6),
|
|
94
|
+
table('blog__posts', 5, [to('author_id', 'blog__authors')]),
|
|
95
|
+
table('blog__authors', 3),
|
|
96
|
+
table('invoices', 4, [
|
|
97
|
+
{
|
|
98
|
+
fromField: 'account_id',
|
|
99
|
+
toSchema: 'billing',
|
|
100
|
+
toTable: 'accounts',
|
|
101
|
+
toField: '_id',
|
|
102
|
+
many: false,
|
|
103
|
+
},
|
|
104
|
+
]),
|
|
105
|
+
],
|
|
106
|
+
} as unknown as SchemaSummary
|
|
107
|
+
|
|
108
|
+
const tableOf = (name: string) =>
|
|
109
|
+
APP.tables.find((t) => t.name === name) as SchemaSummary['tables'][number]
|
|
110
|
+
|
|
111
|
+
function rects(schema: SchemaSummary, layout: SchemaLayout): Map<string, Rect> {
|
|
112
|
+
const out = new Map<string, Rect>()
|
|
113
|
+
for (const t of schema.tables) {
|
|
114
|
+
const at = layout.tables[t.name] as { x: number; y: number }
|
|
115
|
+
out.set(t.name, {
|
|
116
|
+
...at,
|
|
117
|
+
width: NODE_WIDTH,
|
|
118
|
+
height: nodeHeight(schema, t),
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
for (const [id, at] of Object.entries(layout.stubs))
|
|
122
|
+
out.set(id, { ...at, width: STUB_NODE_WIDTH, height: 28 })
|
|
123
|
+
return out
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function input(overrides: Partial<GraphInput> = {}): GraphInput {
|
|
127
|
+
return {
|
|
128
|
+
schema: APP,
|
|
129
|
+
positions: {},
|
|
130
|
+
notes: [],
|
|
131
|
+
selectedId: null,
|
|
132
|
+
focusIds: null,
|
|
133
|
+
noteHandlers: {
|
|
134
|
+
onTextChange: () => undefined,
|
|
135
|
+
onDelete: () => undefined,
|
|
136
|
+
onEditEnd: () => undefined,
|
|
137
|
+
},
|
|
138
|
+
onOpenSchema: () => undefined,
|
|
139
|
+
routing: new Map(),
|
|
140
|
+
...overrides,
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const GROUPS = {
|
|
145
|
+
core: ['dms-core__audit', 'dms-core__users', 'dms-core__sessions'],
|
|
146
|
+
shop: ['shop__orders', 'shop__customers', 'shop__items', 'shop__products'],
|
|
147
|
+
blog: ['blog__posts', 'blog__authors'],
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
describe('diagram layout', () => {
|
|
151
|
+
const layout = layOutSchema(APP)
|
|
152
|
+
const placed = rects(APP, layout)
|
|
153
|
+
|
|
154
|
+
it('lays out no table or stub over another', () => {
|
|
155
|
+
const all = [...placed]
|
|
156
|
+
for (let i = 0; i < all.length; i++) {
|
|
157
|
+
for (let j = i + 1; j < all.length; j++) {
|
|
158
|
+
const [a, ra] = all[i] as [string, Rect]
|
|
159
|
+
const [b, rb] = all[j] as [string, Rect]
|
|
160
|
+
expect(overlaps(ra, rb), `${a} / ${b}`).toBe(false)
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
it('fills a canvas shaped like a wide screen, not a column', () => {
|
|
166
|
+
const bounds = boundsOf([...placed.values()])
|
|
167
|
+
const ratio = bounds.width / bounds.height
|
|
168
|
+
expect(ratio).toBeGreaterThan(DEFAULT_ASPECT / 1.5)
|
|
169
|
+
expect(ratio).toBeLessThan(DEFAULT_ASPECT * 1.5)
|
|
170
|
+
// A square canvas gets a squarer layout.
|
|
171
|
+
const square = boundsOf([
|
|
172
|
+
...rects(APP, layOutSchema(APP, { aspect: 1 })).values(),
|
|
173
|
+
])
|
|
174
|
+
expect(square.width / square.height).toBeLessThan(ratio)
|
|
175
|
+
expect(square.width / square.height).toBeGreaterThan(1 / 1.5)
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
it('keeps linked tables together, with no other table among them', () => {
|
|
179
|
+
for (const [name, members] of Object.entries(GROUPS)) {
|
|
180
|
+
const box = boundsOf(members.map((m) => placed.get(m) as Rect))
|
|
181
|
+
for (const [other, rect] of placed) {
|
|
182
|
+
if (members.includes(other) || other.startsWith('stub::')) continue
|
|
183
|
+
expect(overlaps(box, rect), `${name} / ${other}`).toBe(false)
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// The stub of another schema sits next to the table it hangs from.
|
|
187
|
+
const stub = placed.get('stub::billing::accounts') as Rect
|
|
188
|
+
const invoices = placed.get('invoices') as Rect
|
|
189
|
+
expect(Math.abs(stub.x - invoices.x)).toBeLessThan(NODE_WIDTH + 200)
|
|
190
|
+
expect(Math.abs(stub.y - invoices.y)).toBeLessThan(200)
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
it('runs dagre left to right within a group', () => {
|
|
194
|
+
const items = placed.get('shop__items') as Rect
|
|
195
|
+
const orders = placed.get('shop__orders') as Rect
|
|
196
|
+
const customers = placed.get('shop__customers') as Rect
|
|
197
|
+
expect(items.x).toBeLessThan(orders.x)
|
|
198
|
+
expect(orders.x).toBeLessThan(customers.x)
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
it('places the groups first, then the tables on their own by prefix and name', () => {
|
|
202
|
+
// Rows are bands no table crosses: merge the tables' heights.
|
|
203
|
+
const bands: [number, number][] = []
|
|
204
|
+
for (const rect of [...placed.values()].sort((a, b) => a.y - b.y)) {
|
|
205
|
+
const last = bands.at(-1)
|
|
206
|
+
if (last && rect.y <= last[1])
|
|
207
|
+
last[1] = Math.max(last[1], rect.y + rect.height)
|
|
208
|
+
else bands.push([rect.y, rect.y + rect.height])
|
|
209
|
+
}
|
|
210
|
+
expect(bands.length).toBeGreaterThan(1)
|
|
211
|
+
const rowOf = (name: string) => {
|
|
212
|
+
const { y } = placed.get(name) as Rect
|
|
213
|
+
return bands.findIndex(([top, bottom]) => y >= top && y <= bottom)
|
|
214
|
+
}
|
|
215
|
+
const linked = Object.values(GROUPS).flat()
|
|
216
|
+
const lastGroupRow = Math.max(...linked.map(rowOf))
|
|
217
|
+
const order = prefixOrder(ISOLATED.map((t) => t.name))
|
|
218
|
+
// Rows follow the order: a table never sits on a row above one before it.
|
|
219
|
+
for (let i = 1; i < order.length; i++)
|
|
220
|
+
expect(rowOf(order[i] as string)).toBeGreaterThanOrEqual(
|
|
221
|
+
rowOf(order[i - 1] as string),
|
|
222
|
+
)
|
|
223
|
+
// Tables on their own start on or after the groups' first row.
|
|
224
|
+
expect(rowOf(order[0] as string)).toBeGreaterThanOrEqual(
|
|
225
|
+
Math.min(...linked.map(rowOf)),
|
|
226
|
+
)
|
|
227
|
+
expect(lastGroupRow).toBeLessThanOrEqual(rowOf(order.at(-1) as string))
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
it('orders by prefix, the tables without one last, then by name', () => {
|
|
231
|
+
expect(
|
|
232
|
+
prefixOrder(['plain', 'b__x', 'a__z', 'a__y', 'aa', 'b__a']),
|
|
233
|
+
).toEqual(['a__y', 'a__z', 'b__a', 'b__x', 'aa', 'plain'])
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
it('keeps clear of the notes', () => {
|
|
237
|
+
const note = { x: 300, y: 0, width: 220, height: 140 }
|
|
238
|
+
const around = rects(APP, layOutSchema(APP, { obstacles: [note] }))
|
|
239
|
+
for (const [name, rect] of around)
|
|
240
|
+
expect(overlaps(rect, note), name).toBe(false)
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
it('groups linked ids in their order', () => {
|
|
244
|
+
expect(
|
|
245
|
+
linkedGroups(
|
|
246
|
+
['a', 'b', 'c', 'd', 'e'],
|
|
247
|
+
[
|
|
248
|
+
['a', 'c'],
|
|
249
|
+
['d', 'c'],
|
|
250
|
+
],
|
|
251
|
+
),
|
|
252
|
+
).toEqual([['a', 'c', 'd'], ['b'], ['e']])
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
it('packs one block per row when the rows can hold no more', () => {
|
|
256
|
+
const packed = packBlocks(
|
|
257
|
+
[
|
|
258
|
+
{ id: 'a', width: 100, height: 400 },
|
|
259
|
+
{ id: 'b', width: 100, height: 400 },
|
|
260
|
+
],
|
|
261
|
+
0.1,
|
|
262
|
+
)
|
|
263
|
+
expect(packed.get('a')?.x).toBe(packed.get('b')?.x)
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
it('puts the tallest block of a row first and stacks short ones beside it', () => {
|
|
267
|
+
const blocks = [
|
|
268
|
+
{ id: 'short1', width: 100, height: 100 },
|
|
269
|
+
{ id: 'tall', width: 300, height: 600 },
|
|
270
|
+
{ id: 'short2', width: 100, height: 100 },
|
|
271
|
+
{ id: 'short3', width: 100, height: 100 },
|
|
272
|
+
]
|
|
273
|
+
expect(shelfRows(blocks, 600)).toEqual([blocks])
|
|
274
|
+
const packed = packBlocks(blocks, 1)
|
|
275
|
+
expect(packed.get('tall')).toEqual({ x: 0, y: 0 })
|
|
276
|
+
// The short ones share one column, in their order, under each other.
|
|
277
|
+
const xs = new Set(
|
|
278
|
+
['short1', 'short2', 'short3'].map((id) => packed.get(id)?.x),
|
|
279
|
+
)
|
|
280
|
+
expect(xs.size).toBe(1)
|
|
281
|
+
expect(packed.get('short1')?.y).toBe(0)
|
|
282
|
+
expect(packed.get('short2')?.y).toBe(100 + PACK_GAP)
|
|
283
|
+
expect(packed.get('short3')?.y).toBe(2 * (100 + PACK_GAP))
|
|
284
|
+
})
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
describe('folded tables', () => {
|
|
288
|
+
it('shows the first columns and every column an arrow ends on', () => {
|
|
289
|
+
const shown = shownColumns(APP, tableOf('dms-core__audit'), false)
|
|
290
|
+
expect(shown.foldable).toBe(true)
|
|
291
|
+
expect(shown.columns.slice(0, FOLDED_COLUMNS)).toEqual(
|
|
292
|
+
Object.keys(tableOf('dms-core__audit').fields).slice(0, FOLDED_COLUMNS),
|
|
293
|
+
)
|
|
294
|
+
// Its key, its relation column, and the column sessions point at.
|
|
295
|
+
expect(shown.columns).toContain('_id')
|
|
296
|
+
expect(shown.columns).toContain('user_id')
|
|
297
|
+
expect(shown.columns).toContain('field_30')
|
|
298
|
+
expect(shown.columns).toHaveLength(FOLDED_COLUMNS + 2)
|
|
299
|
+
expect(shown.hiddenCount).toBe(61 - FOLDED_COLUMNS - 2)
|
|
300
|
+
const open = shownColumns(APP, tableOf('dms-core__audit'), true)
|
|
301
|
+
expect(open.columns).toHaveLength(61)
|
|
302
|
+
expect(open.hiddenCount).toBe(0)
|
|
303
|
+
})
|
|
304
|
+
|
|
305
|
+
it('leaves small tables as they are, with no fold row', () => {
|
|
306
|
+
const shown = shownColumns(APP, tableOf('shop__orders'), false)
|
|
307
|
+
expect(shown).toMatchObject({ foldable: false, hiddenCount: 0 })
|
|
308
|
+
expect(nodeHeight(APP, tableOf('shop__orders'))).toBe(44 + 6 * 24)
|
|
309
|
+
})
|
|
310
|
+
|
|
311
|
+
it('lays out at the folded height', () => {
|
|
312
|
+
const audit = tableOf('dms-core__audit')
|
|
313
|
+
expect(nodeHeight(APP, audit)).toBe(44 + (FOLDED_COLUMNS + 2 + 1) * 24)
|
|
314
|
+
expect(nodeHeight(APP, audit, true)).toBe(44 + (61 + 1) * 24)
|
|
315
|
+
})
|
|
316
|
+
|
|
317
|
+
it('never ends an arrow on a row that is not drawn', () => {
|
|
318
|
+
const graph = buildGraph(input())
|
|
319
|
+
const columns = new Map(
|
|
320
|
+
graph.nodes
|
|
321
|
+
.filter((n) => n.type === TABLE_NODE_TYPE)
|
|
322
|
+
.map((n) => [n.id, (n.data as unknown as TableNodeData).columns]),
|
|
323
|
+
)
|
|
324
|
+
for (const edge of graph.edges) {
|
|
325
|
+
const source = edge.sourceHandle.split('::')[0] as string
|
|
326
|
+
const target = edge.targetHandle.split('::')[0] as string
|
|
327
|
+
expect(columns.get(edge.source)).toContain(source)
|
|
328
|
+
if (!edge.data.isStubTarget)
|
|
329
|
+
expect(columns.get(edge.target)).toContain(target)
|
|
330
|
+
}
|
|
331
|
+
})
|
|
332
|
+
|
|
333
|
+
it('draws an expanded table whole, above the others', () => {
|
|
334
|
+
const graph = buildGraph(input({ expanded: new Set(['dms-core__audit']) }))
|
|
335
|
+
const node = graph.nodes.find(
|
|
336
|
+
(n) => n.id === tableNodeId('app', 'dms-core__audit'),
|
|
337
|
+
)
|
|
338
|
+
const data = node?.data as unknown as TableNodeData
|
|
339
|
+
expect(data.columns).toHaveLength(61)
|
|
340
|
+
expect(data).toMatchObject({ expanded: true, hiddenCount: 0 })
|
|
341
|
+
expect(node?.zIndex).toBe(1)
|
|
342
|
+
})
|
|
343
|
+
|
|
344
|
+
it('unfolds the table a search finds a folded column in', () => {
|
|
345
|
+
const none = new Set<string>()
|
|
346
|
+
const audit = 'dms-core__audit'
|
|
347
|
+
expect(expandForSearch(APP, audit, 'field_40', none)).toEqual(
|
|
348
|
+
new Set([audit]),
|
|
349
|
+
)
|
|
350
|
+
// A column already drawn, or a match on the name only, leaves it folded.
|
|
351
|
+
expect(expandForSearch(APP, audit, 'field_11', none)).toBe(none)
|
|
352
|
+
expect(expandForSearch(APP, audit, 'audit', none)).toBe(none)
|
|
353
|
+
expect(expandForSearch(APP, audit, 'user_id', none)).toBe(none)
|
|
354
|
+
})
|
|
355
|
+
})
|
|
356
|
+
|
|
357
|
+
describe('start view', () => {
|
|
358
|
+
const size = { width: 1600, height: 900 }
|
|
359
|
+
|
|
360
|
+
it('fits the diagram when it reads at 40% or closer', () => {
|
|
361
|
+
const bounds = { x: 0, y: 0, width: 2000, height: 1000 }
|
|
362
|
+
expect(fitZoom(bounds, size, 0.25)).toBeCloseTo(0.64)
|
|
363
|
+
expect(startViewport(bounds, 0.64, 0.4, { x: 32, y: 80 })).toBeNull()
|
|
364
|
+
})
|
|
365
|
+
|
|
366
|
+
it('starts at 40% on the top-left corner of a larger one', () => {
|
|
367
|
+
const bounds = { x: -100, y: 50, width: 12000, height: 6000 }
|
|
368
|
+
const zoom = fitZoom(bounds, size, 0.25)
|
|
369
|
+
expect(zoom).toBeLessThan(0.4)
|
|
370
|
+
expect(startViewport(bounds, zoom, 0.4, { x: 32, y: 80 })).toEqual({
|
|
371
|
+
x: 32 + 100 * 0.4,
|
|
372
|
+
y: 80 - 50 * 0.4,
|
|
373
|
+
zoom: 0.4,
|
|
374
|
+
})
|
|
375
|
+
})
|
|
376
|
+
|
|
377
|
+
it('reads the example schema at 40% or closer on a wide screen', () => {
|
|
378
|
+
const bounds = boundsOf([...rects(APP, layOutSchema(APP)).values()])
|
|
379
|
+
// The layout before this change: one column about as tall as the
|
|
380
|
+
// schema's tables stacked.
|
|
381
|
+
expect(fitZoom(bounds, size, 0.25)).toBeGreaterThan(0.2)
|
|
382
|
+
})
|
|
383
|
+
})
|
|
@@ -75,6 +75,7 @@ vi.stubGlobal('regionalDayNumber', regional.regionalDayNumber)
|
|
|
75
75
|
vi.stubGlobal('useToast', () => ({ add: noop }))
|
|
76
76
|
vi.stubGlobal('useConfirm', () => ({ confirm: async () => false }))
|
|
77
77
|
vi.stubGlobal('useDrawer', () => ({ open: noop }))
|
|
78
|
+
vi.stubGlobal('resolveDmsComponent', engine.resolveDmsComponent)
|
|
78
79
|
vi.stubGlobal('useUnsavedChanges', noop)
|
|
79
80
|
vi.stubGlobal('useDmsUserSession', () => ({
|
|
80
81
|
user: vue.ref({ _id: 'me' }),
|
|
@@ -98,6 +99,7 @@ const UI_COMPONENTS = [
|
|
|
98
99
|
'DmsCard',
|
|
99
100
|
'DmsChart',
|
|
100
101
|
'DmsCodeSnippet',
|
|
102
|
+
'DmsContainerFooter',
|
|
101
103
|
'DmsEmptyState',
|
|
102
104
|
'DmsEyebrow',
|
|
103
105
|
'DmsFieldRow',
|
|
@@ -106,6 +108,7 @@ const UI_COMPONENTS = [
|
|
|
106
108
|
'DmsFormRequiredLegend',
|
|
107
109
|
'DmsInputCode',
|
|
108
110
|
'DmsInputText',
|
|
111
|
+
'DmsNavCardGridBlock',
|
|
109
112
|
'DmsSaveBar',
|
|
110
113
|
'DmsSegmented',
|
|
111
114
|
'DmsStatusSummary',
|
|
@@ -140,6 +143,117 @@ const uiStub = (name: string): Component =>
|
|
|
140
143
|
h('div', { 'data-stub': name }, slots.default?.()),
|
|
141
144
|
})
|
|
142
145
|
|
|
146
|
+
/** A node of the browser mount's tree: an element, a text or a comment. */
|
|
147
|
+
interface MountNode {
|
|
148
|
+
tag?: string
|
|
149
|
+
text?: string
|
|
150
|
+
props: Record<string, unknown>
|
|
151
|
+
children: MountNode[]
|
|
152
|
+
parent: MountNode | null
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const mountNode = (fields: Partial<MountNode>): MountNode => ({
|
|
156
|
+
props: {},
|
|
157
|
+
children: [],
|
|
158
|
+
parent: null,
|
|
159
|
+
...fields,
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
function detach(node: MountNode): void {
|
|
163
|
+
const siblings = node.parent?.children
|
|
164
|
+
if (siblings) siblings.splice(siblings.indexOf(node), 1)
|
|
165
|
+
node.parent = null
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// A DOM-less renderer: enough of Vue's node operations to mount a component
|
|
169
|
+
// tree in Node and read back what it shows.
|
|
170
|
+
const { createApp: createMountApp } = vue.createRenderer<MountNode, MountNode>({
|
|
171
|
+
createElement: (tag) => mountNode({ tag }),
|
|
172
|
+
createText: (text) => mountNode({ text }),
|
|
173
|
+
createComment: () => mountNode({ text: '' }),
|
|
174
|
+
setText: (node, text) => {
|
|
175
|
+
node.text = text
|
|
176
|
+
},
|
|
177
|
+
setElementText: (node, text) => {
|
|
178
|
+
node.children = [mountNode({ text, parent: node })]
|
|
179
|
+
},
|
|
180
|
+
insert: (child, parent, anchor) => {
|
|
181
|
+
detach(child)
|
|
182
|
+
const at = anchor ? parent.children.indexOf(anchor) : -1
|
|
183
|
+
if (at < 0) parent.children.push(child)
|
|
184
|
+
else parent.children.splice(at, 0, child)
|
|
185
|
+
child.parent = parent
|
|
186
|
+
},
|
|
187
|
+
remove: detach,
|
|
188
|
+
parentNode: (node) => node.parent,
|
|
189
|
+
nextSibling: (node) => {
|
|
190
|
+
const siblings = node.parent?.children ?? []
|
|
191
|
+
return siblings[siblings.indexOf(node) + 1] ?? null
|
|
192
|
+
},
|
|
193
|
+
patchProp: (node, key, _previous, next) => {
|
|
194
|
+
node.props[key] = next
|
|
195
|
+
},
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
function mountText(node: MountNode): string {
|
|
199
|
+
if (node.tag === undefined) return node.text ?? ''
|
|
200
|
+
const attributes = Object.entries(node.props)
|
|
201
|
+
.filter(([, value]) => typeof value !== 'function')
|
|
202
|
+
.map(
|
|
203
|
+
([key, value]) =>
|
|
204
|
+
` ${key}="${typeof value === 'string' ? value : JSON.stringify(value)}"`,
|
|
205
|
+
)
|
|
206
|
+
.join('')
|
|
207
|
+
return `<${node.tag}${attributes}>${node.children.map(mountText).join('')}</${node.tag}>`
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** A component mounted in a browser, as a client navigation shows it. */
|
|
211
|
+
export interface BrowserMount {
|
|
212
|
+
/**
|
|
213
|
+
* Settles once the page's suspense resolved: when a client navigation
|
|
214
|
+
* would show the component.
|
|
215
|
+
*/
|
|
216
|
+
shown: Promise<void>
|
|
217
|
+
/** What the component shows now (`''` while the navigation waits). */
|
|
218
|
+
text: () => string
|
|
219
|
+
reads: BackendRead[]
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Mounts `component` in a browser's app (no server render to hydrate) inside
|
|
224
|
+
* the `<Suspense>` a page navigation renders in, answering each backend
|
|
225
|
+
* request with `respond`, which may answer later (a promise).
|
|
226
|
+
*/
|
|
227
|
+
export function browserMount(
|
|
228
|
+
component: Component,
|
|
229
|
+
respond: Backend,
|
|
230
|
+
props: Record<string, unknown> = {},
|
|
231
|
+
): BrowserMount {
|
|
232
|
+
backend = respond
|
|
233
|
+
reads.length = 0
|
|
234
|
+
const runtime = engine.createDmsFrontendRuntime(undefined, {}, false)
|
|
235
|
+
let resolveShown!: () => void
|
|
236
|
+
const shown = new Promise<void>((resolve) => (resolveShown = resolve))
|
|
237
|
+
const app = createMountApp({
|
|
238
|
+
render: () =>
|
|
239
|
+
h(
|
|
240
|
+
vue.Suspense,
|
|
241
|
+
{ onResolve: () => resolveShown() },
|
|
242
|
+
{ default: () => h(component, props) },
|
|
243
|
+
),
|
|
244
|
+
})
|
|
245
|
+
engine.provideDmsFrontendRuntime(app, runtime)
|
|
246
|
+
// The tests compile the components for a server, whose setups record
|
|
247
|
+
// themselves in the render's context: an empty one stands in for it.
|
|
248
|
+
app.provide(vue.ssrContextKey, {})
|
|
249
|
+
app.component('DmsClientOnly', engine.DmsClientOnly)
|
|
250
|
+
for (const name of UI_COMPONENTS) app.component(name, uiStub(name))
|
|
251
|
+
app.config.warnHandler = noop
|
|
252
|
+
const root = mountNode({ tag: 'root' })
|
|
253
|
+
app.mount(root)
|
|
254
|
+
return { shown, text: () => mountText(root), reads }
|
|
255
|
+
}
|
|
256
|
+
|
|
143
257
|
export interface ServerRender {
|
|
144
258
|
html: string
|
|
145
259
|
payload: DmsPayload
|
|
@@ -78,3 +78,51 @@ describe('translated templates', () => {
|
|
|
78
78
|
expect(unscoped).toEqual([])
|
|
79
79
|
})
|
|
80
80
|
})
|
|
81
|
+
|
|
82
|
+
// The backend pages name their texts by key: a key left behind in a page, or
|
|
83
|
+
// a page block whose keys were dropped, shows the raw `$dms_database...` path.
|
|
84
|
+
const PAGES_DIR = join(import.meta.dirname, '../../src/pages')
|
|
85
|
+
|
|
86
|
+
function resolves(messages: Messages, key: string): boolean {
|
|
87
|
+
let node: string | Messages | undefined = messages
|
|
88
|
+
for (const part of key.split('.')) {
|
|
89
|
+
if (typeof node !== 'object') return false
|
|
90
|
+
node = node[part]
|
|
91
|
+
}
|
|
92
|
+
return typeof node === 'string'
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
describe('page texts', () => {
|
|
96
|
+
const pageKeys = readdirSync(PAGES_DIR)
|
|
97
|
+
.filter((file) => file.endsWith('.ts'))
|
|
98
|
+
.flatMap((file) => [
|
|
99
|
+
...readFileSync(join(PAGES_DIR, file), 'utf8').matchAll(
|
|
100
|
+
/"\$(dms_database\.[\w.]+)"/g,
|
|
101
|
+
),
|
|
102
|
+
])
|
|
103
|
+
.map(([, key]) => key)
|
|
104
|
+
|
|
105
|
+
it('finds the keys of the pages', () => {
|
|
106
|
+
expect(pageKeys.length).toBeGreaterThan(0)
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
it.each(files)('translates every key the pages name in %s', (file) => {
|
|
110
|
+
const messages = JSON.parse(
|
|
111
|
+
readFileSync(join(LOCALES_DIR, file), 'utf8'),
|
|
112
|
+
) as Messages
|
|
113
|
+
expect(pageKeys.filter((key) => !resolves(messages, key))).toEqual([])
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it('shows no beta notice on the overview', () => {
|
|
117
|
+
const overview = readFileSync(join(PAGES_DIR, 'overview.ts'), 'utf8')
|
|
118
|
+
expect(overview).not.toMatch(/\bBanner\(/)
|
|
119
|
+
for (const file of files) {
|
|
120
|
+
const messages = JSON.parse(
|
|
121
|
+
readFileSync(join(LOCALES_DIR, file), 'utf8'),
|
|
122
|
+
) as Messages
|
|
123
|
+
expect(resolves(messages, 'dms_database.overview.beta.title')).toBe(
|
|
124
|
+
false,
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
})
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
import { useDiagramPersistence } from '../app/build/composables/useDiagramPersistence'
|
|
8
8
|
import { useQueryStore } from '../app/build/composables/useQueryStore'
|
|
9
9
|
import InstancePicker from '../app/components/InstancePicker.vue'
|
|
10
|
+
import JsonCellPanel from '../app/components/JsonCellPanel.vue'
|
|
10
11
|
import RowDrawer from '../app/components/RowDrawer.vue'
|
|
11
12
|
|
|
12
13
|
// The reads the module makes on demand go through `useApiData` too
|
|
@@ -95,6 +96,86 @@ describe('server render: what only the browser reads', () => {
|
|
|
95
96
|
expect(page.reads).toEqual([])
|
|
96
97
|
})
|
|
97
98
|
|
|
99
|
+
it("a row's drawer: values given the room, an even end slot, a sticky footer", async () => {
|
|
100
|
+
const page = await serverRender(RowDrawer, {
|
|
101
|
+
tab: { id: 't', schema: 'shop', table: 'orders', instance: '' },
|
|
102
|
+
rowId: 'r1',
|
|
103
|
+
row: {
|
|
104
|
+
_id: 'r1',
|
|
105
|
+
status: 'open',
|
|
106
|
+
pinned: true,
|
|
107
|
+
description:
|
|
108
|
+
'A long description that runs past what the value column shows.',
|
|
109
|
+
address: { city: 'Liège' },
|
|
110
|
+
},
|
|
111
|
+
columns: [
|
|
112
|
+
{ name: '_id', type: 'string', isPrimaryKey: true },
|
|
113
|
+
{ name: 'status', type: 'string', isPrimaryKey: false },
|
|
114
|
+
{ name: 'pinned', type: 'boolean', isPrimaryKey: false },
|
|
115
|
+
{ name: 'description', type: 'string', isPrimaryKey: false },
|
|
116
|
+
{ name: 'address', type: 'object', isPrimaryKey: false },
|
|
117
|
+
],
|
|
118
|
+
readOnly: false,
|
|
119
|
+
navigation: {
|
|
120
|
+
index: 0,
|
|
121
|
+
total: 50,
|
|
122
|
+
hasPrev: false,
|
|
123
|
+
hasNext: true,
|
|
124
|
+
prev: () => undefined,
|
|
125
|
+
next: () => undefined,
|
|
126
|
+
},
|
|
127
|
+
onStage: () => undefined,
|
|
128
|
+
onReview: () => undefined,
|
|
129
|
+
})
|
|
130
|
+
// The DMS row header holds the position and the steps.
|
|
131
|
+
expect(page.html).not.toMatch(/1\s*\/\s*50/)
|
|
132
|
+
expect(page.html).not.toContain('i-ph-caret-up')
|
|
133
|
+
expect(page.html).toContain('data-row-scope')
|
|
134
|
+
// A short value beside its label, a long text and JSON across the row.
|
|
135
|
+
const row = (field: string) =>
|
|
136
|
+
page.html.match(
|
|
137
|
+
new RegExp(`<div[^>]*data-field-row="${field}"[^>]*>`),
|
|
138
|
+
)?.[0] ?? ''
|
|
139
|
+
expect(row('status')).toContain('layout="form"')
|
|
140
|
+
expect(row('description')).toContain('layout="stack"')
|
|
141
|
+
expect(row('address')).toContain('layout="stack"')
|
|
142
|
+
expect(page.html.match(/data-stub="DmsTextarea"/g)).toHaveLength(2)
|
|
143
|
+
// Every editable field, the switch too, keeps the same end slot.
|
|
144
|
+
expect(page.html.match(/data-null-slot/g)).toHaveLength(4)
|
|
145
|
+
expect(page.html.match(/icon="i-ph-circle-dashed"/g)).toHaveLength(4)
|
|
146
|
+
// The DMS footer, at the drawer's bottom.
|
|
147
|
+
expect(page.html).toMatch(
|
|
148
|
+
/data-stub="DmsContainerFooter"[^>]*data-row-footer|data-row-footer[^>]*data-stub="DmsContainerFooter"/,
|
|
149
|
+
)
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
it("a structured cell's JSON editor is a drawer body, with its own Apply and Cancel", async () => {
|
|
153
|
+
const page = await serverRender(JsonCellPanel, {
|
|
154
|
+
column: 'address',
|
|
155
|
+
value: { city: 'Liège' },
|
|
156
|
+
readOnly: false,
|
|
157
|
+
})
|
|
158
|
+
expect(page.reads).toEqual([])
|
|
159
|
+
// The DMS drawer is the surface: no slideover of its own.
|
|
160
|
+
expect(page.html).not.toContain('USlideover')
|
|
161
|
+
expect(page.html).toContain('DmsInputCode')
|
|
162
|
+
// Stacked for the drawer: the label above an editor across it, which
|
|
163
|
+
// fills the drawer's height, never fewer than 12 lines.
|
|
164
|
+
expect(page.html).toMatch(/layout="stack"[^>]*fill/)
|
|
165
|
+
expect(page.html).toMatch(/fill[^>]*min-lines="12"/)
|
|
166
|
+
expect(page.html).not.toContain('max-lines')
|
|
167
|
+
expect(page.html).toContain('data-stub="DmsContainerFooter"')
|
|
168
|
+
expect(page.html).toContain('dms_database.data.json.apply')
|
|
169
|
+
expect(page.html).toContain('dms_database.common.cancel')
|
|
170
|
+
const readOnly = await serverRender(JsonCellPanel, {
|
|
171
|
+
column: 'address',
|
|
172
|
+
value: { city: 'Liège' },
|
|
173
|
+
readOnly: true,
|
|
174
|
+
})
|
|
175
|
+
expect(readOnly.html).not.toContain('dms_database.data.json.apply')
|
|
176
|
+
expect(readOnly.html).toContain('dms_database.common.cancel')
|
|
177
|
+
})
|
|
178
|
+
|
|
98
179
|
it('the instance picker reads nothing until its menu opens', async () => {
|
|
99
180
|
const page = await serverRender(
|
|
100
181
|
InstancePicker,
|