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';
|
2018-02-04 14:32:33 +01:00
|
|
|
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 {
|
2018-02-04 14:32:33 +01:00
|
|
|
static propTypes = {
|
|
|
|
fetchApplication: PropTypes.func.isRequired,
|
|
|
|
appName: PropTypes.string,
|
|
|
|
application: PropTypes.object,
|
2018-02-08 11:23:07 +01:00
|
|
|
location: PropTypes.object,
|
2018-02-04 14:32:33 +01:00
|
|
|
storeApplicationMetaData: PropTypes.func.isRequired,
|
2020-09-23 23:18:53 +02:00
|
|
|
deleteApplication: PropTypes.func.isRequired,
|
2019-01-16 10:39:58 +01:00
|
|
|
hasPermission: PropTypes.func.isRequired,
|
2020-09-23 23:18:53 +02:00
|
|
|
history: PropTypes.object.isRequired,
|
2018-02-04 14:32:33 +01:00
|
|
|
};
|
|
|
|
|
2020-09-25 21:09:26 +02:00
|
|
|
constructor(props) {
|
2020-09-24 20:32:38 +02:00
|
|
|
super();
|
2020-09-25 21:09:26 +02:00
|
|
|
this.state = { activeTab: 0, loading: !props.application };
|
2016-12-13 20:54:53 +01:00
|
|
|
}
|
|
|
|
|
2017-08-28 19:15:47 +02:00
|
|
|
componentDidMount() {
|
2020-09-25 21:09:26 +02:00
|
|
|
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);
|
2020-09-23 23:18:53 +02:00
|
|
|
|
|
|
|
deleteApplication = async evt => {
|
|
|
|
evt.preventDefault();
|
|
|
|
const { deleteApplication, appName } = this.props;
|
|
|
|
await deleteApplication(appName);
|
|
|
|
this.props.history.push('/applications');
|
|
|
|
};
|
|
|
|
|
2017-08-28 19:15:47 +02:00
|
|
|
render() {
|
2020-09-25 21:09:26 +02:00
|
|
|
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
|
|
|
}
|
2019-01-16 10:39:58 +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;
|
2016-12-05 16:01:09 +01:00
|
|
|
|
2017-08-28 19:15:47 +02:00
|
|
|
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}
|
|
|
|
/>
|
2017-08-28 19:15:47 +02:00
|
|
|
) : (
|
2020-09-24 20:32:38 +02:00
|
|
|
<ApplicationUpdate application={application} storeApplicationMetaData={storeApplicationMetaData} />
|
2017-08-28 19:15:47 +02:00
|
|
|
);
|
2016-12-13 20:54:53 +01:00
|
|
|
|
|
|
|
return (
|
2017-02-14 12:11:18 +01:00
|
|
|
<Card shadow={0} className={commonStyles.fullwidth}>
|
2017-08-28 21:40:44 +02:00
|
|
|
<CardTitle style={{ paddingTop: '24px', paddingRight: '64px', wordBreak: 'break-all' }}>
|
2020-09-23 23:18:53 +02:00
|
|
|
<Icon name={icon || 'apps'} />
|
2020-09-23 21:47:07 +02:00
|
|
|
{appName}
|
2017-02-14 12:11:18 +01:00
|
|
|
</CardTitle>
|
2017-08-28 19:15:47 +02:00
|
|
|
{description && <CardText>{description}</CardText>}
|
|
|
|
{url && (
|
|
|
|
<CardMenu>
|
|
|
|
<IconLink url={url} icon="link" />
|
|
|
|
</CardMenu>
|
|
|
|
)}
|
2019-01-16 10:39:58 +01:00
|
|
|
{hasPermission(UPDATE_APPLICATION) ? (
|
2020-09-23 23:18:53 +02:00
|
|
|
<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>
|
2019-01-16 10:39:58 +01:00
|
|
|
) : (
|
|
|
|
''
|
|
|
|
)}
|
2016-12-09 14:02:36 +01:00
|
|
|
|
2017-02-14 12:11:18 +01:00
|
|
|
{content}
|
|
|
|
</Card>
|
2016-12-05 15:15:01 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 20:54:53 +01:00
|
|
|
export default ClientApplications;
|