feat: add a disabled option in repo alert settings

This commit is contained in:
Ravinou 2023-11-10 16:24:58 +01:00
parent 1f519c50fa
commit 10ad738755
No known key found for this signature in database
GPG key ID: EEEE670C40F6A4D7
7 changed files with 38 additions and 21 deletions

View file

@ -6,6 +6,7 @@ import {
IconInfoCircle, IconInfoCircle,
IconChevronDown, IconChevronDown,
IconChevronUp, IconChevronUp,
IconBellOff,
} from '@tabler/icons-react'; } from '@tabler/icons-react';
import timestampConverter from '../../helpers/functions/timestampConverter'; import timestampConverter from '../../helpers/functions/timestampConverter';
import StorageBar from '../UI/StorageBar/StorageBar'; import StorageBar from '../UI/StorageBar/StorageBar';
@ -53,22 +54,33 @@ export default function Repo(props) {
setDisplayDetails(boolean); setDisplayDetails(boolean);
}; };
//Status indicator
const statusIndicator = () => {
return props.status
? classes.statusIndicatorGreen
: classes.statusIndicatorRed;
};
//Alert indicator
const alertIndicator = () => {
if (props.alert === 0) {
return (
<div className={classes.alertIcon}>
<IconBellOff size={16} color='grey' />
</div>
);
}
};
return ( return (
<> <>
{displayDetails ? ( {displayDetails ? (
<> <>
<div className={classes.RepoOpen}> <div className={classes.RepoOpen}>
<div className={classes.openFlex}> <div className={classes.openFlex}>
{props.status ? ( <div className={statusIndicator()} />
<div
className={classes.statusIndicatorGreen}
></div>
) : (
<div
className={classes.statusIndicatorRed}
></div>
)}
<div className={classes.alias}>{props.alias}</div> <div className={classes.alias}>{props.alias}</div>
{alertIndicator()}
{props.comment && ( {props.comment && (
<div className={classes.comment}> <div className={classes.comment}>
<IconInfoCircle size={16} color='grey' /> <IconInfoCircle size={16} color='grey' />
@ -141,16 +153,9 @@ export default function Repo(props) {
<> <>
<div className={classes.RepoClose}> <div className={classes.RepoClose}>
<div className={classes.closeFlex}> <div className={classes.closeFlex}>
{props.status ? ( <div className={statusIndicator()} />
<div
className={classes.statusIndicatorGreen}
></div>
) : (
<div
className={classes.statusIndicatorRed}
></div>
)}
<div className={classes.alias}>{props.alias}</div> <div className={classes.alias}>{props.alias}</div>
{alertIndicator()}
{props.comment && ( {props.comment && (
<div className={classes.comment}> <div className={classes.comment}>
<IconInfoCircle size={16} color='#637381' /> <IconInfoCircle size={16} color='#637381' />

View file

@ -148,6 +148,15 @@
} }
} }
/* Alert icon */
.alertIcon {
display: flex;
flex-direction: row;
align-items: center;
margin-left: 10px;
}
/* GENERAL */ /* GENERAL */
.alias { .alias {
font-weight: bold; font-weight: bold;

View file

@ -116,6 +116,7 @@ export default function RepoList() {
alias={repo.alias} alias={repo.alias}
status={repo.status} status={repo.status}
lastSave={repo.lastSave} lastSave={repo.lastSave}
alert={repo.alert}
repositoryName={repo.repositoryName} repositoryName={repo.repositoryName}
storageSize={repo.storageSize} storageSize={repo.storageSize}
storageUsed={repo.storageUsed} storageUsed={repo.storageUsed}

View file

@ -23,6 +23,7 @@ export default function RepoManage(props) {
} = useForm({ mode: 'onChange' }); } = useForm({ mode: 'onChange' });
//List of possible times for alerts //List of possible times for alerts
const alertOptions = [ const alertOptions = [
{ value: 0, label: 'Disabled' },
{ value: 3600, label: '1 hour' }, { value: 3600, label: '1 hour' },
{ value: 21600, label: '6 hours' }, { value: 21600, label: '6 hours' },
{ value: 43200, label: '12 hours' }, { value: 43200, label: '12 hours' },
@ -471,7 +472,7 @@ export default function RepoManage(props) {
x.value === x.value ===
targetRepo.alert targetRepo.alert
) )
: alertOptions[3] : alertOptions[4]
} }
control={control} control={control}
render={({ render={({

View file

@ -102,6 +102,7 @@ export default async function handler(req, res) {
for (let index in newRepoList) { for (let index in newRepoList) {
if ( if (
!newRepoList[index].status && !newRepoList[index].status &&
newRepoList[index].alert !== 0 &&
(!newRepoList[index].lastStatusAlertSend || (!newRepoList[index].lastStatusAlertSend ||
date - newRepoList[index].lastStatusAlertSend > 90000) date - newRepoList[index].lastStatusAlertSend > 90000)
) { ) {

View file

@ -19,7 +19,7 @@ export default async function handler(req, res) {
const { alias, sshPublicKey, size, comment, alert, lanCommand } = const { alias, sshPublicKey, size, comment, alert, lanCommand } =
req.body; req.body;
//We check that we receive data for each variable. Only "comment" and "lanCommand" are optional in the form. //We check that we receive data for each variable. Only "comment" and "lanCommand" are optional in the form.
if (!alias || !sshPublicKey || !size || !alert) { if (!alias || !sshPublicKey || !size || (!alert && alert !== 0)) {
//If a variable is empty. //If a variable is empty.
res.status(422).json({ res.status(422).json({
message: 'Unexpected data', message: 'Unexpected data',

View file

@ -19,7 +19,7 @@ export default async function handler(req, res) {
const { alias, sshPublicKey, size, comment, alert, lanCommand } = const { alias, sshPublicKey, size, comment, alert, lanCommand } =
req.body; req.body;
//We check that we receive data for each variable. Only "comment" and "lanCommand" are optional in the form. //We check that we receive data for each variable. Only "comment" and "lanCommand" are optional in the form.
if (!alias || !sshPublicKey || !size || !alert) { if (!alias || !sshPublicKey || !size || (!alert && alert !== 0)) {
//If a variable is empty. //If a variable is empty.
res.status(422).json({ res.status(422).json({
message: 'Unexpected data', message: 'Unexpected data',