Skip to content

Commit f4bd875

Browse files
committed
feat(ui,signature): add button and shortcut c to clear stale (>24hr) signatures
1 parent 0f9f7fb commit f4bd875

File tree

2 files changed

+48
-7
lines changed

2 files changed

+48
-7
lines changed

ui/src/main/scala/controltower/page/map/view/MapView.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,23 @@ private final class MapView(
190190
cls := "system-add-dialog"
191191
)
192192
),
193+
// C -> cleanup stale signatures in system
194+
modalKeyBinding[(MapSystemSnapshot, Instant)](
195+
"c",
196+
controller.mapRole.map(RoleController.canEditSignatures).combineWith(ws.isConnected).map(_ && _),
197+
_.filterWith(controller.selectedSystem, _.isDefined)
198+
.withCurrentValueOf(controller.selectedSystem, time)
199+
.map((ev, opt, now) => (ev, (opt.get, now))),
200+
{ case ((system, now), onClose) =>
201+
val staleAt = now.minus(StaleSignatureInterval)
202+
val stale = system.signatures.filter(_.updatedAt.isBefore(staleAt))
203+
204+
if (stale.nonEmpty)
205+
controller.actionsBus.onNext(MapAction.RemoveSignatures(system.system.systemId, stale.map(_.id).toSet))
206+
207+
onClose.onNext(())
208+
}
209+
),
193210
// delete -> remove system
194211
modalKeyBinding(
195212
"Delete",

ui/src/main/scala/controltower/page/map/view/SystemSignatureView.scala

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import java.time.{Duration, Instant}
1313
enum SignatureFilter derives CanEqual:
1414
case All, Wormhole, Combat, Indy, Hacking, Unscanned
1515

16+
val StaleSignatureInterval: Duration = Duration.ofDays(1)
17+
1618
enum ConnectionTarget derives CanEqual:
1719
def idOpt: Option[ConnectionId] =
1820
this match
@@ -124,16 +126,10 @@ private inline def sigView(
124126
.combineWith(currentFilter.signal)
125127
.map((sigs, filter) => s"${sigs.count(isVisibleWithFilter(filter, _))}/${sigs.length}")
126128
),
127-
// TODO not sure this is necessary!
128-
// button(
129-
// idAttr := "sig-select-all",
130-
// typ := "button",
131-
// cls := "ti",
132-
// cls := "ti-select-all"
133-
// ),
134129
button(
135130
idAttr := "sig-paste-signatures",
136131
typ := "button",
132+
title := "Paste signatures",
137133
cls := "ti",
138134
cls := "ti-clipboard-plus",
139135
disabled <-- canEdit.map(!_),
@@ -158,6 +154,7 @@ private inline def sigView(
158154
button(
159155
idAttr := "sig-add-signature",
160156
typ := "button",
157+
title := "Add a signature",
161158
cls := "ti",
162159
cls := "ti-plus",
163160
disabled <-- canEdit.map(!_),
@@ -181,6 +178,7 @@ private inline def sigView(
181178
button(
182179
idAttr := "sig-edit-signature",
183180
typ := "button",
181+
title := "Edit signature",
184182
disabled <-- canEdit.combineWith(selected.signal).map(!_ || _.size != 1),
185183
cls := "ti",
186184
cls := "ti-pencil",
@@ -204,9 +202,34 @@ private inline def sigView(
204202
)
205203
)
206204
),
205+
button(
206+
idAttr := "sig-remove-stale",
207+
typ := "button",
208+
title := "Remove stale signatures",
209+
cls := "sig-destructive",
210+
cls := "ti",
211+
cls := "ti-hours-24",
212+
disabled <-- canEdit.map(!_),
213+
onClick.stopPropagation.mapToUnit.compose(
214+
_.withCurrentValueOf(time, signatures, solarSystem)
215+
) --> ((now: Instant, signatures: List[MapSystemSignature], solarSystem) =>
216+
val staleAt = now.minus(StaleSignatureInterval)
217+
val stale = signatures.filter(_.updatedAt.isBefore(staleAt))
218+
219+
if (stale.nonEmpty)
220+
Modal.showConfirmation(
221+
s"Remove ${stale.size} signatures?",
222+
s"Confirm removal of signatures in ${solarSystem.name}?",
223+
Observer(_ => actions.onNext(MapAction.RemoveSignatures(solarSystem.id, stale.map(_.id).toSet))),
224+
true,
225+
selected.clearUpdater
226+
)
227+
)
228+
),
207229
button(
208230
idAttr := "sig-remove-selected",
209231
typ := "button",
232+
title := "Remove selected signatures",
210233
disabled <-- canEdit.combineWith(selected.signal).map(!_ || _.isEmpty),
211234
cls := "sig-destructive",
212235
cls := "ti",
@@ -225,6 +248,7 @@ private inline def sigView(
225248
button(
226249
idAttr := "sig-remove-all-signatures",
227250
typ := "button",
251+
title := "Remove all signatures",
228252
cls := "sig-destructive",
229253
cls := "ti",
230254
cls := "ti-clear-all",

0 commit comments

Comments
 (0)