@stacksjs/defaults 0.75.538 → 0.75.541

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 (152) hide show
  1. package/ai/AGENTS.md +2 -0
  2. package/ai/skills/stacks-actions/SKILL.md +1 -1
  3. package/ai/skills/stacks-auth/SKILL.md +8 -1
  4. package/ai/skills/stacks-dashboard/SKILL.md +196 -3
  5. package/ai/skills/stacks-dependencies/SKILL.md +46 -0
  6. package/ai/skills/stacks-development/SKILL.md +1 -1
  7. package/ai/skills/stacks-flow/SKILL.md +7 -0
  8. package/ai/skills/stacks-hq/SKILL.md +146 -0
  9. package/ai/skills/stacks-models/SKILL.md +21 -3
  10. package/ai/skills/stacks-native/CATALOG.md +22 -9
  11. package/ai/skills/stacks-new-app/SKILL.md +175 -0
  12. package/ai/skills/stacks-repl/SKILL.md +61 -43
  13. package/ai/skills/stacks-stx/SKILL.md +6 -2
  14. package/ai/skills/stacks-upstream/SKILL.md +188 -0
  15. package/ai/skills/stacks-writing-for-agents/SKILL.md +1 -1
  16. package/app/Actions/Dashboard/Data/UserIndexAction.ts +20 -2
  17. package/app/Actions/Dashboard/Models/ModelDestroyAction.ts +48 -12
  18. package/app/Actions/Dashboard/Models/ModelOptionsAction.ts +103 -0
  19. package/app/Actions/Dashboard/Models/ModelRelatedAction.ts +42 -0
  20. package/app/Actions/Dashboard/Models/ModelShowAction.ts +75 -12
  21. package/app/Actions/Dashboard/Models/ModelStoreAction.ts +7 -1
  22. package/app/Actions/Dashboard/Models/ModelUpdateAction.ts +16 -2
  23. package/app/Actions/Dashboard/Models/model-destroy.ts +75 -0
  24. package/app/Actions/Dashboard/Models/model-options.ts +56 -0
  25. package/app/Actions/Dashboard/Models/model-related.ts +202 -0
  26. package/app/Actions/Dashboard/Models/model-relations.ts +172 -0
  27. package/app/Actions/Dashboard/Models/model-write.ts +240 -51
  28. package/app/Actions/Dashboard/Users/UserInviteAction.ts +50 -0
  29. package/app/Actions/Dashboard/Users/user-invitation.ts +110 -0
  30. package/app/Models/Activity.ts +4 -0
  31. package/app/Models/AnalyticsEvent.ts +4 -0
  32. package/app/Models/Automation.ts +4 -0
  33. package/app/Models/AutomationRun.ts +4 -0
  34. package/app/Models/Board.ts +4 -1
  35. package/app/Models/BoardColumn.ts +4 -1
  36. package/app/Models/Campaign.ts +4 -0
  37. package/app/Models/CampaignSend.ts +4 -0
  38. package/app/Models/CampaignVariant.ts +4 -0
  39. package/app/Models/Card.ts +4 -1
  40. package/app/Models/CardAttachment.ts +4 -0
  41. package/app/Models/CommunicationSuppression.ts +4 -0
  42. package/app/Models/ConsentEvent.ts +4 -0
  43. package/app/Models/Deployment.ts +1 -0
  44. package/app/Models/EmailList.ts +4 -0
  45. package/app/Models/EmailListSubscriber.ts +4 -0
  46. package/app/Models/Error.ts +4 -0
  47. package/app/Models/FailedJob.ts +4 -0
  48. package/app/Models/FeedbackToken.ts +4 -0
  49. package/app/Models/GdprRequest.ts +4 -0
  50. package/app/Models/Job.ts +4 -0
  51. package/app/Models/Log.ts +4 -0
  52. package/app/Models/MagicLinkToken.ts +4 -0
  53. package/app/Models/MailPreference.ts +4 -0
  54. package/app/Models/Notification.ts +4 -0
  55. package/app/Models/NotificationDelivery.ts +4 -0
  56. package/app/Models/PersonalAccessToken.ts +4 -0
  57. package/app/Models/QueryLog.ts +4 -0
  58. package/app/Models/Referral.ts +4 -0
  59. package/app/Models/Release.ts +1 -0
  60. package/app/Models/Request.ts +4 -0
  61. package/app/Models/SenderDomain.ts +4 -0
  62. package/app/Models/Site.ts +1 -0
  63. package/app/Models/SiteDomain.ts +4 -0
  64. package/app/Models/SocialPost.ts +4 -0
  65. package/app/Models/StorageItemTask.ts +4 -1
  66. package/app/Models/Subscriber.ts +4 -0
  67. package/app/Models/Subscription.ts +4 -0
  68. package/app/Models/Team.ts +1 -0
  69. package/app/Models/TeamInvitation.ts +1 -0
  70. package/app/Models/TeamMember.ts +1 -0
  71. package/app/Models/UsageEvent.ts +4 -0
  72. package/app/Models/User.ts +15 -3
  73. package/functions/dashboard-model-record.test.ts +276 -18
  74. package/functions/dashboard-model-record.ts +412 -55
  75. package/functions/data.ts +2 -0
  76. package/ide/vscode/package.json +1 -1
  77. package/package.json +5 -5
  78. package/resources/components/Dashboard/Analytics/AnalyticsHub.stx +1 -1
  79. package/resources/components/Dashboard/Analytics/CampaignAnalytics.stx +1 -1
  80. package/resources/components/Dashboard/Analytics/EventAnalytics.stx +1 -1
  81. package/resources/components/Dashboard/Analytics/SalesAnalytics.stx +1 -1
  82. package/resources/components/Dashboard/Analytics/WebAnalyticsBreakdown.stx +1 -1
  83. package/resources/components/Dashboard/App/RequestsOverview.stx +1 -1
  84. package/resources/components/Dashboard/App/SourceInventory.stx +1 -1
  85. package/resources/components/Dashboard/Auth/AccessTokens.stx +1 -1
  86. package/resources/components/Dashboard/Buddy/BuddyAssistant.stx +1 -1
  87. package/resources/components/Dashboard/Ci/CiDashboard.stx +1 -1
  88. package/resources/components/Dashboard/Commerce/Delivery/DeliveryPagination.stx +1 -1
  89. package/resources/components/Dashboard/Commerce/ProductWaitlistDashboard.stx +1 -1
  90. package/resources/components/Dashboard/Commerce/RestaurantWaitlistDashboard.stx +1 -1
  91. package/resources/components/Dashboard/Content/BlogDashboard.stx +1 -1
  92. package/resources/components/Dashboard/DashboardLayout.stx +1 -1
  93. package/resources/components/Dashboard/Data/DataRecords.stx +43 -22
  94. package/resources/components/Dashboard/Data/UserInvite.stx +107 -0
  95. package/resources/components/Dashboard/Email/CapturedMailDashboard.stx +1 -1
  96. package/resources/components/Dashboard/Email/EmailActivityDashboard.stx +1 -1
  97. package/resources/components/Dashboard/Email/InboxDashboard.stx +1 -1
  98. package/resources/components/Dashboard/Email/InboxMessageDetail.stx +2 -2
  99. package/resources/components/Dashboard/Email/InboxSettingsDashboard.stx +1 -1
  100. package/resources/components/Dashboard/Home/DashboardHome.stx +6 -1
  101. package/resources/components/Dashboard/Infrastructure/CloudDashboard.stx +1 -1
  102. package/resources/components/Dashboard/Infrastructure/DnsDashboard.stx +1 -1
  103. package/resources/components/Dashboard/Infrastructure/HealthDashboard.stx +1 -1
  104. package/resources/components/Dashboard/Infrastructure/InsightsDashboard.stx +1 -1
  105. package/resources/components/Dashboard/Infrastructure/LogsDashboard.stx +1 -1
  106. package/resources/components/Dashboard/Infrastructure/MailboxesDashboard.stx +1 -1
  107. package/resources/components/Dashboard/Infrastructure/ServerDetailsDashboard.stx +1 -1
  108. package/resources/components/Dashboard/Infrastructure/ServerlessDashboard.stx +1 -1
  109. package/resources/components/Dashboard/Infrastructure/ServersDashboard.stx +1 -1
  110. package/resources/components/Dashboard/Jobs/JobDetail.stx +1 -1
  111. package/resources/components/Dashboard/Jobs/JobTable.stx +2 -2
  112. package/resources/components/Dashboard/Kanban/KanbanBoardDashboard.stx +1 -1
  113. package/resources/components/Dashboard/Kanban/KanbanBoardsDashboard.stx +1 -1
  114. package/resources/components/Dashboard/Management/PermissionsDashboard.stx +1 -1
  115. package/resources/components/Dashboard/Marketing/AbandonedCartsDashboard.stx +1 -1
  116. package/resources/components/Dashboard/Marketing/CampaignsDashboard.stx +1 -1
  117. package/resources/components/Dashboard/Marketing/MarketingListsDashboard.stx +1 -1
  118. package/resources/components/Dashboard/Marketing/SocialPostsDashboard.stx +1 -1
  119. package/resources/components/Dashboard/Models/ModelFieldInputs.stx +125 -0
  120. package/resources/components/Dashboard/Models/ModelRecordCreate.stx +24 -66
  121. package/resources/components/Dashboard/Models/ModelRecordDetail.stx +36 -8
  122. package/resources/components/Dashboard/Models/ModelRecordEdit.stx +36 -32
  123. package/resources/components/Dashboard/Models/ModelRecordsDashboard.stx +72 -28
  124. package/resources/components/Dashboard/Models/ModelRelatedPanels.stx +99 -0
  125. package/resources/components/Dashboard/Models/ModelRelationPicker.stx +247 -0
  126. package/resources/components/Dashboard/Models/ModelsOverview.stx +1 -1
  127. package/resources/components/Dashboard/Notifications/NotificationDeliveries.stx +1 -1
  128. package/resources/components/Dashboard/Notifications/NotificationDeliveryHistory.stx +1 -1
  129. package/resources/components/Dashboard/Notifications/NotificationDeliveryOverview.stx +1 -1
  130. package/resources/components/Dashboard/Queries/QueryDashboard.stx +1 -1
  131. package/resources/components/Dashboard/Queries/QueryDetail.stx +1 -1
  132. package/resources/components/Dashboard/Queue/QueueDashboard.stx +1 -1
  133. package/resources/components/Dashboard/Realtime/RealtimeDashboard.stx +1 -1
  134. package/resources/components/Dashboard/Releases/ReleaseDashboard.stx +1 -1
  135. package/resources/components/Dashboard/Search/SearchEngineDashboard.stx +1 -1
  136. package/resources/components/Dashboard/Settings/MailSettingsDashboard.stx +1 -1
  137. package/resources/components/Dashboard/Settings/SettingsDashboard.stx +1 -1
  138. package/resources/components/Dashboard/Teams/TeamPeopleDashboard.stx +1 -1
  139. package/resources/components/Dashboard/UI/Drawer.stx +1 -1
  140. package/resources/components/Dashboard/UI/Input.stx +3 -2
  141. package/resources/components/Dashboard/UI/Modal.stx +1 -1
  142. package/resources/components/Dashboard/UI/Select.stx +8 -4
  143. package/resources/components/Dashboard/UI/Textarea.stx +18 -12
  144. package/resources/emails/password-reset.stx +3 -1
  145. package/routes/dashboard-api.ts +9 -0
  146. package/scaffold/config/analytics.ts +5 -3
  147. package/scaffold/resources/components/NextStep.stx +13 -0
  148. package/scaffold/resources/partials/head.stx +31 -0
  149. package/scaffold/resources/views/index.stx +23 -47
  150. package/scaffold/resources/views/layouts/default.stx +23 -0
  151. package/views/dashboard/data/users/invite.stx +8 -0
  152. package/views/dashboard/layouts/default.stx +21 -2
@@ -8,7 +8,8 @@
8
8
  // writes go through the model, so scopes, casts and observers apply.
9
9
  import { useNavigation } from '@stacksjs/defaults/views/dashboard/composables/useNavigation'
10
10
  import { dashboardApi } from '@stacksjs/defaults/functions/dashboard-api'
11
- import { modelRecordCreateHref, modelRecordEditHref, modelRecordHref } from '@stacksjs/defaults/functions/dashboard-model-record'
11
+ import type { ModelRelationTarget, ModelWriteCapabilities } from '@stacksjs/defaults/functions/dashboard-model-record'
12
+ import { deleteModelRecord, modelDeleteNotice, modelDeleteWarning, modelListColumnNames, modelListFilters, modelRecordCreateHref, modelRecordEditHref, modelRecordHref, modelRelationCell, NO_WRITES, userInviteHref } from '@stacksjs/defaults/functions/dashboard-model-record'
12
13
  import { pushToast } from '@stacksjs/defaults/functions/toasts'
13
14
 
14
15
  interface ColumnMeta {
@@ -17,14 +18,9 @@ interface ColumnMeta {
17
18
  type: 'number' | 'boolean' | 'date' | 'json' | 'text'
18
19
  }
19
20
 
20
- interface WriteCapabilities {
21
- create: boolean
22
- update: boolean
23
- destroy: boolean
24
- }
25
-
26
21
  interface ResponseShape {
27
22
  modelName: string
23
+ modelLabel?: string
28
24
  tableName: string
29
25
  rows: Array<Record<string, unknown>>
30
26
  displayColumns: string[]
@@ -36,7 +32,13 @@ interface ResponseShape {
36
32
  sort: string
37
33
  dir: 'asc' | 'desc'
38
34
  writable: boolean
39
- writeCapabilities: WriteCapabilities
35
+ writeCapabilities: ModelWriteCapabilities
36
+ /** Rows erased under the app's data-subject rules (users only). */
37
+ anonymizedIds?: Array<number | string>
38
+ /** The columns the list draws: the model's own choice, or all of them. */
39
+ listColumns?: string[]
40
+ relations?: Record<string, ModelRelationTarget>
41
+ relationNames?: Record<string, Record<string, string>>
40
42
  updateColumns: string[]
41
43
  migrated?: boolean
42
44
  error: string | null
@@ -46,8 +48,14 @@ const PER_PAGE_OPTIONS = [25, 50, 100, 200]
46
48
  const navigation = useNavigation()
47
49
 
48
50
  const modelName = state('')
51
+ // The class name, for the one message that tells a developer what was looked for.
52
+ const modelClass = state('')
49
53
  const tableName = state('')
50
54
  const rows = state<Array<Record<string, unknown>>>([])
55
+ const anonymizedIds = state<string[]>([])
56
+ // Columns that hold another model's id, and what those records are called.
57
+ const relations = state<Record<string, ModelRelationTarget>>({})
58
+ const relationNames = state<Record<string, Record<string, string>>>({})
51
59
  const columnMeta = state<ColumnMeta[]>([])
52
60
  const totalCount = state(0)
53
61
  const page = state(1)
@@ -56,14 +64,16 @@ const lastPage = state(1)
56
64
  const sort = state('')
57
65
  const dir = state<'asc' | 'desc'>('desc')
58
66
  const search = state(navigation.urlQuery('q') || '')
59
- const filters = state<Record<string, string>>({})
60
- const writeCapabilities = state<WriteCapabilities>({ create: false, update: false, destroy: false })
67
+ // A list opened from a record's panel arrives narrowed to that record.
68
+ const filters = state<Record<string, string>>(modelListFilters(navigation.urlQuery('filters')))
69
+ const writeCapabilities = state<ModelWriteCapabilities>(NO_WRITES)
61
70
  const error = state<string | null>(null)
62
71
  // False when the model's table has not been created yet: the server checked the
63
72
  // catalog after the query failed, so this is never a guess from an error.
64
73
  const migrated = state(true)
65
74
  const loading = state(true)
66
- const showFilters = state(false)
75
+ // Open when it arrives filtered, so what narrowed the list can be seen and cleared.
76
+ const showFilters = state(Object.keys(filters()).length > 0)
67
77
 
68
78
  const saving = state(false)
69
79
  const confirmingDelete = state<Record<string, unknown> | null>(null)
@@ -99,7 +109,7 @@ const deleteDescription = derived(() => {
99
109
  const row = confirmingDelete()
100
110
  if (!row)
101
111
  return ''
102
- return `Row ${row.id} will be removed through the model, so soft deletes and observers apply.`
112
+ return modelDeleteWarning(`Row ${row.id}`, writeCapabilities().anonymize)
103
113
  })
104
114
 
105
115
  // Skeleton rows while a query is in flight. Matching the real row count
@@ -125,8 +135,17 @@ function formatCell(value: unknown, type: ColumnMeta['type']): string {
125
135
  return text.length > 120 ? `${text.slice(0, 120)}…` : text
126
136
  }
127
137
 
138
+ /** A cell that points at another model's record: its name, and where it leads. */
139
+ function relationCell(row: Record<string, unknown>, column: ColumnMeta) {
140
+ return modelRelationCell(column.name, row[column.name], relations(), relationNames())
141
+ }
142
+
143
+ function relationHref(row: Record<string, unknown>, column: ColumnMeta): string {
144
+ return relationCell(row, column)?.href ?? ''
145
+ }
146
+
128
147
  function cellValue(row: Record<string, unknown>, column: ColumnMeta): string {
129
- return formatCell(row[column.name], column.type)
148
+ return relationCell(row, column)?.text ?? formatCell(row[column.name], column.type)
130
149
  }
131
150
 
132
151
  // Returned as COMPLETE class strings and applied with `:class`, because a
@@ -168,21 +187,28 @@ async function load() {
168
187
 
169
188
  const data = await dashboardApi<ResponseShape>(`/api/dashboard/models/${encodeURIComponent(slug())}?${params}`)
170
189
 
171
- modelName.set(data.modelName ?? '')
190
+ modelName.set(data.modelLabel ?? data.modelName ?? '')
191
+ modelClass.set(data.modelName ?? '')
172
192
  tableName.set(data.tableName ?? '')
173
193
  rows.set(data.rows ?? [])
194
+ anonymizedIds.set((data.anonymizedIds ?? []).map(String))
174
195
  // Only reassign when the column set actually changes. It is the same for
175
196
  // every page and every sort of a given model, and re-rendering the
176
197
  // header `:for` on each query both wastes work and trips a reconciler
177
198
  // bug that leaves the columns rotated out of order.
178
- const nextColumns = data.columnMeta ?? []
199
+ relations.set(data.relations ?? {})
200
+ relationNames.set(data.relationNames ?? {})
201
+ // The columns the model chose for its list, and any the list is filtered on.
202
+ const every = data.columnMeta ?? []
203
+ const shown = modelListColumnNames(every.map(column => column.name), data.listColumns, active)
204
+ const nextColumns = shown.map(name => every.find(column => column.name === name)!).filter(Boolean)
179
205
  const sameColumns = nextColumns.length === columnMeta().length
180
206
  && nextColumns.every((c, i) => c.name === columnMeta()[i]?.name)
181
207
  if (!sameColumns) columnMeta.set(nextColumns)
182
208
  totalCount.set(data.totalCount ?? 0)
183
209
  lastPage.set(data.lastPage ?? 1)
184
210
  sort.set(data.sort ?? '')
185
- writeCapabilities.set(data.writeCapabilities ?? { create: false, update: false, destroy: false })
211
+ writeCapabilities.set({ ...NO_WRITES, ...data.writeCapabilities })
186
212
  migrated.set(data.migrated !== false)
187
213
  error.set(data.error ?? null)
188
214
  }
@@ -233,6 +259,12 @@ function onPerPageChange() {
233
259
  void load()
234
260
  }
235
261
 
262
+ // An anonymized account keeps its eye and loses its pencil and trash: there
263
+ // is nothing left to edit, and deleting it again changes nothing.
264
+ function isAnonymized(row: Record<string, unknown>): boolean {
265
+ return anonymizedIds().includes(String(row.id))
266
+ }
267
+
236
268
  // The eye and the pencil each open a page of the record's own.
237
269
  function startEdit(row: Record<string, unknown>) {
238
270
  navigate(modelRecordEditHref(slug(), String(row.id)))
@@ -247,17 +279,19 @@ function openCreate(): void {
247
279
  navigate(modelRecordCreateHref(slug()))
248
280
  }
249
281
 
282
+ // A user is invited, not typed in: the account's holder chooses the password.
283
+ function openInvite(): void {
284
+ navigate(userInviteHref(`/models/${slug()}`))
285
+ }
286
+
250
287
  async function confirmDelete() {
251
288
  const row = confirmingDelete()
252
289
  if (!row) return
253
290
  saving.set(true)
254
291
  try {
255
- const result = await dashboardApi<{ ok: boolean, error?: string }>(
256
- `/api/dashboard/models/${encodeURIComponent(slug())}/${row.id}`,
257
- { method: 'DELETE' },
258
- )
259
- if (!result?.ok) throw new Error(result?.error || 'The delete was rejected.')
260
- pushToast('success', `${modelName()} ${row.id} deleted`)
292
+ const outcome = await deleteModelRecord(slug(), String(row.id))
293
+ const notice = modelDeleteNotice(`${modelName()} ${row.id}`, outcome)
294
+ pushToast('success', notice.title, { detail: notice.detail })
261
295
  confirmingDelete.set(null)
262
296
  // Deleting the last row of the final page would strand the viewer on an
263
297
  // empty page, so step back one.
@@ -284,17 +318,24 @@ void load()
284
318
  `:text` bindings here stay reactive. -->
285
319
  <div class="flex flex-wrap gap-4 items-start justify-between">
286
320
  <div class="min-w-0">
287
- <h1 class="font-semibold text-2xl text-neutral-900 truncate dark:text-white" :text="modelName()"></h1>
321
+ <h1 class="font-bold text-2xl text-neutral-900 truncate dark:text-white" :text="modelName()"></h1>
288
322
  <p class="mt-1 text-[13px] text-neutral-500 dark:text-neutral-400" :text="subtitle()"></p>
289
323
  </div>
290
324
  <div class="flex gap-2 items-center">
291
325
  <Button
292
- :if="writeCapabilities().create"
326
+ :if="writeCapabilities().create && !writeCapabilities().invite"
293
327
  @click="openCreate"
294
328
  >
295
329
  <span aria-hidden="true" class="h-4 w-4 i-hugeicons-add-01"></span>
296
330
  Create
297
331
  </Button>
332
+ <Button
333
+ :if="writeCapabilities().invite"
334
+ @click="openInvite"
335
+ >
336
+ <span aria-hidden="true" class="h-4 w-4 i-hugeicons-mail-send-01"></span>
337
+ Invite
338
+ </Button>
298
339
  <Button
299
340
  :if="migrated()"
300
341
  variant="secondary"
@@ -349,7 +390,7 @@ void load()
349
390
  <h3 class="font-medium text-[13px] text-red-800 dark:text-red-200">Couldn't load <span :text="modelName()"></span></h3>
350
391
  <p class="mt-1 text-[13px] text-red-600 dark:text-red-300" :text="error()"></p>
351
392
  <p class="mt-2 text-[12px] text-red-500 dark:text-red-400">
352
- Looked for an ORM model named <code :text="modelName()"></code> and a table named <code :text="tableName()"></code>.
393
+ Looked for an ORM model named <code :text="modelClass()"></code> and a table named <code :text="tableName()"></code>.
353
394
  </p>
354
395
  </div>
355
396
  </div>
@@ -423,13 +464,16 @@ void load()
423
464
 
424
465
  <tbody :if="!loading()" class="divide-black/5 divide-y dark:divide-white/8">
425
466
  <tr :for="row in rows()" class="hover:bg-neutral-50 dark:hover:bg-white/5 transition-colors group">
426
- <td :for="column in columnMeta()" :class="cellClass(column)" :title="cellValue(row, column)">{{ cellValue(row, column) }}</td>
467
+ <td :for="column in columnMeta()" :class="cellClass(column)" :title="cellValue(row, column)">
468
+ <StxLink :if="relationHref(row, column)" :to="relationHref(row, column)" class="font-medium text-blue-600 dark:text-blue-400 hover:underline">{{ cellValue(row, column) }}</StxLink>
469
+ <span :if="!relationHref(row, column)">{{ cellValue(row, column) }}</span>
470
+ </td>
427
471
  <td class="right-0 sticky z-10 px-3 py-2 text-right bg-white dark:bg-neutral-900 group-hover:bg-neutral-50 dark:group-hover:bg-white/5 border-black/5 border-l dark:border-white/10 transition-colors">
428
472
  <ModelRecordActions
429
473
  :record="row"
430
474
  :modelName="modelName()"
431
- :canUpdate="writeCapabilities().update"
432
- :canDestroy="writeCapabilities().destroy"
475
+ :canUpdate="writeCapabilities().update && !isAnonymized(row)"
476
+ :canDestroy="writeCapabilities().destroy && !isAnonymized(row)"
433
477
  @view="startView"
434
478
  @edit="startEdit"
435
479
  @delete="confirmingDelete.set($event)"
@@ -0,0 +1,99 @@
1
+ <script client>
2
+ // The records that point at the record on this page, one panel per model: a
3
+ // team's members and its invitations, a user's team memberships. From the
4
+ // model's own `hasMany` and `hasOne`, so nothing is set up per model.
5
+ //
6
+ // Each panel is the newest few with a count. The eye opens one, "View all"
7
+ // opens that model's list narrowed to this record, and "Add" opens its create
8
+ // form with this record already chosen.
9
+ import type { ModelRelatedPanel } from '../../../../functions/dashboard-model-record'
10
+ import { modelRecordHref, modelRelatedCreateHref, modelRelatedListHref } from '../../../../functions/dashboard-model-record'
11
+
12
+ const panels = useReactiveProp<ModelRelatedPanel[]>('panels', [])
13
+ const parentId = useReactiveProp('parentId', '')
14
+ /** This page, for a create form to come back to. */
15
+ const from = useReactiveProp('from', '')
16
+
17
+ /** Beside the heading. Nothing when the panel is empty: the line below already says so. */
18
+ function countLabel(panel: ModelRelatedPanel): string {
19
+ if (panel.kind === 'one' || panel.total === 0)
20
+ return ''
21
+ return panel.total > panel.rows.length ? `Newest ${panel.rows.length} of ${panel.total}` : String(panel.total)
22
+ }
23
+
24
+ /**
25
+ * The eye, named for what it opens. A row is often called by a record it
26
+ * points at (a membership by its list), and "View Enterprise Leads" would
27
+ * promise the list, not the membership.
28
+ */
29
+ function viewAction(panel: ModelRelatedPanel) {
30
+ return [{ action: 'view', label: `View ${panel.label.toLowerCase()}` }]
31
+ }
32
+
33
+ function emptyTitle(panel: ModelRelatedPanel): string {
34
+ return panel.kind === 'one' ? `No ${panel.label.toLowerCase()}` : `No ${panel.title.toLowerCase()} yet`
35
+ }
36
+
37
+ /** A second of a `hasOne` would break the "one": only offered while there is none. */
38
+ function canAdd(panel: ModelRelatedPanel): boolean {
39
+ return panel.canCreate && (panel.kind === 'many' || panel.total === 0)
40
+ }
41
+
42
+ function tableColumns(panel: ModelRelatedPanel) {
43
+ return panel.columns.map((column, index) => ({
44
+ key: column.key,
45
+ label: column.label,
46
+ type: column.type,
47
+ align: column.type === 'datetime' ? 'right' : 'left',
48
+ sortable: false,
49
+ emptyText: '-',
50
+ class: index === 0
51
+ ? 'font-medium text-neutral-900 dark:text-white'
52
+ : column.type === 'datetime' ? 'text-neutral-500 text-xs whitespace-nowrap dark:text-neutral-400' : 'text-neutral-600 dark:text-neutral-300',
53
+ }))
54
+ }
55
+
56
+ function open(panel: ModelRelatedPanel, payload: { row: Record<string, unknown> }): void {
57
+ navigate(modelRecordHref(panel.slug, payload.row.id as number | string))
58
+ }
59
+
60
+ function viewAll(panel: ModelRelatedPanel): void {
61
+ navigate(modelRelatedListHref(panel, parentId()))
62
+ }
63
+
64
+ function add(panel: ModelRelatedPanel): void {
65
+ navigate(modelRelatedCreateHref(panel, parentId(), from()))
66
+ }
67
+ </script>
68
+
69
+ <div class="flex flex-col gap-6" data-related-panels>
70
+ <div :for="panel in panels()" class="min-w-0" data-related-panel>
71
+ <Card padding="none">
72
+ <div class="flex flex-wrap gap-3 items-center justify-between px-6 py-4 border-b border-neutral-200 dark:border-neutral-700">
73
+ <div class="flex gap-3 items-baseline min-w-0">
74
+ <h2 class="font-semibold text-base text-neutral-900 truncate dark:text-white">{{ panel.title }}</h2>
75
+ <span :if="countLabel(panel)" class="text-neutral-500 text-xs whitespace-nowrap dark:text-neutral-400">{{ countLabel(panel) }}</span>
76
+ </div>
77
+ <div class="flex flex-none gap-2 items-center">
78
+ <Button :if="panel.kind === 'many' && panel.total > 0" variant="secondary" size="sm" @click="viewAll(panel)">View all</Button>
79
+ <Button :if="canAdd(panel)" variant="secondary" size="sm" @click="add(panel)">
80
+ <span aria-hidden="true" class="h-3.5 w-3.5 i-hugeicons-add-01"></span>
81
+ {{ 'Add ' + panel.label.toLowerCase() }}
82
+ </Button>
83
+ </div>
84
+ </div>
85
+
86
+ <Table
87
+ :if="panel.rows.length > 0"
88
+ :columns="tableColumns(panel)"
89
+ :data="panel.rows"
90
+ :framed="false"
91
+ :row-actions="viewAction(panel)"
92
+ :action-label-key="panel.columns[0] ? panel.columns[0].key : 'id'"
93
+ @row-action="open(panel, $event)"
94
+ />
95
+
96
+ <p :if="panel.rows.length === 0" class="px-6 py-5 text-neutral-500 text-sm dark:text-neutral-400">{{ emptyTitle(panel) }}</p>
97
+ </Card>
98
+ </div>
99
+ </div>
@@ -0,0 +1,247 @@
1
+ <script client>
2
+ // Choosing a record of another model, for a `belongsTo` field: a team for a
3
+ // member, a board for a card. The field stores an id, and this asks for the
4
+ // record by name instead, so nobody has to find a number on another page and
5
+ // type it here.
6
+ //
7
+ // Two states. With a record chosen it shows which, with a way to clear it.
8
+ // Without one it is a search box: typing lists the records whose name (or, for
9
+ // people, email) matches, and the arrow keys and Enter pick one.
10
+ import type { ModelOption } from '../../../../functions/dashboard-model-record'
11
+ import { fetchModelOptions } from '../../../../functions/dashboard-model-record'
12
+
13
+ const slug = useReactiveProp('slug', '')
14
+ const value = useReactiveProp('value', '')
15
+ const label = useReactiveProp('label', '')
16
+ const name = useReactiveProp('name', '')
17
+ const required = useReactiveProp('required', false)
18
+ const disabled = useReactiveProp('disabled', false)
19
+ const error = useReactiveProp('error', '')
20
+ const emit = defineEmits(['update:value'])
21
+ const generatedId = useId('relation')
22
+
23
+ const chosen = state<ModelOption | null>(null)
24
+ const query = state('')
25
+ const options = state<ModelOption[]>([])
26
+ const open = state(false)
27
+ const searching = state(false)
28
+ const failed = state('')
29
+ const active = state(0)
30
+ // Answers can arrive out of order; only the latest search may fill the list.
31
+ let asked = 0
32
+
33
+ const inputId = derived(() => `${generatedId}-input`)
34
+ const listId = derived(() => `${generatedId}-list`)
35
+ const what = derived(() => (label() || 'record').toLowerCase())
36
+ // No article to get wrong: the label above already says what is being chosen.
37
+ const placeholder = derived(() => 'Search by name')
38
+ const emptyText = derived(() => query().trim() ? `No ${what()} matches "${query().trim()}".` : `There are no ${what()} records yet.`)
39
+ const boxClass = derived(() => [
40
+ 'flex gap-2 items-center px-3 h-8 w-full text-[13px] rounded-lg border transition-all duration-150',
41
+ 'bg-white dark:bg-white/10 text-stone-900 dark:text-neutral-100',
42
+ error()
43
+ ? 'border-red-400/60 dark:border-red-500/60'
44
+ : 'border-stone-200/80 dark:border-white/15',
45
+ disabled() ? 'opacity-40 cursor-not-allowed' : '',
46
+ ].join(' '))
47
+ const inputClass = derived(() => [
48
+ 'block pl-8 pr-3 h-8 w-full text-[13px] rounded-lg border transition-all duration-150',
49
+ 'bg-white dark:bg-white/10 text-stone-900 dark:text-neutral-100',
50
+ 'placeholder:text-stone-400 dark:placeholder:text-neutral-500',
51
+ 'focus:outline-none focus:ring-2 focus:ring-blue-500/20 focus:ring-offset-0',
52
+ error()
53
+ ? 'border-red-400/60 dark:border-red-500/60 focus:border-red-500'
54
+ : 'border-stone-200/80 dark:border-white/15 focus:border-blue-400 hover:border-stone-300 dark:hover:border-white/25',
55
+ disabled() ? 'opacity-40 cursor-not-allowed' : '',
56
+ ].join(' '))
57
+
58
+ function optionClass(index: number): string {
59
+ return index === active()
60
+ ? 'flex flex-col px-3 py-2 w-full text-left bg-blue-50 dark:bg-blue-500/20'
61
+ : 'flex flex-col px-3 py-2 w-full text-left hover:bg-neutral-50 dark:hover:bg-white/5'
62
+ }
63
+
64
+ /** Name the record the field already points at. */
65
+ async function describeValue(): Promise<void> {
66
+ const id = String(value() ?? '')
67
+ if (!id) {
68
+ chosen.set(null)
69
+ return
70
+ }
71
+ if (chosen() && String(chosen()!.id) === id)
72
+ return
73
+ try {
74
+ const [option] = await fetchModelOptions(slug(), { ids: [id] })
75
+ // A record that is gone still shows as what the field holds, by its id.
76
+ chosen.set(option ?? { id, label: `${label() || 'Record'} #${id}`, hint: 'This record no longer exists.' })
77
+ }
78
+ catch {
79
+ chosen.set({ id, label: `${label() || 'Record'} #${id}`, hint: '' })
80
+ }
81
+ }
82
+
83
+ async function search(): Promise<void> {
84
+ const mine = ++asked
85
+ searching.set(true)
86
+ failed.set('')
87
+ try {
88
+ const found = await fetchModelOptions(slug(), { q: query().trim() })
89
+ if (mine !== asked)
90
+ return
91
+ options.set(found)
92
+ active.set(0)
93
+ }
94
+ catch (reason) {
95
+ if (mine !== asked)
96
+ return
97
+ options.set([])
98
+ failed.set(reason instanceof Error ? reason.message : 'The list could not be loaded.')
99
+ }
100
+ finally {
101
+ if (mine === asked)
102
+ searching.set(false)
103
+ }
104
+ }
105
+
106
+ const searchSoon = useDebounce(() => {
107
+ void search()
108
+ }, 200)
109
+
110
+ function onInput(event: Event): void {
111
+ query.set((event.target as HTMLInputElement).value)
112
+ open.set(true)
113
+ searchSoon()
114
+ }
115
+
116
+ function onFocus(): void {
117
+ if (disabled())
118
+ return
119
+ open.set(true)
120
+ void search()
121
+ }
122
+
123
+ // Options keep the input focused while they are pressed (see the template),
124
+ // so losing focus means the visitor has moved on.
125
+ function onBlur(): void {
126
+ open.set(false)
127
+ }
128
+
129
+ function choose(option: ModelOption): void {
130
+ chosen.set(option)
131
+ open.set(false)
132
+ query.set('')
133
+ emit('update:value', String(option.id))
134
+ }
135
+
136
+ function clear(): void {
137
+ if (disabled())
138
+ return
139
+ chosen.set(null)
140
+ options.set([])
141
+ emit('update:value', '')
142
+ }
143
+
144
+ function onKeydown(event: KeyboardEvent): void {
145
+ if (event.key === 'ArrowDown') {
146
+ event.preventDefault()
147
+ open.set(true)
148
+ active.set(Math.min(active() + 1, Math.max(0, options().length - 1)))
149
+ }
150
+ else if (event.key === 'ArrowUp') {
151
+ event.preventDefault()
152
+ active.set(Math.max(active() - 1, 0))
153
+ }
154
+ else if (event.key === 'Enter') {
155
+ // Never the form's submit: Enter in a search box picks from its list.
156
+ event.preventDefault()
157
+ const option = options()[active()]
158
+ if (open() && option)
159
+ choose(option)
160
+ }
161
+ else if (event.key === 'Escape') {
162
+ open.set(false)
163
+ }
164
+ }
165
+
166
+ effect(() => {
167
+ // Also when the page sets the value after this mounts, as an edit form does.
168
+ value()
169
+ void describeValue()
170
+ })
171
+ </script>
172
+
173
+ <div class="relative w-full" data-relation-picker>
174
+ <label :if="label()" :for="inputId()" class="block mb-1.5 font-medium text-[13px] tracking-tight" :class="error() ? 'text-red-600 dark:text-red-400' : 'text-stone-600 dark:text-neutral-400'">
175
+ <span :text="label()"></span>
176
+ <span :if="required()" class="ml-0.5 text-red-500">*</span>
177
+ </label>
178
+
179
+ <input type="hidden" :name="name() || null" :value="value()">
180
+
181
+ <div :if="chosen()" :class="boxClass()" data-relation-chosen>
182
+ <span class="flex-1 min-w-0 truncate">
183
+ <span class="font-medium" :text="chosen()?.label"></span>
184
+ <span :if="chosen()?.hint" class="ml-2 text-stone-500 dark:text-neutral-400" :text="chosen()?.hint"></span>
185
+ </span>
186
+ <button
187
+ type="button"
188
+ class="flex flex-none items-center justify-center h-5 w-5 text-stone-400 dark:text-neutral-400 hover:text-stone-700 dark:hover:text-neutral-100 rounded"
189
+ :disabled="disabled()"
190
+ :aria-label="'Choose a different ' + what()"
191
+ :title="'Choose a different ' + what()"
192
+ @click="clear"
193
+ >
194
+ <span aria-hidden="true" class="h-3.5 w-3.5 i-hugeicons-cancel-01"></span>
195
+ </button>
196
+ </div>
197
+
198
+ <div :if="!chosen()" class="relative">
199
+ <div class="flex absolute inset-y-0 left-0 items-center pl-2.5 text-neutral-400 pointer-events-none">
200
+ <span aria-hidden="true" class="h-3.5 w-3.5 i-hugeicons-search-01"></span>
201
+ </div>
202
+ <input
203
+ :id="inputId()"
204
+ type="text"
205
+ role="combobox"
206
+ autocomplete="off"
207
+ aria-autocomplete="list"
208
+ :aria-expanded="open() ? 'true' : 'false'"
209
+ :aria-controls="listId()"
210
+ :aria-invalid="error() ? 'true' : null"
211
+ :aria-label="label() || null"
212
+ :placeholder="placeholder()"
213
+ :value="query()"
214
+ :disabled="disabled()"
215
+ :class="inputClass()"
216
+ @input="onInput"
217
+ @focus="onFocus"
218
+ @blur="onBlur"
219
+ @keydown="onKeydown"
220
+ >
221
+
222
+ <div
223
+ :if="open()"
224
+ :id="listId()"
225
+ role="listbox"
226
+ :aria-label="label() || 'Records'"
227
+ class="absolute left-0 overflow-y-auto right-0 top-full z-30 mt-1 max-h-64 bg-white dark:bg-neutral-900 border border-stone-200 rounded-lg dark:border-white/15 shadow-lg"
228
+ >
229
+ <button
230
+ :for="(option, index) in options()"
231
+ type="button"
232
+ role="option"
233
+ :aria-selected="index === active() ? 'true' : 'false'"
234
+ :class="optionClass(index)"
235
+ @mousedown.prevent="choose(option)"
236
+ >
237
+ <span class="font-medium text-[13px] text-stone-900 truncate dark:text-neutral-100" :text="option.label"></span>
238
+ <span :if="option.hint" class="text-[12px] text-stone-500 truncate dark:text-neutral-400" :text="option.hint"></span>
239
+ </button>
240
+ <p :if="searching() && options().length === 0" class="px-3 py-2 text-[12px] text-stone-500 dark:text-neutral-400">Searching</p>
241
+ <p :if="!searching() && !failed() && options().length === 0" class="px-3 py-2 text-[12px] text-stone-500 dark:text-neutral-400" :text="emptyText()"></p>
242
+ <p :if="failed()" role="alert" class="px-3 py-2 text-[12px] text-red-600 dark:text-red-400" :text="failed()"></p>
243
+ </div>
244
+ </div>
245
+
246
+ <p :if="error()" class="mt-1.5 text-[12px] text-red-600 dark:text-red-400" :text="error()"></p>
247
+ </div>
@@ -107,7 +107,7 @@ onMount(() => {
107
107
  <div class="flex flex-col gap-6">
108
108
  <header class="flex flex-col gap-4 sm:flex-row sm:items-end sm:justify-between">
109
109
  <div>
110
- <h1 class="font-semibold text-2xl text-neutral-900 tracking-tight dark:text-white">{{ title() }}</h1>
110
+ <h1 class="font-bold text-2xl text-neutral-900 tracking-tight dark:text-white">{{ title() }}</h1>
111
111
  <p class="mt-1 max-w-3xl text-neutral-500 text-sm dark:text-neutral-400">{{ description() }}</p>
112
112
  </div>
113
113
  <Button variant="secondary" :loading="loading()" @click="loadModels">
@@ -104,7 +104,7 @@ onMount(loadDeliveries)
104
104
  </div>
105
105
  <div class="sm:flex sm:items-center">
106
106
  <div class="sm:flex-auto">
107
- <h1 class="font-semibold leading-6 text-base text-gray-900 dark:text-neutral-100">{{ title }}</h1>
107
+ <h1 class="font-bold text-2xl text-gray-900 dark:text-neutral-100">{{ title }}</h1>
108
108
  <p class="mt-2 text-gray-700 text-sm dark:text-neutral-300">{{ description }}</p>
109
109
  </div>
110
110
  <div class="sm:flex-none mt-4 sm:ml-16 sm:mt-0">
@@ -112,7 +112,7 @@ onMount(load)
112
112
  </div>
113
113
  <div class="sm:flex sm:items-start sm:justify-between">
114
114
  <div>
115
- <h1 class="font-semibold leading-6 text-base text-gray-900 dark:text-neutral-100">Notification History</h1>
115
+ <h1 class="font-bold text-2xl text-gray-900 dark:text-neutral-100">Notification History</h1>
116
116
  <p class="mt-2 text-gray-700 text-sm dark:text-neutral-300">Search and inspect persisted notification transport attempts.</p>
117
117
  </div>
118
118
  <StxLink to="/notifications/dashboard" class="inline-flex gap-2 items-center mt-4 px-3 py-2 sm:mt-0 font-semibold text-gray-900 text-sm dark:text-neutral-100 bg-white dark:bg-neutral-700 hover:bg-gray-50 dark:hover:bg-neutral-600 ring-1 ring-gray-300 ring-inset rounded-md dark:ring-neutral-600 shadow-sm">
@@ -77,7 +77,7 @@ onMount(loadOverview)
77
77
  </div>
78
78
  <div class="flex gap-4 items-start justify-between">
79
79
  <div>
80
- <h1 class="font-semibold leading-6 text-base text-gray-900 dark:text-neutral-100">Notifications Overview</h1>
80
+ <h1 class="font-bold text-2xl text-gray-900 dark:text-neutral-100">Notifications Overview</h1>
81
81
  <p class="mt-2 text-gray-700 text-sm dark:text-neutral-300">Live transport health across every notification channel.</p>
82
82
  </div>
83
83
  <Button href="/notifications/history" variant="secondary">
@@ -131,7 +131,7 @@ onMount(() => {
131
131
  <div class="flex flex-col gap-6">
132
132
  <header class="flex flex-col gap-4 sm:flex-row sm:items-end sm:justify-between">
133
133
  <div>
134
- <h1 class="font-semibold text-2xl text-neutral-900 tracking-tight dark:text-white">{{ pageTitle() }}</h1>
134
+ <h1 class="font-bold text-2xl text-neutral-900 tracking-tight dark:text-white">{{ pageTitle() }}</h1>
135
135
  <p class="mt-1 text-neutral-500 text-sm dark:text-neutral-400">{{ pageDescription() }}</p>
136
136
  </div>
137
137
  <div class="flex flex-wrap gap-3 items-center">
@@ -66,7 +66,7 @@ onMount(() => {
66
66
  </StxLink>
67
67
  <div class="flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between">
68
68
  <div>
69
- <h1 class="font-semibold text-2xl text-neutral-900 tracking-tight dark:text-white">Query Details</h1>
69
+ <h1 class="font-bold text-2xl text-neutral-900 tracking-tight dark:text-white">Query Details</h1>
70
70
  <p class="mt-1 text-neutral-500 text-sm dark:text-neutral-400">A safe projection of one native database log record.</p>
71
71
  </div>
72
72
  <span :if="record()" :class="'inline-flex px-2.5 py-1 font-medium text-xs rounded-md ' + statusClass(record()?.status || 'completed')">{{ record()?.status }}</span>
@@ -97,7 +97,7 @@ onMount(() => {
97
97
  })
98
98
  </script>
99
99
 
100
- <div class="space-y-6">
100
+ <div class="flex flex-col gap-6">
101
101
  <PageHeader title="Queue" description="Recorded queue state and shared worker heartbeats.">
102
102
  <div class="flex gap-2 items-center">
103
103
  <span :class="'inline-flex items-center px-2.5 py-1 font-medium text-xs rounded-full ' + (queueConnected() ? 'text-green-700 bg-green-100 dark:text-green-300 dark:bg-green-950' : 'text-red-700 bg-red-100 dark:text-red-300 dark:bg-red-950')">
@@ -137,7 +137,7 @@ onDestroy(() => {
137
137
  })
138
138
  </script>
139
139
 
140
- <div class="space-y-6">
140
+ <div class="flex flex-col gap-6">
141
141
  <PageHeader title="Realtime" description="Recorded Websocket model events and a native connection inspector.">
142
142
  <Button variant="secondary" :loading="isLoading()" @click="loadRealtime">
143
143
  <span :if="!isLoading()" class="h-4 w-4 i-hugeicons-refresh"></span>