diff --git a/plans/task-fix-template-view.md b/plans/task-fix-template-view.md new file mode 100644 index 0000000..e18f0c4 --- /dev/null +++ b/plans/task-fix-template-view.md @@ -0,0 +1,542 @@ +# Task Fix: Quotation Template JSON Viewer Overflow & Sheet Refactor + +## Status + +Planned Fix + +## Objective + +Fix the Quotation Template settings page layout overflow caused by rendering a full PDFME JSON schema inline. + +The page should no longer render large JSON content directly in the main content area. Instead, each template version should expose a compact `View JSON` action that opens a scrollable Sheet viewer. + +This fix improves: + +* page readability +* button visibility +* layout stability +* JSON review experience +* future maintainability for large PDFME templates + +--- + +## Problem + +Current page: + +```txt +/dashboard/crm/settings/templates +``` + +renders full JSON schema inline. + +Observed issue: + +* full JSON expands vertically and horizontally +* content overflows the visible page +* buttons/actions become hard to find +* page is difficult to operate +* JSON block dominates the whole settings page + +Current pattern is likely similar to: + +```tsx +
{JSON.stringify(schemaJson, null, 2)}
+```
+
+or:
+
+```tsx
+{JSON.stringify(version.schemaJson, null, 2)}
+```
+
+This should be removed from the main page layout.
+
+---
+
+## Screenshot Context
+
+Current UI shows:
+
+```txt
+Quotation Templates
+Template Configuration Center
+ALLA Quotation Standard
+Version 1.0
+Large inline JSON block
+```
+
+The large inline JSON causes the page to become visually noisy and may hide or push important actions away from the viewport.
+
+---
+
+## Mandatory Review
+
+Review before implementation:
+
+```txt
+src/app/dashboard/crm/settings/templates/**
+src/features/crm/document-templates/**
+src/features/crm/quotations/**
+src/components/ui/sheet.tsx
+src/components/ui/button.tsx
+```
+
+Also search for inline JSON rendering:
+
+```bash
+rg "JSON.stringify|schemaJson|schema_json|
+ {JSON.stringify(schemaJson, null, 2)}
+
+```
+
+Correct:
+
+```tsx
+
+ {formattedJson}
+
+ + {filePath} +
+``` + +--- + +## Verification + +Run: + +```bash +npm exec tsc --noEmit +npm run build +``` + +Manual verification: + +```txt +Open /dashboard/crm/settings/templates +Page no longer shows full JSON inline +Page does not overflow because of JSON +Template version card remains compact +View JSON button is visible +Click View JSON +Sheet opens from right side +JSON displays formatted +JSON scrolls inside Sheet +Copy JSON works +Close Sheet +No regression in quotation PDF preview/download +``` + +Search verification: + +```bash +rg "JSON.stringify| formatSchemaJson(schemaJson), [schemaJson]);
+ const pageCount = React.useMemo(() => getSchemaPageCount(schemaJson), [schemaJson]);
+ const hasSchemaJson = formattedJson !== '{}';
+
+ async function handleCopy() {
+ try {
+ await navigator.clipboard.writeText(formattedJson);
+ toast.success('Copied JSON');
+ } catch {
+ toast.error('Unable to copy JSON');
+ }
+ }
+
+ return (
+
+
+
+
+
+
+
+ Template Schema JSON
+
+ Version {version}
+ {filePath ? ` | ${filePath}` : ''}
+
+
+
+
+
+ {pageCount > 0 ? `Pages: ${pageCount}` : 'Schema metadata unavailable'}
+
+
+
+
+
+ {hasSchemaJson ? (
+
+ {formattedJson}
+
+ ) : (
+
+ No schema JSON available.
+
+ )}
+
+
+ );
+}
diff --git a/src/features/foundation/document-template/components/template-settings.tsx b/src/features/foundation/document-template/components/template-settings.tsx
index 848b297..41a763c 100644
--- a/src/features/foundation/document-template/components/template-settings.tsx
+++ b/src/features/foundation/document-template/components/template-settings.tsx
@@ -18,6 +18,7 @@ import { Input } from '@/components/ui/input';
import { Switch } from '@/components/ui/switch';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
import { Textarea } from '@/components/ui/textarea';
+import { TemplateJsonSheet } from './template-json-sheet';
import {
createDocumentTemplateMappingMutation,
createDocumentTemplateMutation,
@@ -182,6 +183,10 @@ function Field({
);
}
+function getTableColumnCount(version: DocumentTemplateVersionDetail) {
+ return version.mappings.reduce((total, mapping) => total + mapping.columns.length, 0);
+}
+
function TemplateDialog({
open,
onOpenChange,
@@ -574,40 +579,61 @@ function TemplateDetailCard({ templateId }: { templateId: string }) {
No versions created yet.
) : null}
- {template.versions.map((version) => (
-
-
-
-
- Version {version.version}
-
- {version.filePath || 'No file path set'}{version.previewImageUrl ? ` • ${version.previewImageUrl}` : ''}
+ {template.versions.map((version) => (
+
+
+
+
+ Version {version.version}
+
+
+ File Path
+
+ {version.filePath || 'No file path set'}
+
+
+
+ Mappings
+ {version.mappings.length}
+
+
+ Table Columns
+ {getTableColumnCount(version)}
+
+
+ Preview Image
+
+ {version.previewImageUrl || '-'}
+
+
+
+
+
+
+ {version.isActive ? 'Active' : 'Inactive'}
+
+
+
+
-
-
- {version.isActive ? 'Active' : 'Inactive'}
-
-
-
-
-
- {JSON.stringify(version.schemaJson, null, 2)}
-
-
{version.mappings.map((mapping) => (