Skip to content

Commit 6560c93

Browse files
committed
Remove deeplink blueprint validation in renderer
1 parent 0ea9e30 commit 6560c93

File tree

2 files changed

+27
-57
lines changed

2 files changed

+27
-57
lines changed

src/modules/add-site/hooks/use-blueprint-deeplink.ts

Lines changed: 27 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useI18n } from '@wordpress/react-i18n';
2-
import { useCallback, useEffect, useState } from 'react';
2+
import { useCallback, useState } from 'react';
33
import { useIpcListener } from 'src/hooks/use-ipc-listener';
44
import { getIpcApi } from 'src/lib/get-ipc-api';
55
import { Blueprint } from 'src/stores/wpcom-api';
@@ -10,7 +10,6 @@ type BlueprintMetadata = {
1010
};
1111

1212
interface UseBlueprintDeeplinkOptions {
13-
showModal: boolean;
1413
isAnySiteProcessing: boolean;
1514
openModal: () => void;
1615
setSelectedBlueprint: ( blueprint?: Blueprint ) => void;
@@ -31,7 +30,6 @@ export function useBlueprintDeeplink(
3130
): UseBlueprintDeeplinkReturn {
3231
const { __ } = useI18n();
3332
const {
34-
showModal,
3533
isAnySiteProcessing,
3634
openModal,
3735
setSelectedBlueprint,
@@ -40,13 +38,11 @@ export function useBlueprintDeeplink(
4038
setBlueprintPreferredVersions,
4139
} = options;
4240

43-
const [ pendingBlueprintPath, setPendingBlueprintPath ] = useState< string | null >( null );
4441
const [ initialNavigatorPath, setInitialNavigatorPath ] = useState< string >( '/' );
4542
const [ blueprintError, setBlueprintError ] = useState< string | null >( null );
4643

4744
const resetDeeplinkState = useCallback( () => {
4845
setInitialNavigatorPath( '/' );
49-
setPendingBlueprintPath( null );
5046
setBlueprintError( null );
5147
}, [] );
5248

@@ -94,11 +90,33 @@ export function useBlueprintDeeplink(
9490
if ( isAnySiteProcessing ) {
9591
return;
9692
}
97-
setPendingBlueprintPath( blueprintPath );
98-
setInitialNavigatorPath( '/blueprint/create' );
99-
openModal();
93+
try {
94+
const blueprintJson = await getIpcApi().readBlueprintFile( blueprintPath );
95+
96+
const fileName = blueprintPath.split( /[/\\]/ ).pop() || 'blueprint.json';
97+
const fileBlueprint = createBlueprintFromData(
98+
blueprintJson,
99+
`file:${ fileName }`,
100+
fileName.replace( '.json', '' ),
101+
__( 'Blueprint loaded from URL' )
102+
);
103+
104+
setSelectedBlueprint( fileBlueprint );
105+
applyPreferredVersions( blueprintJson );
106+
setInitialNavigatorPath( '/blueprint/create' );
107+
openModal();
108+
} catch ( error ) {
109+
console.error( 'Failed to load blueprint from URL:', error );
110+
}
100111
},
101-
[ isAnySiteProcessing, openModal ]
112+
[
113+
isAnySiteProcessing,
114+
__,
115+
createBlueprintFromData,
116+
setSelectedBlueprint,
117+
applyPreferredVersions,
118+
openModal,
119+
]
102120
);
103121
useIpcListener( 'add-site-blueprint-from-url', handleBlueprintFromUrl );
104122

@@ -135,53 +153,6 @@ export function useBlueprintDeeplink(
135153
);
136154
useIpcListener( 'add-site-blueprint-from-base64', handleBlueprintFromBase64 );
137155

138-
// Load and set blueprint when modal opens with a pending blueprint
139-
useEffect( () => {
140-
if ( showModal && pendingBlueprintPath ) {
141-
const loadBlueprintFromPath = async () => {
142-
try {
143-
const blueprintJson = await getIpcApi().readBlueprintFile( pendingBlueprintPath );
144-
145-
const validation = await getIpcApi().validateBlueprint( blueprintJson );
146-
147-
if ( ! validation.valid ) {
148-
const errorMessage = validation.error || __( 'Invalid Blueprint format' );
149-
throw new Error( errorMessage );
150-
}
151-
152-
const fileName = pendingBlueprintPath.split( /[/\\]/ ).pop() || 'blueprint.json';
153-
const fileBlueprint = createBlueprintFromData(
154-
blueprintJson,
155-
`file:${ fileName }`,
156-
fileName.replace( '.json', '' ),
157-
__( 'Blueprint loaded from URL' )
158-
);
159-
160-
setSelectedBlueprint( fileBlueprint );
161-
applyPreferredVersions( blueprintJson );
162-
setPendingBlueprintPath( null );
163-
} catch ( error ) {
164-
const errorMessage =
165-
error instanceof Error
166-
? error.message
167-
: __( 'Failed to load blueprint. Please check the blueprint file and try again.' );
168-
setBlueprintError( errorMessage );
169-
setPendingBlueprintPath( null );
170-
}
171-
};
172-
173-
void loadBlueprintFromPath();
174-
}
175-
}, [
176-
showModal,
177-
pendingBlueprintPath,
178-
createBlueprintFromData,
179-
setSelectedBlueprint,
180-
applyPreferredVersions,
181-
setBlueprintError,
182-
__,
183-
] );
184-
185156
return {
186157
initialNavigatorPath,
187158
blueprintError,

src/modules/add-site/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ export default function AddSite( { className, variant = 'outlined' }: AddSitePro
379379

380380
const { initialNavigatorPath, blueprintError, setBlueprintError, resetDeeplinkState } =
381381
useBlueprintDeeplink( {
382-
showModal,
383382
isAnySiteProcessing,
384383
openModal,
385384
setSelectedBlueprint,

0 commit comments

Comments
 (0)