2022-08-02 20:41:59 +02:00
|
|
|
import DataTable from 'react-data-table-component';
|
2022-08-05 20:20:03 +02:00
|
|
|
import Services from './Services';
|
2022-11-01 22:32:32 +01:00
|
|
|
import Icon from "@mdi/react";
|
|
|
|
import {mdiCloseOutline} from "@mdi/js";
|
2022-11-02 18:05:01 +01:00
|
|
|
import * as identity from './api/identity';
|
2022-08-02 20:24:01 +02:00
|
|
|
|
2022-08-03 17:54:11 +02:00
|
|
|
const Environments = (props) => {
|
2022-11-01 21:52:02 +01:00
|
|
|
const humanizeDuration = require("humanize-duration")
|
2022-11-02 17:55:44 +01:00
|
|
|
const disableEnvironment = (envId) => {
|
|
|
|
console.log(envId)
|
|
|
|
if(window.confirm('really disable environment "' + envId +'"?')) {
|
|
|
|
console.log("will delete environment: " + envId)
|
2022-11-02 18:05:01 +01:00
|
|
|
identity.disable({body: {identity: envId}}).then(resp => {
|
|
|
|
console.log(resp);
|
|
|
|
})
|
2022-11-02 17:55:44 +01:00
|
|
|
}
|
|
|
|
}
|
2022-11-01 21:52:02 +01:00
|
|
|
|
2022-08-02 20:41:59 +02:00
|
|
|
const columns = [
|
2022-08-08 19:24:14 +02:00
|
|
|
{
|
|
|
|
name: 'Description',
|
|
|
|
selector: row => row.environment.description,
|
|
|
|
sortable: true,
|
|
|
|
},
|
2022-08-02 20:41:59 +02:00
|
|
|
{
|
2022-08-03 20:25:27 +02:00
|
|
|
name: 'Host',
|
2022-08-05 19:54:34 +02:00
|
|
|
selector: row => row.environment.host,
|
2022-08-02 20:41:59 +02:00
|
|
|
sortable: true,
|
|
|
|
},
|
|
|
|
{
|
2022-08-03 20:25:27 +02:00
|
|
|
name: 'Address',
|
2022-08-05 19:54:34 +02:00
|
|
|
selector: row => row.environment.address,
|
2022-08-03 20:25:27 +02:00
|
|
|
sortable: true,
|
|
|
|
},
|
2022-08-02 20:41:59 +02:00
|
|
|
{
|
2022-08-05 21:56:44 +02:00
|
|
|
name: 'Identity',
|
2022-10-19 18:35:29 +02:00
|
|
|
selector: row => row.environment.zId,
|
2022-08-02 20:41:59 +02:00
|
|
|
sortable: true,
|
|
|
|
},
|
2022-11-01 22:32:32 +01:00
|
|
|
{
|
|
|
|
name: 'Actions',
|
|
|
|
selector: row => <>
|
2022-11-02 17:55:44 +01:00
|
|
|
<button data-value={row.environment.zId} onClick={e => disableEnvironment(row.environment.zId)} title={"Disable Environment '"+row.environment.zId+"'"}>
|
|
|
|
<Icon path={mdiCloseOutline} size={0.7}/>
|
|
|
|
</button>
|
2022-11-01 22:32:32 +01:00
|
|
|
</>
|
|
|
|
},
|
2022-08-02 20:41:59 +02:00
|
|
|
{
|
2022-11-01 21:52:02 +01:00
|
|
|
name: 'Uptime',
|
2022-11-01 22:03:32 +01:00
|
|
|
selector: row => humanizeDuration(Date.now() - row.environment.updatedAt),
|
2022-08-02 20:41:59 +02:00
|
|
|
sortable: true,
|
2022-08-03 20:25:27 +02:00
|
|
|
},
|
2022-08-02 20:41:59 +02:00
|
|
|
]
|
|
|
|
|
2022-08-05 20:20:03 +02:00
|
|
|
const servicesComponent = ({ data }) => <Services services={data.services} />
|
2022-10-19 21:21:15 +02:00
|
|
|
const servicesExpanded = row => row.services != null && row.services.length > 0
|
2022-08-05 20:20:03 +02:00
|
|
|
|
2022-11-01 21:52:02 +01:00
|
|
|
console.log('now', Date.now())
|
|
|
|
|
2022-08-02 20:24:01 +02:00
|
|
|
return (
|
|
|
|
<div>
|
2022-08-05 19:54:34 +02:00
|
|
|
<h2>Environments</h2>
|
|
|
|
{ props.overview && props.overview.length > 0 && (
|
2022-08-02 20:41:59 +02:00
|
|
|
<div>
|
|
|
|
<DataTable
|
|
|
|
columns={columns}
|
2022-08-05 19:54:34 +02:00
|
|
|
data={props.overview}
|
2022-08-03 16:58:47 +02:00
|
|
|
defaultSortFieldId={1}
|
2022-08-05 20:20:03 +02:00
|
|
|
expandableRows
|
|
|
|
expandableRowsComponent={servicesComponent}
|
|
|
|
expandableRowExpanded={servicesExpanded}
|
2022-08-02 20:41:59 +02:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
2022-08-02 20:24:01 +02:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
};
|
|
|
|
|
2022-08-03 17:54:11 +02:00
|
|
|
export default Environments;
|