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
|
|
|
|
2021-03-30 15:14:02 +02:00
|
|
|
import { Avatar, Link, Icon, IconButton, Button, LinearProgress, Typography } from '@material-ui/core';
|
|
|
|
import ConditionallyRender from '../common/ConditionallyRender/ConditionallyRender';
|
2020-09-26 22:14:56 +02:00
|
|
|
import { formatFullDateTimeWithLocale, formatDateWithLocale } 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';
|
2021-03-30 15:14:02 +02:00
|
|
|
import TabNav from '../common/TabNav/TabNav';
|
|
|
|
import Dialogue from '../common/Dialogue';
|
|
|
|
import PageContent from '../common/PageContent';
|
|
|
|
import HeaderTitle from '../common/HeaderTitle';
|
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();
|
2021-03-30 15:14:02 +02:00
|
|
|
this.state = {
|
|
|
|
activeTab: 0,
|
|
|
|
loading: !props.application,
|
|
|
|
prompt: false,
|
|
|
|
};
|
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-26 22:14:56 +02:00
|
|
|
formatDate = v => formatDateWithLocale(v, this.props.location.locale);
|
2020-09-23 23:18:53 +02:00
|
|
|
|
|
|
|
deleteApplication = async evt => {
|
|
|
|
evt.preventDefault();
|
2021-03-30 15:14:02 +02:00
|
|
|
// if (window.confirm('Are you sure you want to remove this application?')) {
|
2020-09-23 23:18:53 +02:00
|
|
|
const { deleteApplication, appName } = this.props;
|
|
|
|
await deleteApplication(appName);
|
|
|
|
this.props.history.push('/applications');
|
2021-03-30 15:14:02 +02:00
|
|
|
// }
|
2020-09-23 23:18:53 +02:00
|
|
|
};
|
|
|
|
|
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>
|
2021-03-30 15:14:02 +02:00
|
|
|
<LinearProgress />
|
2020-09-25 21:09:26 +02:00
|
|
|
</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-26 22:14:56 +02:00
|
|
|
const { appName, instances, strategies, seenToggles, url, description, icon = 'apps', createdAt } = application;
|
2016-12-05 16:01:09 +01:00
|
|
|
|
2021-03-30 15:14:02 +02:00
|
|
|
const toggleModal = () => {
|
|
|
|
this.setState(prev => ({ ...prev, prompt: !prev.prompt }));
|
|
|
|
};
|
|
|
|
|
|
|
|
const renderModal = () => (
|
|
|
|
<Dialogue
|
|
|
|
open={this.state.prompt}
|
|
|
|
onClose={toggleModal}
|
|
|
|
onClick={this.deleteApplication}
|
|
|
|
title="Are you sure you want to delete this application?"
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const tabData = [
|
|
|
|
{
|
|
|
|
label: 'Application overview',
|
|
|
|
component: (
|
|
|
|
<ApplicationView
|
|
|
|
strategies={strategies}
|
|
|
|
instances={instances}
|
|
|
|
seenToggles={seenToggles}
|
|
|
|
hasPermission={hasPermission}
|
|
|
|
formatFullDateTime={this.formatFullDateTime}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Edit application',
|
|
|
|
component: (
|
|
|
|
<ApplicationUpdate application={application} storeApplicationMetaData={storeApplicationMetaData} />
|
|
|
|
),
|
|
|
|
},
|
|
|
|
];
|
2016-12-13 20:54:53 +01:00
|
|
|
|
|
|
|
return (
|
2021-03-30 15:14:02 +02:00
|
|
|
<PageContent
|
|
|
|
headerContent={
|
|
|
|
<HeaderTitle
|
|
|
|
title={
|
|
|
|
<span
|
|
|
|
style={{
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Avatar style={{ marginRight: '8px' }}>
|
|
|
|
<Icon>{icon || 'apps'}</Icon>
|
|
|
|
</Avatar>
|
|
|
|
{appName}
|
|
|
|
</span>
|
|
|
|
}
|
|
|
|
actions={
|
|
|
|
<>
|
|
|
|
<ConditionallyRender
|
|
|
|
condition={url}
|
|
|
|
show={
|
|
|
|
<IconButton component={Link} href={url}>
|
|
|
|
<Icon>link</Icon>
|
|
|
|
</IconButton>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<ConditionallyRender
|
|
|
|
condition={hasPermission(UPDATE_APPLICATION)}
|
|
|
|
show={
|
|
|
|
<Button color="secondary" title="Delete application" onClick={toggleModal}>
|
|
|
|
Delete
|
|
|
|
</Button>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<div>
|
|
|
|
<Typography variant="body1">{description || ''}</Typography>
|
|
|
|
<Typography variant="body2">
|
2020-09-26 22:14:56 +02:00
|
|
|
Created: <strong>{this.formatDate(createdAt)}</strong>
|
2021-03-30 15:14:02 +02:00
|
|
|
</Typography>
|
|
|
|
</div>
|
|
|
|
<ConditionallyRender
|
|
|
|
condition={hasPermission(UPDATE_APPLICATION)}
|
|
|
|
show={
|
|
|
|
<div>
|
|
|
|
{renderModal()}
|
2016-12-09 14:02:36 +01:00
|
|
|
|
2021-03-30 15:14:02 +02:00
|
|
|
<TabNav tabData={tabData} />
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</PageContent>
|
2016-12-05 15:15:01 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 20:54:53 +01:00
|
|
|
export default ClientApplications;
|