@open-mercato/cli 0.11.1-develop.8665.1.2455b2503c → 0.11.1-develop.8724.1.beb07a9e96
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/.turbo/turbo-build.log +4 -2
- package/dist/agentic/guides/module-facts.json +1884 -195
- package/dist/agentic/guides/module-facts.v2.json +1884 -195
- package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
- package/dist/agentic/guides/modules/ai_assistant/index.md +1 -1
- package/dist/agentic/guides/modules/api_docs/index.md +1 -1
- package/dist/agentic/guides/modules/api_keys/index.md +1 -1
- package/dist/agentic/guides/modules/assisted_selling/index.md +1 -1
- package/dist/agentic/guides/modules/attachments/index.md +1 -1
- package/dist/agentic/guides/modules/audit_logs/index.md +1 -1
- package/dist/agentic/guides/modules/auth/index.md +1 -1
- package/dist/agentic/guides/modules/availability/index.md +1 -1
- package/dist/agentic/guides/modules/backups/index.md +1 -1
- package/dist/agentic/guides/modules/business_rules/index.md +1 -1
- package/dist/agentic/guides/modules/carrier_inpost/index.md +1 -1
- package/dist/agentic/guides/modules/cart/index.md +1 -1
- package/dist/agentic/guides/modules/catalog/index.md +1 -1
- package/dist/agentic/guides/modules/channel_apns/index.md +1 -1
- package/dist/agentic/guides/modules/channel_discord/index.md +1 -1
- package/dist/agentic/guides/modules/channel_expo/index.md +1 -1
- package/dist/agentic/guides/modules/channel_fcm/index.md +1 -1
- package/dist/agentic/guides/modules/channel_gmail/index.md +1 -1
- package/dist/agentic/guides/modules/channel_imap/index.md +1 -1
- package/dist/agentic/guides/modules/channel_resend/index.md +1 -1
- package/dist/agentic/guides/modules/channel_ses/index.md +1 -1
- package/dist/agentic/guides/modules/channel_smtp/index.md +1 -1
- package/dist/agentic/guides/modules/checkout/index.md +1 -1
- package/dist/agentic/guides/modules/communication_channels/exact-override-targets.md +1 -1
- package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
- package/dist/agentic/guides/modules/communication_channels/workers.md +1 -1
- package/dist/agentic/guides/modules/configs/index.md +1 -1
- package/dist/agentic/guides/modules/content/index.md +1 -1
- package/dist/agentic/guides/modules/currencies/active-extension-bindings.md +11 -0
- package/dist/agentic/guides/modules/currencies/di-registrations-rich.md +1 -1
- package/dist/agentic/guides/modules/currencies/di-service-tokens.md +1 -1
- package/dist/agentic/guides/modules/currencies/exact-override-targets.md +1 -1
- package/dist/agentic/guides/modules/currencies/index.md +3 -2
- package/dist/agentic/guides/modules/customer_accounts/index.md +1 -1
- package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
- package/dist/agentic/guides/modules/customers/index.md +1 -1
- package/dist/agentic/guides/modules/dashboards/index.md +1 -1
- package/dist/agentic/guides/modules/data_sync/index.md +1 -1
- package/dist/agentic/guides/modules/design_system/index.md +1 -1
- package/dist/agentic/guides/modules/devices/index.md +1 -1
- package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
- package/dist/agentic/guides/modules/directory/index.md +1 -1
- package/dist/agentic/guides/modules/documents/index.md +1 -1
- package/dist/agentic/guides/modules/ecommerce/index.md +1 -1
- package/dist/agentic/guides/modules/entities/index.md +1 -1
- package/dist/agentic/guides/modules/eudr/index.md +1 -1
- package/dist/agentic/guides/modules/events/exact-override-targets.md +1 -1
- package/dist/agentic/guides/modules/events/index.md +1 -1
- package/dist/agentic/guides/modules/events/workers.md +1 -1
- package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
- package/dist/agentic/guides/modules/forms/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_autopay/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_tpay/index.md +1 -1
- package/dist/agentic/guides/modules/generators/index.md +1 -1
- package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
- package/dist/agentic/guides/modules/integrations/index.md +1 -1
- package/dist/agentic/guides/modules/ledger/acl-features.md +16 -0
- package/dist/agentic/guides/modules/ledger/active-extension-bindings.md +11 -0
- package/dist/agentic/guides/modules/ledger/backend-pages.md +21 -0
- package/dist/agentic/guides/modules/ledger/domain-commands.md +22 -0
- package/dist/agentic/guides/modules/ledger/encryption.md +11 -0
- package/dist/agentic/guides/modules/ledger/entities.md +17 -0
- package/dist/agentic/guides/modules/ledger/events.md +19 -0
- package/dist/agentic/guides/modules/ledger/exact-override-targets.md +30 -0
- package/dist/agentic/guides/modules/ledger/index.md +22 -0
- package/dist/agentic/guides/modules/ledger/owned-contract-module-metadata.md +11 -0
- package/dist/agentic/guides/modules/ledger/setup.md +11 -0
- package/dist/agentic/guides/modules/ledger/umes-hosts.md +26 -0
- package/dist/agentic/guides/modules/messages/index.md +1 -1
- package/dist/agentic/guides/modules/notifications/index.md +1 -1
- package/dist/agentic/guides/modules/onboarding/index.md +1 -1
- package/dist/agentic/guides/modules/payment_gateways/active-extension-bindings.md +1 -1
- package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
- package/dist/agentic/guides/modules/perspectives/index.md +1 -1
- package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
- package/dist/agentic/guides/modules/planner/index.md +1 -1
- package/dist/agentic/guides/modules/portal/index.md +1 -1
- package/dist/agentic/guides/modules/progress/index.md +1 -1
- package/dist/agentic/guides/modules/promotions/index.md +1 -1
- package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
- package/dist/agentic/guides/modules/query_index/index.md +1 -1
- package/dist/agentic/guides/modules/record_locks/index.md +1 -1
- package/dist/agentic/guides/modules/resources/index.md +1 -1
- package/dist/agentic/guides/modules/sales/index.md +1 -1
- package/dist/agentic/guides/modules/scheduler/index.md +1 -1
- package/dist/agentic/guides/modules/search/index.md +1 -1
- package/dist/agentic/guides/modules/security/index.md +1 -1
- package/dist/agentic/guides/modules/seeds/index.md +1 -1
- package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
- package/dist/agentic/guides/modules/sso/index.md +1 -1
- package/dist/agentic/guides/modules/staff/index.md +1 -1
- package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
- package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
- package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
- package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
- package/dist/agentic/guides/modules/telemetry/index.md +1 -1
- package/dist/agentic/guides/modules/tillio/index.md +1 -1
- package/dist/agentic/guides/modules/translations/index.md +1 -1
- package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
- package/dist/agentic/guides/modules/webhooks/index.md +1 -1
- package/dist/agentic/guides/modules/wms/index.md +1 -1
- package/dist/agentic/guides/modules/workflows/di-registrations-rich.md +11 -10
- package/dist/agentic/guides/modules/workflows/di-service-tokens.md +11 -10
- package/dist/agentic/guides/modules/workflows/exact-override-targets.md +11 -10
- package/dist/agentic/guides/modules/workflows/index.md +1 -1
- package/dist/agentic/guides/reference-module-facts.json +2 -2
- package/dist/agentic/guides/reference-modules/example/index.md +1 -1
- package/dist/agentic/guides/upstream/AGENTS.md +4 -4
- package/dist/agentic/guides/upstream/manifest.json +2 -2
- package/dist/agentic/shared/AGENTS.md.template +1 -1
- package/dist/agentic/shared/ai/harness/cases.json +1 -1
- package/dist/lib/scaffold/field-dsl.js +393 -0
- package/dist/lib/scaffold/field-dsl.js.map +7 -0
- package/dist/lib/scaffold/index.js +412 -0
- package/dist/lib/scaffold/index.js.map +7 -0
- package/dist/lib/scaffold/targets.js +42 -0
- package/dist/lib/scaffold/targets.js.map +7 -0
- package/dist/lib/scaffold/templates/create-page.js +52 -0
- package/dist/lib/scaffold/templates/create-page.js.map +7 -0
- package/dist/lib/scaffold/templates/detail-page.js +186 -0
- package/dist/lib/scaffold/templates/detail-page.js.map +7 -0
- package/dist/lib/scaffold/templates/form-config.js +42 -0
- package/dist/lib/scaffold/templates/form-config.js.map +7 -0
- package/dist/lib/scaffold/templates/index.js +27 -0
- package/dist/lib/scaffold/templates/index.js.map +7 -0
- package/dist/lib/scaffold/templates/list-page.js +190 -0
- package/dist/lib/scaffold/templates/list-page.js.map +7 -0
- package/dist/lib/scaffold/templates/metas.js +47 -0
- package/dist/lib/scaffold/templates/metas.js.map +7 -0
- package/dist/lib/scaffold/templates/module-files.js +85 -0
- package/dist/lib/scaffold/templates/module-files.js.map +7 -0
- package/dist/lib/testing/integration-discovery.js +32 -3
- package/dist/lib/testing/integration-discovery.js.map +2 -2
- package/dist/lib/testing/integration.js +232 -8
- package/dist/lib/testing/integration.js.map +2 -2
- package/dist/lib/worker-job-handler.js +7 -1
- package/dist/lib/worker-job-handler.js.map +2 -2
- package/dist/mercato.js +6 -1
- package/dist/mercato.js.map +2 -2
- package/package.json +7 -7
- package/src/lib/__tests__/agentic-workflows-ownership.test.ts +79 -0
- package/src/lib/__tests__/worker-job-handler.test.ts +30 -0
- package/src/lib/scaffold/__tests__/__snapshots__/scaffold-golden.test.ts.snap +1742 -0
- package/src/lib/scaffold/__tests__/fixtures/typescript-toolchain.cjs +5 -0
- package/src/lib/scaffold/__tests__/helpers.ts +75 -0
- package/src/lib/scaffold/__tests__/scaffold-ds-contract.test.ts +275 -0
- package/src/lib/scaffold/__tests__/scaffold-golden.test.ts +267 -0
- package/src/lib/scaffold/__tests__/scaffold-runtime.test.tsx +193 -0
- package/src/lib/scaffold/field-dsl.ts +491 -0
- package/src/lib/scaffold/index.ts +531 -0
- package/src/lib/scaffold/targets.ts +68 -0
- package/src/lib/scaffold/templates/create-page.ts +52 -0
- package/src/lib/scaffold/templates/detail-page.ts +190 -0
- package/src/lib/scaffold/templates/form-config.ts +42 -0
- package/src/lib/scaffold/templates/index.ts +27 -0
- package/src/lib/scaffold/templates/list-page.ts +190 -0
- package/src/lib/scaffold/templates/metas.ts +48 -0
- package/src/lib/scaffold/templates/module-files.ts +87 -0
- package/src/lib/testing/__tests__/integration-app-only-playwright.test.ts +225 -0
- package/src/lib/testing/__tests__/integration-app-only.test.ts +320 -0
- package/src/lib/testing/__tests__/integration-discovery.test.ts +45 -1
- package/src/lib/testing/integration-discovery.ts +32 -2
- package/src/lib/testing/integration.ts +293 -11
- package/src/lib/worker-job-handler.ts +17 -1
- package/src/mercato.ts +7 -1
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
const detailPageTemplate = `"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import { useRouter } from 'next/navigation'
|
|
5
|
+
import { Page, PageBody } from '@open-mercato/ui/backend/Page'
|
|
6
|
+
import { CrudForm } from '@open-mercato/ui/backend/CrudForm'
|
|
7
|
+
import { FormHeader } from '@open-mercato/ui/backend/forms/FormHeader'
|
|
8
|
+
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@open-mercato/ui/primitives/tabs'
|
|
9
|
+
import { LoadingMessage, ErrorMessage } from '@open-mercato/ui/backend/detail'
|
|
10
|
+
import { apiCall, withScopedApiRequestHeaders } from '@open-mercato/ui/backend/utils/apiCall'
|
|
11
|
+
import { updateCrud, deleteCrud } from '@open-mercato/ui/backend/utils/crud'
|
|
12
|
+
import { buildOptimisticLockHeader } from '@open-mercato/ui/backend/utils/optimisticLock'
|
|
13
|
+
import { useGuardedMutation } from '@open-mercato/ui/backend/injection/useGuardedMutation'
|
|
14
|
+
import { flash } from '@open-mercato/ui/backend/FlashMessages'
|
|
15
|
+
import { useConfirmDialog } from '@open-mercato/ui/backend/confirm-dialog'
|
|
16
|
+
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
17
|
+
import { getTelemetryRuntime } from '@open-mercato/shared/lib/telemetry/runtime'
|
|
18
|
+
import { {{entityCamel}}UpdateSchema, type {{entityPascal}}UpdateInput } from '../../../data/validators'
|
|
19
|
+
{{statusImports}}import {
|
|
20
|
+
{{entityUpperSnake}}_ENTITY_ID,
|
|
21
|
+
create{{entityPascal}}FormFields,
|
|
22
|
+
create{{entityPascal}}FormGroups,
|
|
23
|
+
} from '../../../components/formConfig'
|
|
24
|
+
|
|
25
|
+
type {{entityPascal}}Record = {
|
|
26
|
+
id: string
|
|
27
|
+
updatedAt?: string | null
|
|
28
|
+
{{rowTypeFields}}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type {{entityPascal}}ListResponse = {
|
|
32
|
+
items: {{entityPascal}}Record[]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default function {{entityPascal}}DetailPage({ params }: { params?: { id?: string } }) {
|
|
36
|
+
const t = useT()
|
|
37
|
+
const router = useRouter()
|
|
38
|
+
const id = typeof params?.id === 'string' ? params.id : null
|
|
39
|
+
const { confirm, ConfirmDialogElement } = useConfirmDialog()
|
|
40
|
+
const { runMutation, retryLastMutation } = useGuardedMutation({ contextId: '{{moduleId}}.detail' })
|
|
41
|
+
const [record, setRecord] = React.useState<{{entityPascal}}Record | null>(null)
|
|
42
|
+
const [isLoading, setIsLoading] = React.useState(true)
|
|
43
|
+
const [loadError, setLoadError] = React.useState<string | null>(null)
|
|
44
|
+
const [reloadToken, setReloadToken] = React.useState(0)
|
|
45
|
+
|
|
46
|
+
React.useEffect(() => {
|
|
47
|
+
let cancelled = false
|
|
48
|
+
async function load() {
|
|
49
|
+
if (!id) {
|
|
50
|
+
setLoadError(t('{{moduleId}}.detail.notFound', '{{entityTitle}} not found'))
|
|
51
|
+
setIsLoading(false)
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
setIsLoading(true)
|
|
55
|
+
setLoadError(null)
|
|
56
|
+
try {
|
|
57
|
+
const query = new URLSearchParams({ ids: id, pageSize: '1' })
|
|
58
|
+
const call = await apiCall<{{entityPascal}}ListResponse>('/api/{{moduleId}}?' + query.toString())
|
|
59
|
+
if (cancelled) return
|
|
60
|
+
if (!call.ok) {
|
|
61
|
+
setLoadError(t('{{moduleId}}.detail.loadError', 'Failed to load {{entityLower}}'))
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
const item = call.result?.items?.[0] ?? null
|
|
65
|
+
if (!item) {
|
|
66
|
+
setLoadError(t('{{moduleId}}.detail.notFound', '{{entityTitle}} not found'))
|
|
67
|
+
return
|
|
68
|
+
}
|
|
69
|
+
setRecord(item)
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if (cancelled) return
|
|
72
|
+
getTelemetryRuntime()?.reportError(error, { module: '{{moduleId}}', code: '{{moduleId}}.detail_load_failed' })
|
|
73
|
+
setLoadError(t('{{moduleId}}.detail.loadError', 'Failed to load {{entityLower}}'))
|
|
74
|
+
} finally {
|
|
75
|
+
if (!cancelled) setIsLoading(false)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
void load()
|
|
79
|
+
return () => { cancelled = true }
|
|
80
|
+
}, [id, reloadToken, t])
|
|
81
|
+
|
|
82
|
+
const fields = React.useMemo(() => create{{entityPascal}}FormFields(t), [t])
|
|
83
|
+
const groups = React.useMemo(() => create{{entityPascal}}FormGroups(t), [t])
|
|
84
|
+
|
|
85
|
+
// updatedAt MUST stay in initialValues: CrudForm auto-derives the
|
|
86
|
+
// x-om-ext-optimistic-lock-expected-updated-at header from it on submit AND delete.
|
|
87
|
+
const initialValues = React.useMemo<Partial<{{entityPascal}}UpdateInput> | undefined>(() => {
|
|
88
|
+
if (!record) return undefined
|
|
89
|
+
return {
|
|
90
|
+
id: record.id,
|
|
91
|
+
updatedAt: record.updatedAt ?? undefined,
|
|
92
|
+
{{initialValueLines}}
|
|
93
|
+
}
|
|
94
|
+
}, [record])
|
|
95
|
+
|
|
96
|
+
const handleDelete = React.useCallback(async () => {
|
|
97
|
+
if (!record) return
|
|
98
|
+
const confirmed = await confirm({
|
|
99
|
+
title: t('{{moduleId}}.delete.confirmTitle', 'Delete {{entityLower}}?'),
|
|
100
|
+
description: t('{{moduleId}}.delete.confirmDescription', 'This action cannot be undone.'),
|
|
101
|
+
variant: 'destructive',
|
|
102
|
+
})
|
|
103
|
+
if (!confirmed) return
|
|
104
|
+
try {
|
|
105
|
+
await runMutation({
|
|
106
|
+
operation: () =>
|
|
107
|
+
withScopedApiRequestHeaders(
|
|
108
|
+
buildOptimisticLockHeader(record.updatedAt ?? undefined),
|
|
109
|
+
() => deleteCrud('{{moduleId}}', record.id),
|
|
110
|
+
),
|
|
111
|
+
context: {
|
|
112
|
+
formId: '{{moduleId}}.detail',
|
|
113
|
+
resourceKind: '{{moduleId}}.{{entitySnake}}',
|
|
114
|
+
resourceId: record.id,
|
|
115
|
+
retryLastMutation,
|
|
116
|
+
},
|
|
117
|
+
mutationPayload: { id: record.id },
|
|
118
|
+
})
|
|
119
|
+
flash(t('{{moduleId}}.delete.success', '{{entityTitle}} deleted'), 'success')
|
|
120
|
+
router.push('/backend/{{moduleId}}')
|
|
121
|
+
} catch {
|
|
122
|
+
flash(t('{{moduleId}}.delete.error', 'Failed to delete {{entityLower}}'), 'error')
|
|
123
|
+
}
|
|
124
|
+
}, [confirm, record, retryLastMutation, router, runMutation, t])
|
|
125
|
+
|
|
126
|
+
if (isLoading) {
|
|
127
|
+
return (
|
|
128
|
+
<Page>
|
|
129
|
+
<PageBody>
|
|
130
|
+
<LoadingMessage label={t('{{moduleId}}.detail.loading', 'Loading {{entityLower}}')} />
|
|
131
|
+
</PageBody>
|
|
132
|
+
</Page>
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (loadError || !record) {
|
|
137
|
+
return (
|
|
138
|
+
<Page>
|
|
139
|
+
<PageBody>
|
|
140
|
+
<ErrorMessage label={loadError ?? t('{{moduleId}}.detail.notFound', '{{entityTitle}} not found')} />
|
|
141
|
+
</PageBody>
|
|
142
|
+
</Page>
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
<Page>
|
|
148
|
+
<PageBody>
|
|
149
|
+
<FormHeader
|
|
150
|
+
mode="detail"
|
|
151
|
+
backHref="/backend/{{moduleId}}"
|
|
152
|
+
title={{{detailTitleExpr}}}
|
|
153
|
+
{{statusBadgeProp}} onDelete={() => { void handleDelete() }}
|
|
154
|
+
deleteLabel={t('{{moduleId}}.detail.actions.delete', 'Delete')}
|
|
155
|
+
/>
|
|
156
|
+
<Tabs defaultValue="overview" variant="underline" className="mt-4">
|
|
157
|
+
<TabsList aria-label={t('{{moduleId}}.detail.tabs.label', '{{entityTitle}} sections')}>
|
|
158
|
+
<TabsTrigger value="overview">{t('{{moduleId}}.detail.tabs.overview', 'Overview')}</TabsTrigger>
|
|
159
|
+
{/* Extension point: add related-entity tabs here (activity, attachments, ...). */}
|
|
160
|
+
</TabsList>
|
|
161
|
+
<TabsContent value="overview">
|
|
162
|
+
<CrudForm<{{entityPascal}}UpdateInput>
|
|
163
|
+
schema={{{entityCamel}}UpdateSchema}
|
|
164
|
+
fields={fields}
|
|
165
|
+
groups={groups}
|
|
166
|
+
initialValues={initialValues}
|
|
167
|
+
entityIds={[{{entityUpperSnake}}_ENTITY_ID]}
|
|
168
|
+
submitLabel={t('{{moduleId}}.form.submit', 'Save')}
|
|
169
|
+
onSubmit={async (values) => {
|
|
170
|
+
await updateCrud('{{moduleId}}', values)
|
|
171
|
+
flash(t('{{moduleId}}.detail.updateSuccess', '{{entityTitle}} updated'), 'success')
|
|
172
|
+
setReloadToken((token) => token + 1)
|
|
173
|
+
}}
|
|
174
|
+
/>
|
|
175
|
+
</TabsContent>
|
|
176
|
+
</Tabs>
|
|
177
|
+
</PageBody>
|
|
178
|
+
{ConfirmDialogElement}
|
|
179
|
+
</Page>
|
|
180
|
+
)
|
|
181
|
+
}
|
|
182
|
+
`;
|
|
183
|
+
export {
|
|
184
|
+
detailPageTemplate
|
|
185
|
+
};
|
|
186
|
+
//# sourceMappingURL=detail-page.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/lib/scaffold/templates/detail-page.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Detail page template (lineage: om-ds-guardian page-templates.md \u00A7Detail Page,\n * upgraded to the shipped primitives: FormHeader mode=\"detail\" + Tabs\n * variant=\"underline\", optimistic locking via initialValues.updatedAt).\n *\n * Deliberately stays on public primitives \u2014 the customers module's\n * DetailTabsLayout is module-internal and MUST NOT be copied here.\n */\nexport const detailPageTemplate = `\"use client\"\n\nimport * as React from 'react'\nimport { useRouter } from 'next/navigation'\nimport { Page, PageBody } from '@open-mercato/ui/backend/Page'\nimport { CrudForm } from '@open-mercato/ui/backend/CrudForm'\nimport { FormHeader } from '@open-mercato/ui/backend/forms/FormHeader'\nimport { Tabs, TabsContent, TabsList, TabsTrigger } from '@open-mercato/ui/primitives/tabs'\nimport { LoadingMessage, ErrorMessage } from '@open-mercato/ui/backend/detail'\nimport { apiCall, withScopedApiRequestHeaders } from '@open-mercato/ui/backend/utils/apiCall'\nimport { updateCrud, deleteCrud } from '@open-mercato/ui/backend/utils/crud'\nimport { buildOptimisticLockHeader } from '@open-mercato/ui/backend/utils/optimisticLock'\nimport { useGuardedMutation } from '@open-mercato/ui/backend/injection/useGuardedMutation'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { useConfirmDialog } from '@open-mercato/ui/backend/confirm-dialog'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { getTelemetryRuntime } from '@open-mercato/shared/lib/telemetry/runtime'\nimport { {{entityCamel}}UpdateSchema, type {{entityPascal}}UpdateInput } from '../../../data/validators'\n{{statusImports}}import {\n {{entityUpperSnake}}_ENTITY_ID,\n create{{entityPascal}}FormFields,\n create{{entityPascal}}FormGroups,\n} from '../../../components/formConfig'\n\ntype {{entityPascal}}Record = {\n id: string\n updatedAt?: string | null\n{{rowTypeFields}}\n}\n\ntype {{entityPascal}}ListResponse = {\n items: {{entityPascal}}Record[]\n}\n\nexport default function {{entityPascal}}DetailPage({ params }: { params?: { id?: string } }) {\n const t = useT()\n const router = useRouter()\n const id = typeof params?.id === 'string' ? params.id : null\n const { confirm, ConfirmDialogElement } = useConfirmDialog()\n const { runMutation, retryLastMutation } = useGuardedMutation({ contextId: '{{moduleId}}.detail' })\n const [record, setRecord] = React.useState<{{entityPascal}}Record | null>(null)\n const [isLoading, setIsLoading] = React.useState(true)\n const [loadError, setLoadError] = React.useState<string | null>(null)\n const [reloadToken, setReloadToken] = React.useState(0)\n\n React.useEffect(() => {\n let cancelled = false\n async function load() {\n if (!id) {\n setLoadError(t('{{moduleId}}.detail.notFound', '{{entityTitle}} not found'))\n setIsLoading(false)\n return\n }\n setIsLoading(true)\n setLoadError(null)\n try {\n const query = new URLSearchParams({ ids: id, pageSize: '1' })\n const call = await apiCall<{{entityPascal}}ListResponse>('/api/{{moduleId}}?' + query.toString())\n if (cancelled) return\n if (!call.ok) {\n setLoadError(t('{{moduleId}}.detail.loadError', 'Failed to load {{entityLower}}'))\n return\n }\n const item = call.result?.items?.[0] ?? null\n if (!item) {\n setLoadError(t('{{moduleId}}.detail.notFound', '{{entityTitle}} not found'))\n return\n }\n setRecord(item)\n } catch (error) {\n if (cancelled) return\n getTelemetryRuntime()?.reportError(error, { module: '{{moduleId}}', code: '{{moduleId}}.detail_load_failed' })\n setLoadError(t('{{moduleId}}.detail.loadError', 'Failed to load {{entityLower}}'))\n } finally {\n if (!cancelled) setIsLoading(false)\n }\n }\n void load()\n return () => { cancelled = true }\n }, [id, reloadToken, t])\n\n const fields = React.useMemo(() => create{{entityPascal}}FormFields(t), [t])\n const groups = React.useMemo(() => create{{entityPascal}}FormGroups(t), [t])\n\n // updatedAt MUST stay in initialValues: CrudForm auto-derives the\n // x-om-ext-optimistic-lock-expected-updated-at header from it on submit AND delete.\n const initialValues = React.useMemo<Partial<{{entityPascal}}UpdateInput> | undefined>(() => {\n if (!record) return undefined\n return {\n id: record.id,\n updatedAt: record.updatedAt ?? undefined,\n{{initialValueLines}}\n }\n }, [record])\n\n const handleDelete = React.useCallback(async () => {\n if (!record) return\n const confirmed = await confirm({\n title: t('{{moduleId}}.delete.confirmTitle', 'Delete {{entityLower}}?'),\n description: t('{{moduleId}}.delete.confirmDescription', 'This action cannot be undone.'),\n variant: 'destructive',\n })\n if (!confirmed) return\n try {\n await runMutation({\n operation: () =>\n withScopedApiRequestHeaders(\n buildOptimisticLockHeader(record.updatedAt ?? undefined),\n () => deleteCrud('{{moduleId}}', record.id),\n ),\n context: {\n formId: '{{moduleId}}.detail',\n resourceKind: '{{moduleId}}.{{entitySnake}}',\n resourceId: record.id,\n retryLastMutation,\n },\n mutationPayload: { id: record.id },\n })\n flash(t('{{moduleId}}.delete.success', '{{entityTitle}} deleted'), 'success')\n router.push('/backend/{{moduleId}}')\n } catch {\n flash(t('{{moduleId}}.delete.error', 'Failed to delete {{entityLower}}'), 'error')\n }\n }, [confirm, record, retryLastMutation, router, runMutation, t])\n\n if (isLoading) {\n return (\n <Page>\n <PageBody>\n <LoadingMessage label={t('{{moduleId}}.detail.loading', 'Loading {{entityLower}}')} />\n </PageBody>\n </Page>\n )\n }\n\n if (loadError || !record) {\n return (\n <Page>\n <PageBody>\n <ErrorMessage label={loadError ?? t('{{moduleId}}.detail.notFound', '{{entityTitle}} not found')} />\n </PageBody>\n </Page>\n )\n }\n\n return (\n <Page>\n <PageBody>\n <FormHeader\n mode=\"detail\"\n backHref=\"/backend/{{moduleId}}\"\n title={{{detailTitleExpr}}}\n{{statusBadgeProp}} onDelete={() => { void handleDelete() }}\n deleteLabel={t('{{moduleId}}.detail.actions.delete', 'Delete')}\n />\n <Tabs defaultValue=\"overview\" variant=\"underline\" className=\"mt-4\">\n <TabsList aria-label={t('{{moduleId}}.detail.tabs.label', '{{entityTitle}} sections')}>\n <TabsTrigger value=\"overview\">{t('{{moduleId}}.detail.tabs.overview', 'Overview')}</TabsTrigger>\n {/* Extension point: add related-entity tabs here (activity, attachments, ...). */}\n </TabsList>\n <TabsContent value=\"overview\">\n <CrudForm<{{entityPascal}}UpdateInput>\n schema={{{entityCamel}}UpdateSchema}\n fields={fields}\n groups={groups}\n initialValues={initialValues}\n entityIds={[{{entityUpperSnake}}_ENTITY_ID]}\n submitLabel={t('{{moduleId}}.form.submit', 'Save')}\n onSubmit={async (values) => {\n await updateCrud('{{moduleId}}', values)\n flash(t('{{moduleId}}.detail.updateSuccess', '{{entityTitle}} updated'), 'success')\n setReloadToken((token) => token + 1)\n }}\n />\n </TabsContent>\n </Tabs>\n </PageBody>\n {ConfirmDialogElement}\n </Page>\n )\n}\n`\n"],
|
|
5
|
+
"mappings": "AAQO,MAAM,qBAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const formConfigTemplate = `import { z } from 'zod'
|
|
2
|
+
import type { CrudField, CrudFormGroup } from '@open-mercato/ui/backend/CrudForm'
|
|
3
|
+
import type { TranslateFn } from '@open-mercato/shared/lib/i18n/context'
|
|
4
|
+
import { {{entityCamel}}CreateSchema } from '../data/validators'
|
|
5
|
+
|
|
6
|
+
/** Entity id used to load custom-field sets once the module declares \`ce.ts\`. */
|
|
7
|
+
export const {{entityUpperSnake}}_ENTITY_ID = '{{moduleId}}:{{entitySnake}}'
|
|
8
|
+
|
|
9
|
+
export type {{entityPascal}}FormValues = z.infer<typeof {{entityCamel}}CreateSchema>
|
|
10
|
+
|
|
11
|
+
export function create{{entityPascal}}FormSchema() {
|
|
12
|
+
return {{entityCamel}}CreateSchema
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function create{{entityPascal}}FormFields(t: TranslateFn): CrudField[] {
|
|
16
|
+
return [
|
|
17
|
+
{{crudFields}}
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function create{{entityPascal}}FormGroups(t: TranslateFn): CrudFormGroup[] {
|
|
22
|
+
return [
|
|
23
|
+
{
|
|
24
|
+
id: 'details',
|
|
25
|
+
title: t('{{moduleId}}.form.groups.details', 'Details'),
|
|
26
|
+
column: 1,
|
|
27
|
+
fields: [{{fieldIdList}}],
|
|
28
|
+
},
|
|
29
|
+
// Custom-field sets registered for {{entityUpperSnake}}_ENTITY_ID render here.
|
|
30
|
+
{
|
|
31
|
+
id: 'attributes',
|
|
32
|
+
title: t('{{moduleId}}.form.groups.attributes', 'Attributes'),
|
|
33
|
+
column: 2,
|
|
34
|
+
kind: 'customFields',
|
|
35
|
+
},
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
`;
|
|
39
|
+
export {
|
|
40
|
+
formConfigTemplate
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=form-config.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/lib/scaffold/templates/form-config.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * components/formConfig.ts template (customers formConfig pattern: zod schema +\n * CrudField[] + groups from one place so create/detail can never disagree).\n */\nexport const formConfigTemplate = `import { z } from 'zod'\nimport type { CrudField, CrudFormGroup } from '@open-mercato/ui/backend/CrudForm'\nimport type { TranslateFn } from '@open-mercato/shared/lib/i18n/context'\nimport { {{entityCamel}}CreateSchema } from '../data/validators'\n\n/** Entity id used to load custom-field sets once the module declares \\`ce.ts\\`. */\nexport const {{entityUpperSnake}}_ENTITY_ID = '{{moduleId}}:{{entitySnake}}'\n\nexport type {{entityPascal}}FormValues = z.infer<typeof {{entityCamel}}CreateSchema>\n\nexport function create{{entityPascal}}FormSchema() {\n return {{entityCamel}}CreateSchema\n}\n\nexport function create{{entityPascal}}FormFields(t: TranslateFn): CrudField[] {\n return [\n{{crudFields}}\n ]\n}\n\nexport function create{{entityPascal}}FormGroups(t: TranslateFn): CrudFormGroup[] {\n return [\n {\n id: 'details',\n title: t('{{moduleId}}.form.groups.details', 'Details'),\n column: 1,\n fields: [{{fieldIdList}}],\n },\n // Custom-field sets registered for {{entityUpperSnake}}_ENTITY_ID render here.\n {\n id: 'attributes',\n title: t('{{moduleId}}.form.groups.attributes', 'Attributes'),\n column: 2,\n kind: 'customFields',\n },\n ]\n}\n`\n"],
|
|
5
|
+
"mappings": "AAIO,MAAM,qBAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { listPageTemplate } from "./list-page.js";
|
|
2
|
+
import { createPageTemplate } from "./create-page.js";
|
|
3
|
+
import { detailPageTemplate } from "./detail-page.js";
|
|
4
|
+
import { listMetaTemplate, createMetaTemplate, detailMetaTemplate } from "./metas.js";
|
|
5
|
+
import { formConfigTemplate } from "./form-config.js";
|
|
6
|
+
import {
|
|
7
|
+
validatorsTemplate,
|
|
8
|
+
statusMapTemplate,
|
|
9
|
+
aclTemplate,
|
|
10
|
+
setupTemplate,
|
|
11
|
+
moduleIndexTemplate
|
|
12
|
+
} from "./module-files.js";
|
|
13
|
+
export {
|
|
14
|
+
aclTemplate,
|
|
15
|
+
createMetaTemplate,
|
|
16
|
+
createPageTemplate,
|
|
17
|
+
detailMetaTemplate,
|
|
18
|
+
detailPageTemplate,
|
|
19
|
+
formConfigTemplate,
|
|
20
|
+
listMetaTemplate,
|
|
21
|
+
listPageTemplate,
|
|
22
|
+
moduleIndexTemplate,
|
|
23
|
+
setupTemplate,
|
|
24
|
+
statusMapTemplate,
|
|
25
|
+
validatorsTemplate
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/lib/scaffold/templates/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Executable template source of truth for `mercato module scaffold --with-ui`\n * (spec: .ai/specs/2026-07-05-ds-module-ui-scaffold.md \u00A7Template source of truth).\n *\n * Templates are embedded as TypeScript string constants (not loose `.tpl`\n * assets) because `packages/cli/build.mjs` bundles `src/**\\/*.ts` only \u2014 this\n * way the templates ship inside the published `@open-mercato/cli` dist with no\n * extra copy step, and standalone apps get byte-identical templates versioned\n * with the CLI. Interpolation is `{{placeholder}}` substitution only \u2014 no\n * template engine (see `renderTemplate` in `../index.ts`).\n *\n * These templates are pinned by `__tests__/scaffold-golden.test.ts` (golden\n * files) and `__tests__/scaffold-ds-contract.test.ts` (DS lint + guardian\n * checklist): a template edit can never ship invisibly.\n */\nexport { listPageTemplate } from './list-page'\nexport { createPageTemplate } from './create-page'\nexport { detailPageTemplate } from './detail-page'\nexport { listMetaTemplate, createMetaTemplate, detailMetaTemplate } from './metas'\nexport { formConfigTemplate } from './form-config'\nexport {\n validatorsTemplate,\n statusMapTemplate,\n aclTemplate,\n setupTemplate,\n moduleIndexTemplate,\n} from './module-files'\n"],
|
|
5
|
+
"mappings": "AAeA,SAAS,wBAAwB;AACjC,SAAS,0BAA0B;AACnC,SAAS,0BAA0B;AACnC,SAAS,kBAAkB,oBAAoB,0BAA0B;AACzE,SAAS,0BAA0B;AACnC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
const listPageTemplate = `"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import Link from 'next/link'
|
|
5
|
+
import { useRouter } from 'next/navigation'
|
|
6
|
+
import { Page, PageBody } from '@open-mercato/ui/backend/Page'
|
|
7
|
+
import { DataTable, type DataTableExportFormat } from '@open-mercato/ui/backend/DataTable'
|
|
8
|
+
import type { LegacyColumnDef as ColumnDef } from '@tanstack/react-table/legacy'
|
|
9
|
+
import { Button } from '@open-mercato/ui/primitives/button'
|
|
10
|
+
import { EmptyState } from '@open-mercato/ui/primitives/empty-state'
|
|
11
|
+
import { RowActions } from '@open-mercato/ui/backend/RowActions'
|
|
12
|
+
import { apiCall, withScopedApiRequestHeaders } from '@open-mercato/ui/backend/utils/apiCall'
|
|
13
|
+
import { buildCrudExportUrl, deleteCrud } from '@open-mercato/ui/backend/utils/crud'
|
|
14
|
+
import { buildOptimisticLockHeader } from '@open-mercato/ui/backend/utils/optimisticLock'
|
|
15
|
+
import { useGuardedMutation } from '@open-mercato/ui/backend/injection/useGuardedMutation'
|
|
16
|
+
import { flash } from '@open-mercato/ui/backend/FlashMessages'
|
|
17
|
+
import { useConfirmDialog } from '@open-mercato/ui/backend/confirm-dialog'
|
|
18
|
+
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
19
|
+
import { getTelemetryRuntime } from '@open-mercato/shared/lib/telemetry/runtime'
|
|
20
|
+
{{dateImport}}{{filterTypeImport}}{{statusImports}}
|
|
21
|
+
type {{entityPascal}}Row = {
|
|
22
|
+
id: string
|
|
23
|
+
updatedAt?: string | null
|
|
24
|
+
{{rowTypeFields}}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type {{entityPascal}}ListResponse = {
|
|
28
|
+
items: {{entityPascal}}Row[]
|
|
29
|
+
total: number
|
|
30
|
+
totalPages: number
|
|
31
|
+
totalIsCapped?: boolean
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// DS guardrail: keep pageSize at or below 100.
|
|
35
|
+
const PAGE_SIZE = 25
|
|
36
|
+
|
|
37
|
+
export default function {{entityPascal}}ListPage() {
|
|
38
|
+
const t = useT()
|
|
39
|
+
const router = useRouter()
|
|
40
|
+
const { confirm, ConfirmDialogElement } = useConfirmDialog()
|
|
41
|
+
const { runMutation, retryLastMutation } = useGuardedMutation({ contextId: '{{moduleId}}.list' })
|
|
42
|
+
const [rows, setRows] = React.useState<{{entityPascal}}Row[]>([])
|
|
43
|
+
const [isLoading, setIsLoading] = React.useState(true)
|
|
44
|
+
const [loadError, setLoadError] = React.useState<string | null>(null)
|
|
45
|
+
const [page, setPage] = React.useState(1)
|
|
46
|
+
const [total, setTotal] = React.useState(0)
|
|
47
|
+
const [totalPages, setTotalPages] = React.useState(1)
|
|
48
|
+
const [totalIsCapped, setTotalIsCapped] = React.useState(false)
|
|
49
|
+
const [search, setSearch] = React.useState('')
|
|
50
|
+
{{filterStateLine}} const [reloadToken, setReloadToken] = React.useState(0)
|
|
51
|
+
|
|
52
|
+
const listParams = React.useMemo(() => {
|
|
53
|
+
const params: Record<string, string | number> = { page, pageSize: PAGE_SIZE }
|
|
54
|
+
if (search) params.search = search
|
|
55
|
+
{{filterParamLines}} return params
|
|
56
|
+
}, {{listParamsDeps}})
|
|
57
|
+
|
|
58
|
+
React.useEffect(() => {
|
|
59
|
+
let cancelled = false
|
|
60
|
+
async function load() {
|
|
61
|
+
setIsLoading(true)
|
|
62
|
+
setLoadError(null)
|
|
63
|
+
try {
|
|
64
|
+
const query = new URLSearchParams()
|
|
65
|
+
for (const [key, value] of Object.entries(listParams)) query.set(key, String(value))
|
|
66
|
+
const fallback: {{entityPascal}}ListResponse = { items: [], total: 0, totalPages: 1 }
|
|
67
|
+
const call = await apiCall<{{entityPascal}}ListResponse>('/api/{{moduleId}}?' + query.toString(), undefined, { fallback })
|
|
68
|
+
if (cancelled) return
|
|
69
|
+
if (!call.ok) {
|
|
70
|
+
setLoadError(t('{{moduleId}}.list.loadError', 'Failed to load {{moduleTitleLower}}'))
|
|
71
|
+
flash(t('{{moduleId}}.list.loadError', 'Failed to load {{moduleTitleLower}}'), 'error')
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
const result = call.result ?? fallback
|
|
75
|
+
setRows(result.items)
|
|
76
|
+
setTotal(result.total)
|
|
77
|
+
setTotalPages(result.totalPages)
|
|
78
|
+
setTotalIsCapped(result.totalIsCapped === true)
|
|
79
|
+
} catch (error) {
|
|
80
|
+
if (cancelled) return
|
|
81
|
+
getTelemetryRuntime()?.reportError(error, { module: '{{moduleId}}', code: '{{moduleId}}.list_load_failed' })
|
|
82
|
+
setLoadError(t('{{moduleId}}.list.loadError', 'Failed to load {{moduleTitleLower}}'))
|
|
83
|
+
} finally {
|
|
84
|
+
if (!cancelled) setIsLoading(false)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
void load()
|
|
88
|
+
return () => { cancelled = true }
|
|
89
|
+
}, [listParams, reloadToken, t])
|
|
90
|
+
|
|
91
|
+
const handleDelete = React.useCallback(async (row: {{entityPascal}}Row) => {
|
|
92
|
+
const confirmed = await confirm({
|
|
93
|
+
title: t('{{moduleId}}.delete.confirmTitle', 'Delete {{entityLower}}?'),
|
|
94
|
+
description: t('{{moduleId}}.delete.confirmDescription', 'This action cannot be undone.'),
|
|
95
|
+
variant: 'destructive',
|
|
96
|
+
})
|
|
97
|
+
if (!confirmed) return
|
|
98
|
+
try {
|
|
99
|
+
// Optimistic locking is ON by default: derive the expected-updated-at
|
|
100
|
+
// header from the row the user acted on.
|
|
101
|
+
await runMutation({
|
|
102
|
+
operation: () =>
|
|
103
|
+
withScopedApiRequestHeaders(
|
|
104
|
+
buildOptimisticLockHeader(row.updatedAt ?? undefined),
|
|
105
|
+
() => deleteCrud('{{moduleId}}', row.id),
|
|
106
|
+
),
|
|
107
|
+
context: {
|
|
108
|
+
formId: '{{moduleId}}.list',
|
|
109
|
+
resourceKind: '{{moduleId}}.{{entitySnake}}',
|
|
110
|
+
resourceId: row.id,
|
|
111
|
+
retryLastMutation,
|
|
112
|
+
},
|
|
113
|
+
mutationPayload: { id: row.id },
|
|
114
|
+
})
|
|
115
|
+
flash(t('{{moduleId}}.delete.success', '{{entityTitle}} deleted'), 'success')
|
|
116
|
+
setReloadToken((token) => token + 1)
|
|
117
|
+
} catch {
|
|
118
|
+
flash(t('{{moduleId}}.delete.error', 'Failed to delete {{entityLower}}'), 'error')
|
|
119
|
+
}
|
|
120
|
+
}, [confirm, retryLastMutation, runMutation, t])
|
|
121
|
+
|
|
122
|
+
const columns = React.useMemo<ColumnDef<{{entityPascal}}Row>[]>(() => [
|
|
123
|
+
{{columnsBlock}}
|
|
124
|
+
], [t])
|
|
125
|
+
|
|
126
|
+
{{filtersMemo}} const exporter = React.useMemo(() => ({
|
|
127
|
+
getUrl: (format: DataTableExportFormat) => buildCrudExportUrl('{{moduleId}}', { ...listParams, exportScope: 'view' }, format),
|
|
128
|
+
filename: (format: DataTableExportFormat) => '{{moduleId}}.' + format,
|
|
129
|
+
}), [listParams])
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<Page>
|
|
133
|
+
<PageBody>
|
|
134
|
+
<DataTable<{{entityPascal}}Row>
|
|
135
|
+
title={t('{{moduleId}}.list.title', '{{moduleTitle}}')}
|
|
136
|
+
actions={(
|
|
137
|
+
<Button asChild>
|
|
138
|
+
<Link href="/backend/{{moduleId}}/create">{t('{{moduleId}}.list.actions.create', 'Create {{entityLower}}')}</Link>
|
|
139
|
+
</Button>
|
|
140
|
+
)}
|
|
141
|
+
columns={columns}
|
|
142
|
+
data={rows}
|
|
143
|
+
isLoading={isLoading}
|
|
144
|
+
error={loadError}
|
|
145
|
+
searchValue={search}
|
|
146
|
+
onSearchChange={(value) => { setSearch(value); setPage(1) }}
|
|
147
|
+
searchPlaceholder={t('{{moduleId}}.list.searchPlaceholder', 'Search {{moduleTitleLower}}')}
|
|
148
|
+
{{filterProps}} exporter={exporter}
|
|
149
|
+
extensionTableId="{{moduleId}}.list"
|
|
150
|
+
onRowClick={(row) => router.push('/backend/{{moduleId}}/' + row.id)}
|
|
151
|
+
rowActions={(row) => (
|
|
152
|
+
<RowActions
|
|
153
|
+
items={[
|
|
154
|
+
{
|
|
155
|
+
id: 'edit',
|
|
156
|
+
label: t('{{moduleId}}.list.actions.edit', 'Edit'),
|
|
157
|
+
onSelect: () => { router.push('/backend/{{moduleId}}/' + row.id) },
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
id: 'delete',
|
|
161
|
+
label: t('{{moduleId}}.list.actions.delete', 'Delete'),
|
|
162
|
+
destructive: true,
|
|
163
|
+
onSelect: () => { void handleDelete(row) },
|
|
164
|
+
},
|
|
165
|
+
]}
|
|
166
|
+
/>
|
|
167
|
+
)}
|
|
168
|
+
emptyState={(
|
|
169
|
+
<EmptyState
|
|
170
|
+
title={t('{{moduleId}}.list.empty.title', 'No {{moduleTitleLower}} yet')}
|
|
171
|
+
description={t('{{moduleId}}.list.empty.description', 'Create your first {{entityLower}} to get started.')}
|
|
172
|
+
actions={(
|
|
173
|
+
<Button asChild>
|
|
174
|
+
<Link href="/backend/{{moduleId}}/create">{t('{{moduleId}}.list.actions.create', 'Create {{entityLower}}')}</Link>
|
|
175
|
+
</Button>
|
|
176
|
+
)}
|
|
177
|
+
/>
|
|
178
|
+
)}
|
|
179
|
+
pagination={{ page, pageSize: PAGE_SIZE, total, totalPages, totalIsCapped, onPageChange: setPage }}
|
|
180
|
+
/>
|
|
181
|
+
</PageBody>
|
|
182
|
+
{ConfirmDialogElement}
|
|
183
|
+
</Page>
|
|
184
|
+
)
|
|
185
|
+
}
|
|
186
|
+
`;
|
|
187
|
+
export {
|
|
188
|
+
listPageTemplate
|
|
189
|
+
};
|
|
190
|
+
//# sourceMappingURL=list-page.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/lib/scaffold/templates/list-page.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * List page template (lineage: om-ds-guardian page-templates.md \u00A7List Page,\n * trimmed from packages/core/src/modules/customers/backend/customers/people/page.tsx).\n */\nexport const listPageTemplate = `\"use client\"\n\nimport * as React from 'react'\nimport Link from 'next/link'\nimport { useRouter } from 'next/navigation'\nimport { Page, PageBody } from '@open-mercato/ui/backend/Page'\nimport { DataTable, type DataTableExportFormat } from '@open-mercato/ui/backend/DataTable'\nimport type { LegacyColumnDef as ColumnDef } from '@tanstack/react-table/legacy'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { EmptyState } from '@open-mercato/ui/primitives/empty-state'\nimport { RowActions } from '@open-mercato/ui/backend/RowActions'\nimport { apiCall, withScopedApiRequestHeaders } from '@open-mercato/ui/backend/utils/apiCall'\nimport { buildCrudExportUrl, deleteCrud } from '@open-mercato/ui/backend/utils/crud'\nimport { buildOptimisticLockHeader } from '@open-mercato/ui/backend/utils/optimisticLock'\nimport { useGuardedMutation } from '@open-mercato/ui/backend/injection/useGuardedMutation'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { useConfirmDialog } from '@open-mercato/ui/backend/confirm-dialog'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { getTelemetryRuntime } from '@open-mercato/shared/lib/telemetry/runtime'\n{{dateImport}}{{filterTypeImport}}{{statusImports}}\ntype {{entityPascal}}Row = {\n id: string\n updatedAt?: string | null\n{{rowTypeFields}}\n}\n\ntype {{entityPascal}}ListResponse = {\n items: {{entityPascal}}Row[]\n total: number\n totalPages: number\n totalIsCapped?: boolean\n}\n\n// DS guardrail: keep pageSize at or below 100.\nconst PAGE_SIZE = 25\n\nexport default function {{entityPascal}}ListPage() {\n const t = useT()\n const router = useRouter()\n const { confirm, ConfirmDialogElement } = useConfirmDialog()\n const { runMutation, retryLastMutation } = useGuardedMutation({ contextId: '{{moduleId}}.list' })\n const [rows, setRows] = React.useState<{{entityPascal}}Row[]>([])\n const [isLoading, setIsLoading] = React.useState(true)\n const [loadError, setLoadError] = React.useState<string | null>(null)\n const [page, setPage] = React.useState(1)\n const [total, setTotal] = React.useState(0)\n const [totalPages, setTotalPages] = React.useState(1)\n const [totalIsCapped, setTotalIsCapped] = React.useState(false)\n const [search, setSearch] = React.useState('')\n{{filterStateLine}} const [reloadToken, setReloadToken] = React.useState(0)\n\n const listParams = React.useMemo(() => {\n const params: Record<string, string | number> = { page, pageSize: PAGE_SIZE }\n if (search) params.search = search\n{{filterParamLines}} return params\n }, {{listParamsDeps}})\n\n React.useEffect(() => {\n let cancelled = false\n async function load() {\n setIsLoading(true)\n setLoadError(null)\n try {\n const query = new URLSearchParams()\n for (const [key, value] of Object.entries(listParams)) query.set(key, String(value))\n const fallback: {{entityPascal}}ListResponse = { items: [], total: 0, totalPages: 1 }\n const call = await apiCall<{{entityPascal}}ListResponse>('/api/{{moduleId}}?' + query.toString(), undefined, { fallback })\n if (cancelled) return\n if (!call.ok) {\n setLoadError(t('{{moduleId}}.list.loadError', 'Failed to load {{moduleTitleLower}}'))\n flash(t('{{moduleId}}.list.loadError', 'Failed to load {{moduleTitleLower}}'), 'error')\n return\n }\n const result = call.result ?? fallback\n setRows(result.items)\n setTotal(result.total)\n setTotalPages(result.totalPages)\n setTotalIsCapped(result.totalIsCapped === true)\n } catch (error) {\n if (cancelled) return\n getTelemetryRuntime()?.reportError(error, { module: '{{moduleId}}', code: '{{moduleId}}.list_load_failed' })\n setLoadError(t('{{moduleId}}.list.loadError', 'Failed to load {{moduleTitleLower}}'))\n } finally {\n if (!cancelled) setIsLoading(false)\n }\n }\n void load()\n return () => { cancelled = true }\n }, [listParams, reloadToken, t])\n\n const handleDelete = React.useCallback(async (row: {{entityPascal}}Row) => {\n const confirmed = await confirm({\n title: t('{{moduleId}}.delete.confirmTitle', 'Delete {{entityLower}}?'),\n description: t('{{moduleId}}.delete.confirmDescription', 'This action cannot be undone.'),\n variant: 'destructive',\n })\n if (!confirmed) return\n try {\n // Optimistic locking is ON by default: derive the expected-updated-at\n // header from the row the user acted on.\n await runMutation({\n operation: () =>\n withScopedApiRequestHeaders(\n buildOptimisticLockHeader(row.updatedAt ?? undefined),\n () => deleteCrud('{{moduleId}}', row.id),\n ),\n context: {\n formId: '{{moduleId}}.list',\n resourceKind: '{{moduleId}}.{{entitySnake}}',\n resourceId: row.id,\n retryLastMutation,\n },\n mutationPayload: { id: row.id },\n })\n flash(t('{{moduleId}}.delete.success', '{{entityTitle}} deleted'), 'success')\n setReloadToken((token) => token + 1)\n } catch {\n flash(t('{{moduleId}}.delete.error', 'Failed to delete {{entityLower}}'), 'error')\n }\n }, [confirm, retryLastMutation, runMutation, t])\n\n const columns = React.useMemo<ColumnDef<{{entityPascal}}Row>[]>(() => [\n{{columnsBlock}}\n ], [t])\n\n{{filtersMemo}} const exporter = React.useMemo(() => ({\n getUrl: (format: DataTableExportFormat) => buildCrudExportUrl('{{moduleId}}', { ...listParams, exportScope: 'view' }, format),\n filename: (format: DataTableExportFormat) => '{{moduleId}}.' + format,\n }), [listParams])\n\n return (\n <Page>\n <PageBody>\n <DataTable<{{entityPascal}}Row>\n title={t('{{moduleId}}.list.title', '{{moduleTitle}}')}\n actions={(\n <Button asChild>\n <Link href=\"/backend/{{moduleId}}/create\">{t('{{moduleId}}.list.actions.create', 'Create {{entityLower}}')}</Link>\n </Button>\n )}\n columns={columns}\n data={rows}\n isLoading={isLoading}\n error={loadError}\n searchValue={search}\n onSearchChange={(value) => { setSearch(value); setPage(1) }}\n searchPlaceholder={t('{{moduleId}}.list.searchPlaceholder', 'Search {{moduleTitleLower}}')}\n{{filterProps}} exporter={exporter}\n extensionTableId=\"{{moduleId}}.list\"\n onRowClick={(row) => router.push('/backend/{{moduleId}}/' + row.id)}\n rowActions={(row) => (\n <RowActions\n items={[\n {\n id: 'edit',\n label: t('{{moduleId}}.list.actions.edit', 'Edit'),\n onSelect: () => { router.push('/backend/{{moduleId}}/' + row.id) },\n },\n {\n id: 'delete',\n label: t('{{moduleId}}.list.actions.delete', 'Delete'),\n destructive: true,\n onSelect: () => { void handleDelete(row) },\n },\n ]}\n />\n )}\n emptyState={(\n <EmptyState\n title={t('{{moduleId}}.list.empty.title', 'No {{moduleTitleLower}} yet')}\n description={t('{{moduleId}}.list.empty.description', 'Create your first {{entityLower}} to get started.')}\n actions={(\n <Button asChild>\n <Link href=\"/backend/{{moduleId}}/create\">{t('{{moduleId}}.list.actions.create', 'Create {{entityLower}}')}</Link>\n </Button>\n )}\n />\n )}\n pagination={{ page, pageSize: PAGE_SIZE, total, totalPages, totalIsCapped, onPageChange: setPage }}\n />\n </PageBody>\n {ConfirmDialogElement}\n </Page>\n )\n}\n`\n"],
|
|
5
|
+
"mappings": "AAIO,MAAM,mBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const listMetaTemplate = `export const metadata = {
|
|
2
|
+
requireAuth: true,
|
|
3
|
+
requireFeatures: ['{{featuresPrefix}}.view'],
|
|
4
|
+
pageTitle: '{{moduleTitle}}',
|
|
5
|
+
pageTitleKey: '{{moduleId}}.nav.title',
|
|
6
|
+
pageGroup: '{{moduleTitle}}',
|
|
7
|
+
pageGroupKey: '{{moduleId}}.nav.group',
|
|
8
|
+
pageOrder: 100,
|
|
9
|
+
icon: 'list',
|
|
10
|
+
breadcrumb: [{ label: '{{moduleTitle}}', labelKey: '{{moduleId}}.nav.title' }],
|
|
11
|
+
}
|
|
12
|
+
`;
|
|
13
|
+
const createMetaTemplate = `export const metadata = {
|
|
14
|
+
requireAuth: true,
|
|
15
|
+
requireFeatures: ['{{featuresPrefix}}.create'],
|
|
16
|
+
pageTitle: 'Create {{entityLower}}',
|
|
17
|
+
pageTitleKey: '{{moduleId}}.create.title',
|
|
18
|
+
pageGroup: '{{moduleTitle}}',
|
|
19
|
+
pageGroupKey: '{{moduleId}}.nav.group',
|
|
20
|
+
pageOrder: 101,
|
|
21
|
+
icon: 'plus',
|
|
22
|
+
breadcrumb: [
|
|
23
|
+
{ label: '{{moduleTitle}}', labelKey: '{{moduleId}}.nav.title', href: '/backend/{{moduleId}}' },
|
|
24
|
+
{ label: 'Create', labelKey: '{{moduleId}}.create.title' },
|
|
25
|
+
],
|
|
26
|
+
}
|
|
27
|
+
`;
|
|
28
|
+
const detailMetaTemplate = `export const metadata = {
|
|
29
|
+
requireAuth: true,
|
|
30
|
+
requireFeatures: ['{{featuresPrefix}}.view'],
|
|
31
|
+
pageTitle: '{{entityTitle}} details',
|
|
32
|
+
pageTitleKey: '{{moduleId}}.detail.title',
|
|
33
|
+
pageGroup: '{{moduleTitle}}',
|
|
34
|
+
pageGroupKey: '{{moduleId}}.nav.group',
|
|
35
|
+
navHidden: true,
|
|
36
|
+
breadcrumb: [
|
|
37
|
+
{ label: '{{moduleTitle}}', labelKey: '{{moduleId}}.nav.title', href: '/backend/{{moduleId}}' },
|
|
38
|
+
{ label: 'Details', labelKey: '{{moduleId}}.detail.title' },
|
|
39
|
+
],
|
|
40
|
+
}
|
|
41
|
+
`;
|
|
42
|
+
export {
|
|
43
|
+
createMetaTemplate,
|
|
44
|
+
detailMetaTemplate,
|
|
45
|
+
listMetaTemplate
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=metas.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/lib/scaffold/templates/metas.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * page.meta.ts templates \u2014 nav + RBAC contract copied from\n * packages/core/src/modules/customers/backend/customers/people/page.meta.ts.\n */\n\nexport const listMetaTemplate = `export const metadata = {\n requireAuth: true,\n requireFeatures: ['{{featuresPrefix}}.view'],\n pageTitle: '{{moduleTitle}}',\n pageTitleKey: '{{moduleId}}.nav.title',\n pageGroup: '{{moduleTitle}}',\n pageGroupKey: '{{moduleId}}.nav.group',\n pageOrder: 100,\n icon: 'list',\n breadcrumb: [{ label: '{{moduleTitle}}', labelKey: '{{moduleId}}.nav.title' }],\n}\n`\n\nexport const createMetaTemplate = `export const metadata = {\n requireAuth: true,\n requireFeatures: ['{{featuresPrefix}}.create'],\n pageTitle: 'Create {{entityLower}}',\n pageTitleKey: '{{moduleId}}.create.title',\n pageGroup: '{{moduleTitle}}',\n pageGroupKey: '{{moduleId}}.nav.group',\n pageOrder: 101,\n icon: 'plus',\n breadcrumb: [\n { label: '{{moduleTitle}}', labelKey: '{{moduleId}}.nav.title', href: '/backend/{{moduleId}}' },\n { label: 'Create', labelKey: '{{moduleId}}.create.title' },\n ],\n}\n`\n\nexport const detailMetaTemplate = `export const metadata = {\n requireAuth: true,\n requireFeatures: ['{{featuresPrefix}}.view'],\n pageTitle: '{{entityTitle}} details',\n pageTitleKey: '{{moduleId}}.detail.title',\n pageGroup: '{{moduleTitle}}',\n pageGroupKey: '{{moduleId}}.nav.group',\n navHidden: true,\n breadcrumb: [\n { label: '{{moduleTitle}}', labelKey: '{{moduleId}}.nav.title', href: '/backend/{{moduleId}}' },\n { label: 'Details', labelKey: '{{moduleId}}.detail.title' },\n ],\n}\n`\n"],
|
|
5
|
+
"mappings": "AAKO,MAAM,mBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAazB,MAAM,qBAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgB3B,MAAM,qBAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|