@antelopejs/dms-database 0.5.0 → 0.5.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.
Files changed (41) hide show
  1. package/README.md +1 -1
  2. package/dist/config.d.ts +2 -2
  3. package/dist/config.js.map +1 -1
  4. package/dist/routes/connections.js +7 -2
  5. package/dist/routes/connections.js.map +1 -1
  6. package/dist/routes/data.js +4 -1
  7. package/dist/routes/data.js.map +1 -1
  8. package/dist/service/builderRefusal.d.ts +2 -0
  9. package/dist/service/builderRefusal.js +28 -0
  10. package/dist/service/builderRefusal.js.map +1 -0
  11. package/dist/service/connectionRefusals.d.ts +17 -0
  12. package/dist/service/connectionRefusals.js +26 -0
  13. package/dist/service/connectionRefusals.js.map +1 -0
  14. package/dist/service/connectionState.d.ts +0 -2
  15. package/dist/service/connectionState.js +21 -11
  16. package/dist/service/connectionState.js.map +1 -1
  17. package/dist/service/connections.js +3 -2
  18. package/dist/service/connections.js.map +1 -1
  19. package/frontend-vue/app/build/components/DataGridFooter.vue +16 -1
  20. package/frontend-vue/app/build/composables/reloadForSelection.ts +3 -5
  21. package/frontend-vue/app/build/composables/useDataBrowserGrid.ts +1 -0
  22. package/frontend-vue/app/build/composables/useDataBrowserTabs.ts +91 -15
  23. package/frontend-vue/app/build/data/gridData.ts +22 -1
  24. package/frontend-vue/app/build/data/recentTables.ts +15 -14
  25. package/frontend-vue/app/build/data/useStagedSave.ts +0 -3
  26. package/frontend-vue/app/components/DataBrowser.vue +9 -14
  27. package/frontend-vue/app/components/DataBrowserSidebar.vue +1 -0
  28. package/frontend-vue/app/components/DataGrid.vue +5 -12
  29. package/frontend-vue/app/components/DatabaseSwitcher.vue +0 -2
  30. package/frontend-vue/app/components/TableInspector.vue +11 -6
  31. package/frontend-vue/i18n/locales/database-en-GB.json +12 -0
  32. package/frontend-vue/i18n/locales/database-fr-FR.json +12 -0
  33. package/frontend-vue/tests/dataBrowserDatabase.test.ts +89 -0
  34. package/frontend-vue/tests/databaseSwitcher.test.ts +11 -7
  35. package/frontend-vue/tests/editRequest.test.ts +0 -51
  36. package/frontend-vue/tests/externalBrowser.test.ts +125 -0
  37. package/frontend-vue/tests/persistence.test.ts +254 -4
  38. package/frontend-vue/tests/recentTables.test.ts +70 -0
  39. package/frontend-vue/tests/serverRender.test.ts +22 -0
  40. package/package.json +1 -1
  41. package/frontend-vue/app/build/data/staleDatabase.ts +0 -58
@@ -1,7 +1,11 @@
1
1
  import { CROSS_INSTANCE_SENTINEL } from '../utils/stagedSerialization'
2
2
  import { useDataBrowserGrid } from './useDataBrowserGrid'
3
3
  import type { InstanceChoice } from '../data/instanceOptions'
4
- import { rememberTable } from '../data/recentTables'
4
+ import {
5
+ type RecentTable,
6
+ readRecentTables,
7
+ rememberTable,
8
+ } from '../data/recentTables'
5
9
  import { useStagedEdits } from '../data/stagedEdits'
6
10
  import {
7
11
  decodeMatch,
@@ -58,7 +62,9 @@ export interface BrowserTab {
58
62
  }
59
63
 
60
64
  const STORAGE_KEY = 'dms-database:data-browser:tabs'
65
+ const DATABASE_STATE = 'dms-database-browser-database'
61
66
  const ACTIVATIONS_STATE = 'dms-database-browser-activations'
67
+ const RECENT_STATE = 'dms-database-browser-recent'
62
68
 
63
69
  function browserTabId(schema: string, instance: string, table: string): string {
64
70
  return `${schema}::${instance}::${table}`
@@ -74,16 +80,24 @@ export function forgetBrowserTabs(): void {
74
80
  }
75
81
 
76
82
  interface PersistedTabs {
83
+ /**
84
+ * The connection the tabs were opened on: another one may not hold their
85
+ * tables. Null when they were opened while the selection was unknown.
86
+ */
87
+ database: string | null
77
88
  tabs: BrowserTab[]
78
89
  activeId: string | null
79
90
  }
80
91
 
92
+ /** The tabs this browser tab kept, with the database they were opened on. */
81
93
  function readPersisted(): PersistedTabs | null {
82
94
  if (typeof window === 'undefined') return null
83
95
  try {
84
96
  const raw = window.sessionStorage.getItem(STORAGE_KEY)
85
97
  if (!raw) return null
86
98
  const parsed = JSON.parse(raw) as PersistedTabs
99
+ const { database } = parsed
100
+ if (typeof database !== 'string' && database !== null) return null
87
101
  if (!Array.isArray(parsed.tabs)) return null
88
102
  const tabs = parsed.tabs
89
103
  .filter(
@@ -112,7 +126,7 @@ function readPersisted(): PersistedTabs | null {
112
126
  const activeId = tabs.some((tab) => tab.id === parsed.activeId)
113
127
  ? parsed.activeId
114
128
  : (tabs[0]?.id ?? null)
115
- return { tabs, activeId }
129
+ return { database, tabs, activeId }
116
130
  } catch {
117
131
  return null
118
132
  }
@@ -127,6 +141,10 @@ export function useDataBrowserTabs() {
127
141
  // Counts the activations, a tab already active included: the sidebar
128
142
  // follows the tab the user goes to, even back to the same one.
129
143
  const activations = useDmsState<number>(ACTIVATIONS_STATE, () => 0)
144
+ const database = useDmsState<string | null>(DATABASE_STATE, () => null)
145
+ // Read from the browser's storage once restored: the server renders
146
+ // without it, and a list only the client has would not match its markup.
147
+ const recent = useDmsState<RecentTable[]>(RECENT_STATE, () => [])
130
148
  const route = useDmsRoute()
131
149
  const router = useDmsRouter()
132
150
  // Captured at setup so closeTab can drop the closed tab's
@@ -147,7 +165,11 @@ export function useDataBrowserTabs() {
147
165
  try {
148
166
  window.sessionStorage.setItem(
149
167
  STORAGE_KEY,
150
- JSON.stringify({ tabs: tabs.value, activeId: activeId.value }),
168
+ JSON.stringify({
169
+ database: database.value,
170
+ tabs: tabs.value,
171
+ activeId: activeId.value,
172
+ }),
151
173
  )
152
174
  } catch {
153
175
  // Quota/private-mode failures only cost tab restoration.
@@ -180,11 +202,14 @@ export function useDataBrowserTabs() {
180
202
  function activateTab(id: string) {
181
203
  const tab = tabs.value.find((candidate) => candidate.id === id)
182
204
  if (!tab) return
183
- rememberTable({
184
- schema: tab.schema,
185
- instance: tab.instance,
186
- table: tab.table,
187
- })
205
+ if (database.value !== null) {
206
+ rememberTable(database.value, {
207
+ schema: tab.schema,
208
+ instance: tab.instance,
209
+ table: tab.table,
210
+ })
211
+ recent.value = readRecentTables(database.value)
212
+ }
188
213
  activeId.value = id
189
214
  activations.value += 1
190
215
  syncUrl()
@@ -345,24 +370,74 @@ export function useDataBrowserTabs() {
345
370
  return true
346
371
  }
347
372
 
348
- // Restore persisted tabs, preview included, then let the URL win for the
349
- // active selection. Call once, from the page's onMounted.
350
- function restore() {
351
- const persisted = readPersisted()
352
- if (persisted) {
353
- tabs.value = persisted.tabs
354
- activeId.value = persisted.activeId
373
+ /** Drops the grid state and staged edits of tabs that are gone; returns their ids. */
374
+ function release(gone: BrowserTab[]): string[] {
375
+ for (const tab of gone) {
376
+ grid.drop(tab.id)
377
+ staged.discard(tab.id)
378
+ }
379
+ return gone.map((tab) => tab.id)
380
+ }
381
+
382
+ /**
383
+ * Makes `owner` the database of the tabs, open and saved: the tabs of
384
+ * another known database are released, tabs of no known database are
385
+ * claimed. Returns the ids released, so a URL that mirrors one of them is
386
+ * cleared instead of opened.
387
+ */
388
+ function settle(owner: string | null, saved: PersistedTabs | null) {
389
+ const dropped: string[] = []
390
+ if (database.value !== null && database.value !== owner) {
391
+ dropped.push(...release(tabs.value))
392
+ tabs.value = []
393
+ activeId.value = null
394
+ }
395
+ if (saved && (saved.database === owner || saved.database === null)) {
396
+ tabs.value = saved.tabs
397
+ activeId.value = saved.activeId
398
+ } else if (saved) {
399
+ dropped.push(...release(saved.tabs))
355
400
  }
401
+ database.value = owner
402
+ recent.value = owner === null ? [] : readRecentTables(owner)
403
+ if (owner !== null && saved?.database !== owner) persist()
404
+ return new Set(dropped)
405
+ }
406
+
407
+ /**
408
+ * Restores the tabs this browser tab kept on the selected database,
409
+ * preview included, then lets the URL win for the active selection. Tabs
410
+ * of another database, kept or still open, are dropped, and a URL that
411
+ * mirrors one of them is cleared. Call once, from the page's onMounted,
412
+ * with the selected connection's id, undefined when the selection is
413
+ * unknown.
414
+ */
415
+ function restore(selected: string | undefined) {
416
+ const saved = readPersisted()
417
+ const dropped = settle(selected ?? saved?.database ?? database.value, saved)
418
+ const target = routeTable()
419
+ if (target && dropped.has(target.id)) return syncUrl()
356
420
  // A schema-only link (?schema=X) is the sidebar's to honour.
357
421
  if (!openFromRoute() && !route.query.schema && activeTab.value) syncUrl()
358
422
  }
359
423
 
424
+ /**
425
+ * Follows a selection the page learns once restored (its connections
426
+ * read again in the background). Register it after restore().
427
+ */
428
+ function follow(selected: string | undefined) {
429
+ if (selected === undefined || selected === database.value) return
430
+ if (settle(selected, null).size > 0) syncUrl()
431
+ }
432
+
360
433
  return {
361
434
  tabs,
362
435
  activeId,
363
436
  activeTab,
364
437
  activations,
365
438
  hasMultipleSchemas,
439
+ /** The tables opened lately on the tabs' database, newest first. */
440
+ recent: computed(() => recent.value),
366
441
  openTab,
367
442
  replaceTab,
368
443
  closeTab,
@@ -370,6 +445,7 @@ export function useDataBrowserTabs() {
370
445
  pinTab,
371
446
  moveTab,
372
447
  restore,
448
+ follow,
373
449
  openFromRoute,
374
450
  }
375
451
  }
@@ -1,4 +1,4 @@
1
- import type { GridColumn } from '../composables/useDataBrowserGrid'
1
+ import type { GridColumn, GridData } from '../composables/useDataBrowserGrid'
2
2
  import type { TableSummary } from '../composables/useDatabaseSchemas'
3
3
 
4
4
  /** Primary key assumed when the backend reports none (MongoDB's implicit id). */
@@ -10,10 +10,15 @@ export interface ColumnsResponse {
10
10
  primaryKey: string | null
11
11
  }
12
12
 
13
+ /** The rows a search or a column filter reads on an external database. */
14
+ export const EXTERNAL_SCAN_CAP = 10_000
15
+
13
16
  export interface ListResponse {
14
17
  results: Record<string, unknown>[]
15
18
  total: number
16
19
  primaryKey: string | null
20
+ /** The rows or the total cover only part of an external table. */
21
+ capped: boolean
17
22
  }
18
23
 
19
24
  /**
@@ -34,6 +39,22 @@ export function columnsOf(
34
39
  }))
35
40
  }
36
41
 
42
+ /** The grid of a page of rows and the table's sampled columns. */
43
+ export function gridDataOf(
44
+ list: ListResponse,
45
+ meta: ColumnsResponse | null,
46
+ table: TableSummary | undefined,
47
+ ): GridData {
48
+ const primaryKey = list.primaryKey ?? meta?.primaryKey ?? null
49
+ return {
50
+ columns: columnsOf(meta, primaryKey, table),
51
+ rows: list.results ?? [],
52
+ total: list.total ?? 0,
53
+ primaryKey,
54
+ capped: list.capped ?? false,
55
+ }
56
+ }
57
+
37
58
  export interface GridCell {
38
59
  r: number
39
60
  c: number
@@ -1,5 +1,5 @@
1
- // The tables opened lately, offered by the data browser's first-visit state
2
- // (D-15). Kept in this browser only.
1
+ // The tables opened lately on each database, offered by the data browser's
2
+ // first-visit state (D-15). Kept in this browser only.
3
3
 
4
4
  export interface RecentTable {
5
5
  schema: string
@@ -8,13 +8,16 @@ export interface RecentTable {
8
8
  openedAt: string
9
9
  }
10
10
 
11
- const STORAGE_KEY = 'dms-database:data-browser:recent'
11
+ const STORAGE_PREFIX = 'dms-database:data-browser:recent:'
12
12
  const MAX_RECENT = 5
13
13
 
14
- export function readRecentTables(): RecentTable[] {
14
+ /** The tables opened lately on `database`, newest first. */
15
+ export function readRecentTables(database: string): RecentTable[] {
15
16
  if (typeof window === 'undefined') return []
16
17
  try {
17
- const parsed = JSON.parse(window.localStorage.getItem(STORAGE_KEY) ?? '[]')
18
+ const parsed = JSON.parse(
19
+ window.localStorage.getItem(STORAGE_PREFIX + database) ?? '[]',
20
+ )
18
21
  return Array.isArray(parsed)
19
22
  ? parsed.filter(
20
23
  (entry): entry is RecentTable =>
@@ -28,9 +31,13 @@ export function readRecentTables(): RecentTable[] {
28
31
  }
29
32
  }
30
33
 
31
- export function rememberTable(entry: Omit<RecentTable, 'openedAt'>) {
34
+ /** Records a table opened on `database` as its newest. */
35
+ export function rememberTable(
36
+ database: string,
37
+ entry: Omit<RecentTable, 'openedAt'>,
38
+ ): void {
32
39
  if (typeof window === 'undefined') return
33
- const others = readRecentTables().filter(
40
+ const others = readRecentTables(database).filter(
34
41
  (recent) =>
35
42
  recent.schema !== entry.schema ||
36
43
  recent.table !== entry.table ||
@@ -41,14 +48,8 @@ export function rememberTable(entry: Omit<RecentTable, 'openedAt'>) {
41
48
  ...others,
42
49
  ].slice(0, MAX_RECENT)
43
50
  try {
44
- window.localStorage.setItem(STORAGE_KEY, JSON.stringify(next))
51
+ window.localStorage.setItem(STORAGE_PREFIX + database, JSON.stringify(next))
45
52
  } catch {
46
53
  // A full or private storage only loses the suggestions.
47
54
  }
48
55
  }
49
-
50
- /** Drops the suggestions: they name the tables of the database browsed before a switch. */
51
- export function forgetRecentTables(): void {
52
- if (typeof window === 'undefined') return
53
- window.localStorage?.removeItem(STORAGE_KEY)
54
- }
@@ -7,7 +7,6 @@ import { h, onScopeDispose } from 'vue'
7
7
  import type { BrowserTab } from '../composables/useDataBrowserTabs'
8
8
  import { useDatabaseConnections } from '../composables/useDatabaseConnections'
9
9
  import { cellLabel } from './cellValues'
10
- import { presentableWriteError } from './staleDatabase'
11
10
  import { type StagedChange, undoBodies, useStagedEdits } from './stagedEdits'
12
11
  import { changesOf, type RowWriteOutcome, writeRows } from './stagedWrites'
13
12
 
@@ -109,8 +108,6 @@ export function useStagedSave(options: StagedSaveOptions) {
109
108
  ...(selected.value ? { connection: selected.value.id } : {}),
110
109
  },
111
110
  body,
112
- }).catch((error: unknown) => {
113
- throw presentableWriteError(error)
114
111
  })
115
112
  }
116
113
 
@@ -7,7 +7,6 @@ import { useDatabaseConnections } from '../build/composables/useDatabaseConnecti
7
7
  import { provideReadOnlyReason } from '../build/data/readOnlyReason'
8
8
  import { useDatabaseSchemas } from '../build/composables/useDatabaseSchemas'
9
9
  import { formatDatabaseRelativeTime } from '../build/utils/relativeTime'
10
- import { type RecentTable, readRecentTables } from '../build/data/recentTables'
11
10
  import { useStagedEdits } from '../build/data/stagedEdits'
12
11
  import DataBrowserAccessBar from '../build/components/DataBrowserAccessBar.vue'
13
12
  import DataBrowserSidebar from './DataBrowserSidebar.vue'
@@ -26,14 +25,20 @@ const {
26
25
  error: schemasError,
27
26
  refresh: refreshSchemas,
28
27
  } = useDatabaseSchemas()
29
- const { ready: connectionsRead } = useDatabaseConnections()
28
+ const { ready: connectionsRead, selected } = useDatabaseConnections()
30
29
  provideReadOnlyReason()
31
- const { tabs, activeTab, restore, openTab, openFromRoute } =
30
+ const { tabs, activeTab, recent, restore, follow, openTab, openFromRoute } =
32
31
  useDataBrowserTabs()
33
32
  const staged = useStagedEdits()
34
33
  const route = useDmsRoute()
35
34
 
36
- onMounted(() => restore())
35
+ onMounted(() => {
36
+ restore(selected.value?.id)
37
+ watch(
38
+ () => selected.value?.id,
39
+ (id) => follow(id),
40
+ )
41
+ })
37
42
  // A link from this page to another table (a relation) keeps the page mounted.
38
43
  watch(
39
44
  () => route.query,
@@ -53,16 +58,6 @@ const activeTableSummary = computed(() =>
53
58
  : undefined,
54
59
  )
55
60
 
56
- // Read once mounted: the server renders without the browser's storage, and
57
- // a list only the client has would not match its markup.
58
- const recent = ref<RecentTable[]>([])
59
- onMounted(() => {
60
- recent.value = readRecentTables()
61
- })
62
- watch(activeTab, () => {
63
- recent.value = readRecentTables()
64
- })
65
-
66
61
  function instanceLabel(instance: string): string {
67
62
  return instanceBadge(instance, t('dms_database.data.scope.all')) ?? ''
68
63
  }
@@ -301,6 +301,7 @@ onKeyStroke('t', (event) => {
301
301
  </nav>
302
302
  </div>
303
303
  <footer
304
+ v-if="countsFailed || !lacks('instances')"
304
305
  class="border-default text-dimmed flex items-center gap-1.5 border-t px-3 py-2 text-[11.5px]"
305
306
  >
306
307
  <UIcon
@@ -21,13 +21,12 @@ import type { BrowserTab } from '../build/composables/useDataBrowserTabs'
21
21
  import type {
22
22
  ColumnFilterState,
23
23
  GridColumn,
24
- GridData,
25
24
  } from '../build/composables/useDataBrowserGrid'
26
25
  import { DATABASE_PAGES, tableAccess } from '../build/utils/databaseLinks'
27
26
  import { type ColumnRole, isPrimaryKey } from '../build/utils/fieldTypes'
28
27
  import {
29
28
  DEFAULT_PRIMARY_KEY,
30
- columnsOf,
29
+ gridDataOf,
31
30
  moveFocus,
32
31
  type ColumnsResponse,
33
32
  type ListResponse,
@@ -98,17 +97,9 @@ const loadError = computed(() => {
98
97
  return error instanceof Error ? error.message : String(error)
99
98
  })
100
99
 
101
- const data = computed<GridData | null>(() => {
100
+ const data = computed(() => {
102
101
  const list = listRead.data.value
103
- if (!list) return null
104
- const meta = columnsRead.data.value
105
- const primaryKey = list.primaryKey ?? meta?.primaryKey ?? null
106
- return {
107
- columns: columnsOf(meta, primaryKey, props.table),
108
- rows: list.results ?? [],
109
- total: list.total ?? 0,
110
- primaryKey,
111
- }
102
+ return list ? gridDataOf(list, columnsRead.data.value, props.table) : null
112
103
  })
113
104
 
114
105
  watch(data, (next) => {
@@ -677,6 +668,8 @@ useEventListener('keydown', (event: KeyboardEvent) => {
677
668
  v-model:page="state.page"
678
669
  v-model:page-size="state.pageSize"
679
670
  :total="total"
671
+ :capped="data?.capped"
672
+ :refined="hasRefinements"
680
673
  />
681
674
  </div>
682
675
  </template>
@@ -9,7 +9,6 @@ import { confirmLeave } from '#dms-ui/app/entries/composables/unsaved-changes/re
9
9
  import { forgetBrowserTabs } from '../build/composables/useDataBrowserTabs'
10
10
  import { useLockedPages } from '../build/composables/useLockedPages'
11
11
  import { useSelectionRecheck } from '../build/composables/useSelectionRecheck'
12
- import { forgetRecentTables } from '../build/data/recentTables'
13
12
  import {
14
13
  ONBOARDING_KEY,
15
14
  type PublicOnboarding,
@@ -44,7 +43,6 @@ async function pick(id: string) {
44
43
  return
45
44
  }
46
45
  forgetBrowserTabs()
47
- forgetRecentTables()
48
46
  window.location.assign(route.path)
49
47
  }
50
48
 
@@ -308,7 +308,7 @@ async function copyName() {
308
308
  :label="t('dms_database.inspector.eyebrow', { schema: schemaId })"
309
309
  />
310
310
  <UBadge
311
- v-if="!loading"
311
+ v-if="!loading && !lacks('instances')"
312
312
  color="neutral"
313
313
  variant="outline"
314
314
  size="sm"
@@ -590,11 +590,16 @@ async function copyName() {
590
590
  <DmsEyebrowLabel
591
591
  class="min-w-0 truncate"
592
592
  :label="
593
- t('dms_database.inspector.sample.position', {
594
- position: sampleOffset + 1,
595
- total: sampleTotal,
596
- instance: sampleInstanceLabel,
597
- })
593
+ lacks('instances')
594
+ ? t('dms_database.inspector.sample.position_uninstanced', {
595
+ position: sampleOffset + 1,
596
+ total: sampleTotal,
597
+ })
598
+ : t('dms_database.inspector.sample.position', {
599
+ position: sampleOffset + 1,
600
+ total: sampleTotal,
601
+ instance: sampleInstanceLabel,
602
+ })
598
603
  "
599
604
  />
600
605
  <UButton
@@ -152,6 +152,8 @@
152
152
  "close_keep": "Keep editing"
153
153
  },
154
154
  "grid": {
155
+ "count_capped": "Counts stop at {count} rows",
156
+ "capped": "Matches among the first {count} rows",
155
157
  "rows": "{count} row | {count} rows",
156
158
  "search": "Search rows",
157
159
  "refresh": "Refresh (R)",
@@ -249,6 +251,11 @@
249
251
  "own": "Project database",
250
252
  "external": "External",
251
253
  "engine_unknown": "Unknown engine",
254
+ "unknown": "This database is no longer one of the project's databases. Reload the page to see the current list.",
255
+ "catalog": {
256
+ "timed_out": "The catalog of {connection} did not answer in time.",
257
+ "refused": "The catalog of {connection} refused to answer. The server log names the cause."
258
+ },
252
259
  "switcher": {
253
260
  "label": "Database",
254
261
  "menu": "Choose the database to browse",
@@ -262,6 +269,10 @@
262
269
  "account_read_only": "This account can only read. Use an account with write access to allow changes.",
263
270
  "account_unverified": "This account's write access could not be checked.",
264
271
  "failed": "The access to the database could not be changed.",
272
+ "refused": "The project's configuration refused the change: {reason}",
273
+ "not_development": "Access can only change while the project runs in development. Reload the page.",
274
+ "no_module_entry": "The console could not find its own module in the project's configuration.",
275
+ "no_builder": "The project's configuration could not be written: the DMS builder did not answer.",
265
276
  "confirm": {
266
277
  "title": "Allow changes to {name}?",
267
278
  "description": "{name} is your customer's live database. Changes you save are written to it at once, and the DMS cannot undo them.",
@@ -557,6 +568,7 @@
557
568
  },
558
569
  "sample": {
559
570
  "position": "Row {position} of {total} · {instance}",
571
+ "position_uninstanced": "Row {position} of {total}",
560
572
  "default_instance": "default instance",
561
573
  "named_instance": "instance {name}",
562
574
  "another": "Another row",
@@ -152,6 +152,8 @@
152
152
  "close_keep": "Continuer"
153
153
  },
154
154
  "grid": {
155
+ "count_capped": "Le décompte s’arrête à {count} lignes",
156
+ "capped": "Correspondances parmi les {count} premières lignes",
155
157
  "rows": "{count} ligne | {count} lignes",
156
158
  "search": "Chercher dans les lignes",
157
159
  "refresh": "Actualiser (R)",
@@ -249,6 +251,11 @@
249
251
  "own": "Base du projet",
250
252
  "external": "Externe",
251
253
  "engine_unknown": "Moteur inconnu",
254
+ "unknown": "Cette base ne fait plus partie des bases du projet. Rechargez la page pour voir la liste à jour.",
255
+ "catalog": {
256
+ "timed_out": "Le catalogue de {connection} n'a pas répondu à temps.",
257
+ "refused": "Le catalogue de {connection} a refusé de répondre. Le journal du serveur en donne la cause."
258
+ },
252
259
  "switcher": {
253
260
  "label": "Base de données",
254
261
  "menu": "Choisir la base à parcourir",
@@ -262,6 +269,10 @@
262
269
  "account_read_only": "Ce compte peut seulement lire. Utilisez un compte avec accès en écriture pour autoriser les modifications.",
263
270
  "account_unverified": "Les droits d'écriture de ce compte n'ont pas pu être vérifiés.",
264
271
  "failed": "L'accès à la base n'a pas pu être modifié.",
272
+ "refused": "La configuration du projet a refusé la modification : {reason}",
273
+ "not_development": "L'accès ne peut changer que lorsque le projet tourne en développement. Rechargez la page.",
274
+ "no_module_entry": "La console n'a pas trouvé son propre module dans la configuration du projet.",
275
+ "no_builder": "La configuration du projet n'a pas pu être écrite : le builder DMS n'a pas répondu.",
265
276
  "confirm": {
266
277
  "title": "Autoriser les modifications de {name} ?",
267
278
  "description": "{name} est la base en production de votre client. Les modifications enregistrées y sont écrites aussitôt, et le DMS ne peut pas les annuler.",
@@ -557,6 +568,7 @@
557
568
  },
558
569
  "sample": {
559
570
  "position": "Ligne {position} sur {total} · {instance}",
571
+ "position_uninstanced": "Ligne {position} sur {total}",
560
572
  "default_instance": "instance par défaut",
561
573
  "named_instance": "instance {name}",
562
574
  "another": "Une autre ligne",
@@ -0,0 +1,89 @@
1
+ import { afterEach, expect, it, vi } from 'vitest'
2
+ import { reactive } from 'vue'
3
+ import { browserMount } from './fixtures/serverRender'
4
+ import {
5
+ OWN,
6
+ connectionsBackend,
7
+ connectionsState,
8
+ } from './fixtures/connections'
9
+ import DataBrowser from '../app/components/DataBrowser.vue'
10
+
11
+ const inertia = vi.hoisted(() => ({
12
+ page: { url: '/modules/database/data' },
13
+ visits: [] as string[],
14
+ }))
15
+
16
+ vi.mock('@inertiajs/vue3', async (original) => {
17
+ const visit =
18
+ (kind: string) =>
19
+ (options: { url: string; onFinish?: (visit: unknown) => void }) => {
20
+ inertia.visits.push(`${kind} ${options.url}`)
21
+ options.onFinish?.({})
22
+ }
23
+ return {
24
+ ...(await original<object>()),
25
+ usePage: () => reactive(inertia.page),
26
+ router: { push: visit('push'), replace: visit('replace') },
27
+ }
28
+ })
29
+
30
+ afterEach(() => {
31
+ vi.unstubAllGlobals()
32
+ inertia.visits.length = 0
33
+ inertia.page.url = '/modules/database/data'
34
+ })
35
+
36
+ const ORDERS = {
37
+ id: 'shop::__DEFAULT__::orders',
38
+ schema: 'shop',
39
+ instance: '__DEFAULT__',
40
+ table: 'orders',
41
+ preview: false,
42
+ }
43
+
44
+ /** A browser tab whose sessionStorage holds `saved`, recording each write. */
45
+ function storing(saved: object, url = '/modules/database/data') {
46
+ inertia.page.url = url
47
+ let raw = JSON.stringify(saved)
48
+ const writes: string[] = []
49
+ vi.stubGlobal('window', {
50
+ addEventListener: vi.fn(),
51
+ removeEventListener: vi.fn(),
52
+ location: {
53
+ origin: 'http://localhost',
54
+ href: `http://localhost${url}`,
55
+ pathname: '/modules/database/data',
56
+ },
57
+ localStorage: { getItem: () => null, setItem: vi.fn() },
58
+ sessionStorage: {
59
+ getItem: () => raw,
60
+ setItem: (_key: string, value: string) => {
61
+ raw = value
62
+ writes.push(value)
63
+ },
64
+ removeItem: vi.fn(),
65
+ },
66
+ })
67
+ return { writes, saved: () => JSON.parse(raw) as unknown }
68
+ }
69
+
70
+ it('keeps the saved tabs and the table link of the selected database when the page arrives with no connections read yet, which a selection watch running before the restore gets wrong', async () => {
71
+ const storage = storing(
72
+ { database: 'own', tabs: [ORDERS], activeId: ORDERS.id },
73
+ '/modules/database/data?schema=shop&table=orders',
74
+ )
75
+ const page = browserMount(
76
+ DataBrowser,
77
+ connectionsBackend(connectionsState(OWN), { others: () => [] }),
78
+ )
79
+ await page.shown
80
+ await new Promise((resolve) => setTimeout(resolve, 0))
81
+ expect(inertia.visits).toEqual([])
82
+ expect(storage.writes.map((write) => JSON.parse(write))).not.toContainEqual(
83
+ expect.objectContaining({ tabs: [] }),
84
+ )
85
+ expect(storage.saved()).toMatchObject({
86
+ database: 'own',
87
+ tabs: [expect.objectContaining({ id: ORDERS.id })],
88
+ })
89
+ })