2017-06-27 19:45:38 +03:00
|
|
|
import React from 'react';
|
|
|
|
import { compose, graphql } from 'react-apollo';
|
|
|
|
import get from 'lodash.get';
|
2017-07-20 23:48:30 +03:00
|
|
|
import forceArray from 'force-array';
|
2017-06-27 19:45:38 +03:00
|
|
|
|
|
|
|
import ManifestQuery from '@graphql/Manifest.gql';
|
|
|
|
import DeploymentGroupBySlugQuery from '@graphql/DeploymentGroupBySlug.gql';
|
|
|
|
|
2017-07-15 06:34:34 +03:00
|
|
|
import ManifestEditOrCreate from '@containers/manifest/edit-or-create';
|
2017-09-05 23:21:44 +03:00
|
|
|
import { Progress } from '@components/manifest';
|
2017-06-27 19:45:38 +03:00
|
|
|
import { LayoutContainer } from '@components/layout';
|
2017-07-28 19:56:03 +03:00
|
|
|
import { Title } from '@components/navigation';
|
2017-08-02 13:29:19 +03:00
|
|
|
import { Loader, ErrorMessage, WarningMessage } from '@components/messaging';
|
2017-06-27 19:45:38 +03:00
|
|
|
|
|
|
|
const Manifest = ({
|
|
|
|
loading,
|
|
|
|
error,
|
|
|
|
manifest = '',
|
2017-07-15 06:34:34 +03:00
|
|
|
environment = '',
|
2017-08-08 13:07:18 +03:00
|
|
|
files = [],
|
2017-06-28 01:48:36 +03:00
|
|
|
deploymentGroup = null,
|
2017-08-08 13:07:18 +03:00
|
|
|
hasManifest = false,
|
2017-06-28 01:48:36 +03:00
|
|
|
match
|
2017-06-27 19:45:38 +03:00
|
|
|
}) => {
|
2017-06-28 01:48:36 +03:00
|
|
|
const stage = match.params.stage;
|
2017-07-28 19:56:03 +03:00
|
|
|
const _title = <Title>Edit Manifest</Title>;
|
2017-07-26 17:28:14 +03:00
|
|
|
|
2017-08-30 14:30:50 +03:00
|
|
|
if (
|
|
|
|
loading ||
|
|
|
|
!deploymentGroup ||
|
|
|
|
(!hasManifest && !deploymentGroup.imported)
|
|
|
|
) {
|
2017-07-28 19:56:03 +03:00
|
|
|
return (
|
|
|
|
<LayoutContainer center>
|
|
|
|
{_title}
|
|
|
|
<Loader />
|
|
|
|
</LayoutContainer>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
return (
|
|
|
|
<LayoutContainer>
|
|
|
|
{_title}
|
2017-08-02 13:29:19 +03:00
|
|
|
<ErrorMessage
|
2017-08-08 13:07:18 +03:00
|
|
|
title="Ooops!"
|
2017-08-08 14:05:38 +03:00
|
|
|
message="An error occurred while loading your deployment group."
|
2017-08-08 13:07:18 +03:00
|
|
|
/>
|
2017-07-28 19:56:03 +03:00
|
|
|
</LayoutContainer>
|
|
|
|
);
|
|
|
|
}
|
2017-06-27 19:45:38 +03:00
|
|
|
|
2017-07-26 17:28:14 +03:00
|
|
|
const _notice =
|
2017-08-28 22:21:08 +03:00
|
|
|
deploymentGroup && deploymentGroup.imported && !manifest ? (
|
|
|
|
<WarningMessage
|
|
|
|
title="Be aware"
|
|
|
|
message="Since this Deployment Group was imported, it doesn't have the initial manifest."
|
|
|
|
/>
|
|
|
|
) : null;
|
2017-06-27 21:42:18 +03:00
|
|
|
|
2017-06-27 19:45:38 +03:00
|
|
|
return (
|
|
|
|
<LayoutContainer>
|
2017-07-28 19:56:03 +03:00
|
|
|
{_title}
|
2017-06-28 01:48:36 +03:00
|
|
|
<Progress stage={stage} edit />
|
2017-06-27 21:42:18 +03:00
|
|
|
{_notice}
|
2017-07-28 19:56:03 +03:00
|
|
|
<ManifestEditOrCreate
|
|
|
|
manifest={manifest}
|
|
|
|
environment={environment}
|
2017-08-08 13:07:18 +03:00
|
|
|
files={files}
|
2017-07-28 19:56:03 +03:00
|
|
|
deploymentGroup={deploymentGroup}
|
|
|
|
edit
|
|
|
|
/>
|
2017-06-27 19:45:38 +03:00
|
|
|
</LayoutContainer>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default compose(
|
|
|
|
graphql(ManifestQuery, {
|
|
|
|
options: props => ({
|
2017-07-20 23:48:30 +03:00
|
|
|
fetchPolicy: 'network-only',
|
2017-06-27 19:45:38 +03:00
|
|
|
variables: {
|
|
|
|
deploymentGroupSlug: props.match.params.deploymentGroup
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
props: ({ data: { deploymentGroup, loading, error } }) => ({
|
2017-08-08 13:07:18 +03:00
|
|
|
files: get(deploymentGroup, 'version.manifest.files', []),
|
2017-06-27 19:45:38 +03:00
|
|
|
manifest: get(deploymentGroup, 'version.manifest.raw', ''),
|
2017-07-15 06:34:34 +03:00
|
|
|
environment: get(deploymentGroup, 'version.manifest.environment', ''),
|
2017-08-08 13:07:18 +03:00
|
|
|
hasManifest: Boolean(get(deploymentGroup, 'version.manifest')),
|
2017-06-27 19:45:38 +03:00
|
|
|
loading,
|
|
|
|
error
|
|
|
|
})
|
|
|
|
}),
|
|
|
|
graphql(DeploymentGroupBySlugQuery, {
|
|
|
|
options: props => ({
|
|
|
|
variables: {
|
|
|
|
slug: props.match.params.deploymentGroup
|
|
|
|
}
|
|
|
|
}),
|
2017-07-26 17:28:14 +03:00
|
|
|
props: ({
|
|
|
|
data: { deploymentGroups, loading, error, startPolling, stopPolling }
|
|
|
|
}) => {
|
2017-07-20 23:48:30 +03:00
|
|
|
const dgs = forceArray(deploymentGroups);
|
|
|
|
|
|
|
|
if (!dgs.length) {
|
|
|
|
startPolling(1000);
|
|
|
|
} else {
|
|
|
|
stopPolling();
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
deploymentGroup: dgs[0],
|
|
|
|
loading,
|
|
|
|
error
|
|
|
|
};
|
|
|
|
}
|
2017-06-27 19:45:38 +03:00
|
|
|
})
|
|
|
|
)(Manifest);
|