@stacksjs/defaults 0.75.489 → 0.75.492
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ai/skills/stacks-actions/SKILL.md +1 -1
- package/ai/skills/stacks-dashboard/SKILL.md +20 -2
- package/ai/skills/stacks-native/CATALOG.md +9 -9
- package/ai/skills/stacks-search-engine/SKILL.md +14 -0
- package/app/Actions/Dashboard/Commerce/CommerceCategoriesAction.ts +7 -13
- package/app/Actions/Dashboard/Commerce/CommerceCustomerChoicesAction.ts +34 -0
- package/app/Actions/Dashboard/Commerce/CommerceDeliveryAction.ts +7 -16
- package/app/Actions/Dashboard/Commerce/CommerceGiftCardsAction.ts +21 -15
- package/app/Actions/Dashboard/Commerce/CommerceGiftCardsExportAction.ts +41 -0
- package/app/Actions/Dashboard/Commerce/CommerceOrderCustomersAction.ts +37 -0
- package/app/Actions/Dashboard/Commerce/CommerceOrdersAction.ts +26 -41
- package/app/Actions/Dashboard/Commerce/CommerceOrdersExportAction.ts +43 -0
- package/app/Actions/Dashboard/Commerce/CommercePaymentsAction.ts +24 -21
- package/app/Actions/Dashboard/Commerce/CommercePaymentsExportAction.ts +41 -0
- package/app/Actions/Dashboard/Commerce/CommercePosAction.ts +18 -48
- package/app/Actions/Dashboard/Commerce/CommercePosProductsAction.ts +39 -0
- package/app/Actions/Dashboard/Commerce/CommercePrintLogsAction.ts +14 -104
- package/app/Actions/Dashboard/Commerce/CommercePrintLogsExportAction.ts +41 -0
- package/app/Actions/Dashboard/Commerce/CommerceProductChoicesAction.ts +32 -0
- package/app/Actions/Dashboard/Commerce/CommerceProductsAction.ts +24 -43
- package/app/Actions/Dashboard/Commerce/CommerceProductsExportAction.ts +44 -0
- package/app/Actions/Dashboard/Commerce/CourierIndexAction.ts +3 -1
- package/app/Actions/Dashboard/Commerce/DeliveryRouteIndexAction.ts +23 -12
- package/app/Actions/Dashboard/Commerce/DigitalDeliveryIndexAction.ts +3 -1
- package/app/Actions/Dashboard/Commerce/LicenseKeyIndexAction.ts +24 -23
- package/app/Actions/Dashboard/Commerce/LicenseKeyOptionsAction.ts +35 -16
- package/app/Actions/Dashboard/Commerce/ProductUnitIndexAction.ts +23 -19
- package/app/Actions/Dashboard/Commerce/ProductVariantIndexAction.ts +25 -18
- package/app/Actions/Dashboard/Commerce/ProductWaitlistIndexAction.ts +22 -22
- package/app/Actions/Dashboard/Commerce/RestaurantWaitlistIndexAction.ts +22 -17
- package/app/Actions/Dashboard/Commerce/ReviewIndexAction.ts +22 -31
- package/app/Actions/Dashboard/Commerce/ShippingMethodIndexAction.ts +3 -1
- package/app/Actions/Dashboard/Commerce/ShippingRateIndexAction.ts +3 -1
- package/app/Actions/Dashboard/Commerce/ShippingZoneIndexAction.ts +3 -1
- package/app/Actions/Dashboard/Commerce/commerce-category-list.test.ts +100 -0
- package/app/Actions/Dashboard/Commerce/commerce-category-list.ts +26 -0
- package/app/Actions/Dashboard/Commerce/commerce-choice-records.ts +56 -0
- package/app/Actions/Dashboard/Commerce/commerce-choices.test.ts +88 -0
- package/app/Actions/Dashboard/Commerce/commerce-choices.ts +70 -0
- package/app/Actions/Dashboard/Commerce/commerce-delivery-overview.test.ts +151 -0
- package/app/Actions/Dashboard/Commerce/commerce-delivery-overview.ts +85 -0
- package/app/Actions/Dashboard/Commerce/commerce-delivery-route-list.test.ts +153 -0
- package/app/Actions/Dashboard/Commerce/commerce-delivery-route-list.ts +180 -0
- package/app/Actions/Dashboard/Commerce/commerce-delivery.ts +24 -9
- package/app/Actions/Dashboard/Commerce/commerce-gift-card-list.test.ts +221 -0
- package/app/Actions/Dashboard/Commerce/commerce-gift-card-list.ts +259 -0
- package/app/Actions/Dashboard/Commerce/commerce-license-key-list.test.ts +184 -0
- package/app/Actions/Dashboard/Commerce/commerce-license-key-list.ts +217 -0
- package/app/Actions/Dashboard/Commerce/commerce-order-list.test.ts +183 -0
- package/app/Actions/Dashboard/Commerce/commerce-order-list.ts +278 -0
- package/app/Actions/Dashboard/Commerce/commerce-order-records.test.ts +29 -0
- package/app/Actions/Dashboard/Commerce/commerce-payment-list.test.ts +180 -0
- package/app/Actions/Dashboard/Commerce/commerce-payment-list.ts +272 -0
- package/app/Actions/Dashboard/Commerce/commerce-pos-catalog.test.ts +171 -0
- package/app/Actions/Dashboard/Commerce/commerce-pos-catalog.ts +152 -0
- package/app/Actions/Dashboard/Commerce/commerce-pos.test.ts +1 -12
- package/app/Actions/Dashboard/Commerce/commerce-pos.ts +0 -26
- package/app/Actions/Dashboard/Commerce/commerce-print-log-list.test.ts +202 -0
- package/app/Actions/Dashboard/Commerce/commerce-print-log-list.ts +286 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-list.test.ts +174 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-list.ts +276 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-unit-list.test.ts +146 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-unit-list.ts +178 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-variant-list.test.ts +165 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-variant-list.ts +209 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-waitlist-list.test.ts +183 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-waitlist-list.ts +170 -0
- package/app/Actions/Dashboard/Commerce/commerce-record.ts +21 -0
- package/app/Actions/Dashboard/Commerce/commerce-restaurant-waitlist-list.test.ts +189 -0
- package/app/Actions/Dashboard/Commerce/commerce-restaurant-waitlist-list.ts +177 -0
- package/app/Actions/Dashboard/Commerce/commerce-review-list.test.ts +193 -0
- package/app/Actions/Dashboard/Commerce/commerce-review-list.ts +220 -0
- package/app/Actions/Dashboard/Commerce/commerce-sql.ts +57 -0
- package/app/Actions/Dashboard/Commerce/payment-records.test.ts +16 -0
- package/app/Actions/Dashboard/Commerce/product-unit-records.test.ts +0 -13
- package/app/Actions/Dashboard/Commerce/product-unit-records.ts +0 -17
- package/app/Actions/Dashboard/Commerce/product-variant-records.test.ts +0 -13
- package/app/Actions/Dashboard/Commerce/product-variant-records.ts +0 -17
- package/app/Actions/Dashboard/Commerce/product-waitlist-records.test.ts +6 -5
- package/app/Actions/Dashboard/Commerce/product-waitlist-records.ts +16 -45
- package/app/Actions/Dashboard/Commerce/restaurant-waitlist-records.ts +4 -24
- package/app/Actions/Dashboard/Content/content-list.ts +10 -0
- package/app/Actions/Dashboard/Content/file-listing-metadata.test.ts +46 -0
- package/app/Actions/Dashboard/Content/file-manager.ts +51 -10
- package/app/Actions/Dashboard/DashboardHomeAction.test.ts +13 -9
- package/app/Actions/Dashboard/DashboardHomeAction.ts +42 -21
- package/app/Actions/Dashboard/Jobs/JobStatsAction.ts +5 -2
- package/app/Actions/Dashboard/Kanban/UsersListAction.ts +13 -9
- package/app/Actions/Dashboard/Kanban/kanban-response.test.ts +40 -0
- package/app/Actions/Dashboard/Kanban/kanban-response.ts +53 -1
- package/app/Actions/Dashboard/Kanban/kanban-users.test.ts +114 -0
- package/app/Actions/Dashboard/Kanban/kanban-users.ts +32 -0
- package/app/Actions/Dashboard/Models/ModelShowAction.ts +8 -0
- package/app/Actions/Dashboard/Models/ModelsIndexAction.ts +16 -2
- package/app/Actions/Dashboard/Models/model-migration.test.ts +27 -0
- package/app/Actions/Dashboard/Models/model-migration.ts +23 -0
- package/app/Actions/Dashboard/Queue/QueueStatsAction.ts +5 -3
- package/app/Actions/Dashboard/Queue/QueueWorkersAction.ts +3 -2
- package/app/Actions/Dashboard/Queue/worker-snapshots.test.ts +31 -0
- package/app/Actions/Dashboard/Queue/worker-snapshots.ts +33 -0
- package/app/Actions/Dashboard/named-search.test.ts +36 -0
- package/app/Actions/Dashboard/named-search.ts +80 -0
- package/app/Models/Request.ts +4 -2
- package/functions/commerce/shippings/dashboard-resource.ts +12 -1
- package/functions/commerce/shippings/delivery-routes.ts +1 -0
- package/functions/commerce/shippings/license-keys.ts +1 -0
- package/functions/dashboard-list.test.ts +146 -1
- package/functions/dashboard-list.ts +216 -1
- package/functions/queue.ts +2 -0
- package/ide/vscode/package.json +1 -1
- package/package.json +2 -2
- package/resources/components/Dashboard/Commerce/CommerceGiftCardBreakdown.stx +38 -12
- package/resources/components/Dashboard/Commerce/CommerceGiftCardsDashboard.stx +122 -68
- package/resources/components/Dashboard/Commerce/CommerceGiftCardsTable.stx +29 -6
- package/resources/components/Dashboard/Commerce/CommerceOrderDialog.stx +59 -2
- package/resources/components/Dashboard/Commerce/CommerceOrdersDashboard.stx +126 -80
- package/resources/components/Dashboard/Commerce/CommerceOrdersTable.stx +28 -3
- package/resources/components/Dashboard/Commerce/CommercePaymentsBreakdown.stx +12 -29
- package/resources/components/Dashboard/Commerce/CommercePaymentsDashboard.stx +139 -60
- package/resources/components/Dashboard/Commerce/CommercePaymentsTable.stx +27 -2
- package/resources/components/Dashboard/Commerce/CommercePosCatalog.stx +17 -1
- package/resources/components/Dashboard/Commerce/CommercePosCheckoutDialog.stx +47 -3
- package/resources/components/Dashboard/Commerce/CommercePosDashboard.stx +59 -49
- package/resources/components/Dashboard/Commerce/CommerceProductsDashboard.stx +116 -82
- package/resources/components/Dashboard/Commerce/CommerceProductsTable.stx +28 -4
- package/resources/components/Dashboard/Commerce/CommerceReviewsDashboard.stx +120 -69
- package/resources/components/Dashboard/Commerce/CommerceReviewsTable.stx +29 -6
- package/resources/components/Dashboard/Commerce/CommerceUnitDialog.stx +63 -8
- package/resources/components/Dashboard/Commerce/CommerceUnitsDashboard.stx +48 -60
- package/resources/components/Dashboard/Commerce/CommerceUnitsTable.stx +29 -3
- package/resources/components/Dashboard/Commerce/CommerceVariantDialog.stx +57 -3
- package/resources/components/Dashboard/Commerce/CommerceVariantsDashboard.stx +59 -61
- package/resources/components/Dashboard/Commerce/CommerceVariantsTable.stx +28 -2
- package/resources/components/Dashboard/Commerce/Delivery/DeliveryRoutesDashboard.stx +79 -52
- package/resources/components/Dashboard/Commerce/Delivery/DeliveryRoutesTable.stx +31 -8
- package/resources/components/Dashboard/Commerce/Delivery/LicenseKeyDialog.stx +71 -13
- package/resources/components/Dashboard/Commerce/Delivery/LicenseKeysDashboard.stx +69 -81
- package/resources/components/Dashboard/Commerce/Delivery/LicenseKeysTable.stx +31 -8
- package/resources/components/Dashboard/Commerce/PrintLogBreakdown.stx +21 -17
- package/resources/components/Dashboard/Commerce/PrintLogsDashboard.stx +23 -22
- package/resources/components/Dashboard/Commerce/ProductWaitlistDashboard.stx +116 -20
- package/resources/components/Dashboard/Commerce/ProductWaitlistEntryDialog.stx +100 -12
- package/resources/components/Dashboard/Commerce/ProductWaitlistTable.stx +34 -16
- package/resources/components/Dashboard/Commerce/RestaurantWaitlistDashboard.stx +107 -19
- package/resources/components/Dashboard/Commerce/RestaurantWaitlistEntryDialog.stx +65 -6
- package/resources/components/Dashboard/Commerce/RestaurantWaitlistTable.stx +29 -3
- package/resources/components/Dashboard/Kanban/KanbanBoardsDashboard.stx +10 -1
- package/resources/components/Dashboard/Kanban/KanbanCardDialog.stx +21 -1
- package/resources/components/Dashboard/Models/ModelRecordsDashboard.stx +24 -4
- package/resources/components/Dashboard/Models/ModelsOverview.stx +13 -2
- package/resources/components/Dashboard/Queue/QueueDashboard.stx +7 -1
- package/routes/dashboard-api.ts +11 -0
- package/views/dashboard/stores/kanban.ts +38 -6
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
<script client>
|
|
2
|
+
import type { ProductChoice } from '../../../../app/Actions/Dashboard/Commerce/commerce-choice-records'
|
|
3
|
+
import type { ProductUnitRecord } from '../../../../app/Actions/Dashboard/Commerce/product-unit-records'
|
|
4
|
+
import { dashboardApi } from '../../../../functions/dashboard-api'
|
|
2
5
|
import { formErrorMessages } from '../../../../functions/dashboard-form'
|
|
3
|
-
import type {
|
|
4
|
-
ProductUnitOption,
|
|
5
|
-
ProductUnitRecord,
|
|
6
|
-
} from '../../../../app/Actions/Dashboard/Commerce/product-unit-records'
|
|
7
6
|
|
|
8
7
|
const open = useReactiveProp('open', false)
|
|
9
8
|
const mode = useReactiveProp('mode', 'add')
|
|
10
9
|
const record = useReactiveProp('record', null as ProductUnitRecord | null)
|
|
11
|
-
const products = useReactiveProp('products', [] as ProductUnitOption[])
|
|
12
10
|
const types = useReactiveProp('types', [] as string[])
|
|
13
11
|
const busy = useReactiveProp('busy', false)
|
|
14
12
|
const errors = useReactiveProp('errors', {} as Record<string, string>)
|
|
@@ -21,6 +19,57 @@ const productId = state('')
|
|
|
21
19
|
const isDefault = state(false)
|
|
22
20
|
let hydrationKey = ''
|
|
23
21
|
|
|
22
|
+
// The product choices are a server search (stacksjs/stacks#3218): this used
|
|
23
|
+
// to be handed the first 500 products by name, so a unit could not be given
|
|
24
|
+
// any later product.
|
|
25
|
+
const productChoices = state<ProductChoice[]>([])
|
|
26
|
+
const productMatches = state(0)
|
|
27
|
+
const productQuery = state('')
|
|
28
|
+
let productRequest = 0
|
|
29
|
+
let productTimer: ReturnType<typeof setTimeout> | null = null
|
|
30
|
+
|
|
31
|
+
async function loadProducts(term: string): Promise<void> {
|
|
32
|
+
const request = ++productRequest
|
|
33
|
+
const params = new URLSearchParams()
|
|
34
|
+
if (term)
|
|
35
|
+
params.set('q', term)
|
|
36
|
+
let found: ProductChoice[] = []
|
|
37
|
+
let count = 0
|
|
38
|
+
try {
|
|
39
|
+
const data = await dashboardApi<{ choices?: ProductChoice[], total?: number }>(`/api/dashboard/commerce/product-choices${term ? `?${params}` : ''}`)
|
|
40
|
+
found = Array.isArray(data.choices) ? data.choices : []
|
|
41
|
+
count = Number(data.total) || found.length
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// Soft-fail: the unit's own product stays selectable.
|
|
45
|
+
}
|
|
46
|
+
if (request !== productRequest)
|
|
47
|
+
return
|
|
48
|
+
productChoices.set(found)
|
|
49
|
+
productMatches.set(count)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function searchProductsSoon(): void {
|
|
53
|
+
if (productTimer)
|
|
54
|
+
clearTimeout(productTimer)
|
|
55
|
+
productTimer = setTimeout(() => { void loadProducts(productQuery().trim()) }, 250)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The choices to show: the search results, with the unit's own product kept in. */
|
|
59
|
+
function products(): ProductChoice[] {
|
|
60
|
+
const found = productChoices()
|
|
61
|
+
const current = record()
|
|
62
|
+
if (!current?.productId || found.some(choice => choice.id === current.productId))
|
|
63
|
+
return found
|
|
64
|
+
return [{ id: current.productId, label: current.productName || `Product ${current.productId}`, detail: '' }, ...found]
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function moreProductsLabel(): string {
|
|
68
|
+
const shown = productChoices().length
|
|
69
|
+
const total = productMatches()
|
|
70
|
+
return total > shown ? `Showing ${shown} of ${total.toLocaleString()} matching products. Search to narrow it down.` : ''
|
|
71
|
+
}
|
|
72
|
+
|
|
24
73
|
effect(() => {
|
|
25
74
|
if (!open()) {
|
|
26
75
|
hydrationKey = ''
|
|
@@ -37,6 +86,8 @@ effect(() => {
|
|
|
37
86
|
description.set(current?.description || '')
|
|
38
87
|
productId.set(current?.productId || '')
|
|
39
88
|
isDefault.set(current?.isDefault || false)
|
|
89
|
+
productQuery.set('')
|
|
90
|
+
void loadProducts('')
|
|
40
91
|
})
|
|
41
92
|
|
|
42
93
|
function submit(): void {
|
|
@@ -90,13 +141,17 @@ function errorMessages(): string[] {
|
|
|
90
141
|
</label>
|
|
91
142
|
<label class="block">
|
|
92
143
|
<span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Product</span>
|
|
93
|
-
<
|
|
144
|
+
<input x-model="productQuery" @input="searchProductsSoon()" type="search" name="product_search" aria-label="Search products by name or id" placeholder="Search by name or id" class="mt-1 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700" />
|
|
145
|
+
</label>
|
|
146
|
+
<div>
|
|
147
|
+
<select x-model="productId" aria-label="Product" class="px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700">
|
|
94
148
|
<option value="">Unassigned</option>
|
|
95
149
|
<template :for="product in products()" :key="product.id">
|
|
96
|
-
<option :value="product.id">{{ product.
|
|
150
|
+
<option :value="product.id" :selected="product.id === productId()">{{ product.label }}</option>
|
|
97
151
|
</template>
|
|
98
152
|
</select>
|
|
99
|
-
|
|
153
|
+
<p :if="moreProductsLabel()" class="mt-1 text-gray-500 text-xs dark:text-neutral-400" :text="moreProductsLabel()"></p>
|
|
154
|
+
</div>
|
|
100
155
|
<label class="block">
|
|
101
156
|
<span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Description</span>
|
|
102
157
|
<textarea x-model="description" rows="3" maxlength="255" class="mt-1 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700"></textarea>
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
<script client>
|
|
2
2
|
import type {
|
|
3
|
-
ProductUnitOption,
|
|
4
3
|
ProductUnitRecord,
|
|
5
4
|
ProductUnitSummary,
|
|
6
5
|
} from '../../../../app/Actions/Dashboard/Commerce/product-unit-records'
|
|
7
6
|
import { DashboardApiError, dashboardApi } from '../../../../functions/dashboard-api'
|
|
7
|
+
import { useServerList } from '../../../../functions/dashboard-list'
|
|
8
8
|
import { pushToast } from '../../../../functions/toasts'
|
|
9
9
|
|
|
10
10
|
interface ProductUnitIndexResponse {
|
|
11
11
|
records: ProductUnitRecord[]
|
|
12
|
-
|
|
12
|
+
total: number
|
|
13
|
+
page: number
|
|
13
14
|
summary: ProductUnitSummary
|
|
15
|
+
types: string[]
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
interface ProductUnitWritePayload {
|
|
@@ -23,15 +25,11 @@ interface ProductUnitWritePayload {
|
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
const emptySummary: ProductUnitSummary = { total: 0, defaults: 0, types: 0, linkedProducts: 0, defaultConflicts: 0 }
|
|
26
|
-
const records = state<ProductUnitRecord[]>([])
|
|
27
|
-
const products = state<ProductUnitOption[]>([])
|
|
28
28
|
const summary = state<ProductUnitSummary>({ ...emptySummary })
|
|
29
|
-
const
|
|
29
|
+
const types = state<string[]>([])
|
|
30
30
|
const typeFilter = state('all')
|
|
31
31
|
const defaultFilter = state('all')
|
|
32
32
|
const sort = state('name')
|
|
33
|
-
const loading = state(true)
|
|
34
|
-
const loadError = state('')
|
|
35
33
|
const dialogOpen = state(false)
|
|
36
34
|
const dialogMode = state<'add' | 'edit'>('add')
|
|
37
35
|
const editingRecord = state<ProductUnitRecord | null>(null)
|
|
@@ -40,40 +38,51 @@ const saving = state(false)
|
|
|
40
38
|
const deleting = state(false)
|
|
41
39
|
const validationErrors = state<Record<string, string>>({})
|
|
42
40
|
|
|
41
|
+
const SELECT_SORTS: Record<string, { sort: string, direction: 'asc' | 'desc' }> = {
|
|
42
|
+
name: { sort: 'name', direction: 'asc' },
|
|
43
|
+
type: { sort: 'type', direction: 'asc' },
|
|
44
|
+
product: { sort: 'product', direction: 'asc' },
|
|
45
|
+
newest: { sort: 'newest', direction: 'desc' },
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// The server searches, filters, sorts and pages (stacksjs/stacks#3218), where
|
|
49
|
+
// this page used to do all of that with the newest 500 units.
|
|
50
|
+
const {
|
|
51
|
+
records,
|
|
52
|
+
total,
|
|
53
|
+
page,
|
|
54
|
+
perPage,
|
|
55
|
+
search,
|
|
56
|
+
loading,
|
|
57
|
+
loadError,
|
|
58
|
+
load,
|
|
59
|
+
changePage,
|
|
60
|
+
changePageSize,
|
|
61
|
+
changeSort,
|
|
62
|
+
} = useServerList<ProductUnitRecord>({
|
|
63
|
+
fetch: params => dashboardApi<ProductUnitIndexResponse>(`/api/dashboard/commerce/units?${params}`),
|
|
64
|
+
defaultSort: () => SELECT_SORTS[sort()] ?? SELECT_SORTS.name!,
|
|
65
|
+
columnSorts: { name: 'name', defaultFlag: 'default', type: 'type', productName: 'product', createdAt: 'created' },
|
|
66
|
+
filters: () => ({ type: typeFilter(), default: defaultFilter() }),
|
|
67
|
+
onLoad: (result) => {
|
|
68
|
+
const data = result as ProductUnitIndexResponse
|
|
69
|
+
summary.set(data.summary ?? { ...emptySummary })
|
|
70
|
+
types.set(Array.isArray(data.types) ? data.types : [])
|
|
71
|
+
},
|
|
72
|
+
onError: error => pushToast('error', 'Could not load product units', { detail: error instanceof Error ? error.message : String(error) }),
|
|
73
|
+
})
|
|
74
|
+
|
|
43
75
|
function unitTypes(): string[] {
|
|
44
|
-
return
|
|
76
|
+
return types()
|
|
45
77
|
}
|
|
46
78
|
|
|
47
|
-
function
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const defaultState = defaultFilter()
|
|
79
|
+
function loadUnits(): Promise<void> {
|
|
80
|
+
return load()
|
|
81
|
+
}
|
|
51
82
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return false
|
|
56
|
-
if (defaultState === 'default' && !record.isDefault)
|
|
57
|
-
return false
|
|
58
|
-
if (defaultState === 'not-default' && record.isDefault)
|
|
59
|
-
return false
|
|
60
|
-
return !query || [
|
|
61
|
-
record.name,
|
|
62
|
-
record.abbreviation,
|
|
63
|
-
record.type,
|
|
64
|
-
record.description,
|
|
65
|
-
record.productName,
|
|
66
|
-
].some(value => value.toLowerCase().includes(query))
|
|
67
|
-
})
|
|
68
|
-
.sort((left, right) => {
|
|
69
|
-
if (sort() === 'type')
|
|
70
|
-
return left.type.localeCompare(right.type) || left.name.localeCompare(right.name)
|
|
71
|
-
if (sort() === 'product')
|
|
72
|
-
return left.productName.localeCompare(right.productName) || left.name.localeCompare(right.name)
|
|
73
|
-
if (sort() === 'newest')
|
|
74
|
-
return Number(right.id) - Number(left.id)
|
|
75
|
-
return left.name.localeCompare(right.name)
|
|
76
|
-
})
|
|
83
|
+
function matchingLabel(): string {
|
|
84
|
+
const count = total()
|
|
85
|
+
return `${count.toLocaleString()} matching product ${count === 1 ? 'unit' : 'units'}`
|
|
77
86
|
}
|
|
78
87
|
|
|
79
88
|
function metricCards(): Array<{ label: string, value: string }> {
|
|
@@ -85,26 +94,6 @@ function metricCards(): Array<{ label: string, value: string }> {
|
|
|
85
94
|
]
|
|
86
95
|
}
|
|
87
96
|
|
|
88
|
-
async function loadUnits(): Promise<void> {
|
|
89
|
-
loading.set(true)
|
|
90
|
-
loadError.set('')
|
|
91
|
-
try {
|
|
92
|
-
const data = await dashboardApi<ProductUnitIndexResponse>('/api/dashboard/commerce/units')
|
|
93
|
-
records.set(Array.isArray(data.records) ? data.records : [])
|
|
94
|
-
products.set(Array.isArray(data.products) ? data.products : [])
|
|
95
|
-
summary.set(data.summary ?? { ...emptySummary })
|
|
96
|
-
}
|
|
97
|
-
catch (error) {
|
|
98
|
-
loadError.set('Product unit records could not be loaded.')
|
|
99
|
-
pushToast('error', 'Could not load product units', {
|
|
100
|
-
detail: error instanceof Error ? error.message : String(error),
|
|
101
|
-
})
|
|
102
|
-
}
|
|
103
|
-
finally {
|
|
104
|
-
loading.set(false)
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
97
|
function openAdd(): void {
|
|
109
98
|
dialogMode.set('add')
|
|
110
99
|
editingRecord.set(null)
|
|
@@ -253,7 +242,7 @@ onMount(() => {
|
|
|
253
242
|
</div>
|
|
254
243
|
|
|
255
244
|
<div class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
|
256
|
-
<p class="text-gray-500 text-sm dark:text-neutral-400">{{
|
|
245
|
+
<p class="text-gray-500 text-sm dark:text-neutral-400">{{ matchingLabel() }}</p>
|
|
257
246
|
<label class="flex gap-2 items-center text-gray-500 text-sm dark:text-neutral-400">
|
|
258
247
|
Sort
|
|
259
248
|
<select x-model="sort" class="px-3 py-1.5 text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-800 border border-gray-300 rounded-md dark:border-neutral-700">
|
|
@@ -265,7 +254,7 @@ onMount(() => {
|
|
|
265
254
|
</label>
|
|
266
255
|
</div>
|
|
267
256
|
|
|
268
|
-
<CommerceUnitsTable :sort-reset-key="sort()" :records="
|
|
257
|
+
<CommerceUnitsTable :sort-reset-key="sort()" :records="records()" :total="total()" :current-page="page()" :per-page="perPage()" :loading="loading()" @edit="openEdit" @delete="openDelete" @page-change="changePage" @page-size-change="changePageSize" @sort="changeSort" />
|
|
269
258
|
</section>
|
|
270
259
|
</div>
|
|
271
260
|
|
|
@@ -273,7 +262,6 @@ onMount(() => {
|
|
|
273
262
|
:open="dialogOpen()"
|
|
274
263
|
:mode="dialogMode()"
|
|
275
264
|
:record="editingRecord()"
|
|
276
|
-
:products="products()"
|
|
277
265
|
:types="unitTypes()"
|
|
278
266
|
:busy="saving()"
|
|
279
267
|
:errors="validationErrors()"
|
|
@@ -7,7 +7,14 @@ const records = useReactiveProp('records', [] as ProductUnitRecord[])
|
|
|
7
7
|
const loading = useReactiveProp('loading', false)
|
|
8
8
|
/** The parent's sort select; a change hands the order back from a header sort. */
|
|
9
9
|
const sortResetKey = useReactiveProp<unknown>('sortResetKey', '')
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* The server pages and sorts what the parent's search and filters match
|
|
12
|
+
* (stacksjs/stacks#3218): how many units match, the page shown and its size.
|
|
13
|
+
*/
|
|
14
|
+
const total = useReactiveProp('total', 0)
|
|
15
|
+
const currentPage = useReactiveProp('currentPage', 1)
|
|
16
|
+
const perPage = useReactiveProp('perPage', 25)
|
|
17
|
+
const emit = defineEmits(['edit', 'delete', 'page-change', 'page-size-change', 'sort'])
|
|
11
18
|
|
|
12
19
|
/**
|
|
13
20
|
* No slots. `UI/Table`'s `cell` and `actions` slots cannot be used yet -
|
|
@@ -50,12 +57,24 @@ const rows = derived(() => records().map(record => ({
|
|
|
50
57
|
function handleRowAction(payload: { action: string, row: ProductUnitRecord }): void {
|
|
51
58
|
emit(payload.action, payload.row)
|
|
52
59
|
}
|
|
60
|
+
|
|
61
|
+
function changePage(page: number): void {
|
|
62
|
+
emit('page-change', page)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function changePageSize(size: number): void {
|
|
66
|
+
emit('page-size-change', size)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function changeSort(sort: { key: string, direction: string }): void {
|
|
70
|
+
emit('sort', sort)
|
|
71
|
+
}
|
|
53
72
|
</script>
|
|
54
73
|
|
|
55
74
|
{{--
|
|
56
75
|
No `searchable` or `filterable`: the parent dashboard already owns the
|
|
57
76
|
search box and the filter selects, and a second set inside the table would
|
|
58
|
-
duplicate them.
|
|
77
|
+
duplicate them. The server pages and sorts what they match.
|
|
59
78
|
--}}
|
|
60
79
|
<Table
|
|
61
80
|
:sort-reset-key="sortResetKey()"
|
|
@@ -65,8 +84,15 @@ function handleRowAction(payload: { action: string, row: ProductUnitRecord }): v
|
|
|
65
84
|
:row-actions="ROW_ACTIONS"
|
|
66
85
|
action-label-key="name"
|
|
67
86
|
paginated
|
|
68
|
-
|
|
87
|
+
manual-pagination
|
|
88
|
+
manual-sort
|
|
89
|
+
:total="total()"
|
|
90
|
+
:current-page="currentPage()"
|
|
91
|
+
:page-size="perPage()"
|
|
69
92
|
empty-title="No product units found"
|
|
70
93
|
empty-description="Adjust the filters or add a ProductUnit record."
|
|
71
94
|
@row-action="handleRowAction"
|
|
95
|
+
@page-change="changePage"
|
|
96
|
+
@page-size-change="changePageSize"
|
|
97
|
+
@sort="changeSort"
|
|
72
98
|
/>
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
<script client>
|
|
2
|
-
import type {
|
|
2
|
+
import type { ProductChoice } from '../../../../app/Actions/Dashboard/Commerce/commerce-choice-records'
|
|
3
|
+
import type { ProductVariantRecord } from '../../../../app/Actions/Dashboard/Commerce/product-variant-records'
|
|
4
|
+
import { dashboardApi } from '../../../../functions/dashboard-api'
|
|
3
5
|
import { formErrorMessages } from '../../../../functions/dashboard-form'
|
|
4
6
|
|
|
5
7
|
const open = useReactiveProp('open', false)
|
|
6
8
|
const mode = useReactiveProp('mode', 'add')
|
|
7
9
|
const record = useReactiveProp('record', null as ProductVariantRecord | null)
|
|
8
|
-
const products = useReactiveProp('products', [] as ProductVariantOption[])
|
|
9
10
|
const types = useReactiveProp('types', [] as string[])
|
|
10
11
|
const busy = useReactiveProp('busy', false)
|
|
11
12
|
const errors = useReactiveProp('errors', {} as Record<string, string>)
|
|
@@ -18,6 +19,57 @@ const status = state<'active' | 'inactive' | 'draft'>('active')
|
|
|
18
19
|
const productId = state('')
|
|
19
20
|
let hydrationKey = ''
|
|
20
21
|
|
|
22
|
+
// The product choices are a server search (stacksjs/stacks#3218): this used
|
|
23
|
+
// to be handed the first 500 products by name, so a variant could not be given
|
|
24
|
+
// any later product.
|
|
25
|
+
const productChoices = state<ProductChoice[]>([])
|
|
26
|
+
const productMatches = state(0)
|
|
27
|
+
const productQuery = state('')
|
|
28
|
+
let productRequest = 0
|
|
29
|
+
let productTimer: ReturnType<typeof setTimeout> | null = null
|
|
30
|
+
|
|
31
|
+
async function loadProducts(term: string): Promise<void> {
|
|
32
|
+
const request = ++productRequest
|
|
33
|
+
const params = new URLSearchParams()
|
|
34
|
+
if (term)
|
|
35
|
+
params.set('q', term)
|
|
36
|
+
let found: ProductChoice[] = []
|
|
37
|
+
let count = 0
|
|
38
|
+
try {
|
|
39
|
+
const data = await dashboardApi<{ choices?: ProductChoice[], total?: number }>(`/api/dashboard/commerce/product-choices${term ? `?${params}` : ''}`)
|
|
40
|
+
found = Array.isArray(data.choices) ? data.choices : []
|
|
41
|
+
count = Number(data.total) || found.length
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// Soft-fail: the variant's own product stays selectable.
|
|
45
|
+
}
|
|
46
|
+
if (request !== productRequest)
|
|
47
|
+
return
|
|
48
|
+
productChoices.set(found)
|
|
49
|
+
productMatches.set(count)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function searchProductsSoon(): void {
|
|
53
|
+
if (productTimer)
|
|
54
|
+
clearTimeout(productTimer)
|
|
55
|
+
productTimer = setTimeout(() => { void loadProducts(productQuery().trim()) }, 250)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The choices to show: the search results, with the variant's own product kept in. */
|
|
59
|
+
function products(): ProductChoice[] {
|
|
60
|
+
const found = productChoices()
|
|
61
|
+
const current = record()
|
|
62
|
+
if (!current?.productId || found.some(choice => choice.id === current.productId))
|
|
63
|
+
return found
|
|
64
|
+
return [{ id: current.productId, label: current.productName || `Product ${current.productId}`, detail: '' }, ...found]
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function moreProductsLabel(): string {
|
|
68
|
+
const shown = productChoices().length
|
|
69
|
+
const total = productMatches()
|
|
70
|
+
return total > shown ? `Showing ${shown} of ${total.toLocaleString()} matching products. Search to narrow it down.` : ''
|
|
71
|
+
}
|
|
72
|
+
|
|
21
73
|
effect(() => {
|
|
22
74
|
if (!open()) {
|
|
23
75
|
hydrationKey = ''
|
|
@@ -34,6 +86,8 @@ effect(() => {
|
|
|
34
86
|
options.set(current?.options.join(', ') || '')
|
|
35
87
|
status.set(current?.status || 'active')
|
|
36
88
|
productId.set(current?.productId || '')
|
|
89
|
+
productQuery.set('')
|
|
90
|
+
void loadProducts('')
|
|
37
91
|
})
|
|
38
92
|
|
|
39
93
|
function submit(): void {
|
|
@@ -70,7 +124,7 @@ function errorMessages(): string[] {
|
|
|
70
124
|
<label class="block"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Variant</span><input x-model="variant" type="text" maxlength="100" required class="mt-1 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700" /></label>
|
|
71
125
|
<label class="block"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Type</span><input x-model="type" type="text" list="product-variant-types" maxlength="50" required class="mt-1 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700" /><datalist id="product-variant-types"><template :for="variantType in types()" :key="variantType"><option :value="variantType"></option></template></datalist></label>
|
|
72
126
|
</div>
|
|
73
|
-
<label class="block"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Product</span><select x-model="productId" class="mt-
|
|
127
|
+
<div><label class="block"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Product</span><input x-model="productQuery" @input="searchProductsSoon()" type="search" name="product_search" aria-label="Search products by name or id" placeholder="Search by name or id" class="mt-1 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700" /></label><select x-model="productId" aria-label="Product" class="mt-2 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700"><option value="">Unassigned</option><template :for="product in products()" :key="product.id"><option :value="product.id" :selected="product.id === productId()">{{ product.label }}</option></template></select><p :if="moreProductsLabel()" class="mt-1 text-gray-500 text-xs dark:text-neutral-400" :text="moreProductsLabel()"></p></div>
|
|
74
128
|
<label class="block"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Description</span><textarea x-model="description" rows="3" class="mt-1 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700"></textarea></label>
|
|
75
129
|
<label class="block"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Options</span><textarea x-model="options" rows="3" placeholder="Small, Medium, Large" class="mt-1 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700"></textarea><span class="block mt-1 text-gray-500 text-xs dark:text-neutral-400">Separate options with commas or new lines.</span></label>
|
|
76
130
|
<label class="block"><span class="font-medium text-gray-700 text-sm dark:text-neutral-200">Status</span><select x-model="status" class="mt-1 px-3 py-2 w-full text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-900 border border-gray-300 rounded-md dark:border-neutral-700"><option value="active">Active</option><option value="inactive">Inactive</option><option value="draft">Draft</option></select></label>
|
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
<script client>
|
|
2
2
|
import type {
|
|
3
|
-
ProductVariantOption,
|
|
4
3
|
ProductVariantRecord,
|
|
5
4
|
ProductVariantSummary,
|
|
6
5
|
} from '../../../../app/Actions/Dashboard/Commerce/product-variant-records'
|
|
7
6
|
import { DashboardApiError, dashboardApi } from '../../../../functions/dashboard-api'
|
|
7
|
+
import { useServerList } from '../../../../functions/dashboard-list'
|
|
8
8
|
import { pushToast } from '../../../../functions/toasts'
|
|
9
9
|
|
|
10
|
+
interface VariantProduct {
|
|
11
|
+
id: string
|
|
12
|
+
name: string
|
|
13
|
+
}
|
|
14
|
+
|
|
10
15
|
interface ProductVariantIndexResponse {
|
|
11
16
|
records: ProductVariantRecord[]
|
|
12
|
-
|
|
17
|
+
total: number
|
|
18
|
+
page: number
|
|
13
19
|
summary: ProductVariantSummary
|
|
20
|
+
types: string[]
|
|
21
|
+
products: VariantProduct[]
|
|
14
22
|
}
|
|
15
23
|
|
|
16
24
|
interface ProductVariantWritePayload {
|
|
@@ -23,16 +31,14 @@ interface ProductVariantWritePayload {
|
|
|
23
31
|
}
|
|
24
32
|
|
|
25
33
|
const emptySummary: ProductVariantSummary = { total: 0, active: 0, draft: 0, linkedProducts: 0 }
|
|
26
|
-
|
|
27
|
-
const products = state<
|
|
34
|
+
// The products that have a variant, for the product filter; the dialog searches every product.
|
|
35
|
+
const products = state<VariantProduct[]>([])
|
|
36
|
+
const types = state<string[]>([])
|
|
28
37
|
const summary = state<ProductVariantSummary>({ ...emptySummary })
|
|
29
|
-
const search = state('')
|
|
30
38
|
const statusFilter = state('all')
|
|
31
39
|
const typeFilter = state('all')
|
|
32
40
|
const productFilter = state('all')
|
|
33
41
|
const sort = state('variant')
|
|
34
|
-
const loading = state(true)
|
|
35
|
-
const loadError = state('')
|
|
36
42
|
const dialogOpen = state(false)
|
|
37
43
|
const dialogMode = state<'add' | 'edit'>('add')
|
|
38
44
|
const editingRecord = state<ProductVariantRecord | null>(null)
|
|
@@ -41,40 +47,52 @@ const saving = state(false)
|
|
|
41
47
|
const deleting = state(false)
|
|
42
48
|
const validationErrors = state<Record<string, string>>({})
|
|
43
49
|
|
|
50
|
+
const SELECT_SORTS: Record<string, { sort: string, direction: 'asc' | 'desc' }> = {
|
|
51
|
+
variant: { sort: 'variant', direction: 'asc' },
|
|
52
|
+
options: { sort: 'options', direction: 'desc' },
|
|
53
|
+
product: { sort: 'product', direction: 'asc' },
|
|
54
|
+
newest: { sort: 'newest', direction: 'desc' },
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// The server searches, filters, sorts and pages (stacksjs/stacks#3218), where
|
|
58
|
+
// this page used to do all of that with the newest 500 variants.
|
|
59
|
+
const {
|
|
60
|
+
records,
|
|
61
|
+
total,
|
|
62
|
+
page,
|
|
63
|
+
perPage,
|
|
64
|
+
search,
|
|
65
|
+
loading,
|
|
66
|
+
loadError,
|
|
67
|
+
load,
|
|
68
|
+
changePage,
|
|
69
|
+
changePageSize,
|
|
70
|
+
changeSort,
|
|
71
|
+
} = useServerList<ProductVariantRecord>({
|
|
72
|
+
fetch: params => dashboardApi<ProductVariantIndexResponse>(`/api/dashboard/commerce/variants?${params}`),
|
|
73
|
+
defaultSort: () => SELECT_SORTS[sort()] ?? SELECT_SORTS.variant!,
|
|
74
|
+
columnSorts: { variant: 'variant', productName: 'product', status: 'status', createdAt: 'created' },
|
|
75
|
+
filters: () => ({ status: statusFilter(), type: typeFilter(), product: productFilter() }),
|
|
76
|
+
onLoad: (result) => {
|
|
77
|
+
const data = result as ProductVariantIndexResponse
|
|
78
|
+
summary.set(data.summary ?? { ...emptySummary })
|
|
79
|
+
types.set(Array.isArray(data.types) ? data.types : [])
|
|
80
|
+
products.set(Array.isArray(data.products) ? data.products : [])
|
|
81
|
+
},
|
|
82
|
+
onError: error => pushToast('error', 'Could not load product variants', { detail: error instanceof Error ? error.message : String(error) }),
|
|
83
|
+
})
|
|
84
|
+
|
|
44
85
|
function variantTypes(): string[] {
|
|
45
|
-
return
|
|
86
|
+
return types()
|
|
46
87
|
}
|
|
47
88
|
|
|
48
|
-
function
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (status !== 'all' && record.status !== status)
|
|
56
|
-
return false
|
|
57
|
-
if (type !== 'all' && record.type !== type)
|
|
58
|
-
return false
|
|
59
|
-
if (product !== 'all' && record.productId !== product)
|
|
60
|
-
return false
|
|
61
|
-
return !query || [
|
|
62
|
-
record.variant,
|
|
63
|
-
record.type,
|
|
64
|
-
record.description,
|
|
65
|
-
record.productName,
|
|
66
|
-
...record.options,
|
|
67
|
-
].some(value => value.toLowerCase().includes(query))
|
|
68
|
-
})
|
|
69
|
-
.sort((left, right) => {
|
|
70
|
-
if (sort() === 'options')
|
|
71
|
-
return right.options.length - left.options.length || left.variant.localeCompare(right.variant)
|
|
72
|
-
if (sort() === 'product')
|
|
73
|
-
return left.productName.localeCompare(right.productName) || left.variant.localeCompare(right.variant)
|
|
74
|
-
if (sort() === 'newest')
|
|
75
|
-
return Number(right.id) - Number(left.id)
|
|
76
|
-
return left.variant.localeCompare(right.variant)
|
|
77
|
-
})
|
|
89
|
+
function loadVariants(): Promise<void> {
|
|
90
|
+
return load()
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function matchingLabel(): string {
|
|
94
|
+
const count = total()
|
|
95
|
+
return `${count.toLocaleString()} matching product ${count === 1 ? 'variant' : 'variants'}`
|
|
78
96
|
}
|
|
79
97
|
|
|
80
98
|
function metricCards(): Array<{ label: string, value: string }> {
|
|
@@ -86,26 +104,6 @@ function metricCards(): Array<{ label: string, value: string }> {
|
|
|
86
104
|
]
|
|
87
105
|
}
|
|
88
106
|
|
|
89
|
-
async function loadVariants(): Promise<void> {
|
|
90
|
-
loading.set(true)
|
|
91
|
-
loadError.set('')
|
|
92
|
-
try {
|
|
93
|
-
const data = await dashboardApi<ProductVariantIndexResponse>('/api/dashboard/commerce/variants')
|
|
94
|
-
records.set(Array.isArray(data.records) ? data.records : [])
|
|
95
|
-
products.set(Array.isArray(data.products) ? data.products : [])
|
|
96
|
-
summary.set(data.summary ?? { ...emptySummary })
|
|
97
|
-
}
|
|
98
|
-
catch (error) {
|
|
99
|
-
loadError.set('Product variant records could not be loaded.')
|
|
100
|
-
pushToast('error', 'Could not load product variants', {
|
|
101
|
-
detail: error instanceof Error ? error.message : String(error),
|
|
102
|
-
})
|
|
103
|
-
}
|
|
104
|
-
finally {
|
|
105
|
-
loading.set(false)
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
107
|
function openAdd(): void {
|
|
110
108
|
dialogMode.set('add')
|
|
111
109
|
editingRecord.set(null)
|
|
@@ -222,13 +220,13 @@ onMount(() => {
|
|
|
222
220
|
</div>
|
|
223
221
|
|
|
224
222
|
<div class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
|
225
|
-
<p class="text-gray-500 text-sm dark:text-neutral-400">{{
|
|
223
|
+
<p class="text-gray-500 text-sm dark:text-neutral-400">{{ matchingLabel() }}</p>
|
|
226
224
|
<label class="flex gap-2 items-center text-gray-500 text-sm dark:text-neutral-400">Sort<select x-model="sort" class="px-3 py-1.5 text-gray-900 text-sm dark:text-white bg-white dark:bg-neutral-800 border border-gray-300 rounded-md dark:border-neutral-700"><option value="variant">Name</option><option value="options">Most options</option><option value="product">Product</option><option value="newest">Newest</option></select></label>
|
|
227
225
|
</div>
|
|
228
226
|
|
|
229
|
-
<CommerceVariantsTable :sort-reset-key="sort()" :records="
|
|
227
|
+
<CommerceVariantsTable :sort-reset-key="sort()" :records="records()" :total="total()" :current-page="page()" :per-page="perPage()" :loading="loading()" @edit="openEdit" @delete="openDelete" @page-change="changePage" @page-size-change="changePageSize" @sort="changeSort" />
|
|
230
228
|
</section>
|
|
231
229
|
</div>
|
|
232
230
|
|
|
233
|
-
<CommerceVariantDialog :open="dialogOpen()" :mode="dialogMode()" :record="editingRecord()" :
|
|
231
|
+
<CommerceVariantDialog :open="dialogOpen()" :mode="dialogMode()" :record="editingRecord()" :types="variantTypes()" :busy="saving()" :errors="validationErrors()" @submit="saveVariant" @close="closeDialog()" />
|
|
234
232
|
<CommerceVariantDeleteDialog :open="Boolean(deletingRecord())" :record="deletingRecord()" :busy="deleting()" @confirm="deleteVariant()" @close="closeDelete()" />
|
|
@@ -7,7 +7,14 @@ const records = useReactiveProp('records', [] as ProductVariantRecord[])
|
|
|
7
7
|
const loading = useReactiveProp('loading', false)
|
|
8
8
|
/** The parent's sort select; a change hands the order back from a header sort. */
|
|
9
9
|
const sortResetKey = useReactiveProp<unknown>('sortResetKey', '')
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* The server pages and sorts what the parent's search and filters match
|
|
12
|
+
* (stacksjs/stacks#3218): how many variants match, the page shown and its size.
|
|
13
|
+
*/
|
|
14
|
+
const total = useReactiveProp('total', 0)
|
|
15
|
+
const currentPage = useReactiveProp('currentPage', 1)
|
|
16
|
+
const perPage = useReactiveProp('perPage', 25)
|
|
17
|
+
const emit = defineEmits(['edit', 'delete', 'page-change', 'page-size-change', 'sort'])
|
|
11
18
|
|
|
12
19
|
/**
|
|
13
20
|
* Two slotted columns, dispatched on `column.key`: the variant with its type
|
|
@@ -47,6 +54,18 @@ const rows = derived(() => records().map(record => ({
|
|
|
47
54
|
function handleRowAction(payload: { action: string, row: ProductVariantRecord }): void {
|
|
48
55
|
emit(payload.action, payload.row)
|
|
49
56
|
}
|
|
57
|
+
|
|
58
|
+
function changePage(page: number): void {
|
|
59
|
+
emit('page-change', page)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function changePageSize(size: number): void {
|
|
63
|
+
emit('page-size-change', size)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function changeSort(sort: { key: string, direction: string }): void {
|
|
67
|
+
emit('sort', sort)
|
|
68
|
+
}
|
|
50
69
|
</script>
|
|
51
70
|
|
|
52
71
|
<Table
|
|
@@ -57,10 +76,17 @@ function handleRowAction(payload: { action: string, row: ProductVariantRecord })
|
|
|
57
76
|
:row-actions="ROW_ACTIONS"
|
|
58
77
|
action-label-key="variant"
|
|
59
78
|
paginated
|
|
60
|
-
|
|
79
|
+
manual-pagination
|
|
80
|
+
manual-sort
|
|
81
|
+
:total="total()"
|
|
82
|
+
:current-page="currentPage()"
|
|
83
|
+
:page-size="perPage()"
|
|
61
84
|
empty-title="No product variants found"
|
|
62
85
|
empty-description="Adjust the filters or add a ProductVariant record."
|
|
63
86
|
@row-action="handleRowAction"
|
|
87
|
+
@page-change="changePage"
|
|
88
|
+
@page-size-change="changePageSize"
|
|
89
|
+
@sort="changeSort"
|
|
64
90
|
>
|
|
65
91
|
<template #cell="{ row, column }">
|
|
66
92
|
<template :if="column.key === 'variant'">
|