@stacksjs/defaults 0.75.538 → 0.75.541
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ai/AGENTS.md +2 -0
- package/ai/skills/stacks-actions/SKILL.md +1 -1
- package/ai/skills/stacks-auth/SKILL.md +8 -1
- package/ai/skills/stacks-dashboard/SKILL.md +196 -3
- package/ai/skills/stacks-dependencies/SKILL.md +46 -0
- package/ai/skills/stacks-development/SKILL.md +1 -1
- package/ai/skills/stacks-flow/SKILL.md +7 -0
- package/ai/skills/stacks-hq/SKILL.md +146 -0
- package/ai/skills/stacks-models/SKILL.md +21 -3
- package/ai/skills/stacks-native/CATALOG.md +22 -9
- package/ai/skills/stacks-new-app/SKILL.md +175 -0
- package/ai/skills/stacks-repl/SKILL.md +61 -43
- package/ai/skills/stacks-stx/SKILL.md +6 -2
- package/ai/skills/stacks-upstream/SKILL.md +188 -0
- package/ai/skills/stacks-writing-for-agents/SKILL.md +1 -1
- package/app/Actions/Dashboard/Data/UserIndexAction.ts +20 -2
- package/app/Actions/Dashboard/Models/ModelDestroyAction.ts +48 -12
- package/app/Actions/Dashboard/Models/ModelOptionsAction.ts +103 -0
- package/app/Actions/Dashboard/Models/ModelRelatedAction.ts +42 -0
- package/app/Actions/Dashboard/Models/ModelShowAction.ts +75 -12
- package/app/Actions/Dashboard/Models/ModelStoreAction.ts +7 -1
- package/app/Actions/Dashboard/Models/ModelUpdateAction.ts +16 -2
- package/app/Actions/Dashboard/Models/model-destroy.ts +75 -0
- package/app/Actions/Dashboard/Models/model-options.ts +56 -0
- package/app/Actions/Dashboard/Models/model-related.ts +202 -0
- package/app/Actions/Dashboard/Models/model-relations.ts +172 -0
- package/app/Actions/Dashboard/Models/model-write.ts +240 -51
- package/app/Actions/Dashboard/Users/UserInviteAction.ts +50 -0
- package/app/Actions/Dashboard/Users/user-invitation.ts +110 -0
- package/app/Models/Activity.ts +4 -0
- package/app/Models/AnalyticsEvent.ts +4 -0
- package/app/Models/Automation.ts +4 -0
- package/app/Models/AutomationRun.ts +4 -0
- package/app/Models/Board.ts +4 -1
- package/app/Models/BoardColumn.ts +4 -1
- package/app/Models/Campaign.ts +4 -0
- package/app/Models/CampaignSend.ts +4 -0
- package/app/Models/CampaignVariant.ts +4 -0
- package/app/Models/Card.ts +4 -1
- package/app/Models/CardAttachment.ts +4 -0
- package/app/Models/CommunicationSuppression.ts +4 -0
- package/app/Models/ConsentEvent.ts +4 -0
- package/app/Models/Deployment.ts +1 -0
- package/app/Models/EmailList.ts +4 -0
- package/app/Models/EmailListSubscriber.ts +4 -0
- package/app/Models/Error.ts +4 -0
- package/app/Models/FailedJob.ts +4 -0
- package/app/Models/FeedbackToken.ts +4 -0
- package/app/Models/GdprRequest.ts +4 -0
- package/app/Models/Job.ts +4 -0
- package/app/Models/Log.ts +4 -0
- package/app/Models/MagicLinkToken.ts +4 -0
- package/app/Models/MailPreference.ts +4 -0
- package/app/Models/Notification.ts +4 -0
- package/app/Models/NotificationDelivery.ts +4 -0
- package/app/Models/PersonalAccessToken.ts +4 -0
- package/app/Models/QueryLog.ts +4 -0
- package/app/Models/Referral.ts +4 -0
- package/app/Models/Release.ts +1 -0
- package/app/Models/Request.ts +4 -0
- package/app/Models/SenderDomain.ts +4 -0
- package/app/Models/Site.ts +1 -0
- package/app/Models/SiteDomain.ts +4 -0
- package/app/Models/SocialPost.ts +4 -0
- package/app/Models/StorageItemTask.ts +4 -1
- package/app/Models/Subscriber.ts +4 -0
- package/app/Models/Subscription.ts +4 -0
- package/app/Models/Team.ts +1 -0
- package/app/Models/TeamInvitation.ts +1 -0
- package/app/Models/TeamMember.ts +1 -0
- package/app/Models/UsageEvent.ts +4 -0
- package/app/Models/User.ts +15 -3
- package/functions/dashboard-model-record.test.ts +276 -18
- package/functions/dashboard-model-record.ts +412 -55
- package/functions/data.ts +2 -0
- package/ide/vscode/package.json +1 -1
- package/package.json +5 -5
- package/resources/components/Dashboard/Analytics/AnalyticsHub.stx +1 -1
- package/resources/components/Dashboard/Analytics/CampaignAnalytics.stx +1 -1
- package/resources/components/Dashboard/Analytics/EventAnalytics.stx +1 -1
- package/resources/components/Dashboard/Analytics/SalesAnalytics.stx +1 -1
- package/resources/components/Dashboard/Analytics/WebAnalyticsBreakdown.stx +1 -1
- package/resources/components/Dashboard/App/RequestsOverview.stx +1 -1
- package/resources/components/Dashboard/App/SourceInventory.stx +1 -1
- package/resources/components/Dashboard/Auth/AccessTokens.stx +1 -1
- package/resources/components/Dashboard/Buddy/BuddyAssistant.stx +1 -1
- package/resources/components/Dashboard/Ci/CiDashboard.stx +1 -1
- package/resources/components/Dashboard/Commerce/Delivery/DeliveryPagination.stx +1 -1
- package/resources/components/Dashboard/Commerce/ProductWaitlistDashboard.stx +1 -1
- package/resources/components/Dashboard/Commerce/RestaurantWaitlistDashboard.stx +1 -1
- package/resources/components/Dashboard/Content/BlogDashboard.stx +1 -1
- package/resources/components/Dashboard/DashboardLayout.stx +1 -1
- package/resources/components/Dashboard/Data/DataRecords.stx +43 -22
- package/resources/components/Dashboard/Data/UserInvite.stx +107 -0
- package/resources/components/Dashboard/Email/CapturedMailDashboard.stx +1 -1
- package/resources/components/Dashboard/Email/EmailActivityDashboard.stx +1 -1
- package/resources/components/Dashboard/Email/InboxDashboard.stx +1 -1
- package/resources/components/Dashboard/Email/InboxMessageDetail.stx +2 -2
- package/resources/components/Dashboard/Email/InboxSettingsDashboard.stx +1 -1
- package/resources/components/Dashboard/Home/DashboardHome.stx +6 -1
- package/resources/components/Dashboard/Infrastructure/CloudDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/DnsDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/HealthDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/InsightsDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/LogsDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/MailboxesDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/ServerDetailsDashboard.stx +1 -1
- 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/JobTable.stx +2 -2
- package/resources/components/Dashboard/Kanban/KanbanBoardDashboard.stx +1 -1
- package/resources/components/Dashboard/Kanban/KanbanBoardsDashboard.stx +1 -1
- package/resources/components/Dashboard/Management/PermissionsDashboard.stx +1 -1
- package/resources/components/Dashboard/Marketing/AbandonedCartsDashboard.stx +1 -1
- package/resources/components/Dashboard/Marketing/CampaignsDashboard.stx +1 -1
- package/resources/components/Dashboard/Marketing/MarketingListsDashboard.stx +1 -1
- package/resources/components/Dashboard/Marketing/SocialPostsDashboard.stx +1 -1
- package/resources/components/Dashboard/Models/ModelFieldInputs.stx +125 -0
- package/resources/components/Dashboard/Models/ModelRecordCreate.stx +24 -66
- package/resources/components/Dashboard/Models/ModelRecordDetail.stx +36 -8
- package/resources/components/Dashboard/Models/ModelRecordEdit.stx +36 -32
- package/resources/components/Dashboard/Models/ModelRecordsDashboard.stx +72 -28
- package/resources/components/Dashboard/Models/ModelRelatedPanels.stx +99 -0
- package/resources/components/Dashboard/Models/ModelRelationPicker.stx +247 -0
- package/resources/components/Dashboard/Models/ModelsOverview.stx +1 -1
- package/resources/components/Dashboard/Notifications/NotificationDeliveries.stx +1 -1
- package/resources/components/Dashboard/Notifications/NotificationDeliveryHistory.stx +1 -1
- package/resources/components/Dashboard/Notifications/NotificationDeliveryOverview.stx +1 -1
- package/resources/components/Dashboard/Queries/QueryDashboard.stx +1 -1
- package/resources/components/Dashboard/Queries/QueryDetail.stx +1 -1
- package/resources/components/Dashboard/Queue/QueueDashboard.stx +1 -1
- package/resources/components/Dashboard/Realtime/RealtimeDashboard.stx +1 -1
- package/resources/components/Dashboard/Releases/ReleaseDashboard.stx +1 -1
- package/resources/components/Dashboard/Search/SearchEngineDashboard.stx +1 -1
- package/resources/components/Dashboard/Settings/MailSettingsDashboard.stx +1 -1
- package/resources/components/Dashboard/Settings/SettingsDashboard.stx +1 -1
- package/resources/components/Dashboard/Teams/TeamPeopleDashboard.stx +1 -1
- package/resources/components/Dashboard/UI/Drawer.stx +1 -1
- package/resources/components/Dashboard/UI/Input.stx +3 -2
- package/resources/components/Dashboard/UI/Modal.stx +1 -1
- package/resources/components/Dashboard/UI/Select.stx +8 -4
- package/resources/components/Dashboard/UI/Textarea.stx +18 -12
- package/resources/emails/password-reset.stx +3 -1
- package/routes/dashboard-api.ts +9 -0
- package/scaffold/config/analytics.ts +5 -3
- package/scaffold/resources/components/NextStep.stx +13 -0
- package/scaffold/resources/partials/head.stx +31 -0
- package/scaffold/resources/views/index.stx +23 -47
- package/scaffold/resources/views/layouts/default.stx +23 -0
- package/views/dashboard/data/users/invite.stx +8 -0
- package/views/dashboard/layouts/default.stx +21 -2
|
@@ -341,7 +341,7 @@
|
|
|
341
341
|
|
|
342
342
|
<div :if="canManage">
|
|
343
343
|
<header class="mb-6">
|
|
344
|
-
<h1 class="font-
|
|
344
|
+
<h1 class="font-bold text-2xl text-zinc-900 dark:text-zinc-100">Permissions Management</h1>
|
|
345
345
|
<p class="mt-1 text-sm text-zinc-500">Manage roles, permissions, and user assignments. Backed by the live <code class="text-xs">user_roles</code> / <code class="text-xs">role_permissions</code> pivots.</p>
|
|
346
346
|
</header>
|
|
347
347
|
|
|
@@ -154,7 +154,7 @@ onMount(() => {
|
|
|
154
154
|
})
|
|
155
155
|
</script>
|
|
156
156
|
|
|
157
|
-
<div class="
|
|
157
|
+
<div class="flex flex-col gap-6">
|
|
158
158
|
<PageHeader title="Abandoned Carts" description="The audience that already chose the products. Every other campaign starts by guessing.">
|
|
159
159
|
<div class="flex gap-2">
|
|
160
160
|
<Button :loading="loading()" variant="secondary" @click="loadCarts()"><span :if="!loading()" aria-hidden="true" class="h-4 w-4 i-hugeicons-refresh"></span>Refresh</Button>
|
|
@@ -262,7 +262,7 @@ onMount(() => {
|
|
|
262
262
|
})
|
|
263
263
|
</script>
|
|
264
264
|
|
|
265
|
-
<div class="
|
|
265
|
+
<div class="flex flex-col gap-6">
|
|
266
266
|
<PageHeader title="Campaigns" description="Manage Campaign records with real audience and delivery aggregates.">
|
|
267
267
|
<div class="flex gap-2">
|
|
268
268
|
<Button :loading="loading()" variant="secondary" @click="loadCampaigns()"><span :if="!loading()" aria-hidden="true" class="h-4 w-4 i-hugeicons-refresh"></span>Refresh</Button>
|
|
@@ -185,7 +185,7 @@ onMount(() => {
|
|
|
185
185
|
})
|
|
186
186
|
</script>
|
|
187
187
|
|
|
188
|
-
<div class="
|
|
188
|
+
<div class="flex flex-col gap-6">
|
|
189
189
|
<PageHeader title="Email lists" description="Manage EmailList records, signup policy, and real membership totals.">
|
|
190
190
|
<div class="flex gap-2">
|
|
191
191
|
<Button :loading="loading()" variant="secondary" @click="loadLists()">
|
|
@@ -177,7 +177,7 @@ onMount(() => {
|
|
|
177
177
|
})
|
|
178
178
|
</script>
|
|
179
179
|
|
|
180
|
-
<div class="
|
|
180
|
+
<div class="flex flex-col gap-6">
|
|
181
181
|
<PageHeader title="Social posts" description="Create and schedule SocialPost records with persisted User ownership and platform metrics.">
|
|
182
182
|
<div class="flex gap-2">
|
|
183
183
|
<Button :loading="loading()" variant="secondary" @click="loadPosts()"><span :if="!loading()" aria-hidden="true" class="h-4 w-4 i-hugeicons-refresh"></span>Refresh</Button>
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
<script client>
|
|
2
|
+
// The inputs of a model's form, one per field, each in the control its kind
|
|
3
|
+
// calls for: a select for a choice, a checkbox for yes or no, a date or a
|
|
4
|
+
// date-and-time picker, a number box, a tall box for prose and for JSON, a
|
|
5
|
+
// search for another model's record, and a line of text for the rest.
|
|
6
|
+
//
|
|
7
|
+
// The create page and the edit page both render this, so a kind of field is
|
|
8
|
+
// drawn once. The page owns the values: this reports each change upward as
|
|
9
|
+
// `{ name, value }` and shows the message a refused save came back with.
|
|
10
|
+
import type { ModelCreateField, ModelFormValues } from '../../../../functions/dashboard-model-record'
|
|
11
|
+
import { modelFieldError } from '../../../../functions/dashboard-model-record'
|
|
12
|
+
|
|
13
|
+
const fields = useReactiveProp<ModelCreateField[]>('fields', [])
|
|
14
|
+
const values = useReactiveProp<ModelFormValues>('values', {})
|
|
15
|
+
const errors = useReactiveProp<Record<string, string[]>>('errors', {})
|
|
16
|
+
const disabled = useReactiveProp('disabled', false)
|
|
17
|
+
const emit = defineEmits(['change'])
|
|
18
|
+
|
|
19
|
+
function text(field: ModelCreateField): string {
|
|
20
|
+
const value = values()[field.name]
|
|
21
|
+
return typeof value === 'string' ? value : ''
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function error(field: ModelCreateField): string {
|
|
25
|
+
return modelFieldError(errors(), field.name)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function inputType(field: ModelCreateField): 'date' | 'datetime-local' | 'email' | 'number' | 'text' {
|
|
29
|
+
if (field.type === 'datetime')
|
|
30
|
+
return 'datetime-local'
|
|
31
|
+
if (field.type === 'date' || field.type === 'email' || field.type === 'number')
|
|
32
|
+
return field.type
|
|
33
|
+
return 'text'
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Everything that is one line: text, email, number, date, date and time. */
|
|
37
|
+
function isLine(field: ModelCreateField): boolean {
|
|
38
|
+
return field.type !== 'boolean' && field.type !== 'enum' && field.type !== 'longtext' && field.type !== 'json' && field.type !== 'relation'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function hint(field: ModelCreateField): string {
|
|
42
|
+
if (field.type === 'json')
|
|
43
|
+
return 'JSON. Checked when you save.'
|
|
44
|
+
if (field.type === 'datetime')
|
|
45
|
+
return 'In your own time zone.'
|
|
46
|
+
return ''
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function change(field: ModelCreateField, value: string | boolean): void {
|
|
50
|
+
emit('change', { name: field.name, value })
|
|
51
|
+
}
|
|
52
|
+
</script>
|
|
53
|
+
|
|
54
|
+
<div class="flex flex-col gap-5">
|
|
55
|
+
<div :for="field in fields()" class="contents">
|
|
56
|
+
<label :if="field.type === 'boolean'" class="flex gap-3 items-start p-3 border border-neutral-200 rounded-lg dark:border-neutral-700">
|
|
57
|
+
<input
|
|
58
|
+
:name="field.name"
|
|
59
|
+
type="checkbox"
|
|
60
|
+
:checked="values()[field.name] === true"
|
|
61
|
+
:disabled="disabled()"
|
|
62
|
+
class="mt-0.5 h-4 w-4 text-blue-600 border-neutral-300 rounded"
|
|
63
|
+
@change="change(field, $event.target.checked)"
|
|
64
|
+
/>
|
|
65
|
+
<span>
|
|
66
|
+
<span class="block font-medium text-neutral-900 text-sm dark:text-white">{{ field.label }}</span>
|
|
67
|
+
<span :if="error(field)" role="alert" class="block mt-0.5 text-red-600 text-xs dark:text-red-400">{{ error(field) }}</span>
|
|
68
|
+
</span>
|
|
69
|
+
</label>
|
|
70
|
+
|
|
71
|
+
<Select
|
|
72
|
+
:if="field.type === 'enum'"
|
|
73
|
+
:name="field.name"
|
|
74
|
+
:value="text(field)"
|
|
75
|
+
:options="field.options"
|
|
76
|
+
:label="field.label"
|
|
77
|
+
:ariaLabel="field.label"
|
|
78
|
+
:required="field.required"
|
|
79
|
+
:disabled="disabled()"
|
|
80
|
+
:error="error(field)"
|
|
81
|
+
@update:value="change(field, $event)"
|
|
82
|
+
/>
|
|
83
|
+
|
|
84
|
+
<ModelRelationPicker
|
|
85
|
+
:if="field.type === 'relation'"
|
|
86
|
+
:slug="field.relation ? field.relation.slug : ''"
|
|
87
|
+
:name="field.name"
|
|
88
|
+
:value="text(field)"
|
|
89
|
+
:label="field.label"
|
|
90
|
+
:required="field.required"
|
|
91
|
+
:disabled="disabled()"
|
|
92
|
+
:error="error(field)"
|
|
93
|
+
@update:value="change(field, $event)"
|
|
94
|
+
/>
|
|
95
|
+
|
|
96
|
+
<Textarea
|
|
97
|
+
:if="field.type === 'longtext' || field.type === 'json'"
|
|
98
|
+
:name="field.name"
|
|
99
|
+
:value="text(field)"
|
|
100
|
+
:label="field.label"
|
|
101
|
+
:ariaLabel="field.label"
|
|
102
|
+
:rows="field.type === 'json' ? 8 : 4"
|
|
103
|
+
:monospace="field.type === 'json'"
|
|
104
|
+
:hint="hint(field)"
|
|
105
|
+
:required="field.required"
|
|
106
|
+
:disabled="disabled()"
|
|
107
|
+
:error="error(field)"
|
|
108
|
+
@update:value="change(field, $event)"
|
|
109
|
+
/>
|
|
110
|
+
|
|
111
|
+
<Input
|
|
112
|
+
:if="isLine(field)"
|
|
113
|
+
:name="field.name"
|
|
114
|
+
:value="text(field)"
|
|
115
|
+
:type="inputType(field)"
|
|
116
|
+
:label="field.label"
|
|
117
|
+
:ariaLabel="field.label"
|
|
118
|
+
:hint="hint(field)"
|
|
119
|
+
:required="field.required"
|
|
120
|
+
:disabled="disabled()"
|
|
121
|
+
:error="error(field)"
|
|
122
|
+
@update:value="change(field, $event)"
|
|
123
|
+
/>
|
|
124
|
+
</div>
|
|
125
|
+
</div>
|
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
// each field's message under its field. A created record opens on its own
|
|
7
7
|
// page.
|
|
8
8
|
import { useNavigation } from '@stacksjs/defaults/views/dashboard/composables/useNavigation'
|
|
9
|
-
import type {
|
|
10
|
-
import { createModelRecord, fetchModelCreateForm, modelRecordBackHref, modelRecordHref, modelRecordListLabel } from '../../../../functions/dashboard-model-record'
|
|
9
|
+
import type { ModelCreateForm, ModelFormValues } from '../../../../functions/dashboard-model-record'
|
|
10
|
+
import { createModelRecord, fetchModelCreateForm, modelFormPayload, modelFormPrefill, modelFormValues, modelRecordBackHref, modelRecordHref, modelRecordListLabel, userInviteHref } from '../../../../functions/dashboard-model-record'
|
|
11
11
|
import { pushToast } from '../../../../functions/toasts'
|
|
12
12
|
|
|
13
13
|
const navigation = useNavigation()
|
|
14
14
|
const form = state<ModelCreateForm | null>(null)
|
|
15
|
-
const values = state<
|
|
15
|
+
const values = state<ModelFormValues>({})
|
|
16
16
|
const loading = state(true)
|
|
17
17
|
const loadError = state('')
|
|
18
18
|
const creating = state(false)
|
|
@@ -30,26 +30,15 @@ const listLabel = derived(() => modelRecordListLabel(form(), listHref()))
|
|
|
30
30
|
const modelName = derived(() => form()?.modelName || 'Record')
|
|
31
31
|
const fields = derived(() => form()?.fields ?? [])
|
|
32
32
|
const canCreate = derived(() => Boolean(form()?.canCreate) && fields().length > 0)
|
|
33
|
+
/** A model added by invitation has no form here; the page points at the one that does. */
|
|
34
|
+
const canInvite = derived(() => !canCreate() && Boolean(form()?.canInvite))
|
|
33
35
|
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
+
function openInvite(): void {
|
|
37
|
+
navigate(userInviteHref(listHref()))
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
return value === null || value === undefined ? '' : String(value)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function fieldError(field: string): string {
|
|
44
|
-
return createErrors()[field]?.[0] || ''
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function inputType(field: ModelCreateField): 'date' | 'datetime-local' | 'email' | 'number' | 'text' {
|
|
48
|
-
if (field.type === 'datetime')
|
|
49
|
-
return 'datetime-local'
|
|
50
|
-
if (field.type === 'date' || field.type === 'email' || field.type === 'number')
|
|
51
|
-
return field.type
|
|
52
|
-
return 'text'
|
|
40
|
+
function setValue(change: { name: string, value: string | boolean }): void {
|
|
41
|
+
values.set({ ...values(), [change.name]: change.value })
|
|
53
42
|
}
|
|
54
43
|
|
|
55
44
|
async function loadForm(): Promise<void> {
|
|
@@ -58,7 +47,8 @@ async function loadForm(): Promise<void> {
|
|
|
58
47
|
try {
|
|
59
48
|
const loaded = await fetchModelCreateForm(slug())
|
|
60
49
|
form.set(loaded)
|
|
61
|
-
|
|
50
|
+
// Opened from a record's panel, the form starts with that record chosen.
|
|
51
|
+
values.set({ ...modelFormValues(loaded.fields), ...modelFormPrefill(loaded.fields, name => navigation.urlQuery(name)) })
|
|
62
52
|
}
|
|
63
53
|
catch (error) {
|
|
64
54
|
form.set(null)
|
|
@@ -76,7 +66,7 @@ async function create(): Promise<void> {
|
|
|
76
66
|
createError.set('')
|
|
77
67
|
createErrors.set({})
|
|
78
68
|
try {
|
|
79
|
-
const result = await createModelRecord(slug(),
|
|
69
|
+
const result = await createModelRecord(slug(), modelFormPayload(fields(), values()))
|
|
80
70
|
if (!result.ok) {
|
|
81
71
|
createError.set(result.error)
|
|
82
72
|
createErrors.set(result.errors)
|
|
@@ -121,12 +111,21 @@ onMount(() => {
|
|
|
121
111
|
</div>
|
|
122
112
|
|
|
123
113
|
<EmptyState
|
|
124
|
-
:if="!loading() && form() && !canCreate()"
|
|
114
|
+
:if="!loading() && form() && !canCreate() && !canInvite()"
|
|
125
115
|
icon="i-hugeicons-square-lock-02"
|
|
126
116
|
:title="modelName() + ' records cannot be created here'"
|
|
127
117
|
description="This model does not accept new records through the dashboard."
|
|
128
118
|
/>
|
|
129
119
|
|
|
120
|
+
<div :if="!loading() && canInvite()" class="flex flex-col gap-4 items-start">
|
|
121
|
+
<EmptyState
|
|
122
|
+
icon="i-hugeicons-mail-send-01"
|
|
123
|
+
:title="modelName() + ' records are added by invitation'"
|
|
124
|
+
description="The account is created and the person is emailed a link to choose their own password."
|
|
125
|
+
/>
|
|
126
|
+
<Button variant="primary" @click="openInvite">{{ 'Invite ' + modelName().toLowerCase() }}</Button>
|
|
127
|
+
</div>
|
|
128
|
+
|
|
130
129
|
<form :if="!loading() && canCreate()" id="model-create-form" class="flex flex-col gap-6" @submit.prevent="create">
|
|
131
130
|
<div :if="createError()" 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">
|
|
132
131
|
{{ createError() }}
|
|
@@ -138,49 +137,8 @@ onMount(() => {
|
|
|
138
137
|
<h2 class="font-semibold text-base text-neutral-900 dark:text-white">{{ modelName() }} Details</h2>
|
|
139
138
|
<p class="mt-1 text-neutral-500 text-xs dark:text-neutral-400">The fields a new {{ modelName().toLowerCase() }} can be given. Anything else is set by the application.</p>
|
|
140
139
|
</div>
|
|
141
|
-
<div class="
|
|
142
|
-
<
|
|
143
|
-
<label :if="field.type === 'boolean'" class="flex gap-3 items-start p-3 border border-neutral-200 rounded-lg dark:border-neutral-700">
|
|
144
|
-
<input
|
|
145
|
-
:name="field.name"
|
|
146
|
-
type="checkbox"
|
|
147
|
-
:checked="Boolean(values()[field.name])"
|
|
148
|
-
:disabled="creating()"
|
|
149
|
-
class="mt-0.5 h-4 w-4 text-blue-600 border-neutral-300 rounded"
|
|
150
|
-
@change="setValue(field.name, $event.target.checked)"
|
|
151
|
-
/>
|
|
152
|
-
<span>
|
|
153
|
-
<span class="block font-medium text-neutral-900 text-sm dark:text-white">{{ field.label }}</span>
|
|
154
|
-
<span :if="fieldError(field.name)" class="block mt-0.5 text-red-600 text-xs dark:text-red-400">{{ fieldError(field.name) }}</span>
|
|
155
|
-
</span>
|
|
156
|
-
</label>
|
|
157
|
-
|
|
158
|
-
<Select
|
|
159
|
-
:if="field.type === 'enum'"
|
|
160
|
-
:name="field.name"
|
|
161
|
-
:value="fieldValue(field.name)"
|
|
162
|
-
:options="field.options"
|
|
163
|
-
:label="field.label"
|
|
164
|
-
:ariaLabel="field.label"
|
|
165
|
-
:required="field.required"
|
|
166
|
-
:disabled="creating()"
|
|
167
|
-
:error="fieldError(field.name)"
|
|
168
|
-
@update:value="setValue(field.name, $event)"
|
|
169
|
-
/>
|
|
170
|
-
|
|
171
|
-
<Input
|
|
172
|
-
:if="field.type !== 'boolean' && field.type !== 'enum'"
|
|
173
|
-
:name="field.name"
|
|
174
|
-
:value="fieldValue(field.name)"
|
|
175
|
-
:type="inputType(field)"
|
|
176
|
-
:label="field.label"
|
|
177
|
-
:ariaLabel="field.label"
|
|
178
|
-
:required="field.required"
|
|
179
|
-
:disabled="creating()"
|
|
180
|
-
:error="fieldError(field.name)"
|
|
181
|
-
@update:value="setValue(field.name, $event)"
|
|
182
|
-
/>
|
|
183
|
-
</div>
|
|
140
|
+
<div class="p-6">
|
|
141
|
+
<ModelFieldInputs :fields="fields()" :values="values()" :errors="createErrors()" :disabled="creating()" @change="setValue" />
|
|
184
142
|
</div>
|
|
185
143
|
</Card>
|
|
186
144
|
</div>
|
|
@@ -6,8 +6,8 @@
|
|
|
6
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
7
|
// has an address to share, open in a tab and come back to.
|
|
8
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'
|
|
9
|
+
import type { ModelRecord, ModelRelatedPanel } from '../../../../functions/dashboard-model-record'
|
|
10
|
+
import { deleteModelRecord, fetchModelRecord, fetchModelRelated, modelDeleteNotice, modelDeleteWarning, modelRecordBackHref, modelRecordEditHref, modelRecordHref, modelRecordListLabel, modelRecordSections, modelRecordTitle } from '../../../../functions/dashboard-model-record'
|
|
11
11
|
import { pushToast } from '../../../../functions/toasts'
|
|
12
12
|
|
|
13
13
|
const navigation = useNavigation()
|
|
@@ -28,20 +28,31 @@ function recordId(): string {
|
|
|
28
28
|
|
|
29
29
|
const from = navigation.urlQuery('from')
|
|
30
30
|
const backHref = derived(() => modelRecordBackHref(slug(), from))
|
|
31
|
+
/** This page, for a form opened from one of its panels to come back to. */
|
|
32
|
+
const selfHref = derived(() => modelRecordHref(slug(), recordId()))
|
|
31
33
|
/** The list in the breadcrumb: "Users" for /data/users, else the model's table. */
|
|
32
34
|
const listLabel = derived(() => modelRecordListLabel(record(), backHref()))
|
|
33
35
|
|
|
34
36
|
const modelName = derived(() => record()?.modelName || 'Record')
|
|
35
37
|
const title = derived(() => record() ? modelRecordTitle(record()!) : '')
|
|
38
|
+
// Who points at this record: its panels. Also after the record itself.
|
|
39
|
+
const related = state<ModelRelatedPanel[]>([])
|
|
40
|
+
// The records this one points at come named with it; one that is gone reads "Team #3".
|
|
36
41
|
const sections = derived(() => record() ? modelRecordSections(record()!) : [])
|
|
37
|
-
|
|
38
|
-
|
|
42
|
+
// An anonymized account has nothing left to edit, and deleting it again
|
|
43
|
+
// would only anonymize what already is. The note below says what it is.
|
|
44
|
+
const canEdit = derived(() => Boolean(record()?.writeCapabilities.update) && !record()?.anonymized)
|
|
45
|
+
const canDelete = derived(() => Boolean(record()?.writeCapabilities.destroy) && !record()?.anonymized)
|
|
39
46
|
|
|
40
47
|
async function loadRecord(): Promise<void> {
|
|
41
48
|
loading.set(true)
|
|
42
49
|
loadError.set('')
|
|
43
50
|
try {
|
|
44
|
-
|
|
51
|
+
const loaded = await fetchModelRecord(slug(), recordId())
|
|
52
|
+
related.set([])
|
|
53
|
+
record.set(loaded)
|
|
54
|
+
// Not awaited, and a page whose panels cannot be read is still the record's page.
|
|
55
|
+
void fetchModelRelated(slug(), recordId()).then(panels => related.set(panels)).catch(() => related.set([]))
|
|
45
56
|
}
|
|
46
57
|
catch (error) {
|
|
47
58
|
record.set(null)
|
|
@@ -63,8 +74,9 @@ async function deleteRecord(): Promise<void> {
|
|
|
63
74
|
return
|
|
64
75
|
working.set(true)
|
|
65
76
|
try {
|
|
66
|
-
await deleteModelRecord(slug(), recordId())
|
|
67
|
-
|
|
77
|
+
const outcome = await deleteModelRecord(slug(), recordId())
|
|
78
|
+
const notice = modelDeleteNotice(`${current.modelName} ${recordId()}`, outcome)
|
|
79
|
+
pushToast('success', notice.title, { detail: notice.detail })
|
|
68
80
|
confirmingDelete.set(false)
|
|
69
81
|
navigate(backHref())
|
|
70
82
|
}
|
|
@@ -110,6 +122,11 @@ onMount(() => {
|
|
|
110
122
|
<Button variant="secondary" size="sm" @click="loadRecord">Try again</Button>
|
|
111
123
|
</div>
|
|
112
124
|
|
|
125
|
+
<div :if="!loading() && record()?.anonymized" role="note" class="flex gap-3 items-start px-4 py-3 text-neutral-700 text-sm dark:text-neutral-200 bg-neutral-100 dark:bg-white/5 border border-neutral-200 rounded-lg dark:border-neutral-700">
|
|
126
|
+
<span aria-hidden="true" class="flex-none mt-0.5 h-4 w-4 text-neutral-500 i-hugeicons-user-remove-01"></span>
|
|
127
|
+
<span>This account was anonymized. Its name and email were removed and it can no longer sign in. Records that refer to it were kept.</span>
|
|
128
|
+
</div>
|
|
129
|
+
|
|
113
130
|
<div :if="!loading() && record()" class="grid gap-6 grid-cols-1 items-start lg:grid-cols-2">
|
|
114
131
|
<div :for="section in sections()" class="min-w-0">
|
|
115
132
|
<Card padding="none">
|
|
@@ -124,6 +141,10 @@ onMount(() => {
|
|
|
124
141
|
</span>
|
|
125
142
|
<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
143
|
<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>
|
|
144
|
+
<StxLink :if="detail.kind === 'link'" :to="detail.href" class="inline-flex gap-1.5 items-center font-medium text-blue-600 dark:text-blue-400 hover:underline">
|
|
145
|
+
{{ detail.value }}
|
|
146
|
+
<span aria-hidden="true" class="h-3.5 w-3.5 i-hugeicons-arrow-right-01"></span>
|
|
147
|
+
</StxLink>
|
|
127
148
|
<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
149
|
</dd>
|
|
129
150
|
</div>
|
|
@@ -132,10 +153,17 @@ onMount(() => {
|
|
|
132
153
|
</div>
|
|
133
154
|
</div>
|
|
134
155
|
|
|
156
|
+
<ModelRelatedPanels
|
|
157
|
+
:if="!loading() && record() && related().length > 0"
|
|
158
|
+
:panels="related()"
|
|
159
|
+
:parentId="recordId()"
|
|
160
|
+
:from="selfHref()"
|
|
161
|
+
/>
|
|
162
|
+
|
|
135
163
|
<ConfirmDialog
|
|
136
164
|
:isOpen="confirmingDelete()"
|
|
137
165
|
:title="'Delete this ' + modelName().toLowerCase() + '?'"
|
|
138
|
-
:description="(title() || modelName()
|
|
166
|
+
:description="modelDeleteWarning(title() || modelName(), Boolean(record()?.writeCapabilities.anonymize))"
|
|
139
167
|
:busy="working()"
|
|
140
168
|
:confirmLabel="working() ? 'Deleting' : 'Delete'"
|
|
141
169
|
@close="confirmingDelete.set(false)"
|
|
@@ -5,17 +5,20 @@
|
|
|
5
5
|
// them, read only, as context. Saving sends only what changed, then returns
|
|
6
6
|
// to where the visitor came from: the record's page, or the list.
|
|
7
7
|
import { useNavigation } from '@stacksjs/defaults/views/dashboard/composables/useNavigation'
|
|
8
|
-
import type { ModelRecord } from '../../../../functions/dashboard-model-record'
|
|
9
|
-
import {
|
|
8
|
+
import type { ModelFormValues, ModelRecord } from '../../../../functions/dashboard-model-record'
|
|
9
|
+
import { fetchModelRecord, modelFormPayload, modelFormValues, modelRecordBackHref, modelRecordHref, modelRecordListLabel, modelRecordSections, updateModelRecord } from '../../../../functions/dashboard-model-record'
|
|
10
10
|
import { pushToast } from '../../../../functions/toasts'
|
|
11
11
|
|
|
12
12
|
const navigation = useNavigation()
|
|
13
13
|
const record = state<ModelRecord | null>(null)
|
|
14
|
-
const values = state<
|
|
14
|
+
const values = state<ModelFormValues>({})
|
|
15
|
+
/** What the form started with, so a save sends only what was changed. */
|
|
16
|
+
const initial = state<ModelFormValues>({})
|
|
15
17
|
const loading = state(true)
|
|
16
18
|
const loadError = state('')
|
|
17
19
|
const saving = state(false)
|
|
18
20
|
const saveError = state('')
|
|
21
|
+
const saveErrors = state<Record<string, string[]>>({})
|
|
19
22
|
|
|
20
23
|
// `/models/{slug}/{id}/edit`
|
|
21
24
|
function slug(): string {
|
|
@@ -35,7 +38,7 @@ const returnHref = derived(() => cameFromView ? viewHref() : listHref())
|
|
|
35
38
|
const listLabel = derived(() => modelRecordListLabel(record(), listHref()))
|
|
36
39
|
const modelName = derived(() => record()?.modelName || 'Record')
|
|
37
40
|
|
|
38
|
-
const writable = derived(() => record()
|
|
41
|
+
const writable = derived(() => record()?.fields ?? [])
|
|
39
42
|
/** What cannot be changed here, formatted as the record's page shows it. */
|
|
40
43
|
const context = derived(() => {
|
|
41
44
|
const current = record()
|
|
@@ -45,10 +48,11 @@ const context = derived(() => {
|
|
|
45
48
|
.flatMap(section => section.details)
|
|
46
49
|
.filter(detail => !current.updateColumns.includes(detail.name))
|
|
47
50
|
})
|
|
48
|
-
const
|
|
51
|
+
const anonymized = derived(() => Boolean(record()?.anonymized))
|
|
52
|
+
const canEdit = derived(() => Boolean(record()?.writeCapabilities.update) && writable().length > 0 && !anonymized())
|
|
49
53
|
|
|
50
|
-
function
|
|
51
|
-
values.set({ ...values(), [
|
|
54
|
+
function setValue(change: { name: string, value: string | boolean }): void {
|
|
55
|
+
values.set({ ...values(), [change.name]: change.value })
|
|
52
56
|
}
|
|
53
57
|
|
|
54
58
|
async function loadRecord(): Promise<void> {
|
|
@@ -57,7 +61,9 @@ async function loadRecord(): Promise<void> {
|
|
|
57
61
|
try {
|
|
58
62
|
const loaded = await fetchModelRecord(slug(), recordId())
|
|
59
63
|
record.set(loaded)
|
|
60
|
-
|
|
64
|
+
const start = modelFormValues(loaded.fields, loaded.row)
|
|
65
|
+
initial.set(start)
|
|
66
|
+
values.set({ ...start })
|
|
61
67
|
}
|
|
62
68
|
catch (error) {
|
|
63
69
|
record.set(null)
|
|
@@ -72,24 +78,25 @@ async function save(): Promise<void> {
|
|
|
72
78
|
const current = record()
|
|
73
79
|
if (!current || saving())
|
|
74
80
|
return
|
|
75
|
-
const fields =
|
|
81
|
+
const fields = modelFormPayload(current.fields, values(), initial())
|
|
76
82
|
if (Object.keys(fields).length === 0) {
|
|
77
83
|
navigate(returnHref())
|
|
78
84
|
return
|
|
79
85
|
}
|
|
80
86
|
saving.set(true)
|
|
81
87
|
saveError.set('')
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
saveError.set(error
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
saving.set(false)
|
|
88
|
+
saveErrors.set({})
|
|
89
|
+
const result = await updateModelRecord(slug(), recordId(), fields)
|
|
90
|
+
saving.set(false)
|
|
91
|
+
if (!result.ok) {
|
|
92
|
+
// A refusal says which field and why; "Validation failed" alone left the
|
|
93
|
+
// visitor to guess which of the inputs it meant.
|
|
94
|
+
saveError.set(result.error)
|
|
95
|
+
saveErrors.set(result.errors)
|
|
96
|
+
return
|
|
92
97
|
}
|
|
98
|
+
pushToast('success', `${current.modelName} ${recordId()} updated`)
|
|
99
|
+
navigate(returnHref())
|
|
93
100
|
}
|
|
94
101
|
|
|
95
102
|
function cancel(): void {
|
|
@@ -125,12 +132,19 @@ onMount(() => {
|
|
|
125
132
|
</div>
|
|
126
133
|
|
|
127
134
|
<EmptyState
|
|
128
|
-
:if="!loading() && record() && !canEdit()"
|
|
135
|
+
:if="!loading() && record() && !canEdit() && !anonymized()"
|
|
129
136
|
icon="i-hugeicons-square-lock-02"
|
|
130
137
|
:title="modelName() + ' records cannot be edited here'"
|
|
131
138
|
description="This model does not allow changes through the dashboard. You can still view the record."
|
|
132
139
|
/>
|
|
133
140
|
|
|
141
|
+
<EmptyState
|
|
142
|
+
:if="!loading() && anonymized()"
|
|
143
|
+
icon="i-hugeicons-user-remove-01"
|
|
144
|
+
title="This account was anonymized"
|
|
145
|
+
description="Its name and email were removed and it can no longer sign in, so there is nothing to edit. Records that refer to it were kept."
|
|
146
|
+
/>
|
|
147
|
+
|
|
134
148
|
<form :if="!loading() && canEdit()" id="model-edit-form" class="flex flex-col gap-6" @submit.prevent="save">
|
|
135
149
|
<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
150
|
{{ saveError() }}
|
|
@@ -139,18 +153,8 @@ onMount(() => {
|
|
|
139
153
|
<div class="grid gap-6 grid-cols-1 items-start lg:grid-cols-2">
|
|
140
154
|
<Card padding="none">
|
|
141
155
|
<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="
|
|
143
|
-
<
|
|
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>
|
|
156
|
+
<div class="p-6">
|
|
157
|
+
<ModelFieldInputs :fields="writable()" :values="values()" :errors="saveErrors()" :disabled="saving()" @change="setValue" />
|
|
154
158
|
</div>
|
|
155
159
|
</Card>
|
|
156
160
|
|