@@ -4,8 +4,8 @@ import { importZplText } from '../../lib/zplImportService';
44import { readFileAsText } from '../../lib/readFile' ;
55import { useLabelStore , type Page } from '../../store/labelStore' ;
66import type { LabelConfig } from '../../types/ObjectType' ;
7- import { formatReportAsText , type ImportResult } from '../../lib/importReport' ;
8- import { ImportSummaryBody } from './ImportReportModal ' ;
7+ import { formatReportAsText , type ImportReport , type ImportResult } from '../../lib/importReport' ;
8+ import { ImportSummaryBody } from './ImportSummary ' ;
99import { useT } from '../../lib/useT' ;
1010import { DialogShell } from '../ui/DialogShell' ;
1111
@@ -35,7 +35,7 @@ export function ZplImportModal({ onClose }: Props) {
3535
3636 const applyImport = ( labelConfig : Partial < LabelConfig > , importedPages : Page [ ] ) => {
3737 if ( appendMode && hasExistingContent ) {
38- // Keep the current label config — the user opted to keep the
38+ // Keep the current label config: the user opted to keep the
3939 // existing design's dimensions, so any imported ^PW/^LL is
4040 // intentionally discarded.
4141 appendPages ( importedPages ) ;
@@ -44,23 +44,41 @@ export function ZplImportModal({ onClose }: Props) {
4444 }
4545 } ;
4646
47- const handleImport = ( ) => {
48- setError ( null ) ;
49- if ( ! zpl . trim ( ) ) {
50- setError ( 'Please paste some ZPL code first.' ) ;
51- return ;
47+ // Feedback through state change: when the import has no findings the
48+ // changed canvas is confirmation enough. We only stop on the result
49+ // view when there is something the user could not otherwise see, i.e.
50+ // one or more findings to review.
51+ const finishImport = ( totalObjects : number , report : ImportReport ) => {
52+ if ( report . findings . length === 0 ) {
53+ onClose ( ) ;
54+ } else {
55+ setResult ( { objectCount : totalObjects , report } ) ;
5256 }
57+ } ;
5358
54- const { labelConfig, pages : importedPages , report } = importZplText ( zpl , label . dpmm ) ;
59+ // Shared post-source path: parse, gate on supported content, hand off
60+ // to the store + finishImport. The two entry points (paste textarea,
61+ // file picker) only differ in how they obtain the text and which
62+ // source-specific error they surface; everything past that point is
63+ // identical, so it lives here.
64+ const processImport = ( text : string ) => {
65+ const { labelConfig, pages : importedPages , report } = importZplText ( text , label . dpmm ) ;
5566 const totalObjects = importedPages . reduce ( ( s , p ) => s + p . objects . length , 0 ) ;
56-
5767 if ( totalObjects === 0 && Object . keys ( labelConfig ) . length === 0 ) {
5868 setError ( 'No supported objects found in the ZPL code.' ) ;
5969 return ;
6070 }
61-
6271 applyImport ( labelConfig , importedPages ) ;
63- setResult ( { objectCount : totalObjects , report } ) ;
72+ finishImport ( totalObjects , report ) ;
73+ } ;
74+
75+ const handleImport = ( ) => {
76+ setError ( null ) ;
77+ if ( ! zpl . trim ( ) ) {
78+ setError ( 'Please paste some ZPL code first.' ) ;
79+ return ;
80+ }
81+ processImport ( zpl ) ;
6482 } ;
6583
6684 const handleFileSelect = async ( e : React . ChangeEvent < HTMLInputElement > ) => {
@@ -81,17 +99,7 @@ export function ZplImportModal({ onClose }: Props) {
8199 setError ( 'The file appears to be empty.' ) ;
82100 return ;
83101 }
84-
85- const { labelConfig, pages : importedPages , report } = importZplText ( text , label . dpmm ) ;
86- const totalObjects = importedPages . reduce ( ( s , p ) => s + p . objects . length , 0 ) ;
87-
88- if ( totalObjects === 0 && Object . keys ( labelConfig ) . length === 0 ) {
89- setError ( 'No supported objects found in the ZPL code.' ) ;
90- return ;
91- }
92-
93- applyImport ( labelConfig , importedPages ) ;
94- setResult ( { objectCount : totalObjects , report } ) ;
102+ processImport ( text ) ;
95103 } ;
96104
97105 const handleCopy = ( ) => {
0 commit comments