1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-06 00:07:44 +01:00
unleash.unleash/frontend/src/component/application/application-edit-component.js

118 lines
4.4 KiB
JavaScript
Raw Normal View History

2016-12-09 14:02:36 +01:00
/* eslint react/no-multi-comp:off */
2020-09-24 20:32:38 +02:00
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
2016-12-05 15:15:01 +01:00
2020-09-24 20:32:38 +02:00
import { Button, Card, CardActions, CardTitle, CardText, CardMenu, Icon, ProgressBar, Tabs, Tab } from 'react-mdl';
import { IconLink, styles as commonStyles } from '../common';
2018-02-08 11:23:07 +01:00
import { formatFullDateTimeWithLocale } from '../common/util';
2020-09-24 20:32:38 +02:00
import { UPDATE_APPLICATION } from '../../permissions';
import ApplicationView from './application-view';
import ApplicationUpdate from './application-update';
2016-12-09 14:02:36 +01:00
2016-12-13 20:54:53 +01:00
class ClientApplications extends PureComponent {
static propTypes = {
fetchApplication: PropTypes.func.isRequired,
appName: PropTypes.string,
application: PropTypes.object,
2018-02-08 11:23:07 +01:00
location: PropTypes.object,
storeApplicationMetaData: PropTypes.func.isRequired,
deleteApplication: PropTypes.func.isRequired,
hasPermission: PropTypes.func.isRequired,
history: PropTypes.object.isRequired,
};
constructor(props) {
2020-09-24 20:32:38 +02:00
super();
this.state = { activeTab: 0, loading: !props.application };
2016-12-13 20:54:53 +01:00
}
componentDidMount() {
this.props.fetchApplication(this.props.appName).finally(() => this.setState({ loading: false }));
2016-12-05 15:15:01 +01:00
}
2020-09-24 20:32:38 +02:00
formatFullDateTime = v => formatFullDateTimeWithLocale(v, this.props.location.locale);
deleteApplication = async evt => {
evt.preventDefault();
const { deleteApplication, appName } = this.props;
await deleteApplication(appName);
this.props.history.push('/applications');
};
render() {
if (this.state.loading) {
return (
<div>
<p>Loading...</p>
<ProgressBar indeterminate />
</div>
);
} else if (!this.props.application) {
return <p>Application ({this.props.appName}) not found</p>;
2016-12-05 15:15:01 +01:00
}
const { application, storeApplicationMetaData, hasPermission } = this.props;
2020-09-24 20:32:38 +02:00
const { appName, instances, strategies, seenToggles, url, description, icon = 'apps' } = application;
const content =
this.state.activeTab === 0 ? (
2020-09-24 20:32:38 +02:00
<ApplicationView
strategies={strategies}
instances={instances}
seenToggles={seenToggles}
hasPermission={hasPermission}
formatFullDateTime={this.formatFullDateTime}
/>
) : (
2020-09-24 20:32:38 +02:00
<ApplicationUpdate application={application} storeApplicationMetaData={storeApplicationMetaData} />
);
2016-12-13 20:54:53 +01:00
return (
<Card shadow={0} className={commonStyles.fullwidth}>
2017-08-28 21:40:44 +02:00
<CardTitle style={{ paddingTop: '24px', paddingRight: '64px', wordBreak: 'break-all' }}>
<Icon name={icon || 'apps'} />
&nbsp;{appName}
</CardTitle>
{description && <CardText>{description}</CardText>}
{url && (
<CardMenu>
<IconLink url={url} icon="link" />
</CardMenu>
)}
{hasPermission(UPDATE_APPLICATION) ? (
<div>
<CardActions
border
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
}}
>
<span />
<Button accent title="Delete application" onClick={this.deleteApplication}>
Delete
</Button>
</CardActions>
<hr />
<Tabs
activeTab={this.state.activeTab}
onChange={tabId => this.setState({ activeTab: tabId })}
ripple
tabBarProps={{ style: { width: '100%' } }}
className="mdl-color--grey-100"
>
<Tab>Details</Tab>
<Tab>Edit</Tab>
</Tabs>
</div>
) : (
''
)}
2016-12-09 14:02:36 +01:00
{content}
</Card>
2016-12-05 15:15:01 +01:00
);
}
}
2016-12-13 20:54:53 +01:00
export default ClientApplications;