Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #289 from gashcrumb/issue-288
Browse files Browse the repository at this point in the history
  • Loading branch information
pure-bot[bot] authored May 15, 2019
2 parents bbbe867 + 991ba31 commit 0b9a8bd
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 98 deletions.
1 change: 0 additions & 1 deletion app/ui-react/packages/api/src/WithServerEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ export class WithServerEvents extends React.Component<IWithEventsProps> {
}
} catch (error) {
this.onFailure(error);
throw error;
}
}

Expand Down
11 changes: 11 additions & 0 deletions app/ui-react/packages/api/src/helpers/integrationFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ export function setIntegrationName(
});
}

export function setIntegrationProperties(
integration: Integration,
properties: StringMap<any>
): Integration {
return produce(integration, nextIntegration => {
Object.keys(properties).forEach(k => {
nextIntegration[k] = properties[k];
});
});
}

/**
* returns true if the provided integration can be published; returns false
* otherwise.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ const addStepPage = (
const saveIntegrationPage = (
<SaveIntegrationPage
cancelHref={(p, s) => resolvers.create.configure.index({ ...p, ...s })}
postSaveHref={resolvers.list}
postSaveHref={(p, s) =>
resolvers.integration.edit.index({
...p,
...s,
})
}
postPublishHref={resolvers.integration.details}
/>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ const addStepPage = (
const saveIntegrationPage = (
<SaveIntegrationPage
cancelHref={(p, s) => resolvers.integration.edit.index({ ...p, ...s })}
postSaveHref={resolvers.list}
postSaveHref={(p, s) =>
resolvers.integration.edit.index({
...p,
...s,
})
}
postPublishHref={resolvers.integration.details}
/>
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { setIntegrationName, WithIntegrationHelpers } from '@syndesis/api';
import {
setIntegrationProperties,
WithIntegrationHelpers,
} from '@syndesis/api';
import { AutoForm, IFormDefinition } from '@syndesis/auto-form';
import * as H from '@syndesis/history';
import { Integration } from '@syndesis/models';
import { IntegrationEditorLayout, IntegrationSaveForm } from '@syndesis/ui';
import { WithRouteData } from '@syndesis/utils';
import * as React from 'react';
import { UIContext } from '../../../../app';
import i18n from '../../../../i18n';
import { PageTitle } from '../../../../shared';
import {
IPostPublishRouteParams,
ISaveIntegrationForm,
ISaveIntegrationRouteParams,
ISaveIntegrationRouteState,
Expand All @@ -17,7 +22,11 @@ export interface ISaveIntegrationPageProps {
p: ISaveIntegrationRouteParams,
s: ISaveIntegrationRouteState
) => H.LocationDescriptor;
postSaveHref: (i: Integration) => H.LocationDescriptorObject;
postSaveHref: (
p: ISaveIntegrationRouteParams,
s: ISaveIntegrationRouteState
) => H.LocationDescriptorObject;
postPublishHref: (p: IPostPublishRouteParams) => H.LocationDescriptorObject;
}

/**
Expand All @@ -37,97 +46,143 @@ export class SaveIntegrationPage extends React.Component<
> {
public render() {
return (
<WithRouteData<ISaveIntegrationRouteParams, ISaveIntegrationRouteState>>
{({ flowId }, { integration }, { history }) => (
<WithIntegrationHelpers>
{({ saveIntegration }) => {
let shouldPublish = false;
const onSave = async (
{ name, description }: ISaveIntegrationForm,
actions: any
) => {
const updatedIntegration = setIntegrationName(
integration,
name
);
// TODO: set the description
await saveIntegration(updatedIntegration);
actions.setSubmitting(false);

if (shouldPublish) {
alert('TODO: publish');
shouldPublish = false;
}
<UIContext.Consumer>
{({ pushNotification }) => (
<WithRouteData<
ISaveIntegrationRouteParams,
ISaveIntegrationRouteState
>>
{({ flowId }, { integration }, { history }) => (
<WithIntegrationHelpers>
{({ deployIntegration, saveIntegration }) => {
let shouldPublish = false;
const onSave = async (
{ name, description }: ISaveIntegrationForm,
actions: any
) => {
const updatedIntegration = setIntegrationProperties(
integration,
{
description,
name,
}
);
const savedIntegration = await saveIntegration(
updatedIntegration
);
actions.setSubmitting(false);

// TODO: toast notification
history.push(this.props.postSaveHref(updatedIntegration));
};
const definition: IFormDefinition = {
name: {
defaultValue: '',
displayName: 'Name',
order: 0,
required: true,
type: 'string',
},
// tslint:disable-next-line
description: {
defaultValue: '',
displayName: 'Description',
order: 1,
type: 'textarea',
},
};
return (
<AutoForm<ISaveIntegrationForm>
i18nRequiredProperty={'* Required field'}
definition={definition}
initialValue={{
description: integration.description,
name: integration.name,
}}
onSave={onSave}
>
{({
fields,
dirty,
handleSubmit,
isSubmitting,
isValid,
submitForm,
}) => (
<>
<PageTitle title={'Save the integration'} />
<IntegrationEditorLayout
title={'Save the integration'}
description={'Update details about this integration.'}
content={
<IntegrationSaveForm handleSubmit={handleSubmit}>
{fields}
</IntegrationSaveForm>
}
cancelHref={this.props.cancelHref(
{ flowId },
{ integration }
)}
onSave={submitForm}
isSaveDisabled={dirty && !isValid}
isSaveLoading={isSubmitting}
onPublish={async () => {
shouldPublish = true;
await submitForm();
}}
isPublishDisabled={dirty && !isValid}
isPublishLoading={isSubmitting}
/>
</>
)}
</AutoForm>
);
}}
</WithIntegrationHelpers>
if (shouldPublish) {
pushNotification(
i18n.t('integrations:PublishingIntegrationMessage'),
'info'
);
deployIntegration(
savedIntegration.id!,
savedIntegration.version!,
false
)
.then(() => {
/* nothing to do on success */
})
.catch(err => {
pushNotification(
i18n.t(
'integrations:PublishingIntegrationFailedMessage',
{
error: err.errorMessage || err.message || err,
}
),
'warning'
);
});
}
if (shouldPublish) {
shouldPublish = false;
history.push(
this.props.postPublishHref({
integrationId: savedIntegration.id!,
})
);
} else {
history.push(
this.props.postSaveHref(
{ flowId, integrationId: savedIntegration.id! },
{ integration: savedIntegration }
)
);
}
};
const definition: IFormDefinition = {
name: {
defaultValue: '',
displayName: 'Name',
order: 0,
required: true,
type: 'string',
},
// tslint:disable-next-line
description: {
defaultValue: '',
displayName: 'Description',
order: 1,
type: 'textarea',
},
};
return (
<AutoForm<ISaveIntegrationForm>
i18nRequiredProperty={'* Required field'}
definition={definition}
initialValue={{
description: integration.description,
name: integration.name,
}}
onSave={onSave}
>
{({
fields,
dirty,
handleSubmit,
isSubmitting,
isValid,
submitForm,
}) => (
<>
<PageTitle title={'Save the integration'} />
<IntegrationEditorLayout
title={'Save the integration'}
description={
'Update details about this integration.'
}
content={
<IntegrationSaveForm handleSubmit={handleSubmit}>
{fields}
</IntegrationSaveForm>
}
cancelHref={this.props.cancelHref(
{ flowId },
{ integration }
)}
onSave={submitForm}
isSaveDisabled={dirty && !isValid}
isSaveLoading={isSubmitting}
onPublish={async () => {
shouldPublish = true;
await submitForm();
}}
isPublishDisabled={dirty && !isValid}
isPublishLoading={isSubmitting}
/>
</>
)}
</AutoForm>
);
}}
</WithIntegrationHelpers>
)}
</WithRouteData>
)}
</WithRouteData>
</UIContext.Consumer>
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,20 @@ export interface IBaseRouteState {
integration: Integration;
}

/**
* @param integration - the integration object.
*/
export interface ISaveIntegrationRouteParams {
flowId: string;
integrationId?: string;
}

export interface ISaveIntegrationForm {
name: string;
description?: string;
}

export interface IPostPublishRouteParams {
integrationId?: string;
}

/**
* @param integration - the integration object.
*/
Expand Down

0 comments on commit 0b9a8bd

Please sign in to comment.