@@ -4,11 +4,12 @@ import {
44import isEqual from "lodash.isequal" ;
55import { useQuery } from "@tanstack/react-query" ;
66import type {
7- ComponentReloadPropsOpts , ConfigurableProp , ConfigurableProps , ConfiguredProps , V1Component ,
7+ ComponentReloadPropsOpts , ConfigurableProp , ConfigurableProps , ConfiguredProps , V1Component , PropValue ,
88} from "@pipedream/sdk" ;
99import { useFrontendClient } from "./frontend-client-context" ;
1010import type { ComponentFormProps } from "../components/ComponentForm" ;
1111import type { FormFieldContext } from "./form-field-context" ;
12+ import { appPropError } from "./use-app" ;
1213
1314export type DynamicProps < T extends ConfigurableProps > = { id : string ; configurable_props : T ; } ; // TODO
1415
@@ -24,6 +25,7 @@ export type FormContext<T extends ConfigurableProps> = {
2425 optionalPropIsEnabled : ( prop : ConfigurableProp ) => boolean ;
2526 optionalPropSetEnabled : ( prop : ConfigurableProp , enabled : boolean ) => void ;
2627 props : ComponentFormProps < T > ;
28+ propsNeedConfiguring : string [ ] ;
2729 queryDisabledIdx ?: number ;
2830 registerField : < T extends ConfigurableProp > ( field : FormFieldContext < T > ) => void ;
2931 setConfiguredProp : ( idx : number , value : unknown ) => void ; // XXX type safety for value (T will rarely be static right?)
@@ -136,6 +138,16 @@ export const FormContextProvider = <T extends ConfigurableProps>({
136138 enabled : reloadPropIdx != null , // TODO or props.dynamicPropsId && !dynamicProps
137139 } ) ;
138140
141+ const [
142+ propsNeedConfiguring ,
143+ setPropsNeedConfiguring ,
144+ ] = useState < string [ ] > ( [ ] ) ;
145+ useEffect ( ( ) => {
146+ checkPropsNeedConfiguring ( )
147+ } , [
148+ configuredProps ,
149+ ] ) ;
150+
139151 // XXX fix types of dynamicProps, props.component so this type decl not needed
140152 let configurableProps : T = dynamicProps ?. configurable_props || formProps . component . configurable_props || [ ] ;
141153 if ( propNames ?. length ) {
@@ -154,7 +166,7 @@ export const FormContextProvider = <T extends ConfigurableProps>({
154166
155167 // these validations are necessary because they might override PropInput for number case for instance
156168 // so can't rely on that base control form validation
157- const propErrors = ( prop : ConfigurableProp , value : unknown ) : string [ ] => {
169+ const propErrors = < T extends ConfigurableProps > ( prop : ConfigurableProp , value : unknown ) : string [ ] => {
158170 const errs : string [ ] = [ ] ;
159171 if ( value === undefined ) {
160172 if ( ! prop . optional ) {
@@ -181,13 +193,9 @@ export const FormContextProvider = <T extends ConfigurableProps>({
181193 }
182194 } else if ( prop . type === "app" ) {
183195 const field = fields [ prop . name ]
184- if ( ! field . extra . app ) {
185- errs . push ( "app field not registered" )
186- } else if ( ! value ) {
187- errs . push ( "no app configured" )
188- } else if ( typeof value === "object" && "authProvisionId" in value && ! value . authProvisionId ) {
189- errs . push ( "no auth provision configured" )
190- }
196+ const app = field . extra . app
197+ const err = appPropError ( prop , value , app )
198+ if ( err ) errs . push ( err )
191199 }
192200 return errs ;
193201 } ;
@@ -316,6 +324,20 @@ export const FormContextProvider = <T extends ConfigurableProps>({
316324 setEnabledOptionalProps ( newEnabledOptionalProps ) ;
317325 } ;
318326
327+ const checkPropsNeedConfiguring = ( ) => {
328+ const _propsNeedConfiguring = [ ]
329+ for ( const prop of configurableProps ) {
330+ if ( ! prop || prop . optional || prop . hidden ) continue
331+ const value = configuredProps [ prop . name as keyof ConfiguredProps < T > ]
332+ const errors = propErrors ( prop , value )
333+ if ( errors . length ) {
334+ _propsNeedConfiguring . push ( prop . name )
335+ }
336+ }
337+ // propsNeedConfiguring.splice(0, propsNeedConfiguring.length, ..._propsNeedConfiguring)
338+ setPropsNeedConfiguring ( _propsNeedConfiguring )
339+ }
340+
319341 const registerField = < T extends ConfigurableProp > ( field : FormFieldContext < T > ) => {
320342 fields [ field . prop . name ] = field
321343 setFields ( fields ) ;
@@ -336,6 +358,7 @@ export const FormContextProvider = <T extends ConfigurableProps>({
336358 fields,
337359 optionalPropIsEnabled,
338360 optionalPropSetEnabled,
361+ propsNeedConfiguring,
339362 queryDisabledIdx,
340363 registerField,
341364 setConfiguredProp,
0 commit comments