import { faSync, faUserFriends } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import axios from 'axios';
import moment from 'moment';
import React, { Component } from 'react';
import Badge from 'react-bootstrap-v5/lib/Badge';
import Button from 'react-bootstrap-v5/lib/Button';
import Col from 'react-bootstrap-v5/lib/Col';
import Dropdown from 'react-bootstrap-v5/lib/Dropdown';
import Row from 'react-bootstrap-v5/lib/Row';
import Spinner from 'react-bootstrap-v5/lib/Spinner';
import { Link } from 'react-router-dom';
import { handleChange } from './forms';
import MyTable from './Table';
import { compare, errorAlert, ownerName, redirectIfNotConnected, sizeDisplayName, sizeWithFailures, sourceQueryStringParams } from './uiutil';
const localSnapshots = "Local Snapshots"
const allSnapshots = "All Snapshots"
export class SourcesTable extends Component {
constructor() {
super();
this.state = {
sources: [],
isLoading: false,
error: null,
localSourceName: "",
multiUser: false,
selectedOwner: localSnapshots,
selectedDirectory: "",
};
this.sync = this.sync.bind(this);
this.fetchSourcesWithoutSpinner = this.fetchSourcesWithoutSpinner.bind(this);
this.handleChange = handleChange.bind(this);
this.cancelSnapshot = this.cancelSnapshot.bind(this);
this.startSnapshot = this.startSnapshot.bind(this);
}
componentDidMount() {
this.setState({ isLoading: true });
this.fetchSourcesWithoutSpinner();
this.interval = window.setInterval(this.fetchSourcesWithoutSpinner, 3000);
}
componentWillUnmount() {
window.clearInterval(this.interval);
}
fetchSourcesWithoutSpinner() {
axios.get('/api/v1/sources').then(result => {
this.setState({
localSourceName: result.data.localUsername + "@" + result.data.localHost,
multiUser: result.data.multiUser,
sources: result.data.sources,
isLoading: false,
});
}).catch(error => {
redirectIfNotConnected(error);
this.setState({
error,
isLoading: false
});
});
}
selectOwner(h) {
this.setState({
selectedOwner: h,
});
}
sync() {
this.setState({ isLoading: true });
axios.post('/api/v1/repo/sync', {}).then(result => {
this.fetchSourcesWithoutSpinner();
}).catch(error => {
errorAlert(error);
this.setState({
error,
isLoading: false
});
});
}
statusCell(x, parent) {
switch (x.cell.value) {
case "IDLE":
return <>
>;
case "PENDING":
return <>
{error.message}
; } if (isLoading) { return{moment(x.cell.value).fromNow()}
: '', }, { id: 'nextSnapshotTime', Header: 'Next Snapshot', width: 160, accessor: x => x.nextSnapshotTime, Cell: x => (x.cell.value && x.row.original.status !== "UPLOADING") ? <>{moment(x.cell.value).fromNow()}
{moment(x.cell.value).isBefore(moment()) && <>