@stacksjs/defaults 0.75.489 → 0.75.490

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 (137) hide show
  1. package/ai/skills/stacks-actions/SKILL.md +1 -1
  2. package/ai/skills/stacks-dashboard/SKILL.md +20 -2
  3. package/ai/skills/stacks-native/CATALOG.md +9 -9
  4. package/ai/skills/stacks-search-engine/SKILL.md +14 -0
  5. package/app/Actions/Dashboard/Commerce/CommerceCategoriesAction.ts +7 -13
  6. package/app/Actions/Dashboard/Commerce/CommerceCustomerChoicesAction.ts +34 -0
  7. package/app/Actions/Dashboard/Commerce/CommerceDeliveryAction.ts +7 -16
  8. package/app/Actions/Dashboard/Commerce/CommerceGiftCardsAction.ts +21 -15
  9. package/app/Actions/Dashboard/Commerce/CommerceGiftCardsExportAction.ts +41 -0
  10. package/app/Actions/Dashboard/Commerce/CommerceOrderCustomersAction.ts +37 -0
  11. package/app/Actions/Dashboard/Commerce/CommerceOrdersAction.ts +26 -41
  12. package/app/Actions/Dashboard/Commerce/CommerceOrdersExportAction.ts +43 -0
  13. package/app/Actions/Dashboard/Commerce/CommercePaymentsAction.ts +24 -21
  14. package/app/Actions/Dashboard/Commerce/CommercePaymentsExportAction.ts +41 -0
  15. package/app/Actions/Dashboard/Commerce/CommercePosAction.ts +18 -48
  16. package/app/Actions/Dashboard/Commerce/CommercePosProductsAction.ts +39 -0
  17. package/app/Actions/Dashboard/Commerce/CommercePrintLogsAction.ts +14 -104
  18. package/app/Actions/Dashboard/Commerce/CommercePrintLogsExportAction.ts +41 -0
  19. package/app/Actions/Dashboard/Commerce/CommerceProductChoicesAction.ts +32 -0
  20. package/app/Actions/Dashboard/Commerce/CommerceProductsAction.ts +24 -43
  21. package/app/Actions/Dashboard/Commerce/CommerceProductsExportAction.ts +44 -0
  22. package/app/Actions/Dashboard/Commerce/CourierIndexAction.ts +3 -1
  23. package/app/Actions/Dashboard/Commerce/DeliveryRouteIndexAction.ts +23 -12
  24. package/app/Actions/Dashboard/Commerce/DigitalDeliveryIndexAction.ts +3 -1
  25. package/app/Actions/Dashboard/Commerce/LicenseKeyIndexAction.ts +24 -23
  26. package/app/Actions/Dashboard/Commerce/LicenseKeyOptionsAction.ts +35 -16
  27. package/app/Actions/Dashboard/Commerce/ProductWaitlistIndexAction.ts +22 -22
  28. package/app/Actions/Dashboard/Commerce/RestaurantWaitlistIndexAction.ts +22 -17
  29. package/app/Actions/Dashboard/Commerce/ReviewIndexAction.ts +22 -31
  30. package/app/Actions/Dashboard/Commerce/ShippingMethodIndexAction.ts +3 -1
  31. package/app/Actions/Dashboard/Commerce/ShippingRateIndexAction.ts +3 -1
  32. package/app/Actions/Dashboard/Commerce/ShippingZoneIndexAction.ts +3 -1
  33. package/app/Actions/Dashboard/Commerce/commerce-category-list.test.ts +100 -0
  34. package/app/Actions/Dashboard/Commerce/commerce-category-list.ts +26 -0
  35. package/app/Actions/Dashboard/Commerce/commerce-choice-records.ts +56 -0
  36. package/app/Actions/Dashboard/Commerce/commerce-choices.test.ts +88 -0
  37. package/app/Actions/Dashboard/Commerce/commerce-choices.ts +70 -0
  38. package/app/Actions/Dashboard/Commerce/commerce-delivery-overview.test.ts +151 -0
  39. package/app/Actions/Dashboard/Commerce/commerce-delivery-overview.ts +85 -0
  40. package/app/Actions/Dashboard/Commerce/commerce-delivery-route-list.test.ts +153 -0
  41. package/app/Actions/Dashboard/Commerce/commerce-delivery-route-list.ts +180 -0
  42. package/app/Actions/Dashboard/Commerce/commerce-delivery.ts +24 -9
  43. package/app/Actions/Dashboard/Commerce/commerce-gift-card-list.test.ts +221 -0
  44. package/app/Actions/Dashboard/Commerce/commerce-gift-card-list.ts +259 -0
  45. package/app/Actions/Dashboard/Commerce/commerce-license-key-list.test.ts +184 -0
  46. package/app/Actions/Dashboard/Commerce/commerce-license-key-list.ts +217 -0
  47. package/app/Actions/Dashboard/Commerce/commerce-order-list.test.ts +183 -0
  48. package/app/Actions/Dashboard/Commerce/commerce-order-list.ts +278 -0
  49. package/app/Actions/Dashboard/Commerce/commerce-order-records.test.ts +29 -0
  50. package/app/Actions/Dashboard/Commerce/commerce-payment-list.test.ts +180 -0
  51. package/app/Actions/Dashboard/Commerce/commerce-payment-list.ts +272 -0
  52. package/app/Actions/Dashboard/Commerce/commerce-pos-catalog.test.ts +171 -0
  53. package/app/Actions/Dashboard/Commerce/commerce-pos-catalog.ts +152 -0
  54. package/app/Actions/Dashboard/Commerce/commerce-pos.test.ts +1 -12
  55. package/app/Actions/Dashboard/Commerce/commerce-pos.ts +0 -26
  56. package/app/Actions/Dashboard/Commerce/commerce-print-log-list.test.ts +202 -0
  57. package/app/Actions/Dashboard/Commerce/commerce-print-log-list.ts +286 -0
  58. package/app/Actions/Dashboard/Commerce/commerce-product-list.test.ts +174 -0
  59. package/app/Actions/Dashboard/Commerce/commerce-product-list.ts +276 -0
  60. package/app/Actions/Dashboard/Commerce/commerce-product-waitlist-list.test.ts +183 -0
  61. package/app/Actions/Dashboard/Commerce/commerce-product-waitlist-list.ts +170 -0
  62. package/app/Actions/Dashboard/Commerce/commerce-record.ts +21 -0
  63. package/app/Actions/Dashboard/Commerce/commerce-restaurant-waitlist-list.test.ts +189 -0
  64. package/app/Actions/Dashboard/Commerce/commerce-restaurant-waitlist-list.ts +177 -0
  65. package/app/Actions/Dashboard/Commerce/commerce-review-list.test.ts +193 -0
  66. package/app/Actions/Dashboard/Commerce/commerce-review-list.ts +220 -0
  67. package/app/Actions/Dashboard/Commerce/commerce-sql.ts +57 -0
  68. package/app/Actions/Dashboard/Commerce/payment-records.test.ts +16 -0
  69. package/app/Actions/Dashboard/Commerce/product-waitlist-records.test.ts +6 -5
  70. package/app/Actions/Dashboard/Commerce/product-waitlist-records.ts +16 -45
  71. package/app/Actions/Dashboard/Commerce/restaurant-waitlist-records.ts +4 -24
  72. package/app/Actions/Dashboard/Content/content-list.ts +10 -0
  73. package/app/Actions/Dashboard/Content/file-listing-metadata.test.ts +46 -0
  74. package/app/Actions/Dashboard/Content/file-manager.ts +51 -10
  75. package/app/Actions/Dashboard/DashboardHomeAction.test.ts +13 -9
  76. package/app/Actions/Dashboard/DashboardHomeAction.ts +42 -21
  77. package/app/Actions/Dashboard/Jobs/JobStatsAction.ts +5 -2
  78. package/app/Actions/Dashboard/Kanban/UsersListAction.ts +13 -9
  79. package/app/Actions/Dashboard/Kanban/kanban-response.test.ts +40 -0
  80. package/app/Actions/Dashboard/Kanban/kanban-response.ts +53 -1
  81. package/app/Actions/Dashboard/Kanban/kanban-users.test.ts +114 -0
  82. package/app/Actions/Dashboard/Kanban/kanban-users.ts +32 -0
  83. package/app/Actions/Dashboard/Models/ModelShowAction.ts +8 -0
  84. package/app/Actions/Dashboard/Models/ModelsIndexAction.ts +16 -2
  85. package/app/Actions/Dashboard/Models/model-migration.test.ts +27 -0
  86. package/app/Actions/Dashboard/Models/model-migration.ts +23 -0
  87. package/app/Actions/Dashboard/Queue/QueueStatsAction.ts +5 -3
  88. package/app/Actions/Dashboard/Queue/QueueWorkersAction.ts +3 -2
  89. package/app/Actions/Dashboard/Queue/worker-snapshots.test.ts +31 -0
  90. package/app/Actions/Dashboard/Queue/worker-snapshots.ts +33 -0
  91. package/app/Actions/Dashboard/named-search.test.ts +36 -0
  92. package/app/Actions/Dashboard/named-search.ts +80 -0
  93. package/app/Models/Request.ts +4 -2
  94. package/functions/commerce/shippings/dashboard-resource.ts +12 -1
  95. package/functions/commerce/shippings/delivery-routes.ts +1 -0
  96. package/functions/commerce/shippings/license-keys.ts +1 -0
  97. package/functions/dashboard-list.test.ts +132 -1
  98. package/functions/dashboard-list.ts +198 -1
  99. package/functions/queue.ts +2 -0
  100. package/ide/vscode/package.json +1 -1
  101. package/package.json +2 -2
  102. package/resources/components/Dashboard/Commerce/CommerceGiftCardBreakdown.stx +38 -12
  103. package/resources/components/Dashboard/Commerce/CommerceGiftCardsDashboard.stx +122 -68
  104. package/resources/components/Dashboard/Commerce/CommerceGiftCardsTable.stx +29 -6
  105. package/resources/components/Dashboard/Commerce/CommerceOrderDialog.stx +59 -2
  106. package/resources/components/Dashboard/Commerce/CommerceOrdersDashboard.stx +126 -80
  107. package/resources/components/Dashboard/Commerce/CommerceOrdersTable.stx +28 -3
  108. package/resources/components/Dashboard/Commerce/CommercePaymentsBreakdown.stx +12 -29
  109. package/resources/components/Dashboard/Commerce/CommercePaymentsDashboard.stx +139 -60
  110. package/resources/components/Dashboard/Commerce/CommercePaymentsTable.stx +27 -2
  111. package/resources/components/Dashboard/Commerce/CommercePosCatalog.stx +17 -1
  112. package/resources/components/Dashboard/Commerce/CommercePosCheckoutDialog.stx +47 -3
  113. package/resources/components/Dashboard/Commerce/CommercePosDashboard.stx +59 -49
  114. package/resources/components/Dashboard/Commerce/CommerceProductsDashboard.stx +116 -82
  115. package/resources/components/Dashboard/Commerce/CommerceProductsTable.stx +28 -4
  116. package/resources/components/Dashboard/Commerce/CommerceReviewsDashboard.stx +120 -69
  117. package/resources/components/Dashboard/Commerce/CommerceReviewsTable.stx +29 -6
  118. package/resources/components/Dashboard/Commerce/Delivery/DeliveryRoutesDashboard.stx +79 -52
  119. package/resources/components/Dashboard/Commerce/Delivery/DeliveryRoutesTable.stx +31 -8
  120. package/resources/components/Dashboard/Commerce/Delivery/LicenseKeyDialog.stx +71 -13
  121. package/resources/components/Dashboard/Commerce/Delivery/LicenseKeysDashboard.stx +69 -81
  122. package/resources/components/Dashboard/Commerce/Delivery/LicenseKeysTable.stx +31 -8
  123. package/resources/components/Dashboard/Commerce/PrintLogBreakdown.stx +21 -17
  124. package/resources/components/Dashboard/Commerce/PrintLogsDashboard.stx +23 -22
  125. package/resources/components/Dashboard/Commerce/ProductWaitlistDashboard.stx +116 -20
  126. package/resources/components/Dashboard/Commerce/ProductWaitlistEntryDialog.stx +100 -12
  127. package/resources/components/Dashboard/Commerce/ProductWaitlistTable.stx +34 -16
  128. package/resources/components/Dashboard/Commerce/RestaurantWaitlistDashboard.stx +107 -19
  129. package/resources/components/Dashboard/Commerce/RestaurantWaitlistEntryDialog.stx +65 -6
  130. package/resources/components/Dashboard/Commerce/RestaurantWaitlistTable.stx +29 -3
  131. package/resources/components/Dashboard/Kanban/KanbanBoardsDashboard.stx +10 -1
  132. package/resources/components/Dashboard/Kanban/KanbanCardDialog.stx +21 -1
  133. package/resources/components/Dashboard/Models/ModelRecordsDashboard.stx +24 -4
  134. package/resources/components/Dashboard/Models/ModelsOverview.stx +13 -2
  135. package/resources/components/Dashboard/Queue/QueueDashboard.stx +7 -1
  136. package/routes/dashboard-api.ts +11 -0
  137. package/views/dashboard/stores/kanban.ts +38 -6
@@ -1,15 +1,18 @@
1
1
  @import('../UI/Table')
2
2
 
3
3
  <script client>
4
- import type { ProductWaitlistOptions, ProductWaitlistRecord } from '../../../../app/Actions/Dashboard/Commerce/product-waitlist-records'
4
+ import type { ProductWaitlistRecord } from '../../../../app/Actions/Dashboard/Commerce/product-waitlist-records'
5
5
 
6
6
  const records = useReactiveProp('records', [] as ProductWaitlistRecord[])
7
- const options = useReactiveProp('options', {
8
- products: [],
9
- customers: [],
10
- } as ProductWaitlistOptions)
11
7
  const loading = useReactiveProp('loading', false)
12
- const emit = defineEmits(['edit', 'delete'])
8
+ /**
9
+ * The server pages and sorts what the parent's search and filter match
10
+ * (stacksjs/stacks#3218): how many entries match, the page shown and its size.
11
+ */
12
+ const total = useReactiveProp('total', 0)
13
+ const currentPage = useReactiveProp('currentPage', 1)
14
+ const perPage = useReactiveProp('perPage', 25)
15
+ const emit = defineEmits(['edit', 'delete', 'page-change', 'page-size-change', 'sort'])
13
16
 
14
17
  const STATUS_CLASSES = {
15
18
  purchased: 'text-purple-700 dark:text-purple-300 bg-purple-50 dark:bg-purple-950/30',
@@ -31,29 +34,37 @@ const ROW_ACTIONS = [
31
34
  { action: 'delete', label: 'Delete waitlist entry for', icon: 'i-hugeicons-waste', class: 'text-red-500' },
32
35
  ]
33
36
 
34
- function productLabel(productId: string): string {
35
- return options().products.find(option => option.id === productId)?.label || (productId ? `Product ${productId}` : 'Not linked')
36
- }
37
-
38
37
  /**
39
- * `contact` and `productName` are computed per row because a column reads a
40
- * field: the contact line falls back through email then phone, and the product
41
- * name is looked up in the options the parent passed.
38
+ * `contact` is computed per row because a column reads a field: the contact
39
+ * line falls back through email then phone. The product's name comes with
40
+ * the entry.
42
41
  */
43
42
  const rows = derived(() => records().map(entry => ({
44
43
  ...entry,
45
44
  contact: entry.email || entry.phone || 'No contact recorded',
46
- productName: productLabel(entry.productId),
45
+ productName: entry.productName || (entry.productId ? `Product ${entry.productId}` : 'Not linked'),
47
46
  })))
48
47
 
49
48
  function handleRowAction(payload: { action: string, row: ProductWaitlistRecord }): void {
50
49
  emit(payload.action, payload.row)
51
50
  }
51
+
52
+ function changePage(page: number): void {
53
+ emit('page-change', page)
54
+ }
55
+
56
+ function changePageSize(size: number): void {
57
+ emit('page-size-change', size)
58
+ }
59
+
60
+ function changeSort(sort: { key: string, direction: string }): void {
61
+ emit('sort', sort)
62
+ }
52
63
  </script>
53
64
 
54
65
  {{--
55
66
  No `searchable` or `filterable`: the parent dashboard owns the search box and
56
- the filter selects. Paging is what was missing.
67
+ the filter select, and the server pages and sorts what they match.
57
68
  --}}
58
69
  <Table
59
70
  :columns="COLUMNS"
@@ -62,8 +73,15 @@ function handleRowAction(payload: { action: string, row: ProductWaitlistRecord }
62
73
  :row-actions="ROW_ACTIONS"
63
74
  action-label-key="name"
64
75
  paginated
65
- :page-size="25"
76
+ manual-pagination
77
+ manual-sort
78
+ :total="total()"
79
+ :current-page="currentPage()"
80
+ :page-size="perPage()"
66
81
  empty-title="No product waitlist records found"
67
82
  empty-description="Add an entry or adjust the current filters."
68
83
  @row-action="handleRowAction"
84
+ @page-change="changePage"
85
+ @page-size-change="changePageSize"
86
+ @sort="changeSort"
69
87
  />
@@ -1,21 +1,31 @@
1
1
  <script client>
2
- import type { RestaurantWaitlistOptions, RestaurantWaitlistRecord, RestaurantWaitlistSummary, RestaurantWaitlistWritePayload } from '../../../../app/Actions/Dashboard/Commerce/restaurant-waitlist-records'
2
+ import type { RestaurantWaitlistRecord, RestaurantWaitlistSummary, RestaurantWaitlistWritePayload } from '../../../../app/Actions/Dashboard/Commerce/restaurant-waitlist-records'
3
3
  import { restaurantWaitlistTimestamp } from '../../../../app/Actions/Dashboard/Commerce/restaurant-waitlist-records'
4
4
  import { DashboardApiError, dashboardApi } from '../../../../functions/dashboard-api'
5
5
  import { pushToast } from '../../../../functions/toasts'
6
6
 
7
7
  interface RestaurantWaitlistResponse {
8
8
  records: RestaurantWaitlistRecord[]
9
+ total: number
10
+ page: number
11
+ perPage: number
9
12
  summary: RestaurantWaitlistSummary
10
- options: RestaurantWaitlistOptions
11
13
  }
12
14
 
13
15
  const records = state<RestaurantWaitlistRecord[]>([])
14
16
  const summary = state<RestaurantWaitlistSummary>({ total: 0, waiting: 0, seated: 0, cancelled: 0, noShow: 0, averageQuotedWait: 0, seatingRate: 0 })
15
- const options = state<RestaurantWaitlistOptions>({ customers: [] })
16
17
  const search = state('')
17
18
  const status = state('all')
18
19
  const preference = state('all')
20
+ // The server searches, filters, sorts and pages (stacksjs/stacks#3218), where
21
+ // this page used to do all of that with the newest 500.
22
+ const matchingTotal = state(0)
23
+ const page = state(1)
24
+ const perPage = state(25)
25
+ const appliedSearch = state('')
26
+ const headerSort = state<{ sort: string, direction: string } | null>(null)
27
+ let listRequest = 0
28
+ let searchTimer: ReturnType<typeof setTimeout> | null = null
19
29
  const isLoading = state(true)
20
30
  const loadError = state('')
21
31
  const entryDialogOpen = state(false)
@@ -34,16 +44,19 @@ const metrics = derived(() => [
34
44
  { label: 'Seating rate', value: `${summary().seatingRate}%` },
35
45
  ])
36
46
 
37
- function rows(): RestaurantWaitlistRecord[] {
38
- const query = search().trim().toLowerCase()
39
- return records().filter((record) => {
40
- if (status() !== 'all' && record.status !== status())
41
- return false
42
- if (preference() !== 'all' && record.tablePreference !== preference())
43
- return false
44
- return !query || [record.name, record.email, record.phone, record.status, record.tablePreference]
45
- .some(value => value.toLowerCase().includes(query))
46
- })
47
+ /** The table's sortable columns, as the server's sort names. */
48
+ const COLUMN_SORTS: Record<string, string> = {
49
+ name: 'name',
50
+ partySize: 'party',
51
+ status: 'status',
52
+ quotedWait: 'quoted',
53
+ preference: 'preference',
54
+ checkIn: 'checkin',
55
+ }
56
+
57
+ function matchingLabel(): string {
58
+ const count = matchingTotal()
59
+ return `${count} matching ${count === 1 ? 'party' : 'parties'}`
47
60
  }
48
61
 
49
62
  function openAddDialog(): void {
@@ -109,25 +122,95 @@ function elapsedMinutes(value: string): number {
109
122
  }
110
123
 
111
124
  async function loadRecords(): Promise<void> {
125
+ const request = ++listRequest
112
126
  isLoading.set(true)
113
127
  loadError.set('')
114
128
  try {
115
- const result = await dashboardApi<RestaurantWaitlistResponse>('/api/dashboard/commerce/waitlist-restaurants')
129
+ const params = new URLSearchParams()
130
+ const order = headerSort() ?? { sort: 'created', direction: 'desc' }
131
+ params.set('sort', order.sort)
132
+ params.set('direction', order.direction)
133
+ if (appliedSearch())
134
+ params.set('q', appliedSearch())
135
+ if (status() !== 'all')
136
+ params.set('status', status())
137
+ if (preference() !== 'all')
138
+ params.set('preference', preference())
139
+ params.set('page', String(page()))
140
+ params.set('per_page', String(perPage()))
141
+ const result = await dashboardApi<RestaurantWaitlistResponse>(`/api/dashboard/commerce/waitlist-restaurants?${params}`)
142
+ // Only the newest request lands.
143
+ if (request !== listRequest)
144
+ return
116
145
  records.set(Array.isArray(result.records) ? result.records : [])
146
+ matchingTotal.set(Number(result.total) || 0)
147
+ page.set(Number(result.page) || 1)
117
148
  summary.set(result.summary ?? { total: 0, waiting: 0, seated: 0, cancelled: 0, noShow: 0, averageQuotedWait: 0, seatingRate: 0 })
118
- options.set(result.options ?? { customers: [] })
119
149
  }
120
150
  catch (error) {
151
+ if (request !== listRequest)
152
+ return
121
153
  loadError.set('Restaurant waitlist records could not be loaded.')
122
154
  pushToast('error', 'Could not load restaurant waitlist', {
123
155
  detail: error instanceof Error ? error.message : String(error),
124
156
  })
125
157
  }
126
158
  finally {
127
- isLoading.set(false)
159
+ if (request === listRequest)
160
+ isLoading.set(false)
128
161
  }
129
162
  }
130
163
 
164
+ function eventValue<T>(value: T | CustomEvent<T>): T {
165
+ return value instanceof CustomEvent ? value.detail : value
166
+ }
167
+
168
+ function changePage(value: number | CustomEvent<number>): void {
169
+ page.set(Number(eventValue(value)) || 1)
170
+ void loadRecords()
171
+ }
172
+
173
+ function changePageSize(value: number | CustomEvent<number>): void {
174
+ perPage.set(Number(eventValue(value)) || 25)
175
+ page.set(1)
176
+ void loadRecords()
177
+ }
178
+
179
+ function changeColumnSort(value: { key: string, direction: string } | CustomEvent<{ key: string, direction: string }>): void {
180
+ const column = eventValue(value)
181
+ const serverSort = COLUMN_SORTS[column.key]
182
+ headerSort.set(serverSort ? { sort: serverSort, direction: column.direction === 'asc' ? 'asc' : 'desc' } : null)
183
+ page.set(1)
184
+ void loadRecords()
185
+ }
186
+
187
+ // The filters ask the server for page 1 when they change, and the search
188
+ // once typing pauses.
189
+ let shownFilters = JSON.stringify([status(), preference()])
190
+ effect(() => {
191
+ const filters = JSON.stringify([status(), preference()])
192
+ if (filters === shownFilters)
193
+ return
194
+ shownFilters = filters
195
+ page.set(1)
196
+ void loadRecords()
197
+ })
198
+
199
+ let shownSearch = search().trim()
200
+ effect(() => {
201
+ const term = search().trim()
202
+ if (term === shownSearch)
203
+ return
204
+ shownSearch = term
205
+ if (searchTimer)
206
+ clearTimeout(searchTimer)
207
+ searchTimer = setTimeout(() => {
208
+ appliedSearch.set(term)
209
+ page.set(1)
210
+ void loadRecords()
211
+ }, 250)
212
+ })
213
+
131
214
  async function saveRecord(payload: RestaurantWaitlistWritePayload): Promise<void> {
132
215
  const current = editingRecord()
133
216
  const isEditing = entryDialogMode() === 'edit' && current !== null
@@ -235,7 +318,7 @@ onMount(() => {
235
318
  <div class="flex flex-col gap-3 lg:flex-row lg:items-end lg:justify-between">
236
319
  <div>
237
320
  <h2 class="font-semibold text-gray-900 dark:text-white">Waitlist parties</h2>
238
- <p class="mt-1 text-gray-500 text-sm dark:text-neutral-400">Up to 200 recent records from the application model.</p>
321
+ <p class="mt-1 text-gray-500 text-sm dark:text-neutral-400">{{ matchingLabel() }}</p>
239
322
  </div>
240
323
  <div class="flex flex-wrap gap-2">
241
324
  <label class="sr-only" for="restaurant-waitlist-status">Status</label>
@@ -260,13 +343,19 @@ onMount(() => {
260
343
  </div>
261
344
 
262
345
  <RestaurantWaitlistTable
263
- :records="rows()"
346
+ :records="records()"
347
+ :total="matchingTotal()"
348
+ :current-page="page()"
349
+ :per-page="perPage()"
264
350
  :loading="isLoading()"
265
351
  :busyId="busyId()"
266
352
  @seat="changeStatus($event, 'seated')"
267
353
  @no-show="changeStatus($event, 'no_show')"
268
354
  @edit="openEditDialog"
269
355
  @delete="openDeleteDialog"
356
+ @page-change="changePage"
357
+ @page-size-change="changePageSize"
358
+ @sort="changeColumnSort"
270
359
  />
271
360
  </section>
272
361
  </div>
@@ -275,7 +364,6 @@ onMount(() => {
275
364
  :open="entryDialogOpen()"
276
365
  :mode="entryDialogMode()"
277
366
  :record="editingRecord()"
278
- :options="options()"
279
367
  :busy="isSaving()"
280
368
  :errors="validationErrors()"
281
369
  @submit="saveRecord"
@@ -1,6 +1,8 @@
1
1
  <script client>
2
- import type { RestaurantWaitlistOptions, RestaurantWaitlistRecord, RestaurantWaitlistWritePayload } from '../../../../app/Actions/Dashboard/Commerce/restaurant-waitlist-records'
2
+ import type { CustomerChoice } from '../../../../app/Actions/Dashboard/Commerce/commerce-choice-records'
3
+ import type { RestaurantWaitlistRecord, RestaurantWaitlistWritePayload } from '../../../../app/Actions/Dashboard/Commerce/restaurant-waitlist-records'
3
4
  import { restaurantWaitlistDateTimeLocal, restaurantWaitlistTimestamp } from '../../../../app/Actions/Dashboard/Commerce/restaurant-waitlist-records'
5
+ import { dashboardApi } from '../../../../functions/dashboard-api'
4
6
  import { formErrorMessages } from '../../../../functions/dashboard-form'
5
7
 
6
8
  type DialogMode = 'add' | 'edit'
@@ -8,7 +10,6 @@ type DialogMode = 'add' | 'edit'
8
10
  const open = useReactiveProp('open', false)
9
11
  const mode = useReactiveProp('mode', 'add' as DialogMode)
10
12
  const record = useReactiveProp('record', null as RestaurantWaitlistRecord | null)
11
- const options = useReactiveProp('options', { customers: [] } as RestaurantWaitlistOptions)
12
13
  const busy = useReactiveProp('busy', false)
13
14
  const errors = useReactiveProp('errors', {} as Record<string, string>)
14
15
  const emit = defineEmits(['submit', 'close'])
@@ -26,6 +27,58 @@ const actualWaitTime = state<number | string>('')
26
27
  const queuePosition = state<number | string>('')
27
28
  let lastSync = ''
28
29
 
30
+ // The customer choices are a server search (stacksjs/stacks#3218): this used
31
+ // to be handed the first 500 customers by name, so a party could not be
32
+ // linked to a customer past the 500th.
33
+ const customerChoices = state<CustomerChoice[]>([])
34
+ const customerMatches = state(0)
35
+ const customerQuery = state('')
36
+ let customerRequest = 0
37
+ let customerTimer: ReturnType<typeof setTimeout> | null = null
38
+
39
+ async function loadCustomers(term: string): Promise<void> {
40
+ const request = ++customerRequest
41
+ const params = new URLSearchParams()
42
+ if (term)
43
+ params.set('q', term)
44
+ try {
45
+ const data = await dashboardApi<{ choices?: CustomerChoice[], total?: number }>(`/api/dashboard/commerce/customer-choices${term ? `?${params}` : ''}`)
46
+ if (request !== customerRequest)
47
+ return
48
+ const choices = Array.isArray(data.choices) ? data.choices : []
49
+ customerChoices.set(choices)
50
+ customerMatches.set(data.total ?? choices.length)
51
+ }
52
+ catch {
53
+ // Soft-fail: the party's own customer stays selectable.
54
+ if (request === customerRequest) {
55
+ customerChoices.set([])
56
+ customerMatches.set(0)
57
+ }
58
+ }
59
+ }
60
+
61
+ function searchCustomersSoon(): void {
62
+ if (customerTimer)
63
+ clearTimeout(customerTimer)
64
+ customerTimer = setTimeout(() => { void loadCustomers(customerQuery().trim()) }, 250)
65
+ }
66
+
67
+ /** The choices to show: the search results, with the party's own customer kept in. */
68
+ const customers = derived((): CustomerChoice[] => {
69
+ const found = customerChoices()
70
+ const entry = record()
71
+ if (!entry?.customerId || found.some(choice => choice.id === entry.customerId))
72
+ return found
73
+ return [{ id: entry.customerId, label: entry.name || `Customer ${entry.customerId}`, detail: entry.email, email: entry.email, phone: entry.phone }, ...found]
74
+ })
75
+
76
+ const moreCustomersLabel = derived(() => {
77
+ const shown = customerChoices().length
78
+ const total = customerMatches()
79
+ return total > shown ? `Showing ${shown} of ${total.toLocaleString()} matching customers. Search to narrow it down.` : ''
80
+ })
81
+
29
82
  function relationId(value: number | string): number | null {
30
83
  if (value === '')
31
84
  return null
@@ -67,11 +120,13 @@ effect(() => {
67
120
 
68
121
  lastSync = signature
69
122
  reset(entry)
123
+ customerQuery.set('')
124
+ void loadCustomers('')
70
125
  })
71
126
 
72
127
  function hydrateCustomer(event: Event): void {
73
128
  const selectedId = (event.target as HTMLSelectElement).value
74
- const customer = options().customers.find(option => option.id === selectedId)
129
+ const customer = customers().find(option => option.id === selectedId)
75
130
  if (!customer)
76
131
  return
77
132
  if (!name().trim())
@@ -125,11 +180,15 @@ function errorMessages(): string[] {
125
180
  <div class="grid gap-4 sm:grid-cols-2 mt-6">
126
181
  <label class="block sm:col-span-2">
127
182
  <span class="block font-medium text-gray-900 text-sm dark:text-neutral-200">Existing customer</span>
128
- <select x-model="customerId" class="block mt-2 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-700 border border-gray-300 rounded-md dark:border-neutral-600" @change="hydrateCustomer($event)">
183
+ <input x-model="customerQuery" @input="searchCustomersSoon()" type="search" name="customer_search" aria-label="Search customers by name, email or phone" placeholder="Search customers by name, email or phone" class="block mt-2 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-700 border border-gray-300 rounded-md dark:border-neutral-600" />
184
+ </label>
185
+ <div class="sm:col-span-2 -mt-2">
186
+ <select x-model="customerId" aria-label="Existing customer" class="block px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-700 border border-gray-300 rounded-md dark:border-neutral-600" @change="hydrateCustomer($event)">
129
187
  <option value="">No linked customer</option>
130
- <option :for="option in options().customers" :value="option.id">{{ option.label }}{{ option.detail ? ' · ' + option.detail : '' }}</option>
188
+ <template :for="option in customers()" :key="option.id"><option :value="option.id" :selected="option.id === String(customerId())">{{ option.label }}{{ option.detail ? ' · ' + option.detail : '' }}</option></template>
131
189
  </select>
132
- </label>
190
+ <p :if="moreCustomersLabel()" class="mt-1 text-gray-500 text-xs dark:text-neutral-400" :text="moreCustomersLabel()"></p>
191
+ </div>
133
192
 
134
193
  <label class="block">
135
194
  <span class="block font-medium text-gray-900 text-sm dark:text-neutral-200">Name</span>
@@ -9,7 +9,14 @@ import {
9
9
  const records = useReactiveProp('records', [] as RestaurantWaitlistRecord[])
10
10
  const loading = useReactiveProp('loading', false)
11
11
  const busyId = useReactiveProp('busyId', '')
12
- const emit = defineEmits(['seat', 'no-show', 'edit', 'delete'])
12
+ /**
13
+ * The server pages and sorts what the parent's search and filters match
14
+ * (stacksjs/stacks#3218): how many parties match, the page shown and its size.
15
+ */
16
+ const total = useReactiveProp('total', 0)
17
+ const currentPage = useReactiveProp('currentPage', 1)
18
+ const perPage = useReactiveProp('perPage', 25)
19
+ const emit = defineEmits(['seat', 'no-show', 'edit', 'delete', 'page-change', 'page-size-change', 'sort'])
13
20
 
14
21
  const STATUS_CLASSES = {
15
22
  seated: 'text-green-700 dark:text-green-300 bg-green-50 dark:bg-green-950/30',
@@ -73,11 +80,23 @@ const rows = derived(() => records().map(entry => ({
73
80
  function handleRowAction(payload: { action: string, row: RestaurantWaitlistRecord }): void {
74
81
  emit(payload.action, payload.row)
75
82
  }
83
+
84
+ function changePage(page: number): void {
85
+ emit('page-change', page)
86
+ }
87
+
88
+ function changePageSize(size: number): void {
89
+ emit('page-size-change', size)
90
+ }
91
+
92
+ function changeSort(sort: { key: string, direction: string }): void {
93
+ emit('sort', sort)
94
+ }
76
95
  </script>
77
96
 
78
97
  {{--
79
98
  No `searchable` or `filterable`: the parent dashboard owns the search box and
80
- the filter selects. Paging is what was missing.
99
+ the filter selects, and the server pages and sorts what they match.
81
100
  --}}
82
101
  <Table
83
102
  :columns="COLUMNS"
@@ -88,8 +107,15 @@ function handleRowAction(payload: { action: string, row: RestaurantWaitlistRecor
88
107
  busy-key="id"
89
108
  :busy-value="busyId()"
90
109
  paginated
91
- :page-size="25"
110
+ manual-pagination
111
+ manual-sort
112
+ :total="total()"
113
+ :current-page="currentPage()"
114
+ :page-size="perPage()"
92
115
  empty-title="No restaurant waitlist records found"
93
116
  empty-description="Add a party or adjust the current filters."
94
117
  @row-action="handleRowAction"
118
+ @page-change="changePage"
119
+ @page-size-change="changePageSize"
120
+ @sort="changeSort"
95
121
  />
@@ -85,6 +85,14 @@
85
85
  : 'Every column on this board will also be deleted.'
86
86
  })
87
87
 
88
+ // The dialog stays open on a failed delete and says why, inside it.
89
+ const boardDeleteError = derived(() => kanban.deleteError() || '')
90
+
91
+ function closeBoardDelete(): void {
92
+ pendingBoardDelete.set(null)
93
+ kanban.deleteError.set(null)
94
+ }
95
+
88
96
  async function confirmBoardDelete(): Promise<void> {
89
97
  const selected = pendingBoardDelete()
90
98
  if (!selected || deletingBoard())
@@ -276,8 +284,9 @@
276
284
  title="Delete this board?"
277
285
  :description="boardDeleteDescription()"
278
286
  :busy="deletingBoard()"
287
+ :error="boardDeleteError()"
279
288
  :confirmLabel="deletingBoard() ? 'Deleting' : 'Delete'"
280
- @close="pendingBoardDelete.set(null)"
289
+ @close="closeBoardDelete"
281
290
  @confirm="confirmBoardDelete"
282
291
  />
283
292
  </div>
@@ -19,6 +19,14 @@ const commentEditDraft = state('')
19
19
  const savingCommentId = state<number | null>(null)
20
20
  const showLabelPicker = state(false)
21
21
  const showAssigneePicker = state(false)
22
+ const assigneeQuery = state('')
23
+ // One search per pause in typing, not one per keystroke.
24
+ const { start: searchAssigneesSoon } = useTimeoutFn(() => { void kanban.loadUsers(assigneeQuery()) }, 250, { immediate: false })
25
+ const moreAssigneesLabel = derived(() => {
26
+ const shown = kanban.users().length
27
+ const total = kanban.usersTotal()
28
+ return total > shown ? `Showing ${shown} of ${total.toLocaleString()} matching users. Search to narrow it down.` : ''
29
+ })
22
30
  const showNewLabelComposer = state(false)
23
31
  const newLabelName = state('')
24
32
  const newLabelColor = state('slate')
@@ -410,8 +418,20 @@ function formatTimestamp(iso: string | null | undefined): string {
410
418
  <span :if="cardAssignees().length === 0" class="italic text-xs text-zinc-500 dark:text-zinc-400">Unassigned</span>
411
419
  </div>
412
420
 
421
+ <input
422
+ :if="showAssigneePicker()"
423
+ type="search"
424
+ name="assignee_search"
425
+ aria-label="Search users to assign"
426
+ placeholder="Search by name or email"
427
+ x-model="assigneeQuery"
428
+ @input="searchAssigneesSoon()"
429
+ class="mb-2 px-2 py-1 w-full text-xs text-zinc-800 dark:text-zinc-200 bg-white dark:bg-zinc-950 border border-zinc-200 rounded dark:border-zinc-800 focus:border-violet-400 focus:outline-none"
430
+ />
431
+ <p :if="showAssigneePicker() && moreAssigneesLabel()" class="mb-2 text-[11px] text-zinc-500 dark:text-zinc-400" :text="moreAssigneesLabel()"></p>
413
432
  <div :if="showAssigneePicker()" class="overflow-y-auto space-y-1 max-h-48">
414
- <p :if="kanban.users().length === 0" class="italic text-xs text-zinc-500 dark:text-zinc-400">No users to assign.</p>
433
+ <p :if="kanban.users().length === 0 && !kanban.userSearch()" class="italic text-xs text-zinc-500 dark:text-zinc-400">No users to assign.</p>
434
+ <p :if="kanban.users().length === 0 && kanban.userSearch()" class="italic text-xs text-zinc-500 dark:text-zinc-400">No users match that search.</p>
415
435
  <button :for="user in kanban.users" type="button" :aria-pressed="String(cardAssignees().some(assignee => assignee.userId === user.id))" @click="toggleAssignee(user.id)" class="flex gap-2 items-center px-2 py-1.5 w-full text-left text-xs hover:bg-zinc-100 dark:hover:bg-zinc-800 rounded">
416
436
  <span class="inline-flex flex-shrink-0 items-center justify-center h-6 w-6 font-medium text-[10px] text-white bg-violet-500 rounded-full" :text="initialsOf(user.name, user.email)"></span>
417
437
  <span class="flex-1 text-zinc-700 truncate dark:text-zinc-200" :text="user.name || user.email"></span>
@@ -47,6 +47,7 @@ interface ResponseShape {
47
47
  writeCapabilities: WriteCapabilities
48
48
  createFields: CreateField[]
49
49
  updateColumns: string[]
50
+ migrated?: boolean
50
51
  error: string | null
51
52
  }
52
53
 
@@ -69,6 +70,9 @@ const writeCapabilities = state<WriteCapabilities>({ create: false, update: fals
69
70
  const createFields = state<CreateField[]>([])
70
71
  const updateColumns = state<string[]>([])
71
72
  const error = state<string | null>(null)
73
+ // False when the model's table has not been created yet: the server checked the
74
+ // catalog after the query failed, so this is never a guess from an error.
75
+ const migrated = state(true)
72
76
  const loading = state(true)
73
77
  const showFilters = state(false)
74
78
 
@@ -103,7 +107,11 @@ const filterLabel = derived(() => {
103
107
  return n === 0 ? 'Filter' : `Filter (${n})`
104
108
  })
105
109
 
106
- const isEmpty = derived(() => !loading() && !error() && rows().length === 0)
110
+ const isEmpty = derived(() => !loading() && !error() && migrated() && rows().length === 0)
111
+
112
+ const subtitle = derived(() => migrated()
113
+ ? `${recordLabel()} · ${tableName()} · via Stacks ORM`
114
+ : `Not migrated · ${tableName()}`)
107
115
  const canManageRows = derived(() => writeCapabilities().update || writeCapabilities().destroy)
108
116
 
109
117
  const deleteDescription = derived(() => {
@@ -213,6 +221,7 @@ async function load() {
213
221
  writeCapabilities.set(data.writeCapabilities ?? { create: false, update: false, destroy: false })
214
222
  createFields.set(data.createFields ?? [])
215
223
  updateColumns.set(data.updateColumns ?? [])
224
+ migrated.set(data.migrated !== false)
216
225
  error.set(data.error ?? null)
217
226
  }
218
227
  catch (e) {
@@ -377,7 +386,7 @@ void load()
377
386
  <div class="flex flex-wrap gap-4 items-start justify-between">
378
387
  <div class="min-w-0">
379
388
  <h1 class="font-semibold text-2xl text-neutral-900 truncate dark:text-white" :text="modelName()"></h1>
380
- <p class="mt-1 text-[13px] text-neutral-500 dark:text-neutral-400" :text="recordLabel() + ' · ' + tableName() + ' · via Stacks ORM'"></p>
389
+ <p class="mt-1 text-[13px] text-neutral-500 dark:text-neutral-400" :text="subtitle()"></p>
381
390
  </div>
382
391
  <div class="flex gap-2 items-center">
383
392
  <Button
@@ -388,6 +397,7 @@ void load()
388
397
  Create
389
398
  </Button>
390
399
  <Button
400
+ :if="migrated()"
391
401
  variant="secondary"
392
402
  size="sm"
393
403
  interaction="toggle"
@@ -401,7 +411,7 @@ void load()
401
411
  </div>
402
412
 
403
413
  <!-- Search + page size -->
404
- <div class="flex flex-wrap gap-3 items-center">
414
+ <div :if="migrated()" class="flex flex-wrap gap-3 items-center">
405
415
  <div class="relative flex-1 max-w-sm">
406
416
  <div class="flex absolute inset-y-0 left-0 items-center pl-3 pointer-events-none">
407
417
  <div class="h-4 w-4 text-neutral-400 dark:text-neutral-500 i-hugeicons-search-01"></div>
@@ -448,6 +458,16 @@ void load()
448
458
  </div>
449
459
  </div>
450
460
 
461
+ <div :if="!loading() && !error() && !migrated()" role="status" class="p-12 text-center bg-white dark:bg-neutral-900 border border-black/8 rounded-xl dark:border-white/10">
462
+ <span aria-hidden="true" class="mx-auto h-10 w-10 text-neutral-300 dark:text-neutral-600 i-hugeicons-database-sync-01"></span>
463
+ <h3 class="mt-3 font-medium text-[15px] text-neutral-900 dark:text-white">
464
+ The <code :text="tableName()"></code> table has not been created yet
465
+ </h3>
466
+ <p class="mt-1.5 text-[13px] text-neutral-500 dark:text-neutral-400">
467
+ Run <code>./buddy migrate</code> to create it, then reload this page.
468
+ </p>
469
+ </div>
470
+
451
471
  <div :if="isEmpty()" class="p-12 text-center bg-white dark:bg-neutral-900 border border-black/8 rounded-xl dark:border-white/10">
452
472
  <span class="mx-auto h-10 w-10 text-neutral-300 dark:text-neutral-600 i-hugeicons-database-01"></span>
453
473
  <h3 class="mt-3 font-medium text-[15px] text-neutral-900 dark:text-white">
@@ -460,7 +480,7 @@ void load()
460
480
  </p>
461
481
  </div>
462
482
 
463
- <div :if="!error() && (rows().length > 0 || loading())" class="overflow-hidden bg-white dark:bg-neutral-900 border border-black/8 rounded-xl dark:border-white/10">
483
+ <div :if="!error() && migrated() && (rows().length > 0 || loading())" class="overflow-hidden bg-white dark:bg-neutral-900 border border-black/8 rounded-xl dark:border-white/10">
464
484
  <div class="overflow-x-auto">
465
485
  <table class="min-w-full">
466
486
  <thead class="bg-neutral-50 dark:bg-white/5">