This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #317 from riccardo-forina/action-configure-form-bu…
…gfix
- Loading branch information
Showing
5 changed files
with
205 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
...-react/syndesis/src/modules/integrations/components/editor/endpoint/ConfigurationForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { | ||
applyUserDefinedDataShapesToAction, | ||
getActionStep, | ||
getActionStepDefinition, | ||
getActionSteps, | ||
} from '@syndesis/api'; | ||
import { AutoForm } from '@syndesis/auto-form'; | ||
import { Action, ActionDescriptor } from '@syndesis/models'; | ||
import { IntegrationEditorForm } from '@syndesis/ui'; | ||
import { | ||
allFieldsRequired, | ||
applyInitialValues, | ||
getRequiredStatusText, | ||
toFormDefinition, | ||
validateConfiguredProperties, | ||
} from '@syndesis/utils'; | ||
import * as React from 'react'; | ||
import i18n from '../../../../../i18n'; | ||
import { IWithConfigurationFormProps } from './WithConfigurationForm'; | ||
|
||
export interface IConfigurationFormProps | ||
extends Pick<IWithConfigurationFormProps, 'configurationStep'>, | ||
Pick<IWithConfigurationFormProps, 'initialValue'>, | ||
Pick<IWithConfigurationFormProps, 'oldAction'>, | ||
Pick<IWithConfigurationFormProps, 'onUpdatedIntegration'>, | ||
Pick<IWithConfigurationFormProps, 'chooseActionHref'> { | ||
action: Action; | ||
descriptor: ActionDescriptor; | ||
children: any; | ||
} | ||
|
||
export const ConfigurationForm: React.FunctionComponent< | ||
IConfigurationFormProps | ||
> = ({ | ||
action, | ||
configurationStep, | ||
descriptor, | ||
initialValue, | ||
oldAction, | ||
chooseActionHref, | ||
onUpdatedIntegration, | ||
children, | ||
}) => { | ||
const [error, setError] = React.useState(); | ||
try { | ||
const steps = getActionSteps(descriptor); | ||
const step = getActionStep(steps, configurationStep); | ||
const definition = getActionStepDefinition(step); | ||
const moreConfigurationSteps = configurationStep < steps.length - 1; | ||
const onSave = async ( | ||
values: { [key: string]: string }, | ||
actions: any | ||
): Promise<void> => { | ||
try { | ||
action = | ||
typeof oldAction !== 'undefined' | ||
? applyUserDefinedDataShapesToAction(oldAction, { | ||
...action, | ||
descriptor, | ||
}) | ||
: action; | ||
await onUpdatedIntegration({ | ||
action, | ||
moreConfigurationSteps, | ||
values, | ||
}); | ||
} catch (e) { | ||
setError(e.message); | ||
} | ||
actions.setSubmitting(false); | ||
}; | ||
const key = JSON.stringify(definition); | ||
initialValue = applyInitialValues(definition, initialValue); | ||
const isInitialValid = validateConfiguredProperties( | ||
definition, | ||
initialValue | ||
); | ||
const requiredPrompt = getRequiredStatusText( | ||
definition, | ||
i18n.t('shared:AllFieldsRequired'), | ||
i18n.t('shared:FieldsMarkedWithStarRequired'), | ||
'' | ||
); | ||
return ( | ||
<AutoForm<{ [key: string]: string }> | ||
i18nRequiredProperty={'* Required field'} | ||
allFieldsRequired={allFieldsRequired(definition)} | ||
i18nFieldsStatusText={requiredPrompt} | ||
definition={toFormDefinition(definition)} | ||
initialValue={initialValue} | ||
isInitialValid={isInitialValid} | ||
onSave={onSave} | ||
validate={(values: { [name: string]: any }): any => | ||
validateConfiguredProperties(definition, values) | ||
} | ||
key={key} | ||
> | ||
{({ fields, handleSubmit, isValid, submitForm }) => ( | ||
<> | ||
<IntegrationEditorForm | ||
i18nFormTitle={`${action.name} - ${action.description}`} | ||
i18nBackAction={'Choose Action'} | ||
i18nNext={'Next'} | ||
isValid={isValid} | ||
submitForm={() => { | ||
setError(undefined); | ||
submitForm(); | ||
}} | ||
handleSubmit={handleSubmit} | ||
backActionHref={chooseActionHref} | ||
error={error} | ||
> | ||
{fields} | ||
</IntegrationEditorForm> | ||
</> | ||
)} | ||
</AutoForm> | ||
); | ||
} catch (e) { | ||
return children; | ||
} | ||
}; |
32 changes: 32 additions & 0 deletions
32
...react/syndesis/src/modules/integrations/components/editor/endpoint/NothingToConfigure.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Action, ActionDescriptor } from '@syndesis/models'; | ||
import { IntegrationEditorNothingToConfigure } from '@syndesis/ui'; | ||
import * as React from 'react'; | ||
import { IWithConfigurationFormProps } from './WithConfigurationForm'; | ||
|
||
export interface INothingToConfigureProps | ||
extends Pick<IWithConfigurationFormProps, 'onUpdatedIntegration'>, | ||
Pick<IWithConfigurationFormProps, 'chooseActionHref'> { | ||
action: Action; | ||
descriptor: ActionDescriptor; | ||
} | ||
|
||
export const NothingToConfigure: React.FunctionComponent< | ||
INothingToConfigureProps | ||
> = ({ action, descriptor, chooseActionHref, onUpdatedIntegration }) => { | ||
const submitForm = () => { | ||
onUpdatedIntegration({ | ||
action: { ...action, descriptor }, | ||
moreConfigurationSteps: false, | ||
values: null, | ||
}); | ||
}; | ||
return ( | ||
<IntegrationEditorNothingToConfigure | ||
i18nAlert={'There are no properties to configure for this action.'} | ||
i18nBackAction={'Choose Action'} | ||
i18nNext={'Next'} | ||
submitForm={submitForm} | ||
backActionHref={chooseActionHref} | ||
/> | ||
); | ||
}; |
Oops, something went wrong.