Web: Bakup: Optimization, added a flag about the ability to show the automatic backup moduleю

This commit is contained in:
Tatiana Lopaeva 2021-10-28 12:15:52 +03:00
parent c488fb0d8e
commit 33245ac05d

View File

@ -11,6 +11,7 @@ import Box from "@appserver/components/box";
import styled from "styled-components";
import FloatingButton from "@appserver/common/components/FloatingButton";
import {
enableRestore,
getBackupProgress,
getBackupSchedule,
} from "@appserver/common/api/portal";
@ -38,23 +39,57 @@ class Backup extends React.Component {
moment.locale(this.lng);
this.state = {
downloadingProgress: false,
downloadingProgress: 100,
enableRestore: false,
isLoading: false,
};
this._isMounted = false;
this.timerId = null;
this.scheduleInformation = "";
}
componentDidMount() {
this._isMounted = true;
const { t } = this.props;
this.setState(
{
isLoading: true,
},
function () {
getBackupSchedule()
.then((backupSchedule) => {
this.setBasicSettings();
}
);
}
setBasicSettings = async () => {
const { t } = this.props;
const requests = [
enableRestore(),
getBackupProgress(),
getBackupSchedule(),
];
let progress, schedule, enable;
[enable, progress, schedule] = await Promise.allSettled(requests);
const backupProgress = progress.value;
const backupSchedule = schedule.value;
if (backupProgress) {
if (!backupProgress.error) {
this._isMounted &&
this.setState({
downloadingProgress: backupProgress.progress,
link: backupProgress.link,
});
if (backupProgress.progress !== 100) {
this.timerId = setInterval(() => this.getProgress(), 5000);
}
}
}
if (backupSchedule) {
if (backupSchedule.storageType === 0)
this.scheduleInformation += `${t("DocumentsModule")} `;
@ -81,48 +116,29 @@ class Backup extends React.Component {
if (backupSchedule.cronParams.period === 0) {
this.scheduleInformation += `(${t(
"DailyPeriodSchedule"
)}, ${moment()
.add(1, "days")
.hour(time)
.minute("00")
.format("LT")})`;
)}, ${moment().add(1, "days").hour(time).minute("00").format("LT")})`;
}
if (backupSchedule.cronParams.period === 2) {
const year = moment().year();
const month = moment().month();
this.scheduleInformation += `(${t(
"MonthlyPeriodSchedule"
)}, ${moment([year, 0, day])
this.scheduleInformation += `(${t("MonthlyPeriodSchedule")}, ${moment([
year,
0,
day,
])
.month(month)
.hour(time)
.minute("00")
.format("Do, LT")})`;
}
}
})
.finally(() =>
this.setState({
isLoading: false,
})
);
}
);
getBackupProgress().then((response) => {
if (response && !response.error) {
this._isMounted &&
this.setState({
downloadingProgress: response.progress,
link: response.link,
enableRestore: enable,
});
if (response.progress !== 100) {
this.timerId = setInterval(() => this.getProgress(), 5000);
}
}
});
}
};
componentWillUnmount() {
this._isMounted = false;
clearInterval(this.timerId);
@ -135,6 +151,7 @@ class Backup extends React.Component {
};
getProgress = () => {
const { t } = this.props;
const { downloadingProgress } = this.state;
getBackupProgress()
.then((response) => {
@ -150,6 +167,7 @@ class Backup extends React.Component {
return;
}
if (this._isMounted) {
downloadingProgress !== response.progress &&
this.setState({
downloadingProgress: response.progress,
});
@ -184,11 +202,13 @@ class Backup extends React.Component {
};
render() {
const { t, helpUrlCreatingBackup } = this.props;
const { downloadingProgress, isLoading } = this.state;
const { downloadingProgress, isLoading, enableRestore } = this.state;
console.log("render", downloadingProgress);
return isLoading ? (
<Loader className="pageLoader" type="rombs" size="40px" />
) : (
<StyledBackup>
{enableRestore && (
<div className="category-item-wrapper">
<div className="category-item-heading">
<Link
@ -212,6 +232,7 @@ class Backup extends React.Component {
{t("AutomaticBackupSettingsDescription")}
</Text>
</div>
)}
<div className="category-item-wrapper">
<div className="category-item-heading">