Skip to content

Commit 05403af

Browse files
committed
Allow protecting/unprotecting services.
1 parent f5e02b5 commit 05403af

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

src/pages/Services.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useCallback, useEffect, useState } from 'react';
2-
import { Delete, OpenInBrowser, StackedBarChart } from '@styled-icons/material';
2+
import { Delete, Lock, LockOpen, OpenInBrowser, StackedBarChart } from '@styled-icons/material';
33
import { dayjs, timeWithHours } from '@timing71/common';
44
import { useHistory } from 'react-router-dom';
55
import styled from 'styled-components';
@@ -36,7 +36,7 @@ const RouteryButton = ({ to, ...props }) => {
3636
);
3737
};
3838

39-
const DeleteButton = ({ reload, uuid }) => {
39+
const DeleteButton = ({ disabled, reload, uuid }) => {
4040
const [ isDeleting, setDeleting ] = useState(false);
4141

4242
const cs = useConnectionService();
@@ -56,7 +56,7 @@ const DeleteButton = ({ reload, uuid }) => {
5656
return (
5757
<Button
5858
danger
59-
disabled={isDeleting}
59+
disabled={disabled || isDeleting}
6060
onClick={doDelete}
6161
title='Delete'
6262
>
@@ -136,7 +136,7 @@ const Actions = styled.div`
136136
column-gap: 1em;
137137
`;
138138

139-
const ServiceEntry = ({ openAnalysis, reload, service }) => {
139+
const ServiceEntry = ({ openAnalysis, reload, service, setProtection }) => {
140140
const finalState = service.sessions ? service.sessions[service.sessions.length - 1] : null;
141141

142142
const duration = service.startTime && finalState?.lastUpdated ?
@@ -164,7 +164,14 @@ const ServiceEntry = ({ openAnalysis, reload, service }) => {
164164
>
165165
<StackedBarChart size={24} /> Analysis
166166
</Button>
167+
<Button
168+
onClick={() => setProtection(service.uuid, !service.protectFromDeletion)}
169+
>
170+
{ service.protectFromDeletion && (<><Lock size={24} /> Unprotect</>)}
171+
{ !service.protectFromDeletion && (<><LockOpen size={24} /> Protect</>)}
172+
</Button>
167173
<DeleteButton
174+
disabled={service.protectFromDeletion}
168175
reload={reload}
169176
uuid={service.uuid}
170177
/>
@@ -224,6 +231,13 @@ export const Services = () => {
224231
[cs]
225232
);
226233

234+
const setProtection = useCallback(
235+
(uuid, protectFromDeletion) => {
236+
cs.send({ type: 'SET_SERVICE_PROTECTION', uuid, protectFromDeletion }).then(reload);
237+
},
238+
[cs, reload]
239+
);
240+
227241
useEffect(reload, [reload]);
228242

229243
return (
@@ -241,16 +255,16 @@ export const Services = () => {
241255
Recent sessions
242256
</PageTitle>
243257
<p>
244-
This page lists recent timing sessions. You can reconnect to them,
245-
launch the analysis screen, or download a replay file. Unless marked
246-
as "protected", sessions will automatically be deleted after 7 days,
247-
or you can delete them manually.
258+
This page lists your recent timing sessions. You can reconnect to
259+
them, launch the analysis screen, or download a replay file. Unless
260+
marked as "protected", sessions will automatically be deleted after 7
261+
days, or you can delete them manually.
248262
</p>
249263
{
250264
services !== null && (
251265
<ServiceTable>
252266
<Heading>
253-
Started at
267+
Date started
254268
</Heading>
255269
<Heading>
256270
Source
@@ -269,6 +283,7 @@ export const Services = () => {
269283
openAnalysis={openAnalysis}
270284
reload={reload}
271285
service={service}
286+
setProtection={setProtection}
272287
/>
273288
)
274289
)

0 commit comments

Comments
 (0)