@open-mercato/core 0.10.1-develop.7975.1.ada24d305c → 0.10.1-develop.7978.1.b4468545b6
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/dist/modules/customers/commands/personCompanyLinks.js +101 -6
- package/dist/modules/customers/commands/personCompanyLinks.js.map +2 -2
- package/dist/modules/warranty_claims/backend/warranty_claims/[id]/page.js.map +2 -2
- package/dist/modules/workflows/backend/instances/page.js +2 -2
- package/dist/modules/workflows/backend/instances/page.js.map +2 -2
- package/package.json +7 -7
- package/src/modules/customers/commands/personCompanyLinks.ts +132 -7
- package/src/modules/warranty_claims/backend/warranty_claims/[id]/page.tsx +0 -1
- package/src/modules/workflows/backend/instances/page.tsx +2 -2
|
@@ -126,7 +126,7 @@ function WorkflowInstancesListPage() {
|
|
|
126
126
|
}, [data, childrenByParent]);
|
|
127
127
|
const handleCancel = async (id, workflowId) => {
|
|
128
128
|
const confirmed = await confirmDialog({
|
|
129
|
-
title: t("workflows.instances.confirm.cancel", {
|
|
129
|
+
title: t("workflows.instances.confirm.cancel", { workflowId }),
|
|
130
130
|
variant: "destructive"
|
|
131
131
|
});
|
|
132
132
|
if (!confirmed) {
|
|
@@ -144,7 +144,7 @@ function WorkflowInstancesListPage() {
|
|
|
144
144
|
};
|
|
145
145
|
const handleRetry = async (id, workflowId) => {
|
|
146
146
|
const ok = await confirmDialog({
|
|
147
|
-
title: t("workflows.instances.confirm.retry", {
|
|
147
|
+
title: t("workflows.instances.confirm.retry", { workflowId }),
|
|
148
148
|
variant: "default"
|
|
149
149
|
});
|
|
150
150
|
if (!ok) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/modules/workflows/backend/instances/page.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport { extensionPoints } from '@open-mercato/core/modules/workflows/extension-points'\nimport Link from 'next/link'\nimport { useRouter } from 'next/navigation'\nimport { Page, PageBody } from '@open-mercato/ui/backend/Page'\nimport { DataTable } from '@open-mercato/ui/backend/DataTable'\nimport type { LegacyColumnDef as ColumnDef } from '@tanstack/react-table/legacy'\nimport type { ExpandedState } from '@tanstack/react-table'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { Spinner } from '@open-mercato/ui/primitives/spinner'\nimport { SegmentedControl, SegmentedControlItem } from '@open-mercato/ui/primitives/segmented-control'\nimport { RowActions } from '@open-mercato/ui/backend/RowActions'\nimport { apiCall } from '@open-mercato/ui/backend/utils/apiCall'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { useQuery, useQueryClient } from '@tanstack/react-query'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport type { FilterDef, FilterValues } from '@open-mercato/ui/backend/FilterBar'\nimport { useConfirmDialog } from '@open-mercato/ui/backend/confirm-dialog'\nimport { useLiveRunUpdates } from '../../components/run/useLiveRunUpdates'\n\ntype WorkflowInstance = {\n id: string\n definitionId: string\n workflowId: string\n version: number\n status: 'RUNNING' | 'PAUSED' | 'COMPLETED' | 'FAILED' | 'CANCELLED' | 'COMPENSATING' | 'COMPENSATED'\n currentStepId: string\n correlationKey: string | null\n startedAt: string\n completedAt: string | null\n cancelledAt: string | null\n errorMessage: string | null\n retryCount: number\n metadata?: { labels?: Record<string, string> | null } | null\n tenantId: string\n organizationId: string\n createdAt: string\n updatedAt: string\n}\n\n// Row shape rendered by the accordion. `children` are lazily-loaded\n// sub-workflow instances; placeholder rows carry a `__placeholder` marker so\n// the loading/empty state renders inline under an expanded parent.\ntype InstanceRow = WorkflowInstance & {\n children?: InstanceRow[]\n __placeholder?: 'loading' | 'empty'\n __parentId?: string\n}\n\nfunction makePlaceholderRow(parentId: string, kind: 'loading' | 'empty'): InstanceRow {\n return {\n id: `${parentId}::${kind}`,\n __placeholder: kind,\n __parentId: parentId,\n } as InstanceRow\n}\n\ntype InstancesResponse = {\n data: WorkflowInstance[]\n pagination: {\n total: number\n limit: number\n offset: number\n hasMore: boolean\n totalIsCapped?: boolean\n }\n}\n\nexport default function WorkflowInstancesListPage() {\n const [page, setPage] = React.useState(1)\n const [pageSize] = React.useState(50)\n const [total, setTotal] = React.useState(0)\n const [totalPages, setTotalPages] = React.useState(1)\n const [totalIsCapped, setTotalIsCapped] = React.useState(false)\n const t = useT()\n const router = useRouter()\n const queryClient = useQueryClient()\n const { confirm: confirmDialog, ConfirmDialogElement } = useConfirmDialog()\n const [filterValues, setFilterValues] = React.useState<FilterValues>({})\n // Grouped (default): list top-level instances and nest sub-workflow children\n // under their parent. Flat: legacy unfiltered view of every instance.\n const [grouped, setGrouped] = React.useState(true)\n const [expanded, setExpanded] = React.useState<ExpandedState>({})\n const [childrenByParent, setChildrenByParent] = React.useState<Map<string, InstanceRow[]>>(new Map())\n\n const buildListParams = React.useCallback(() => {\n const params = new URLSearchParams()\n if (filterValues.status) params.set('status', filterValues.status as string)\n if (filterValues.workflowId) params.set('workflowId', filterValues.workflowId as string)\n if (filterValues.correlationKey) params.set('correlationKey', filterValues.correlationKey as string)\n if (filterValues.entityType) params.set('entityType', filterValues.entityType as string)\n if (filterValues.entityId) params.set('entityId', filterValues.entityId as string)\n // The date-range control emits calendar days; the API widens `startedTo` to\n // cover the whole day, so \"started on the 3rd\" does not exclude everything\n // after midnight.\n const startedAt = filterValues.startedAt as { from?: string; to?: string } | undefined\n if (startedAt?.from) params.set('startedFrom', startedAt.from)\n if (startedAt?.to) params.set('startedTo', startedAt.to)\n if (filterValues.attention) params.set('attention', 'true')\n return params\n }, [filterValues])\n\n const { data, isLoading, error } = useQuery({\n queryKey: ['workflow-instances', 'list', filterValues, page, grouped],\n queryFn: async () => {\n const params = buildListParams()\n const offset = (page - 1) * pageSize\n params.set('limit', pageSize.toString())\n params.set('offset', offset.toString())\n // In grouped mode only top-level instances paginate; children are loaded\n // lazily per parent on expand.\n if (grouped) params.set('hasParent', 'false')\n\n const result = await apiCall<InstancesResponse>(\n `/api/workflows/instances?${params.toString()}`\n )\n\n if (!result.ok) {\n throw new Error('Failed to fetch workflow instances')\n }\n\n const response = result.result\n if (response?.pagination) {\n setTotal(response.pagination.total || 0)\n const calculatedPages = Math.ceil((response.pagination.total || 0) / pageSize)\n setTotalPages(calculatedPages || 1)\n setTotalIsCapped(response.pagination?.totalIsCapped === true)\n }\n\n return response?.data || []\n },\n })\n\n // Live run list (spec \u00A78.3). Instance lifecycle events are broadcast to the\n // browser, so a run that starts, finishes or fails appears without a reload.\n // The hook throttles the burst a busy tenant produces into one refetch.\n useLiveRunUpdates({\n onRefresh: React.useCallback(() => {\n queryClient.invalidateQueries({ queryKey: ['workflow-instances'] })\n }, [queryClient]),\n })\n\n // Reset accordion state whenever the top-level result set changes (filters,\n // page, mode) so stale expansions/children don't leak across views.\n React.useEffect(() => {\n setExpanded({})\n setChildrenByParent(new Map())\n }, [filterValues, page, grouped])\n\n const loadChildren = React.useCallback(async (parentId: string) => {\n setChildrenByParent((prev) => {\n const next = new Map(prev)\n next.set(parentId, [makePlaceholderRow(parentId, 'loading')])\n return next\n })\n // Children are fetched by parent id only \u2014 the top-level content filters\n // (status, workflowId, correlationKey, entity*) scope which parents appear,\n // not which sub-workflows a parent reveals when expanded. Carrying them here\n // would surprise users by hiding a parent's non-matching children.\n const params = new URLSearchParams({ parentInstanceId: parentId, limit: '100' })\n const result = await apiCall<InstancesResponse>(`/api/workflows/instances?${params.toString()}`)\n const children = (result.ok ? result.result?.data ?? [] : []) as InstanceRow[]\n setChildrenByParent((prev) => {\n const next = new Map(prev)\n next.set(parentId, children.length ? children : [makePlaceholderRow(parentId, 'empty')])\n return next\n })\n }, [])\n\n const handleExpandedChange = React.useCallback((updater: ExpandedState | ((old: ExpandedState) => ExpandedState)) => {\n setExpanded((prev) => {\n const next = typeof updater === 'function' ? updater(prev) : updater\n const prevRec = (prev === true ? {} : prev) as Record<string, boolean>\n const nextRec = (next === true ? {} : next) as Record<string, boolean>\n for (const rowId of Object.keys(nextRec)) {\n if (nextRec[rowId] && !prevRec[rowId] && !childrenByParent.has(rowId)) {\n void loadChildren(rowId)\n }\n }\n return next\n })\n }, [childrenByParent, loadChildren])\n\n // Build the nested row tree from the top-level result + lazily-loaded\n // children. A visited set guards against pathological cycles so expansion\n // can never recurse infinitely.\n const treeData = React.useMemo<InstanceRow[]>(() => {\n const buildRow = (instance: WorkflowInstance, ancestors: Set<string>): InstanceRow => {\n const loaded = childrenByParent.get(instance.id)\n if (!loaded) return { ...instance }\n const nextAncestors = new Set(ancestors)\n nextAncestors.add(instance.id)\n const children = loaded.map((child) =>\n child.__placeholder || nextAncestors.has(child.id)\n ? child\n : buildRow(child, nextAncestors)\n )\n return { ...instance, children }\n }\n return (data || []).map((instance) => buildRow(instance, new Set()))\n }, [data, childrenByParent])\n\n const handleCancel = async (id: string, workflowId: string) => {\n const confirmed = await confirmDialog({\n title: t('workflows.instances.confirm.cancel', { id: workflowId }),\n variant: 'destructive',\n })\n if (!confirmed) {\n return\n }\n\n const result = await apiCall(`/api/workflows/instances/${id}/cancel`, {\n method: 'POST',\n })\n\n if (result.ok) {\n flash(t('workflows.instances.messages.cancelled'), 'success')\n queryClient.invalidateQueries({ queryKey: ['workflow-instances'] })\n } else {\n flash(t('workflows.instances.messages.cancelFailed'), 'error')\n }\n }\n\n const handleRetry = async (id: string, workflowId: string) => {\n const ok = await confirmDialog({\n title: t('workflows.instances.confirm.retry', { id: workflowId }),\n variant: 'default',\n })\n if (!ok) {\n return\n }\n\n const result = await apiCall(`/api/workflows/instances/${id}/retry`, {\n method: 'POST',\n })\n\n if (result.ok) {\n flash(t('workflows.instances.messages.retried'), 'success')\n queryClient.invalidateQueries({ queryKey: ['workflow-instances'] })\n } else {\n flash(t('workflows.instances.messages.retryFailed'), 'error')\n }\n }\n\n const handleFiltersApply = React.useCallback((values: FilterValues) => {\n const next: FilterValues = {}\n Object.entries(values).forEach(([key, value]) => {\n if (value !== undefined && value !== '') next[key] = value\n })\n setFilterValues(next)\n setPage(1)\n }, [])\n\n const handleFiltersClear = React.useCallback(() => {\n setFilterValues({})\n setPage(1)\n }, [])\n\n const getStatusBadgeClass = (status: WorkflowInstance['status']) => {\n switch (status) {\n case 'RUNNING':\n return 'bg-status-info-bg text-status-info-text'\n case 'PAUSED':\n return 'bg-status-warning-bg text-status-warning-text'\n case 'COMPLETED':\n return 'bg-status-success-bg text-status-success-text'\n case 'FAILED':\n return 'bg-status-error-bg text-status-error-text'\n case 'CANCELLED':\n return 'bg-status-neutral-bg text-status-neutral-text'\n case 'COMPENSATING':\n return 'bg-status-warning-bg text-status-warning-text'\n case 'COMPENSATED':\n return 'bg-status-neutral-bg text-status-neutral-text'\n default:\n return 'bg-status-neutral-bg text-status-neutral-text'\n }\n }\n\n const filters: FilterDef[] = [\n {\n id: 'status',\n type: 'select',\n label: t('workflows.instances.filters.status'),\n options: [\n { label: t('common.all'), value: '' },\n { label: t('workflows.instances.status.RUNNING'), value: 'RUNNING' },\n { label: t('workflows.instances.status.PAUSED'), value: 'PAUSED' },\n { label: t('workflows.instances.status.COMPLETED'), value: 'COMPLETED' },\n { label: t('workflows.instances.status.FAILED'), value: 'FAILED' },\n { label: t('workflows.instances.status.CANCELLED'), value: 'CANCELLED' },\n { label: t('workflows.instances.status.COMPENSATING'), value: 'COMPENSATING' },\n { label: t('workflows.instances.status.COMPENSATED'), value: 'COMPENSATED' },\n ],\n },\n {\n id: 'workflowId',\n type: 'text',\n label: t('workflows.instances.filters.workflowId'),\n placeholder: t('workflows.instances.filters.workflowIdPlaceholder'),\n },\n {\n id: 'correlationKey',\n type: 'text',\n label: t('workflows.instances.filters.correlationKey'),\n placeholder: t('workflows.instances.filters.correlationKeyPlaceholder'),\n },\n {\n id: 'entityType',\n type: 'text',\n label: t('workflows.instances.filters.entityType'),\n placeholder: t('workflows.instances.filters.entityTypePlaceholder'),\n },\n {\n id: 'entityId',\n type: 'text',\n label: t('workflows.instances.filters.entityId'),\n placeholder: t('workflows.instances.filters.entityIdPlaceholder'),\n },\n {\n id: 'startedAt',\n type: 'dateRange',\n label: t('workflows.instances.filters.startedAt', 'Started'),\n },\n {\n // The failure queue (spec 5.9 / 8.4): a `failureQueue` error directive\n // parks an instance as PAUSED with an engine-owned attention marker. The\n // API has filtered on it since Phase 3a; this is the control for it.\n id: 'attention',\n type: 'checkbox',\n label: t('workflows.instances.filters.attention', 'Needs attention'),\n tooltip: t(\n 'workflows.instances.filters.attentionTooltip',\n 'Instances parked by a failure-queue directive, waiting for a human to triage them.'\n ),\n },\n ]\n\n const columns: ColumnDef<InstanceRow>[] = [\n {\n id: 'workflowId',\n header: t('workflows.instances.fields.workflowId'),\n accessorKey: 'workflowId',\n cell: ({ row }) => {\n if (row.original.__placeholder === 'loading') {\n return (\n <span className=\"inline-flex items-center gap-2 text-sm text-muted-foreground\">\n <Spinner className=\"h-3.5 w-3.5\" />\n {t('workflows.instances.subWorkflows.loading', 'Loading sub-workflows\u2026')}\n </span>\n )\n }\n if (row.original.__placeholder === 'empty') {\n return (\n <span className=\"text-sm text-muted-foreground\">\n {t('workflows.instances.subWorkflows.empty', 'No sub-workflows')}\n </span>\n )\n }\n return (\n <Link href={`/backend/instances/${row.original.id}`} className=\"block hover:underline\">\n <div className=\"font-mono text-sm font-medium\">{row.original.workflowId}</div>\n {row.original.correlationKey && (\n <div className=\"text-xs text-muted-foreground\">\n {t('workflows.instances.fields.correlationKey')}: {row.original.correlationKey}\n </div>\n )}\n </Link>\n )\n },\n },\n {\n id: 'status',\n header: t('workflows.instances.fields.status'),\n accessorKey: 'status',\n cell: ({ row }) => {\n if (row.original.__placeholder) return null\n return (\n <span className={`inline-flex items-center px-2 py-1 rounded text-xs font-medium ${getStatusBadgeClass(row.original.status)}`}>\n {t(`workflows.instances.status.${row.original.status}`)}\n </span>\n )\n },\n },\n {\n id: 'currentStep',\n header: t('workflows.instances.fields.currentStep'),\n accessorKey: 'currentStepId',\n cell: ({ row }) => {\n if (row.original.__placeholder) return null\n return <span className=\"text-sm text-muted-foreground\">{row.original.currentStepId}</span>\n },\n },\n {\n id: 'timing',\n header: t('workflows.instances.fields.timing'),\n cell: ({ row }) => {\n if (row.original.__placeholder) return null\n const started = new Date(row.original.startedAt)\n const completed = row.original.completedAt ? new Date(row.original.completedAt) : null\n const duration = completed ? completed.getTime() - started.getTime() : Date.now() - started.getTime()\n const durationText = duration < 60000\n ? `${Math.floor(duration / 1000)}s`\n : `${Math.floor(duration / 60000)}m`\n\n return (\n <div className=\"text-sm\">\n <div className=\"text-foreground\">{started.toLocaleString()}</div>\n <div className=\"text-xs text-muted-foreground\">\n {completed ? t('workflows.instances.duration') : t('workflows.instances.elapsed')}: {durationText}\n </div>\n </div>\n )\n },\n },\n {\n id: 'retryCount',\n header: t('workflows.instances.fields.retryCount'),\n accessorKey: 'retryCount',\n cell: ({ row }) => {\n if (row.original.__placeholder) return null\n return (\n <span\n className={`text-sm ${\n row.original.retryCount > 0 ? 'font-medium text-status-warning-text' : 'text-muted-foreground'\n }`}\n >\n {row.original.retryCount}\n </span>\n )\n },\n },\n {\n id: 'actions',\n header: '',\n cell: ({ row }) => {\n if (row.original.__placeholder) return null\n const items: Array<{ id: string; label: string; href?: string; onSelect?: () => void }> = [\n {\n id: 'view',\n label: t('workflows.instances.actions.viewDetails'),\n href: `/backend/instances/${row.original.id}`,\n },\n ]\n\n if (row.original.status === 'RUNNING' || row.original.status === 'PAUSED') {\n items.push({\n id: 'cancel',\n label: t('workflows.instances.actions.cancel'),\n onSelect: () => void handleCancel(row.original.id, row.original.workflowId),\n })\n }\n\n if (row.original.status === 'FAILED') {\n items.push({\n id: 'retry',\n label: t('workflows.instances.actions.retry'),\n onSelect: () => void handleRetry(row.original.id, row.original.workflowId),\n })\n }\n\n return <RowActions items={items} />\n },\n },\n ]\n\n if (error) {\n return (\n <Page>\n <PageBody>\n <div className=\"p-8 text-center\">\n <p className=\"text-status-error-text\">{t('workflows.instances.messages.loadFailed')}</p>\n <Button onClick={() => queryClient.invalidateQueries({ queryKey: ['workflow-instances'] })} className=\"mt-4\">\n {t('common.retry')}\n </Button>\n </div>\n </PageBody>\n </Page>\n )\n }\n\n const viewToggle = (\n <SegmentedControl\n value={grouped ? 'grouped' : 'flat'}\n onValueChange={(value) => setGrouped(value === 'grouped')}\n aria-label={t('workflows.instances.list.viewToggle', 'Instance view')}\n >\n <SegmentedControlItem value=\"grouped\">\n {t('workflows.instances.list.topLevelOnly', 'Top-level')}\n </SegmentedControlItem>\n <SegmentedControlItem value=\"flat\">\n {t('workflows.instances.list.showAllFlat', 'All (flat)')}\n </SegmentedControlItem>\n </SegmentedControl>\n )\n\n return (\n <Page>\n <PageBody>\n <DataTable<InstanceRow>\n title={t('workflows.instances.list.title')}\n titleHeadingLevel={1}\n actions={viewToggle}\n columns={columns}\n data={grouped ? treeData : ((data || []) as InstanceRow[])}\n filters={filters}\n filterValues={filterValues}\n onFiltersApply={handleFiltersApply}\n onFiltersClear={handleFiltersClear}\n perspective={{\n tableId: extensionPoints.hosts.instancesTable.tableId,\n }}\n pagination={{ page, pageSize, total, totalPages, totalIsCapped, onPageChange: setPage }}\n isLoading={isLoading}\n {...(grouped ? {\n getSubRows: (row: InstanceRow) => row.children,\n expandable: (row: InstanceRow) => !row.__placeholder,\n expanded,\n onExpandedChange: handleExpandedChange,\n } : {})}\n />\n </PageBody>\n {ConfirmDialogElement}\n </Page>\n )\n}\n"],
|
|
5
|
-
"mappings": ";AA4VY,SACE,KADF;AA1VZ,YAAY,WAAW;AACvB,SAAS,uBAAuB;AAChC,OAAO,UAAU;AACjB,SAAS,iBAAiB;AAC1B,SAAS,MAAM,gBAAgB;AAC/B,SAAS,iBAAiB;AAG1B,SAAS,cAAc;AACvB,SAAS,eAAe;AACxB,SAAS,kBAAkB,4BAA4B;AACvD,SAAS,kBAAkB;AAC3B,SAAS,eAAe;AACxB,SAAS,aAAa;AACtB,SAAS,UAAU,sBAAsB;AACzC,SAAS,YAAY;AAErB,SAAS,wBAAwB;AACjC,SAAS,yBAAyB;AA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YAAY,EAAE,MAAM,UAAU,OAAO,YAAY,eAAe,cAAc,QAAQ;AAAA,QACtF;AAAA,QACC,GAAI,UAAU;AAAA,UACb,YAAY,CAAC,QAAqB,IAAI;AAAA,UACtC,YAAY,CAAC,QAAqB,CAAC,IAAI;AAAA,UACvC;AAAA,UACA,kBAAkB;AAAA,QACpB,IAAI,CAAC;AAAA;AAAA,IACP,GACF;AAAA,IACC;AAAA,KACH;AAEJ;",
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport { extensionPoints } from '@open-mercato/core/modules/workflows/extension-points'\nimport Link from 'next/link'\nimport { useRouter } from 'next/navigation'\nimport { Page, PageBody } from '@open-mercato/ui/backend/Page'\nimport { DataTable } from '@open-mercato/ui/backend/DataTable'\nimport type { LegacyColumnDef as ColumnDef } from '@tanstack/react-table/legacy'\nimport type { ExpandedState } from '@tanstack/react-table'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { Spinner } from '@open-mercato/ui/primitives/spinner'\nimport { SegmentedControl, SegmentedControlItem } from '@open-mercato/ui/primitives/segmented-control'\nimport { RowActions } from '@open-mercato/ui/backend/RowActions'\nimport { apiCall } from '@open-mercato/ui/backend/utils/apiCall'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { useQuery, useQueryClient } from '@tanstack/react-query'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport type { FilterDef, FilterValues } from '@open-mercato/ui/backend/FilterBar'\nimport { useConfirmDialog } from '@open-mercato/ui/backend/confirm-dialog'\nimport { useLiveRunUpdates } from '../../components/run/useLiveRunUpdates'\n\ntype WorkflowInstance = {\n id: string\n definitionId: string\n workflowId: string\n version: number\n status: 'RUNNING' | 'PAUSED' | 'COMPLETED' | 'FAILED' | 'CANCELLED' | 'COMPENSATING' | 'COMPENSATED'\n currentStepId: string\n correlationKey: string | null\n startedAt: string\n completedAt: string | null\n cancelledAt: string | null\n errorMessage: string | null\n retryCount: number\n metadata?: { labels?: Record<string, string> | null } | null\n tenantId: string\n organizationId: string\n createdAt: string\n updatedAt: string\n}\n\n// Row shape rendered by the accordion. `children` are lazily-loaded\n// sub-workflow instances; placeholder rows carry a `__placeholder` marker so\n// the loading/empty state renders inline under an expanded parent.\ntype InstanceRow = WorkflowInstance & {\n children?: InstanceRow[]\n __placeholder?: 'loading' | 'empty'\n __parentId?: string\n}\n\nfunction makePlaceholderRow(parentId: string, kind: 'loading' | 'empty'): InstanceRow {\n return {\n id: `${parentId}::${kind}`,\n __placeholder: kind,\n __parentId: parentId,\n } as InstanceRow\n}\n\ntype InstancesResponse = {\n data: WorkflowInstance[]\n pagination: {\n total: number\n limit: number\n offset: number\n hasMore: boolean\n totalIsCapped?: boolean\n }\n}\n\nexport default function WorkflowInstancesListPage() {\n const [page, setPage] = React.useState(1)\n const [pageSize] = React.useState(50)\n const [total, setTotal] = React.useState(0)\n const [totalPages, setTotalPages] = React.useState(1)\n const [totalIsCapped, setTotalIsCapped] = React.useState(false)\n const t = useT()\n const router = useRouter()\n const queryClient = useQueryClient()\n const { confirm: confirmDialog, ConfirmDialogElement } = useConfirmDialog()\n const [filterValues, setFilterValues] = React.useState<FilterValues>({})\n // Grouped (default): list top-level instances and nest sub-workflow children\n // under their parent. Flat: legacy unfiltered view of every instance.\n const [grouped, setGrouped] = React.useState(true)\n const [expanded, setExpanded] = React.useState<ExpandedState>({})\n const [childrenByParent, setChildrenByParent] = React.useState<Map<string, InstanceRow[]>>(new Map())\n\n const buildListParams = React.useCallback(() => {\n const params = new URLSearchParams()\n if (filterValues.status) params.set('status', filterValues.status as string)\n if (filterValues.workflowId) params.set('workflowId', filterValues.workflowId as string)\n if (filterValues.correlationKey) params.set('correlationKey', filterValues.correlationKey as string)\n if (filterValues.entityType) params.set('entityType', filterValues.entityType as string)\n if (filterValues.entityId) params.set('entityId', filterValues.entityId as string)\n // The date-range control emits calendar days; the API widens `startedTo` to\n // cover the whole day, so \"started on the 3rd\" does not exclude everything\n // after midnight.\n const startedAt = filterValues.startedAt as { from?: string; to?: string } | undefined\n if (startedAt?.from) params.set('startedFrom', startedAt.from)\n if (startedAt?.to) params.set('startedTo', startedAt.to)\n if (filterValues.attention) params.set('attention', 'true')\n return params\n }, [filterValues])\n\n const { data, isLoading, error } = useQuery({\n queryKey: ['workflow-instances', 'list', filterValues, page, grouped],\n queryFn: async () => {\n const params = buildListParams()\n const offset = (page - 1) * pageSize\n params.set('limit', pageSize.toString())\n params.set('offset', offset.toString())\n // In grouped mode only top-level instances paginate; children are loaded\n // lazily per parent on expand.\n if (grouped) params.set('hasParent', 'false')\n\n const result = await apiCall<InstancesResponse>(\n `/api/workflows/instances?${params.toString()}`\n )\n\n if (!result.ok) {\n throw new Error('Failed to fetch workflow instances')\n }\n\n const response = result.result\n if (response?.pagination) {\n setTotal(response.pagination.total || 0)\n const calculatedPages = Math.ceil((response.pagination.total || 0) / pageSize)\n setTotalPages(calculatedPages || 1)\n setTotalIsCapped(response.pagination?.totalIsCapped === true)\n }\n\n return response?.data || []\n },\n })\n\n // Live run list (spec \u00A78.3). Instance lifecycle events are broadcast to the\n // browser, so a run that starts, finishes or fails appears without a reload.\n // The hook throttles the burst a busy tenant produces into one refetch.\n useLiveRunUpdates({\n onRefresh: React.useCallback(() => {\n queryClient.invalidateQueries({ queryKey: ['workflow-instances'] })\n }, [queryClient]),\n })\n\n // Reset accordion state whenever the top-level result set changes (filters,\n // page, mode) so stale expansions/children don't leak across views.\n React.useEffect(() => {\n setExpanded({})\n setChildrenByParent(new Map())\n }, [filterValues, page, grouped])\n\n const loadChildren = React.useCallback(async (parentId: string) => {\n setChildrenByParent((prev) => {\n const next = new Map(prev)\n next.set(parentId, [makePlaceholderRow(parentId, 'loading')])\n return next\n })\n // Children are fetched by parent id only \u2014 the top-level content filters\n // (status, workflowId, correlationKey, entity*) scope which parents appear,\n // not which sub-workflows a parent reveals when expanded. Carrying them here\n // would surprise users by hiding a parent's non-matching children.\n const params = new URLSearchParams({ parentInstanceId: parentId, limit: '100' })\n const result = await apiCall<InstancesResponse>(`/api/workflows/instances?${params.toString()}`)\n const children = (result.ok ? result.result?.data ?? [] : []) as InstanceRow[]\n setChildrenByParent((prev) => {\n const next = new Map(prev)\n next.set(parentId, children.length ? children : [makePlaceholderRow(parentId, 'empty')])\n return next\n })\n }, [])\n\n const handleExpandedChange = React.useCallback((updater: ExpandedState | ((old: ExpandedState) => ExpandedState)) => {\n setExpanded((prev) => {\n const next = typeof updater === 'function' ? updater(prev) : updater\n const prevRec = (prev === true ? {} : prev) as Record<string, boolean>\n const nextRec = (next === true ? {} : next) as Record<string, boolean>\n for (const rowId of Object.keys(nextRec)) {\n if (nextRec[rowId] && !prevRec[rowId] && !childrenByParent.has(rowId)) {\n void loadChildren(rowId)\n }\n }\n return next\n })\n }, [childrenByParent, loadChildren])\n\n // Build the nested row tree from the top-level result + lazily-loaded\n // children. A visited set guards against pathological cycles so expansion\n // can never recurse infinitely.\n const treeData = React.useMemo<InstanceRow[]>(() => {\n const buildRow = (instance: WorkflowInstance, ancestors: Set<string>): InstanceRow => {\n const loaded = childrenByParent.get(instance.id)\n if (!loaded) return { ...instance }\n const nextAncestors = new Set(ancestors)\n nextAncestors.add(instance.id)\n const children = loaded.map((child) =>\n child.__placeholder || nextAncestors.has(child.id)\n ? child\n : buildRow(child, nextAncestors)\n )\n return { ...instance, children }\n }\n return (data || []).map((instance) => buildRow(instance, new Set()))\n }, [data, childrenByParent])\n\n const handleCancel = async (id: string, workflowId: string) => {\n const confirmed = await confirmDialog({\n title: t('workflows.instances.confirm.cancel', { workflowId }),\n variant: 'destructive',\n })\n if (!confirmed) {\n return\n }\n\n const result = await apiCall(`/api/workflows/instances/${id}/cancel`, {\n method: 'POST',\n })\n\n if (result.ok) {\n flash(t('workflows.instances.messages.cancelled'), 'success')\n queryClient.invalidateQueries({ queryKey: ['workflow-instances'] })\n } else {\n flash(t('workflows.instances.messages.cancelFailed'), 'error')\n }\n }\n\n const handleRetry = async (id: string, workflowId: string) => {\n const ok = await confirmDialog({\n title: t('workflows.instances.confirm.retry', { workflowId }),\n variant: 'default',\n })\n if (!ok) {\n return\n }\n\n const result = await apiCall(`/api/workflows/instances/${id}/retry`, {\n method: 'POST',\n })\n\n if (result.ok) {\n flash(t('workflows.instances.messages.retried'), 'success')\n queryClient.invalidateQueries({ queryKey: ['workflow-instances'] })\n } else {\n flash(t('workflows.instances.messages.retryFailed'), 'error')\n }\n }\n\n const handleFiltersApply = React.useCallback((values: FilterValues) => {\n const next: FilterValues = {}\n Object.entries(values).forEach(([key, value]) => {\n if (value !== undefined && value !== '') next[key] = value\n })\n setFilterValues(next)\n setPage(1)\n }, [])\n\n const handleFiltersClear = React.useCallback(() => {\n setFilterValues({})\n setPage(1)\n }, [])\n\n const getStatusBadgeClass = (status: WorkflowInstance['status']) => {\n switch (status) {\n case 'RUNNING':\n return 'bg-status-info-bg text-status-info-text'\n case 'PAUSED':\n return 'bg-status-warning-bg text-status-warning-text'\n case 'COMPLETED':\n return 'bg-status-success-bg text-status-success-text'\n case 'FAILED':\n return 'bg-status-error-bg text-status-error-text'\n case 'CANCELLED':\n return 'bg-status-neutral-bg text-status-neutral-text'\n case 'COMPENSATING':\n return 'bg-status-warning-bg text-status-warning-text'\n case 'COMPENSATED':\n return 'bg-status-neutral-bg text-status-neutral-text'\n default:\n return 'bg-status-neutral-bg text-status-neutral-text'\n }\n }\n\n const filters: FilterDef[] = [\n {\n id: 'status',\n type: 'select',\n label: t('workflows.instances.filters.status'),\n options: [\n { label: t('common.all'), value: '' },\n { label: t('workflows.instances.status.RUNNING'), value: 'RUNNING' },\n { label: t('workflows.instances.status.PAUSED'), value: 'PAUSED' },\n { label: t('workflows.instances.status.COMPLETED'), value: 'COMPLETED' },\n { label: t('workflows.instances.status.FAILED'), value: 'FAILED' },\n { label: t('workflows.instances.status.CANCELLED'), value: 'CANCELLED' },\n { label: t('workflows.instances.status.COMPENSATING'), value: 'COMPENSATING' },\n { label: t('workflows.instances.status.COMPENSATED'), value: 'COMPENSATED' },\n ],\n },\n {\n id: 'workflowId',\n type: 'text',\n label: t('workflows.instances.filters.workflowId'),\n placeholder: t('workflows.instances.filters.workflowIdPlaceholder'),\n },\n {\n id: 'correlationKey',\n type: 'text',\n label: t('workflows.instances.filters.correlationKey'),\n placeholder: t('workflows.instances.filters.correlationKeyPlaceholder'),\n },\n {\n id: 'entityType',\n type: 'text',\n label: t('workflows.instances.filters.entityType'),\n placeholder: t('workflows.instances.filters.entityTypePlaceholder'),\n },\n {\n id: 'entityId',\n type: 'text',\n label: t('workflows.instances.filters.entityId'),\n placeholder: t('workflows.instances.filters.entityIdPlaceholder'),\n },\n {\n id: 'startedAt',\n type: 'dateRange',\n label: t('workflows.instances.filters.startedAt', 'Started'),\n },\n {\n // The failure queue (spec 5.9 / 8.4): a `failureQueue` error directive\n // parks an instance as PAUSED with an engine-owned attention marker. The\n // API has filtered on it since Phase 3a; this is the control for it.\n id: 'attention',\n type: 'checkbox',\n label: t('workflows.instances.filters.attention', 'Needs attention'),\n tooltip: t(\n 'workflows.instances.filters.attentionTooltip',\n 'Instances parked by a failure-queue directive, waiting for a human to triage them.'\n ),\n },\n ]\n\n const columns: ColumnDef<InstanceRow>[] = [\n {\n id: 'workflowId',\n header: t('workflows.instances.fields.workflowId'),\n accessorKey: 'workflowId',\n cell: ({ row }) => {\n if (row.original.__placeholder === 'loading') {\n return (\n <span className=\"inline-flex items-center gap-2 text-sm text-muted-foreground\">\n <Spinner className=\"h-3.5 w-3.5\" />\n {t('workflows.instances.subWorkflows.loading', 'Loading sub-workflows\u2026')}\n </span>\n )\n }\n if (row.original.__placeholder === 'empty') {\n return (\n <span className=\"text-sm text-muted-foreground\">\n {t('workflows.instances.subWorkflows.empty', 'No sub-workflows')}\n </span>\n )\n }\n return (\n <Link href={`/backend/instances/${row.original.id}`} className=\"block hover:underline\">\n <div className=\"font-mono text-sm font-medium\">{row.original.workflowId}</div>\n {row.original.correlationKey && (\n <div className=\"text-xs text-muted-foreground\">\n {t('workflows.instances.fields.correlationKey')}: {row.original.correlationKey}\n </div>\n )}\n </Link>\n )\n },\n },\n {\n id: 'status',\n header: t('workflows.instances.fields.status'),\n accessorKey: 'status',\n cell: ({ row }) => {\n if (row.original.__placeholder) return null\n return (\n <span className={`inline-flex items-center px-2 py-1 rounded text-xs font-medium ${getStatusBadgeClass(row.original.status)}`}>\n {t(`workflows.instances.status.${row.original.status}`)}\n </span>\n )\n },\n },\n {\n id: 'currentStep',\n header: t('workflows.instances.fields.currentStep'),\n accessorKey: 'currentStepId',\n cell: ({ row }) => {\n if (row.original.__placeholder) return null\n return <span className=\"text-sm text-muted-foreground\">{row.original.currentStepId}</span>\n },\n },\n {\n id: 'timing',\n header: t('workflows.instances.fields.timing'),\n cell: ({ row }) => {\n if (row.original.__placeholder) return null\n const started = new Date(row.original.startedAt)\n const completed = row.original.completedAt ? new Date(row.original.completedAt) : null\n const duration = completed ? completed.getTime() - started.getTime() : Date.now() - started.getTime()\n const durationText = duration < 60000\n ? `${Math.floor(duration / 1000)}s`\n : `${Math.floor(duration / 60000)}m`\n\n return (\n <div className=\"text-sm\">\n <div className=\"text-foreground\">{started.toLocaleString()}</div>\n <div className=\"text-xs text-muted-foreground\">\n {completed ? t('workflows.instances.duration') : t('workflows.instances.elapsed')}: {durationText}\n </div>\n </div>\n )\n },\n },\n {\n id: 'retryCount',\n header: t('workflows.instances.fields.retryCount'),\n accessorKey: 'retryCount',\n cell: ({ row }) => {\n if (row.original.__placeholder) return null\n return (\n <span\n className={`text-sm ${\n row.original.retryCount > 0 ? 'font-medium text-status-warning-text' : 'text-muted-foreground'\n }`}\n >\n {row.original.retryCount}\n </span>\n )\n },\n },\n {\n id: 'actions',\n header: '',\n cell: ({ row }) => {\n if (row.original.__placeholder) return null\n const items: Array<{ id: string; label: string; href?: string; onSelect?: () => void }> = [\n {\n id: 'view',\n label: t('workflows.instances.actions.viewDetails'),\n href: `/backend/instances/${row.original.id}`,\n },\n ]\n\n if (row.original.status === 'RUNNING' || row.original.status === 'PAUSED') {\n items.push({\n id: 'cancel',\n label: t('workflows.instances.actions.cancel'),\n onSelect: () => void handleCancel(row.original.id, row.original.workflowId),\n })\n }\n\n if (row.original.status === 'FAILED') {\n items.push({\n id: 'retry',\n label: t('workflows.instances.actions.retry'),\n onSelect: () => void handleRetry(row.original.id, row.original.workflowId),\n })\n }\n\n return <RowActions items={items} />\n },\n },\n ]\n\n if (error) {\n return (\n <Page>\n <PageBody>\n <div className=\"p-8 text-center\">\n <p className=\"text-status-error-text\">{t('workflows.instances.messages.loadFailed')}</p>\n <Button onClick={() => queryClient.invalidateQueries({ queryKey: ['workflow-instances'] })} className=\"mt-4\">\n {t('common.retry')}\n </Button>\n </div>\n </PageBody>\n </Page>\n )\n }\n\n const viewToggle = (\n <SegmentedControl\n value={grouped ? 'grouped' : 'flat'}\n onValueChange={(value) => setGrouped(value === 'grouped')}\n aria-label={t('workflows.instances.list.viewToggle', 'Instance view')}\n >\n <SegmentedControlItem value=\"grouped\">\n {t('workflows.instances.list.topLevelOnly', 'Top-level')}\n </SegmentedControlItem>\n <SegmentedControlItem value=\"flat\">\n {t('workflows.instances.list.showAllFlat', 'All (flat)')}\n </SegmentedControlItem>\n </SegmentedControl>\n )\n\n return (\n <Page>\n <PageBody>\n <DataTable<InstanceRow>\n title={t('workflows.instances.list.title')}\n titleHeadingLevel={1}\n actions={viewToggle}\n columns={columns}\n data={grouped ? treeData : ((data || []) as InstanceRow[])}\n filters={filters}\n filterValues={filterValues}\n onFiltersApply={handleFiltersApply}\n onFiltersClear={handleFiltersClear}\n perspective={{\n tableId: extensionPoints.hosts.instancesTable.tableId,\n }}\n pagination={{ page, pageSize, total, totalPages, totalIsCapped, onPageChange: setPage }}\n isLoading={isLoading}\n {...(grouped ? {\n getSubRows: (row: InstanceRow) => row.children,\n expandable: (row: InstanceRow) => !row.__placeholder,\n expanded,\n onExpandedChange: handleExpandedChange,\n } : {})}\n />\n </PageBody>\n {ConfirmDialogElement}\n </Page>\n )\n}\n"],
|
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wCAAwC,YAAY,GACzD;AAAA;AAAA;AAAA,EACF;AAGF,SACE,qBAAC,QACC;AAAA,wBAAC,YACC;AAAA,MAAC;AAAA;AAAA,QACC,OAAO,EAAE,gCAAgC;AAAA,QACzC,mBAAmB;AAAA,QACnB,SAAS;AAAA,QACT;AAAA,QACA,MAAM,UAAU,WAAa,QAAQ,CAAC;AAAA,QACtC;AAAA,QACA;AAAA,QACA,gBAAgB;AAAA,QAChB,gBAAgB;AAAA,QAChB,aAAa;AAAA,UACX,SAAS,gBAAgB,MAAM,eAAe;AAAA,QAChD;AAAA,QACA,YAAY,EAAE,MAAM,UAAU,OAAO,YAAY,eAAe,cAAc,QAAQ;AAAA,QACtF;AAAA,QACC,GAAI,UAAU;AAAA,UACb,YAAY,CAAC,QAAqB,IAAI;AAAA,UACtC,YAAY,CAAC,QAAqB,CAAC,IAAI;AAAA,UACvC;AAAA,UACA,kBAAkB;AAAA,QACpB,IAAI,CAAC;AAAA;AAAA,IACP,GACF;AAAA,IACC;AAAA,KACH;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/core",
|
|
3
|
-
"version": "0.10.1-develop.
|
|
3
|
+
"version": "0.10.1-develop.7978.1.b4468545b6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -266,16 +266,16 @@
|
|
|
266
266
|
"zod": "^4.6.6"
|
|
267
267
|
},
|
|
268
268
|
"peerDependencies": {
|
|
269
|
-
"@open-mercato/ai-assistant": "0.10.1-develop.
|
|
270
|
-
"@open-mercato/shared": "0.10.1-develop.
|
|
271
|
-
"@open-mercato/ui": "0.10.1-develop.
|
|
269
|
+
"@open-mercato/ai-assistant": "0.10.1-develop.7978.1.b4468545b6",
|
|
270
|
+
"@open-mercato/shared": "0.10.1-develop.7978.1.b4468545b6",
|
|
271
|
+
"@open-mercato/ui": "0.10.1-develop.7978.1.b4468545b6",
|
|
272
272
|
"react": "^19.0.0",
|
|
273
273
|
"react-dom": "^19.0.0"
|
|
274
274
|
},
|
|
275
275
|
"devDependencies": {
|
|
276
|
-
"@open-mercato/ai-assistant": "0.10.1-develop.
|
|
277
|
-
"@open-mercato/shared": "0.10.1-develop.
|
|
278
|
-
"@open-mercato/ui": "0.10.1-develop.
|
|
276
|
+
"@open-mercato/ai-assistant": "0.10.1-develop.7978.1.b4468545b6",
|
|
277
|
+
"@open-mercato/shared": "0.10.1-develop.7978.1.b4468545b6",
|
|
278
|
+
"@open-mercato/ui": "0.10.1-develop.7978.1.b4468545b6",
|
|
279
279
|
"@testing-library/dom": "^10.4.1",
|
|
280
280
|
"@testing-library/jest-dom": "^7.0.1",
|
|
281
281
|
"@testing-library/react": "^16.3.3",
|
|
@@ -59,6 +59,21 @@ type PersonCompanyLinkSnapshot = {
|
|
|
59
59
|
type PersonCompanyLinkUndoPayload = {
|
|
60
60
|
before?: PersonCompanyLinkSnapshot | null
|
|
61
61
|
after?: PersonCompanyLinkSnapshot | null
|
|
62
|
+
createBefore?: PersonCompanyLinkCreateBefore
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
type PersonCompanyLinkCreateBefore = {
|
|
66
|
+
link: PersonCompanyLinkSnapshot | null
|
|
67
|
+
primaryLinkIds: string[]
|
|
68
|
+
profileCompanyId: string | null
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
type PersonCompanyLinkCreateResult = {
|
|
72
|
+
linkId: string
|
|
73
|
+
created: boolean
|
|
74
|
+
undeleted: boolean
|
|
75
|
+
changed: boolean
|
|
76
|
+
createBefore: PersonCompanyLinkCreateBefore
|
|
62
77
|
}
|
|
63
78
|
|
|
64
79
|
/**
|
|
@@ -171,6 +186,10 @@ async function loadPersonCompanyLinkSnapshot(
|
|
|
171
186
|
},
|
|
172
187
|
)
|
|
173
188
|
if (!link) return null
|
|
189
|
+
return snapshotPersonCompanyLink(link)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function snapshotPersonCompanyLink(link: CustomerPersonCompanyLink): PersonCompanyLinkSnapshot {
|
|
174
193
|
const personId = typeof link.person === 'string' ? link.person : link.person.id
|
|
175
194
|
const companyId = typeof link.company === 'string' ? link.company : link.company.id
|
|
176
195
|
return {
|
|
@@ -247,8 +266,88 @@ async function clearPrimaryFlagsForPerson(em: EntityManager, person: CustomerEnt
|
|
|
247
266
|
)
|
|
248
267
|
}
|
|
249
268
|
|
|
250
|
-
|
|
269
|
+
async function restoreCreatePersonCompanyLink(
|
|
270
|
+
ctx: CommandRuntimeContext,
|
|
271
|
+
after: PersonCompanyLinkSnapshot,
|
|
272
|
+
before: PersonCompanyLinkCreateBefore,
|
|
273
|
+
): Promise<void> {
|
|
274
|
+
const em = (ctx.container.resolve('em') as EntityManager).fork()
|
|
275
|
+
const scope = { tenantId: after.tenantId, organizationId: after.organizationId }
|
|
276
|
+
const link = await findOneWithDecryption(
|
|
277
|
+
em,
|
|
278
|
+
CustomerPersonCompanyLink,
|
|
279
|
+
{ id: after.id, ...scope },
|
|
280
|
+
undefined,
|
|
281
|
+
scope,
|
|
282
|
+
)
|
|
283
|
+
if (!link) return
|
|
284
|
+
const person = await requirePersonEntity(em, after.personEntityId, after.tenantId, after.organizationId)
|
|
285
|
+
const profile = await requirePersonProfile(em, person)
|
|
286
|
+
const profileCompanyId = typeof profile.company === 'string' ? profile.company : profile.company?.id ?? null
|
|
287
|
+
const restorePrimaryAssignment = after.isPrimary && link.isPrimary && profileCompanyId === after.companyEntityId
|
|
288
|
+
const company = restorePrimaryAssignment && before.profileCompanyId
|
|
289
|
+
? await requireCompanyEntity(em, before.profileCompanyId, after.tenantId, after.organizationId)
|
|
290
|
+
: null
|
|
291
|
+
const primaryLinkIds = before.primaryLinkIds.filter((id) => id !== link.id)
|
|
292
|
+
|
|
293
|
+
await withAtomicFlush(em, [
|
|
294
|
+
async () => {
|
|
295
|
+
if (restorePrimaryAssignment) {
|
|
296
|
+
await em.nativeUpdate(
|
|
297
|
+
CustomerPersonCompanyLink,
|
|
298
|
+
{ person, ...scope, id: { $ne: link.id }, deletedAt: null, isPrimary: true },
|
|
299
|
+
{ isPrimary: false },
|
|
300
|
+
)
|
|
301
|
+
if (primaryLinkIds.length) {
|
|
302
|
+
await em.nativeUpdate(
|
|
303
|
+
CustomerPersonCompanyLink,
|
|
304
|
+
{ person, ...scope, id: { $in: primaryLinkIds }, deletedAt: null },
|
|
305
|
+
{ isPrimary: true },
|
|
306
|
+
)
|
|
307
|
+
}
|
|
308
|
+
profile.company = company
|
|
309
|
+
}
|
|
310
|
+
link.isPrimary = before.link?.isPrimary ?? false
|
|
311
|
+
link.deletedAt = before.link
|
|
312
|
+
? before.link.deletedAt ? new Date(before.link.deletedAt) : null
|
|
313
|
+
: new Date()
|
|
314
|
+
},
|
|
315
|
+
], { transaction: true })
|
|
316
|
+
|
|
317
|
+
const dataEngine = ctx.container.resolve('dataEngine') as DataEngine
|
|
318
|
+
await emitCrudUndoSideEffects({
|
|
319
|
+
dataEngine,
|
|
320
|
+
action: link.deletedAt ? 'deleted' : 'updated',
|
|
321
|
+
entity: link,
|
|
322
|
+
identifiers: getLinkIdentifiers(link),
|
|
323
|
+
syncOrigin: ctx.syncOrigin,
|
|
324
|
+
events: personCompanyLinkCrudEvents,
|
|
325
|
+
indexer: { entityType: 'customers:customer_person_company_link' },
|
|
326
|
+
})
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const createPersonCompanyLinkCommand: CommandHandler<PersonCompanyLinkCreateInput, PersonCompanyLinkCreateResult> = {
|
|
251
330
|
id: 'customers.personCompanyLinks.create',
|
|
331
|
+
async prepare(rawInput, ctx) {
|
|
332
|
+
const parsed = personCompanyLinkCreateSchema.parse(rawInput)
|
|
333
|
+
ensureTenantScope(ctx, parsed.tenantId)
|
|
334
|
+
ensureOrganizationScope(ctx, parsed.organizationId)
|
|
335
|
+
const em = (ctx.container.resolve('em') as EntityManager).fork()
|
|
336
|
+
const person = await requirePersonEntity(em, parsed.personEntityId, parsed.tenantId, parsed.organizationId)
|
|
337
|
+
const company = await requireCompanyEntity(em, parsed.companyEntityId, parsed.tenantId, parsed.organizationId)
|
|
338
|
+
const profile = await requirePersonProfile(em, person)
|
|
339
|
+
const links = await loadPersonCompanyLinks(em, person)
|
|
340
|
+
const link = links.find((entry) =>
|
|
341
|
+
(typeof entry.company === 'string' ? entry.company : entry.company.id) === company.id,
|
|
342
|
+
) ?? await findDeletedPersonCompanyLink(em, person, company)
|
|
343
|
+
return {
|
|
344
|
+
before: {
|
|
345
|
+
link: link ? await loadPersonCompanyLinkSnapshot(em, link.id, parsed) : null,
|
|
346
|
+
primaryLinkIds: links.filter((entry) => entry.isPrimary).map((entry) => entry.id),
|
|
347
|
+
profileCompanyId: typeof profile.company === 'string' ? profile.company : profile.company?.id ?? null,
|
|
348
|
+
} satisfies PersonCompanyLinkCreateBefore,
|
|
349
|
+
}
|
|
350
|
+
},
|
|
252
351
|
async execute(rawInput, ctx) {
|
|
253
352
|
const parsed = personCompanyLinkCreateSchema.parse(rawInput)
|
|
254
353
|
ensureTenantScope(ctx, parsed.tenantId)
|
|
@@ -263,9 +362,17 @@ const createPersonCompanyLinkCommand: CommandHandler<PersonCompanyLinkCreateInpu
|
|
|
263
362
|
const makePrimary = Boolean(parsed.isPrimary) || existingLinks.length === 0
|
|
264
363
|
const existingLive =
|
|
265
364
|
existingLinks.find((link) => (typeof link.company === 'string' ? link.company : link.company.id) === company.id) ?? null
|
|
365
|
+
// This state must come from execute's decision, not prepare's earlier read: another
|
|
366
|
+
// request may have created the link between prepare and execute.
|
|
367
|
+
const createBefore: PersonCompanyLinkCreateBefore = {
|
|
368
|
+
link: existingLive ? snapshotPersonCompanyLink(existingLive) : null,
|
|
369
|
+
primaryLinkIds: existingLinks.filter((link) => link.isPrimary).map((link) => link.id),
|
|
370
|
+
profileCompanyId: typeof profile.company === 'string' ? profile.company : profile.company?.id ?? null,
|
|
371
|
+
}
|
|
266
372
|
|
|
267
373
|
if (existingLive) {
|
|
268
|
-
|
|
374
|
+
const changed = makePrimary && !existingLive.isPrimary
|
|
375
|
+
if (changed) {
|
|
269
376
|
await withAtomicFlush(em, [
|
|
270
377
|
() => clearPrimaryFlagsForPerson(em, person),
|
|
271
378
|
() => {
|
|
@@ -274,7 +381,7 @@ const createPersonCompanyLinkCommand: CommandHandler<PersonCompanyLinkCreateInpu
|
|
|
274
381
|
},
|
|
275
382
|
], { transaction: true })
|
|
276
383
|
}
|
|
277
|
-
return { linkId: existingLive.id, created: false, undeleted: false }
|
|
384
|
+
return { linkId: existingLive.id, created: false, undeleted: false, changed, createBefore }
|
|
278
385
|
}
|
|
279
386
|
|
|
280
387
|
let link!: CustomerPersonCompanyLink
|
|
@@ -282,6 +389,7 @@ const createPersonCompanyLinkCommand: CommandHandler<PersonCompanyLinkCreateInpu
|
|
|
282
389
|
await withAtomicFlush(em, [
|
|
283
390
|
async () => {
|
|
284
391
|
const deletedLink = await findDeletedPersonCompanyLink(em, person, company)
|
|
392
|
+
if (deletedLink) createBefore.link = snapshotPersonCompanyLink(deletedLink)
|
|
285
393
|
if (makePrimary) {
|
|
286
394
|
await clearPrimaryFlagsForPerson(em, person)
|
|
287
395
|
}
|
|
@@ -323,18 +431,22 @@ const createPersonCompanyLinkCommand: CommandHandler<PersonCompanyLinkCreateInpu
|
|
|
323
431
|
indexer: { entityType: 'customers:customer_person_company_link' },
|
|
324
432
|
})
|
|
325
433
|
|
|
326
|
-
return { linkId: link.id, created: !undeleted, undeleted }
|
|
434
|
+
return { linkId: link.id, created: !undeleted, undeleted, changed: true, createBefore }
|
|
327
435
|
},
|
|
328
436
|
captureAfter: async (_input, result, ctx) => {
|
|
329
|
-
const em = ctx.container.resolve('em') as EntityManager
|
|
437
|
+
const em = (ctx.container.resolve('em') as EntityManager).fork()
|
|
330
438
|
return loadPersonCompanyLinkSnapshot(em, result.linkId, {
|
|
331
439
|
tenantId: ctx.auth?.tenantId ?? null,
|
|
332
440
|
organizationId: ctx.selectedOrganizationId ?? ctx.auth?.orgId ?? null,
|
|
333
441
|
})
|
|
334
442
|
},
|
|
335
443
|
buildLog: async ({ result, snapshots }) => {
|
|
336
|
-
const
|
|
444
|
+
const before = result.createBefore
|
|
337
445
|
const after = snapshots.after as PersonCompanyLinkSnapshot | undefined
|
|
446
|
+
if (!result.changed) {
|
|
447
|
+
return { skipLog: true }
|
|
448
|
+
}
|
|
449
|
+
const { translate } = await resolveTranslations()
|
|
338
450
|
return {
|
|
339
451
|
actionLabel: translate('customers.audit.personCompanyLinks.create', 'Link company to person'),
|
|
340
452
|
resourceKind: 'customers.personCompanyLink',
|
|
@@ -343,10 +455,12 @@ const createPersonCompanyLinkCommand: CommandHandler<PersonCompanyLinkCreateInpu
|
|
|
343
455
|
parentResourceId: after?.personEntityId ?? null,
|
|
344
456
|
tenantId: after?.tenantId ?? null,
|
|
345
457
|
organizationId: after?.organizationId ?? null,
|
|
458
|
+
snapshotBefore: before?.link ?? null,
|
|
346
459
|
snapshotAfter: after ?? null,
|
|
347
460
|
payload: {
|
|
348
461
|
undo: {
|
|
349
462
|
after: after ?? null,
|
|
463
|
+
...(before ? { createBefore: before } : {}),
|
|
350
464
|
...(result.undeleted ? { before: null } : {}),
|
|
351
465
|
} satisfies PersonCompanyLinkUndoPayload,
|
|
352
466
|
},
|
|
@@ -357,6 +471,11 @@ const createPersonCompanyLinkCommand: CommandHandler<PersonCompanyLinkCreateInpu
|
|
|
357
471
|
const after = payload?.after
|
|
358
472
|
if (!after) return
|
|
359
473
|
|
|
474
|
+
if (payload.createBefore) {
|
|
475
|
+
await restoreCreatePersonCompanyLink(ctx, after, payload.createBefore)
|
|
476
|
+
return
|
|
477
|
+
}
|
|
478
|
+
|
|
360
479
|
const em = (ctx.container.resolve('em') as EntityManager).fork()
|
|
361
480
|
const link = await findOneWithDecryption(
|
|
362
481
|
em,
|
|
@@ -431,6 +550,12 @@ const createPersonCompanyLinkCommand: CommandHandler<PersonCompanyLinkCreateInpu
|
|
|
431
550
|
undefined,
|
|
432
551
|
{ tenantId: after.tenantId, organizationId: after.organizationId },
|
|
433
552
|
)
|
|
553
|
+
const existingLinks = await loadPersonCompanyLinks(em, person)
|
|
554
|
+
const createBefore: PersonCompanyLinkCreateBefore = {
|
|
555
|
+
link: link ? snapshotPersonCompanyLink(link) : null,
|
|
556
|
+
primaryLinkIds: existingLinks.filter((entry) => entry.isPrimary).map((entry) => entry.id),
|
|
557
|
+
profileCompanyId: typeof profile.company === 'string' ? profile.company : profile.company?.id ?? null,
|
|
558
|
+
}
|
|
434
559
|
|
|
435
560
|
await withAtomicFlush(em, [
|
|
436
561
|
async () => {
|
|
@@ -471,7 +596,7 @@ const createPersonCompanyLinkCommand: CommandHandler<PersonCompanyLinkCreateInpu
|
|
|
471
596
|
indexer: { entityType: 'customers:customer_person_company_link' },
|
|
472
597
|
})
|
|
473
598
|
|
|
474
|
-
return { linkId: link!.id, created: true, undeleted: false }
|
|
599
|
+
return { linkId: link!.id, created: true, undeleted: false, changed: true, createBefore }
|
|
475
600
|
},
|
|
476
601
|
}
|
|
477
602
|
|
|
@@ -6,7 +6,6 @@ import { useRouter } from 'next/navigation'
|
|
|
6
6
|
import type { LegacyColumnDef as ColumnDef } from '@tanstack/react-table/legacy'
|
|
7
7
|
import { Copy, Hash, Info, MessageSquare, Pencil, RefreshCw, Trash2, UserRound } from 'lucide-react'
|
|
8
8
|
import { hasFeature } from '@open-mercato/shared/security/features'
|
|
9
|
-
import { getTelemetryRuntime } from '@open-mercato/shared/lib/telemetry/runtime'
|
|
10
9
|
import { parseBooleanFromUnknown } from '@open-mercato/shared/lib/boolean'
|
|
11
10
|
import type { TranslateFn, TranslateParams } from '@open-mercato/shared/lib/i18n/context'
|
|
12
11
|
import { useLocale, useT } from '@open-mercato/shared/lib/i18n/context'
|
|
@@ -204,7 +204,7 @@ export default function WorkflowInstancesListPage() {
|
|
|
204
204
|
|
|
205
205
|
const handleCancel = async (id: string, workflowId: string) => {
|
|
206
206
|
const confirmed = await confirmDialog({
|
|
207
|
-
title: t('workflows.instances.confirm.cancel', {
|
|
207
|
+
title: t('workflows.instances.confirm.cancel', { workflowId }),
|
|
208
208
|
variant: 'destructive',
|
|
209
209
|
})
|
|
210
210
|
if (!confirmed) {
|
|
@@ -225,7 +225,7 @@ export default function WorkflowInstancesListPage() {
|
|
|
225
225
|
|
|
226
226
|
const handleRetry = async (id: string, workflowId: string) => {
|
|
227
227
|
const ok = await confirmDialog({
|
|
228
|
-
title: t('workflows.instances.confirm.retry', {
|
|
228
|
+
title: t('workflows.instances.confirm.retry', { workflowId }),
|
|
229
229
|
variant: 'default',
|
|
230
230
|
})
|
|
231
231
|
if (!ok) {
|