@@ -42,132 +42,120 @@ export class Connector<
4242 }
4343
4444 doInitialPcbFootprintStringRender ( ) : void {
45+ super . doInitialPcbFootprintStringRender ( )
46+ }
47+
48+ doInitialStandardConnectorCircuitJsonRender ( ) : void {
4549 const { _parsedProps : props } = this
4650 const connectorProps = this . props as ConnectorProps
4751 const standard = connectorProps . standard
4852
49- if ( standard ) {
50- if ( this . _hasStartedFootprintUrlLoad ) return
51- if ( this . getInheritedProperty ( "partsEngineDisabled" ) ) {
52- super . doInitialPcbFootprintStringRender ( )
53- return
54- }
55- const partsEngine = this . getInheritedProperty ( "partsEngine" )
56- if ( ! partsEngine ?. fetchPartCircuitJson ) {
57- super . doInitialPcbFootprintStringRender ( )
58- return
59- }
60-
61- this . _hasStartedFootprintUrlLoad = true
62-
63- // source_component_id is not yet set (SourceRender runs after PcbFootprintStringRender),
64- // but after the first `await` in the async effect all synchronous render phases
65- // including SourceRender will have run, making source_component_id available.
66- const sourceComponentForQuery = {
67- ftype : "simple_connector" ,
68- name : this . name ,
69- manufacturer_part_number : props . manufacturerPartNumber ?? props . mfn ,
70- standard,
71- }
53+ if ( ! standard ) return
54+ if ( this . _hasStartedFootprintUrlLoad ) return
55+ if ( this . getInheritedProperty ( "partsEngineDisabled" ) ) return
56+ const partsEngine = this . getInheritedProperty ( "partsEngine" )
57+ if ( ! partsEngine ?. fetchPartCircuitJson ) return
7258
73- this . _queueAsyncEffect (
74- "load-standard-connector-circuit-json" ,
75- async ( ) => {
76- const { db } = this . root !
77- try {
78- // Step 1: findPart → supplier part numbers
79- const supplierPartNumbers = await this . _getSupplierPartNumbers (
80- partsEngine ,
81- sourceComponentForQuery ,
82- `standard:${ standard } ` ,
83- )
84-
85- if ( this . source_component_id ) {
86- db . source_component . update ( this . source_component_id , {
87- supplier_part_numbers : supplierPartNumbers ,
88- } )
89- }
59+ this . _hasStartedFootprintUrlLoad = true
9060
91- // Step 2: fetchPartCircuitJson with first available supplier part number
92- let circuitJson : AnyCircuitElement [ ] | null = null
93- for ( const supplier of Object . keys ( supplierPartNumbers ?? { } ) ) {
94- const nums = supplierPartNumbers [ supplier ]
95- if ( Array . isArray ( nums ) && nums . length > 0 ) {
96- const maybeCircuitJson =
97- ( await Promise . resolve (
98- partsEngine . fetchPartCircuitJson ( {
99- supplierPartNumber : nums [ 0 ] ,
100- } ) ,
101- ) ) ?? null
102- if (
103- Array . isArray ( maybeCircuitJson ) &&
104- maybeCircuitJson . length > 0
105- ) {
106- circuitJson = maybeCircuitJson
107- break
108- }
109- }
110- }
61+ // source_component_id is not yet set (SourceRender runs later), but after
62+ // the first await in this async effect synchronous phases complete and
63+ // source_component_id will be available for db updates.
64+ const sourceComponentForQuery = {
65+ ftype : "simple_connector" ,
66+ name : this . name ,
67+ manufacturer_part_number : props . manufacturerPartNumber ?? props . mfn ,
68+ standard,
69+ }
11170
112- // Fallback: manufacturer part number
71+ this . _queueAsyncEffect ( "load-standard-connector-circuit-json" , async ( ) => {
72+ const { db } = this . root !
73+ try {
74+ // Step 1: findPart → supplier part numbers
75+ const supplierPartNumbers = await this . _getSupplierPartNumbers (
76+ partsEngine ,
77+ sourceComponentForQuery ,
78+ `standard:${ standard } ` ,
79+ )
80+
81+ if ( this . source_component_id ) {
82+ db . source_component . update ( this . source_component_id , {
83+ supplier_part_numbers : supplierPartNumbers ,
84+ } )
85+ }
86+
87+ // Step 2: fetchPartCircuitJson with first available supplier part number
88+ let circuitJson : AnyCircuitElement [ ] | null = null
89+ for ( const supplier of Object . keys ( supplierPartNumbers ?? { } ) ) {
90+ const nums = supplierPartNumbers [ supplier ]
91+ if ( Array . isArray ( nums ) && nums . length > 0 ) {
92+ const maybeCircuitJson =
93+ ( await Promise . resolve (
94+ partsEngine . fetchPartCircuitJson ( {
95+ supplierPartNumber : nums [ 0 ] ,
96+ } ) ,
97+ ) ) ?? null
11398 if (
114- ( ! circuitJson || circuitJson . length === 0 ) &&
115- sourceComponentForQuery . manufacturer_part_number
99+ Array . isArray ( maybeCircuitJson ) &&
100+ maybeCircuitJson . length > 0
116101 ) {
117- const maybeCircuitJson =
118- ( await Promise . resolve (
119- partsEngine . fetchPartCircuitJson ( {
120- manufacturerPartNumber :
121- sourceComponentForQuery . manufacturer_part_number ,
122- } ) ,
123- ) ) ?? null
124- if (
125- Array . isArray ( maybeCircuitJson ) &&
126- maybeCircuitJson . length > 0
127- ) {
128- circuitJson = maybeCircuitJson
129- }
130- }
131-
132- if ( circuitJson && circuitJson . length > 0 ) {
133- const fpComponents = createComponentsFromCircuitJson (
134- {
135- componentName : this . name ,
136- componentRotation : String ( props . pcbRotation ?? 0 ) ,
137- footprinterString : `standard:${ standard } ` ,
138- pinLabels : props . pinLabels ,
139- pcbPinLabels : props . pcbPinLabels ,
140- } ,
141- circuitJson ,
142- )
143- this . addAll ( fpComponents )
144- this . _markDirty ( "InitializePortsFromChildren" )
145- }
146- } catch ( error : any ) {
147- if ( this . source_component_id ) {
148- db . source_component . update ( this . source_component_id , {
149- supplier_part_numbers : { } ,
150- } )
102+ circuitJson = maybeCircuitJson
103+ break
151104 }
152- const errorObj = unknown_error_finding_part . parse ( {
153- type : "unknown_error_finding_part" ,
154- message : `Failed to fetch circuit JSON for ${ this . getString ( ) } (standard="${ standard } "): ${ error . message } ` ,
155- source_component_id : this . source_component_id ?? undefined ,
156- subcircuit_id : this . getSubcircuit ( ) ?. subcircuit_id ,
157- } )
158- db . unknown_error_finding_part . insert ( errorObj )
159105 }
160- } ,
161- )
162- return
163- }
164-
165- super . doInitialPcbFootprintStringRender ( )
106+ }
107+
108+ // Fallback: manufacturer part number
109+ if (
110+ ( ! circuitJson || circuitJson . length === 0 ) &&
111+ sourceComponentForQuery . manufacturer_part_number
112+ ) {
113+ const maybeCircuitJson =
114+ ( await Promise . resolve (
115+ partsEngine . fetchPartCircuitJson ( {
116+ manufacturerPartNumber :
117+ sourceComponentForQuery . manufacturer_part_number ,
118+ } ) ,
119+ ) ) ?? null
120+ if ( Array . isArray ( maybeCircuitJson ) && maybeCircuitJson . length > 0 ) {
121+ circuitJson = maybeCircuitJson
122+ }
123+ }
124+
125+ if ( circuitJson && circuitJson . length > 0 ) {
126+ const fpComponents = createComponentsFromCircuitJson (
127+ {
128+ componentName : this . name ,
129+ componentRotation : String ( props . pcbRotation ?? 0 ) ,
130+ footprinterString : `standard:${ standard } ` ,
131+ pinLabels : props . pinLabels ,
132+ pcbPinLabels : props . pcbPinLabels ,
133+ } ,
134+ circuitJson ,
135+ )
136+ this . addAll ( fpComponents )
137+ this . _markDirty ( "InitializePortsFromChildren" )
138+ }
139+ } catch ( error : any ) {
140+ if ( this . source_component_id ) {
141+ db . source_component . update ( this . source_component_id , {
142+ supplier_part_numbers : { } ,
143+ } )
144+ }
145+ const errorObj = unknown_error_finding_part . parse ( {
146+ type : "unknown_error_finding_part" ,
147+ message : `Failed to fetch circuit JSON for ${ this . getString ( ) } (standard="${ standard } "): ${ error . message } ` ,
148+ source_component_id : this . source_component_id ?? undefined ,
149+ subcircuit_id : this . getSubcircuit ( ) ?. subcircuit_id ,
150+ } )
151+ db . unknown_error_finding_part . insert ( errorObj )
152+ }
153+ } )
166154 }
167155
168156 doInitialPartsEngineRender ( ) : void {
169157 // For standard connectors, supplier part numbers are already resolved
170- // during PcbFootprintStringRender via findPart + fetchPartCircuitJson
158+ // during StandardConnectorCircuitJsonRender via findPart + fetchPartCircuitJson
171159 if ( this . _isUsingStandardPartsEngineCircuitJsonFlow ( ) ) return
172160 super . doInitialPartsEngineRender ( )
173161 }
0 commit comments