@stacksjs/defaults 0.75.529 → 0.75.537
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-build/SKILL.md +1 -1
- package/ai/skills/stacks-dashboard/SKILL.md +2 -2
- package/ai/skills/stacks-database/SKILL.md +1 -1
- package/ai/skills/stacks-migrations/SKILL.md +2 -2
- package/ai/skills/stacks-native/CATALOG.md +6 -6
- package/app/Actions/Dashboard/Commerce/CommerceCouponsAction.ts +27 -15
- package/app/Actions/Dashboard/Commerce/CommerceCouponsExportAction.ts +45 -0
- package/app/Actions/Dashboard/Commerce/CommerceCustomersAction.ts +22 -12
- package/app/Actions/Dashboard/Commerce/CommerceCustomersExportAction.ts +44 -0
- package/app/Actions/Dashboard/Commerce/CommercePosCheckoutAction.ts +9 -29
- package/app/Actions/Dashboard/Commerce/CommercePrintDevicesAction.ts +7 -9
- package/app/Actions/Dashboard/Commerce/CommerceProductDetailAction.ts +9 -8
- package/app/Actions/Dashboard/Commerce/CommerceTaxesAction.ts +7 -9
- package/app/Actions/Dashboard/Commerce/ManufacturerIndexAction.ts +8 -20
- package/app/Actions/Dashboard/Commerce/commerce-coupon-list.test.ts +203 -0
- package/app/Actions/Dashboard/Commerce/commerce-coupon-list.ts +248 -0
- package/app/Actions/Dashboard/Commerce/commerce-customer-list.test.ts +183 -0
- package/app/Actions/Dashboard/Commerce/commerce-customer-list.ts +186 -0
- package/app/Actions/Dashboard/Commerce/commerce-customer-records.test.ts +1 -34
- package/app/Actions/Dashboard/Commerce/commerce-customer-records.ts +0 -11
- package/app/Actions/Dashboard/Commerce/commerce-manufacturer-list.test.ts +118 -0
- package/app/Actions/Dashboard/Commerce/commerce-manufacturer-list.ts +41 -0
- package/app/Actions/Dashboard/Commerce/commerce-pos-catalog.test.ts +17 -5
- package/app/Actions/Dashboard/Commerce/commerce-pos-catalog.ts +17 -3
- package/app/Actions/Dashboard/Commerce/commerce-print-device-list.test.ts +99 -0
- package/app/Actions/Dashboard/Commerce/commerce-print-device-list.ts +18 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-list.ts +5 -5
- package/app/Actions/Dashboard/Commerce/commerce-product-options.test.ts +81 -0
- package/app/Actions/Dashboard/Commerce/commerce-tax-rate-list.test.ts +99 -0
- package/app/Actions/Dashboard/Commerce/commerce-tax-rate-list.ts +18 -0
- package/app/Actions/Dashboard/Commerce/coupon-records.test.ts +1 -16
- package/app/Actions/Dashboard/Commerce/coupon-records.ts +6 -10
- package/app/Actions/Dashboard/Commerce/manufacturer-records.test.ts +5 -17
- package/app/Actions/Dashboard/Commerce/manufacturer-records.ts +0 -29
- package/app/Actions/Dashboard/Email/captured-mail.test.ts +16 -0
- package/app/Actions/Dashboard/Email/captured-mail.ts +9 -1
- package/app/Actions/Dashboard/Models/model-write.ts +36 -3
- package/app/Actions/Dashboard/Notifications/NotificationDeliveryHistoryAction.ts +13 -58
- package/app/Actions/Dashboard/Notifications/notification-delivery-history.ts +74 -0
- package/app/Actions/SitemapAction.ts +3 -1
- package/app/Models/Notification.ts +3 -1
- package/app/Models/NotificationDelivery.ts +4 -0
- package/app/Models/User.ts +10 -1
- package/bootstrap.ts +10 -2
- package/functions/commerce/tax-types.ts +21 -0
- package/functions/dashboard-list.test.ts +16 -0
- package/functions/dashboard-list.ts +14 -6
- package/functions/dashboard-model-record.test.ts +139 -0
- package/functions/dashboard-model-record.ts +353 -0
- package/functions/monitoring/errors.ts +22 -103
- package/functions/notifications/deliveries.ts +7 -38
- package/functions/queries.ts +7 -10
- package/ide/vscode/package.json +1 -1
- package/package.json +5 -5
- package/resources/components/Dashboard/Analytics/AnalyticsHub.stx +2 -2
- package/resources/components/Dashboard/Analytics/CampaignAnalytics.stx +22 -28
- package/resources/components/Dashboard/Analytics/EventAnalytics.stx +26 -34
- package/resources/components/Dashboard/Analytics/SalesAnalytics.stx +29 -37
- package/resources/components/Dashboard/Analytics/WebAnalyticsBreakdown.stx +12 -16
- package/resources/components/Dashboard/Analytics/WebAnalyticsDashboard.stx +43 -53
- package/resources/components/Dashboard/App/RequestsOverview.stx +2 -1
- package/resources/components/Dashboard/App/SourceInventory.stx +2 -1
- package/resources/components/Dashboard/Auth/AccessTokens.stx +3 -5
- package/resources/components/Dashboard/Billing/BillingPaymentMethodsPanel.stx +9 -11
- package/resources/components/Dashboard/Billing/BillingSettings.stx +1 -1
- package/resources/components/Dashboard/Buddy/BuddyAssistant.stx +4 -6
- package/resources/components/Dashboard/Commerce/CommerceCategoriesDashboard.stx +2 -2
- package/resources/components/Dashboard/Commerce/CommerceCategoriesTable.stx +3 -3
- package/resources/components/Dashboard/Commerce/CommerceCategoryDialog.stx +2 -2
- package/resources/components/Dashboard/Commerce/CommerceCategoryHierarchy.stx +3 -5
- package/resources/components/Dashboard/Commerce/CommerceCouponBreakdown.stx +17 -13
- package/resources/components/Dashboard/Commerce/CommerceCouponDialog.stx +1 -1
- package/resources/components/Dashboard/Commerce/CommerceCouponsDashboard.stx +57 -85
- package/resources/components/Dashboard/Commerce/CommerceCouponsTable.stx +32 -9
- package/resources/components/Dashboard/Commerce/CommerceCustomerDialog.stx +1 -1
- package/resources/components/Dashboard/Commerce/CommerceCustomersDashboard.stx +49 -83
- package/resources/components/Dashboard/Commerce/CommerceCustomersTable.stx +32 -9
- package/resources/components/Dashboard/Commerce/CommerceGiftCardBreakdown.stx +9 -15
- package/resources/components/Dashboard/Commerce/CommerceGiftCardDialog.stx +1 -1
- package/resources/components/Dashboard/Commerce/CommerceGiftCardsDashboard.stx +35 -119
- package/resources/components/Dashboard/Commerce/CommerceGiftCardsTable.stx +3 -3
- package/resources/components/Dashboard/Commerce/CommerceManufacturerDialog.stx +1 -1
- package/resources/components/Dashboard/Commerce/CommerceManufacturersDashboard.stx +3 -5
- package/resources/components/Dashboard/Commerce/CommerceManufacturersTable.stx +2 -2
- package/resources/components/Dashboard/Commerce/CommerceOrderDialog.stx +4 -4
- package/resources/components/Dashboard/Commerce/CommerceOrdersDashboard.stx +42 -129
- package/resources/components/Dashboard/Commerce/CommerceOrdersTable.stx +3 -3
- package/resources/components/Dashboard/Commerce/CommerceOverviewDashboard.stx +1 -1
- package/resources/components/Dashboard/Commerce/CommerceOverviewOrdersTable.stx +9 -11
- package/resources/components/Dashboard/Commerce/CommerceOverviewProductsTable.stx +5 -7
- package/resources/components/Dashboard/Commerce/CommerceOverviewStats.stx +14 -16
- package/resources/components/Dashboard/Commerce/CommercePaymentsBreakdown.stx +12 -18
- package/resources/components/Dashboard/Commerce/CommercePaymentsDashboard.stx +41 -120
- package/resources/components/Dashboard/Commerce/CommercePaymentsTable.stx +1 -1
- package/resources/components/Dashboard/Commerce/CommercePosCart.stx +13 -15
- package/resources/components/Dashboard/Commerce/CommercePosCatalog.stx +17 -19
- package/resources/components/Dashboard/Commerce/CommercePosCheckoutDialog.stx +2 -2
- package/resources/components/Dashboard/Commerce/CommercePosDashboard.stx +1 -1
- package/resources/components/Dashboard/Commerce/CommercePosReceiptDialog.stx +1 -1
- package/resources/components/Dashboard/Commerce/CommerceProductDetailDashboard.stx +5 -5
- package/resources/components/Dashboard/Commerce/CommerceProductDialog.stx +3 -3
- package/resources/components/Dashboard/Commerce/CommerceProductsDashboard.stx +41 -122
- package/resources/components/Dashboard/Commerce/CommerceProductsTable.stx +3 -3
- package/resources/components/Dashboard/Commerce/CommerceReviewEditDialog.stx +1 -1
- package/resources/components/Dashboard/Commerce/CommerceReviewsDashboard.stx +38 -122
- package/resources/components/Dashboard/Commerce/CommerceReviewsTable.stx +2 -2
- package/resources/components/Dashboard/Commerce/CommerceTaxDialog.stx +3 -3
- package/resources/components/Dashboard/Commerce/CommerceTaxesDashboard.stx +5 -4
- package/resources/components/Dashboard/Commerce/CommerceTaxesTable.stx +4 -3
- package/resources/components/Dashboard/Commerce/CommerceUnitDialog.stx +3 -7
- package/resources/components/Dashboard/Commerce/CommerceUnitsDashboard.stx +3 -5
- package/resources/components/Dashboard/Commerce/CommerceUnitsTable.stx +2 -2
- package/resources/components/Dashboard/Commerce/CommerceVariantDialog.stx +3 -3
- package/resources/components/Dashboard/Commerce/CommerceVariantsDashboard.stx +4 -4
- package/resources/components/Dashboard/Commerce/CommerceVariantsTable.stx +3 -5
- package/resources/components/Dashboard/Commerce/Delivery/CourierDialog.stx +1 -1
- package/resources/components/Dashboard/Commerce/Delivery/CouriersDashboard.stx +1 -1
- package/resources/components/Dashboard/Commerce/Delivery/CouriersTable.stx +2 -2
- package/resources/components/Dashboard/Commerce/Delivery/DeliveryOverviewDashboard.stx +44 -52
- package/resources/components/Dashboard/Commerce/Delivery/DeliveryPagination.stx +2 -2
- package/resources/components/Dashboard/Commerce/Delivery/DeliveryRouteDialog.stx +1 -1
- package/resources/components/Dashboard/Commerce/Delivery/DeliveryRoutesDashboard.stx +1 -1
- package/resources/components/Dashboard/Commerce/Delivery/DeliveryRoutesTable.stx +2 -2
- package/resources/components/Dashboard/Commerce/Delivery/DigitalDeliveriesDashboard.stx +1 -1
- package/resources/components/Dashboard/Commerce/Delivery/DigitalDeliveryTable.stx +2 -2
- package/resources/components/Dashboard/Commerce/Delivery/LicenseKeyDialog.stx +3 -3
- package/resources/components/Dashboard/Commerce/Delivery/LicenseKeysDashboard.stx +1 -1
- package/resources/components/Dashboard/Commerce/Delivery/LicenseKeysTable.stx +2 -2
- package/resources/components/Dashboard/Commerce/Delivery/ShippingMethodsDashboard.stx +1 -1
- package/resources/components/Dashboard/Commerce/Delivery/ShippingMethodsTable.stx +2 -2
- package/resources/components/Dashboard/Commerce/Delivery/ShippingRateDialog.stx +2 -2
- package/resources/components/Dashboard/Commerce/Delivery/ShippingRatesDashboard.stx +1 -1
- package/resources/components/Dashboard/Commerce/Delivery/ShippingRatesTable.stx +2 -2
- package/resources/components/Dashboard/Commerce/Delivery/ShippingZoneDialog.stx +1 -1
- package/resources/components/Dashboard/Commerce/Delivery/ShippingZonesDashboard.stx +1 -1
- package/resources/components/Dashboard/Commerce/Delivery/ShippingZonesTable.stx +4 -8
- package/resources/components/Dashboard/Commerce/PaymentDetailsDialog.stx +1 -3
- package/resources/components/Dashboard/Commerce/PrintDeviceBreakdown.stx +9 -15
- package/resources/components/Dashboard/Commerce/PrintDeviceDialog.stx +1 -1
- package/resources/components/Dashboard/Commerce/PrintDevicesDashboard.stx +3 -3
- package/resources/components/Dashboard/Commerce/PrintDevicesTable.stx +3 -3
- package/resources/components/Dashboard/Commerce/PrintLogBreakdown.stx +3 -9
- package/resources/components/Dashboard/Commerce/PrintLogDetailsDialog.stx +1 -1
- package/resources/components/Dashboard/Commerce/PrintLogsDashboard.stx +4 -4
- package/resources/components/Dashboard/Commerce/PrintLogsTable.stx +8 -10
- package/resources/components/Dashboard/Commerce/ProductWaitlistDashboard.stx +37 -109
- package/resources/components/Dashboard/Commerce/ProductWaitlistEntryDialog.stx +3 -3
- package/resources/components/Dashboard/Commerce/ProductWaitlistTable.stx +2 -2
- package/resources/components/Dashboard/Commerce/RestaurantWaitlistDashboard.stx +38 -112
- package/resources/components/Dashboard/Commerce/RestaurantWaitlistEntryDialog.stx +2 -2
- package/resources/components/Dashboard/Commerce/RestaurantWaitlistTable.stx +2 -2
- package/resources/components/Dashboard/Content/AuthorsDashboard.stx +4 -4
- package/resources/components/Dashboard/Content/BlogDashboard.stx +4 -4
- package/resources/components/Dashboard/Content/CommentsDashboard.stx +36 -83
- package/resources/components/Dashboard/Content/ContentDashboard.stx +12 -14
- package/resources/components/Dashboard/Content/ContentTaxonomyDashboard.stx +2 -2
- package/resources/components/Dashboard/Content/FileManagerDashboard.stx +8 -12
- package/resources/components/Dashboard/Content/FileStoragePanel.stx +6 -10
- package/resources/components/Dashboard/Content/FileUploadDialog.stx +1 -3
- package/resources/components/Dashboard/Content/PagesDashboard.stx +39 -78
- package/resources/components/Dashboard/Content/PostEditorDialog.stx +4 -8
- package/resources/components/Dashboard/Content/PostsDashboard.stx +44 -85
- package/resources/components/Dashboard/Content/SeoDashboard.stx +5 -4
- package/resources/components/Dashboard/Data/DataRecords.stx +140 -12
- package/resources/components/Dashboard/Deployments/DeploymentList.stx +4 -4
- package/resources/components/Dashboard/Deployments/DeploymentTable.stx +3 -1
- package/resources/components/Dashboard/Elements/DropdownNavigation.stx +5 -7
- package/resources/components/Dashboard/Email/CapturedMailDashboard.stx +1 -3
- package/resources/components/Dashboard/Email/CapturedMailList.stx +18 -20
- package/resources/components/Dashboard/Email/EmailActivityDashboard.stx +24 -28
- package/resources/components/Dashboard/Email/EmailSettingsList.stx +6 -8
- package/resources/components/Dashboard/Email/EmailSettingsNavigation.stx +10 -12
- package/resources/components/Dashboard/Email/EmailSidebar.stx +33 -37
- package/resources/components/Dashboard/Email/InboxMessageDetail.stx +1 -1
- package/resources/components/Dashboard/Email/InboxMessageList.stx +16 -18
- package/resources/components/Dashboard/Email/InboxSettingsDashboard.stx +1 -1
- package/resources/components/Dashboard/Environment/EnvironmentDashboard.stx +2 -2
- package/resources/components/Dashboard/GlobalSearch.stx +19 -21
- package/resources/components/Dashboard/Home/DashboardHome.stx +8 -1
- package/resources/components/Dashboard/Infrastructure/CloudDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/DnsDashboard.stx +27 -13
- package/resources/components/Dashboard/Infrastructure/LogsDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/MailboxesDashboard.stx +46 -8
- package/resources/components/Dashboard/Infrastructure/ServerlessDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/ServersDashboard.stx +1 -1
- package/resources/components/Dashboard/Jobs/JobDetail.stx +1 -1
- package/resources/components/Dashboard/Jobs/JobHistory.stx +44 -57
- package/resources/components/Dashboard/Jobs/JobTable.stx +23 -25
- package/resources/components/Dashboard/Kanban/KanbanCardDialog.stx +1 -1
- package/resources/components/Dashboard/Library/ComponentsDashboard.stx +1 -1
- package/resources/components/Dashboard/Management/AssignmentDrawer.stx +5 -7
- package/resources/components/Dashboard/Management/PermissionsDashboard.stx +35 -43
- package/resources/components/Dashboard/Marketing/AbandonedCartsDashboard.stx +11 -13
- package/resources/components/Dashboard/Marketing/CampaignDialog.stx +1 -3
- package/resources/components/Dashboard/Marketing/CampaignsDashboard.stx +2 -2
- package/resources/components/Dashboard/Marketing/CampaignsTable.stx +2 -2
- package/resources/components/Dashboard/Marketing/MarketingListsDashboard.stx +1 -1
- package/resources/components/Dashboard/Marketing/MarketingListsTable.stx +2 -2
- package/resources/components/Dashboard/Marketing/SocialPostDialog.stx +1 -3
- package/resources/components/Dashboard/Marketing/SocialPostsDashboard.stx +2 -2
- package/resources/components/Dashboard/Marketing/SocialPostsTable.stx +2 -2
- package/resources/components/Dashboard/Models/ModelRecordActions.stx +11 -2
- package/resources/components/Dashboard/Models/ModelRecordCreate.stx +193 -0
- package/resources/components/Dashboard/Models/ModelRecordDetail.stx +144 -0
- package/resources/components/Dashboard/Models/ModelRecordEdit.stx +176 -0
- package/resources/components/Dashboard/Models/ModelRecordsDashboard.stx +52 -186
- package/resources/components/Dashboard/Models/ModelsOverview.stx +2 -4
- package/resources/components/Dashboard/Monitoring/ErrorDashboard.stx +47 -81
- package/resources/components/Dashboard/Monitoring/ErrorTable.stx +4 -2
- package/resources/components/Dashboard/NotFoundDashboard.stx +4 -4
- package/resources/components/Dashboard/Notifications/NotificationDeliveryHistory.stx +43 -77
- package/resources/components/Dashboard/Notifications/NotificationDeliveryOverview.stx +15 -17
- package/resources/components/Dashboard/Notifications/NotificationDeliveryTable.stx +1 -1
- package/resources/components/Dashboard/Operations/AuditDashboard.stx +1 -1
- package/resources/components/Dashboard/Operations/ChangeDashboard.stx +1 -1
- package/resources/components/Dashboard/Operations/IncidentDashboard.stx +1 -1
- package/resources/components/Dashboard/Operations/MigrationDashboard.stx +2 -2
- package/resources/components/Dashboard/Operations/RecoveryDashboard.stx +1 -1
- package/resources/components/Dashboard/Operations/SchedulerDashboard.stx +1 -1
- package/resources/components/Dashboard/Queries/QueryDashboard.stx +60 -86
- package/resources/components/Dashboard/Queries/QueryDetail.stx +5 -9
- package/resources/components/Dashboard/Realtime/RealtimeDashboard.stx +6 -8
- package/resources/components/Dashboard/Remote/RemoteConsole.stx +14 -20
- package/resources/components/Dashboard/Settings/AppearanceSettingsDashboard.stx +48 -54
- package/resources/components/Dashboard/Settings/MailSettingsDashboard.stx +8 -8
- package/resources/components/Dashboard/Settings/SettingsDashboard.stx +43 -47
- package/resources/components/Dashboard/Teams/TeamInvitationDashboard.stx +2 -2
- package/resources/components/Dashboard/UI/ActivityTable.stx +2 -1
- package/resources/components/Dashboard/UI/Button.stx +15 -0
- package/resources/components/Dashboard/UI/MetricCards.stx +5 -7
- package/resources/components/Dashboard/UI/Pagination.stx +3 -5
- package/resources/components/Dashboard/UI/QuickLinks.stx +2 -2
- package/resources/components/Dashboard/UI/Select.stx +1 -0
- package/resources/components/Dashboard/UI/Table.stx +139 -96
- package/resources/components/Dashboard/UI/Tabs.stx +18 -20
- package/routes/dashboard-api.ts +2 -0
- package/routes/dashboard.ts +246 -253
- package/routes/storefront.ts +31 -0
- package/stx-components-plugin.ts +12 -1
- package/views/dashboard/content/categories/index.stx +1 -1
- package/views/dashboard/content/tags/index.stx +1 -1
- package/views/dashboard/layouts/default.stx +27 -12
- package/views/dashboard/models/[model]/[id]/edit.stx +8 -0
- package/views/dashboard/models/[model]/[id].stx +8 -0
- package/views/dashboard/models/[model]/create.stx +8 -0
- package/resources/components/Dashboard/CreateRecordModal.stx +0 -138
- package/resources/components/Dashboard/Models/EditRecordModal.stx +0 -81
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
<script client>
|
|
2
|
+
// A record's own page (`/models/{slug}/{id}`), where the eye on any table row
|
|
3
|
+
// leads. A breadcrumb back to the list, "View User", and the record's fields
|
|
4
|
+
// as titled cards two across: what it is, its settings, its identifiers and
|
|
5
|
+
// its timestamps, each field a label over its value. Edit (which opens the
|
|
6
|
+
// record's edit page) and Delete appear where the model's API allows them. A page rather than a dialog, so a record
|
|
7
|
+
// has an address to share, open in a tab and come back to.
|
|
8
|
+
import { useNavigation } from '@stacksjs/defaults/views/dashboard/composables/useNavigation'
|
|
9
|
+
import type { ModelRecord } from '../../../../functions/dashboard-model-record'
|
|
10
|
+
import { deleteModelRecord, fetchModelRecord, modelRecordBackHref, modelRecordEditHref, modelRecordListLabel, modelRecordSections, modelRecordTitle } from '../../../../functions/dashboard-model-record'
|
|
11
|
+
import { pushToast } from '../../../../functions/toasts'
|
|
12
|
+
|
|
13
|
+
const navigation = useNavigation()
|
|
14
|
+
const record = state<ModelRecord | null>(null)
|
|
15
|
+
const loading = state(true)
|
|
16
|
+
const loadError = state('')
|
|
17
|
+
const confirmingDelete = state(false)
|
|
18
|
+
const working = state(false)
|
|
19
|
+
|
|
20
|
+
// `/models/{slug}/{id}`: the last two segments of the address.
|
|
21
|
+
function slug(): string {
|
|
22
|
+
return navigation.urlSegment(-2)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function recordId(): string {
|
|
26
|
+
return navigation.urlSegment(-1)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const from = navigation.urlQuery('from')
|
|
30
|
+
const backHref = derived(() => modelRecordBackHref(slug(), from))
|
|
31
|
+
/** The list in the breadcrumb: "Users" for /data/users, else the model's table. */
|
|
32
|
+
const listLabel = derived(() => modelRecordListLabel(record(), backHref()))
|
|
33
|
+
|
|
34
|
+
const modelName = derived(() => record()?.modelName || 'Record')
|
|
35
|
+
const title = derived(() => record() ? modelRecordTitle(record()!) : '')
|
|
36
|
+
const sections = derived(() => record() ? modelRecordSections(record()!) : [])
|
|
37
|
+
const canEdit = derived(() => Boolean(record()?.writeCapabilities.update))
|
|
38
|
+
const canDelete = derived(() => Boolean(record()?.writeCapabilities.destroy))
|
|
39
|
+
|
|
40
|
+
async function loadRecord(): Promise<void> {
|
|
41
|
+
loading.set(true)
|
|
42
|
+
loadError.set('')
|
|
43
|
+
try {
|
|
44
|
+
record.set(await fetchModelRecord(slug(), recordId()))
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
record.set(null)
|
|
48
|
+
loadError.set(error instanceof Error ? error.message : 'This record could not be loaded.')
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
loading.set(false)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// The edit page comes back here after saving or cancelling.
|
|
56
|
+
function editRecord(): void {
|
|
57
|
+
navigate(modelRecordEditHref(slug(), recordId(), { from: backHref() === from ? from : undefined, via: 'view' }))
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function deleteRecord(): Promise<void> {
|
|
61
|
+
const current = record()
|
|
62
|
+
if (!current)
|
|
63
|
+
return
|
|
64
|
+
working.set(true)
|
|
65
|
+
try {
|
|
66
|
+
await deleteModelRecord(slug(), recordId())
|
|
67
|
+
pushToast('success', `${current.modelName} ${recordId()} deleted`)
|
|
68
|
+
confirmingDelete.set(false)
|
|
69
|
+
navigate(backHref())
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
pushToast('error', 'Could not delete', { detail: error instanceof Error ? error.message : String(error) })
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
working.set(false)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
onMount(() => {
|
|
80
|
+
void loadRecord()
|
|
81
|
+
})
|
|
82
|
+
</script>
|
|
83
|
+
|
|
84
|
+
<div class="flex flex-col gap-6">
|
|
85
|
+
<header class="flex flex-col gap-4 sm:flex-row sm:items-end sm:justify-between">
|
|
86
|
+
<div class="min-w-0">
|
|
87
|
+
<nav aria-label="Breadcrumb" class="flex gap-2 items-center mb-2 text-neutral-500 text-sm dark:text-neutral-400">
|
|
88
|
+
<StxLink :to="backHref()" class="font-medium hover:text-blue-600 dark:hover:text-blue-400">{{ listLabel() }}</StxLink>
|
|
89
|
+
<span aria-hidden="true" class="h-4 w-4 i-hugeicons-arrow-right-01"></span>
|
|
90
|
+
<span aria-current="page">View</span>
|
|
91
|
+
</nav>
|
|
92
|
+
<h1 class="font-bold text-3xl text-neutral-900 tracking-tight truncate dark:text-white">View {{ modelName() }}</h1>
|
|
93
|
+
</div>
|
|
94
|
+
<div :if="record()" class="flex flex-none gap-2 items-center">
|
|
95
|
+
<Button :if="canDelete()" variant="outline" @click="confirmingDelete.set(true)">
|
|
96
|
+
<span aria-hidden="true" class="h-4 w-4 text-red-500 i-hugeicons-delete-02"></span>
|
|
97
|
+
Delete
|
|
98
|
+
</Button>
|
|
99
|
+
<Button :if="canEdit()" variant="primary" @click="editRecord">Edit</Button>
|
|
100
|
+
</div>
|
|
101
|
+
</header>
|
|
102
|
+
|
|
103
|
+
<div :if="loading()" class="flex items-center justify-center py-20 text-neutral-500 text-sm dark:text-neutral-400">
|
|
104
|
+
<span aria-hidden="true" class="mr-2 h-5 w-5 animate-spin i-hugeicons-loading-03"></span>
|
|
105
|
+
Loading record
|
|
106
|
+
</div>
|
|
107
|
+
|
|
108
|
+
<div :if="!loading() && loadError()" role="alert" class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between px-4 py-3 text-red-700 text-sm dark:text-red-300 bg-red-50 dark:bg-red-950/40 border border-red-200 rounded-lg dark:border-red-900">
|
|
109
|
+
<span>{{ loadError() }}</span>
|
|
110
|
+
<Button variant="secondary" size="sm" @click="loadRecord">Try again</Button>
|
|
111
|
+
</div>
|
|
112
|
+
|
|
113
|
+
<div :if="!loading() && record()" class="grid gap-6 grid-cols-1 items-start lg:grid-cols-2">
|
|
114
|
+
<div :for="section in sections()" class="min-w-0">
|
|
115
|
+
<Card padding="none">
|
|
116
|
+
<h2 class="px-6 py-4 font-semibold text-base text-neutral-900 dark:text-white border-b border-neutral-200 dark:border-neutral-700">{{ section.title }}</h2>
|
|
117
|
+
<dl :class="section.columns === 2 ? 'grid gap-x-8 gap-y-6 grid-cols-1 sm:grid-cols-2 p-6' : 'flex flex-col gap-6 p-6'">
|
|
118
|
+
<div :for="detail in section.details" :class="detail.wide ? 'min-w-0 sm:col-span-2' : 'min-w-0'">
|
|
119
|
+
<dt class="font-medium text-neutral-900 text-sm dark:text-white">{{ detail.label }}</dt>
|
|
120
|
+
<dd class="mt-1.5 text-sm">
|
|
121
|
+
<span :if="detail.kind === 'boolean'" class="inline-flex gap-1.5 items-center text-neutral-700 dark:text-neutral-200">
|
|
122
|
+
<span aria-hidden="true" :class="detail.yes ? 'h-5 w-5 text-green-600 dark:text-green-400 i-hugeicons-checkmark-circle-02' : 'h-5 w-5 text-neutral-400 dark:text-neutral-500 i-hugeicons-cancel-circle'"></span>
|
|
123
|
+
{{ detail.value }}
|
|
124
|
+
</span>
|
|
125
|
+
<span :if="detail.kind === 'badge'" class="inline-flex px-2 py-0.5 font-medium text-neutral-800 text-xs dark:text-neutral-100 border border-neutral-400 rounded-md dark:border-neutral-500">{{ detail.value }}</span>
|
|
126
|
+
<pre :if="detail.kind === 'json'" class="overflow-x-auto p-3 font-mono text-neutral-800 text-xs dark:text-neutral-200 bg-neutral-50 dark:bg-neutral-900 rounded-lg">{{ detail.value }}</pre>
|
|
127
|
+
<span :if="detail.kind === 'text'" :class="detail.empty ? 'text-neutral-400 dark:text-neutral-500' : 'break-words text-neutral-700 dark:text-neutral-200'">{{ detail.value }}</span>
|
|
128
|
+
</dd>
|
|
129
|
+
</div>
|
|
130
|
+
</dl>
|
|
131
|
+
</Card>
|
|
132
|
+
</div>
|
|
133
|
+
</div>
|
|
134
|
+
|
|
135
|
+
<ConfirmDialog
|
|
136
|
+
:isOpen="confirmingDelete()"
|
|
137
|
+
:title="'Delete this ' + modelName().toLowerCase() + '?'"
|
|
138
|
+
:description="(title() || modelName()) + ' will be removed through the model, so soft deletes and observers apply.'"
|
|
139
|
+
:busy="working()"
|
|
140
|
+
:confirmLabel="working() ? 'Deleting' : 'Delete'"
|
|
141
|
+
@close="confirmingDelete.set(false)"
|
|
142
|
+
@confirm="deleteRecord"
|
|
143
|
+
/>
|
|
144
|
+
</div>
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
<script client>
|
|
2
|
+
// A record's edit page (`/models/{slug}/{id}/edit`), where the pencil on any
|
|
3
|
+
// table row and the Edit button on the record's page lead. The fields the
|
|
4
|
+
// model's API lets the dashboard change are inputs; the rest are shown beside
|
|
5
|
+
// them, read only, as context. Saving sends only what changed, then returns
|
|
6
|
+
// to where the visitor came from: the record's page, or the list.
|
|
7
|
+
import { useNavigation } from '@stacksjs/defaults/views/dashboard/composables/useNavigation'
|
|
8
|
+
import type { ModelRecord } from '../../../../functions/dashboard-model-record'
|
|
9
|
+
import { changedModelFields, fetchModelRecord, modelRecordBackHref, modelRecordFields, modelRecordHref, modelRecordListLabel, modelRecordSections, updateModelRecord } from '../../../../functions/dashboard-model-record'
|
|
10
|
+
import { pushToast } from '../../../../functions/toasts'
|
|
11
|
+
|
|
12
|
+
const navigation = useNavigation()
|
|
13
|
+
const record = state<ModelRecord | null>(null)
|
|
14
|
+
const values = state<Record<string, string>>({})
|
|
15
|
+
const loading = state(true)
|
|
16
|
+
const loadError = state('')
|
|
17
|
+
const saving = state(false)
|
|
18
|
+
const saveError = state('')
|
|
19
|
+
|
|
20
|
+
// `/models/{slug}/{id}/edit`
|
|
21
|
+
function slug(): string {
|
|
22
|
+
return navigation.urlSegment(-3)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function recordId(): string {
|
|
26
|
+
return navigation.urlSegment(-2)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const from = navigation.urlQuery('from')
|
|
30
|
+
const cameFromView = navigation.urlQuery('via') === 'view'
|
|
31
|
+
const listHref = derived(() => modelRecordBackHref(slug(), from))
|
|
32
|
+
const viewHref = derived(() => modelRecordHref(slug(), recordId(), listHref() === from ? from : undefined))
|
|
33
|
+
/** After saving or cancelling: the page the visitor came from. */
|
|
34
|
+
const returnHref = derived(() => cameFromView ? viewHref() : listHref())
|
|
35
|
+
const listLabel = derived(() => modelRecordListLabel(record(), listHref()))
|
|
36
|
+
const modelName = derived(() => record()?.modelName || 'Record')
|
|
37
|
+
|
|
38
|
+
const writable = derived(() => record() ? modelRecordFields(record()!).filter(field => !field.readonly) : [])
|
|
39
|
+
/** What cannot be changed here, formatted as the record's page shows it. */
|
|
40
|
+
const context = derived(() => {
|
|
41
|
+
const current = record()
|
|
42
|
+
if (!current)
|
|
43
|
+
return []
|
|
44
|
+
return modelRecordSections(current)
|
|
45
|
+
.flatMap(section => section.details)
|
|
46
|
+
.filter(detail => !current.updateColumns.includes(detail.name))
|
|
47
|
+
})
|
|
48
|
+
const canEdit = derived(() => Boolean(record()?.writeCapabilities.update) && writable().length > 0)
|
|
49
|
+
|
|
50
|
+
function updateValue(field: string, event: Event): void {
|
|
51
|
+
values.set({ ...values(), [field]: (event.target as HTMLInputElement).value })
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function loadRecord(): Promise<void> {
|
|
55
|
+
loading.set(true)
|
|
56
|
+
loadError.set('')
|
|
57
|
+
try {
|
|
58
|
+
const loaded = await fetchModelRecord(slug(), recordId())
|
|
59
|
+
record.set(loaded)
|
|
60
|
+
values.set(Object.fromEntries(modelRecordFields(loaded).filter(field => !field.readonly).map(field => [field.name, field.value])))
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
record.set(null)
|
|
64
|
+
loadError.set(error instanceof Error ? error.message : 'This record could not be loaded.')
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
loading.set(false)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function save(): Promise<void> {
|
|
72
|
+
const current = record()
|
|
73
|
+
if (!current || saving())
|
|
74
|
+
return
|
|
75
|
+
const fields = changedModelFields(current.row, values())
|
|
76
|
+
if (Object.keys(fields).length === 0) {
|
|
77
|
+
navigate(returnHref())
|
|
78
|
+
return
|
|
79
|
+
}
|
|
80
|
+
saving.set(true)
|
|
81
|
+
saveError.set('')
|
|
82
|
+
try {
|
|
83
|
+
await updateModelRecord(slug(), recordId(), fields)
|
|
84
|
+
pushToast('success', `${current.modelName} ${recordId()} updated`)
|
|
85
|
+
navigate(returnHref())
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
saveError.set(error instanceof Error ? error.message : 'The changes could not be saved.')
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
saving.set(false)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function cancel(): void {
|
|
96
|
+
if (!saving())
|
|
97
|
+
navigate(returnHref())
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
onMount(() => {
|
|
101
|
+
void loadRecord()
|
|
102
|
+
})
|
|
103
|
+
</script>
|
|
104
|
+
|
|
105
|
+
<div class="flex flex-col gap-6">
|
|
106
|
+
<header class="min-w-0">
|
|
107
|
+
<nav aria-label="Breadcrumb" class="flex gap-2 items-center mb-2 text-neutral-500 text-sm dark:text-neutral-400">
|
|
108
|
+
<StxLink :to="listHref()" class="font-medium hover:text-blue-600 dark:hover:text-blue-400">{{ listLabel() }}</StxLink>
|
|
109
|
+
<span aria-hidden="true" class="h-4 w-4 i-hugeicons-arrow-right-01"></span>
|
|
110
|
+
<StxLink :to="viewHref()" class="font-medium hover:text-blue-600 dark:hover:text-blue-400">View</StxLink>
|
|
111
|
+
<span aria-hidden="true" class="h-4 w-4 i-hugeicons-arrow-right-01"></span>
|
|
112
|
+
<span aria-current="page">Edit</span>
|
|
113
|
+
</nav>
|
|
114
|
+
<h1 class="font-bold text-3xl text-neutral-900 tracking-tight truncate dark:text-white">Edit {{ modelName() }}</h1>
|
|
115
|
+
</header>
|
|
116
|
+
|
|
117
|
+
<div :if="loading()" class="flex items-center justify-center py-20 text-neutral-500 text-sm dark:text-neutral-400">
|
|
118
|
+
<span aria-hidden="true" class="mr-2 h-5 w-5 animate-spin i-hugeicons-loading-03"></span>
|
|
119
|
+
Loading record
|
|
120
|
+
</div>
|
|
121
|
+
|
|
122
|
+
<div :if="!loading() && loadError()" role="alert" class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between px-4 py-3 text-red-700 text-sm dark:text-red-300 bg-red-50 dark:bg-red-950/40 border border-red-200 rounded-lg dark:border-red-900">
|
|
123
|
+
<span>{{ loadError() }}</span>
|
|
124
|
+
<Button variant="secondary" size="sm" @click="loadRecord">Try again</Button>
|
|
125
|
+
</div>
|
|
126
|
+
|
|
127
|
+
<EmptyState
|
|
128
|
+
:if="!loading() && record() && !canEdit()"
|
|
129
|
+
icon="i-hugeicons-square-lock-02"
|
|
130
|
+
:title="modelName() + ' records cannot be edited here'"
|
|
131
|
+
description="This model does not allow changes through the dashboard. You can still view the record."
|
|
132
|
+
/>
|
|
133
|
+
|
|
134
|
+
<form :if="!loading() && canEdit()" id="model-edit-form" class="flex flex-col gap-6" @submit.prevent="save">
|
|
135
|
+
<div :if="saveError()" role="alert" class="px-4 py-3 text-red-700 text-sm dark:text-red-300 bg-red-50 dark:bg-red-950/40 border border-red-200 rounded-lg dark:border-red-900">
|
|
136
|
+
{{ saveError() }}
|
|
137
|
+
</div>
|
|
138
|
+
|
|
139
|
+
<div class="grid gap-6 grid-cols-1 items-start lg:grid-cols-2">
|
|
140
|
+
<Card padding="none">
|
|
141
|
+
<h2 class="px-6 py-4 font-semibold text-base text-neutral-900 dark:text-white border-b border-neutral-200 dark:border-neutral-700">{{ modelName() }} Details</h2>
|
|
142
|
+
<div class="flex flex-col gap-5 p-6">
|
|
143
|
+
<div :for="field in writable()" class="flex flex-col gap-1.5">
|
|
144
|
+
<label :for="'model-edit-' + field.name" class="font-medium text-neutral-900 text-sm dark:text-white">{{ field.label }}</label>
|
|
145
|
+
<input
|
|
146
|
+
:id="'model-edit-' + field.name"
|
|
147
|
+
:name="field.name"
|
|
148
|
+
type="text"
|
|
149
|
+
:value="values()[field.name] ?? field.value"
|
|
150
|
+
class="px-3 py-2 text-neutral-900 text-sm dark:text-neutral-100 bg-white dark:bg-white/10 border border-black/10 rounded-lg dark:border-white/15 focus:border-blue-400 focus:outline-none focus:ring-2 focus:ring-blue-500/20"
|
|
151
|
+
@input="updateValue(field.name, $event)"
|
|
152
|
+
>
|
|
153
|
+
</div>
|
|
154
|
+
</div>
|
|
155
|
+
</Card>
|
|
156
|
+
|
|
157
|
+
<Card :if="context().length > 0" padding="none">
|
|
158
|
+
<div class="px-6 py-4 border-b border-neutral-200 dark:border-neutral-700">
|
|
159
|
+
<h2 class="font-semibold text-base text-neutral-900 dark:text-white">Read only</h2>
|
|
160
|
+
<p class="mt-1 text-neutral-500 text-xs dark:text-neutral-400">Set by the application. These cannot be changed from here.</p>
|
|
161
|
+
</div>
|
|
162
|
+
<dl class="grid gap-x-8 gap-y-6 grid-cols-1 sm:grid-cols-2 p-6">
|
|
163
|
+
<div :for="detail in context()" :class="detail.wide ? 'min-w-0 sm:col-span-2' : 'min-w-0'">
|
|
164
|
+
<dt class="font-medium text-neutral-900 text-sm dark:text-white">{{ detail.label }}</dt>
|
|
165
|
+
<dd :class="detail.empty ? 'mt-1.5 text-sm text-neutral-400 dark:text-neutral-500' : 'mt-1.5 text-sm break-words text-neutral-700 dark:text-neutral-200'">{{ detail.value }}</dd>
|
|
166
|
+
</div>
|
|
167
|
+
</dl>
|
|
168
|
+
</Card>
|
|
169
|
+
</div>
|
|
170
|
+
|
|
171
|
+
<div class="flex gap-3 items-center">
|
|
172
|
+
<Button type="submit" variant="primary" :loading="saving()">Save changes</Button>
|
|
173
|
+
<Button variant="secondary" :disabled="saving()" @click="cancel">Cancel</Button>
|
|
174
|
+
</div>
|
|
175
|
+
</form>
|
|
176
|
+
</div>
|