Skip to content

Commit

Permalink
feat(ui): add Delete key binding to remove systems
Browse files Browse the repository at this point in the history
  • Loading branch information
updraft0 committed Jun 11, 2024
1 parent a4ee8ce commit 2050285
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
11 changes: 6 additions & 5 deletions ui/src/main/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@
box-sizing: border-box;
}

button {
padding: 0;
color: $gray-lightest;
}

:root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
Expand All @@ -49,6 +44,12 @@ button {
scrollbar-color: $gray-darker $gray-dark;
}


button {
padding: 2px;
color: $gray-lightest;
}

table {
border-collapse: collapse;
}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/main/scala/controltower/component/Modal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ object Modal:
div(
cls := "dialog-view",
cls := "confirm-dialog-view",
div(cls := "dialog-header", title),
h2(cls := "dialog-header", title),
div(cls := "dialog-body", description),
form(
method := "dialog",
Expand Down
10 changes: 10 additions & 0 deletions ui/src/main/scala/controltower/page/map/view/MapView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ private class MapView(

div(
idAttr := "map-view-inner",

// delete -> remove system

// TODO: make helpers for these
documentEvents(
_.onKeyDown
.filter(ev => !ev.repeat && ev.code == "Delete")
).mapToUnit.compose(_.withCurrentValueOf(controller.selectedSystem)).filterNot(_.isEmpty).map(_.get) --> (
system => removeSystemConfirm(system, controller.actionsBus)(using rds)
),
div(
idAttr := "map-parent",
cls := "grid",
Expand Down
30 changes: 19 additions & 11 deletions ui/src/main/scala/controltower/page/map/view/ToolbarView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,7 @@ class ToolbarView(
"ti-trash",
disableWhenNotSelectedAndRole(selected, mapRole, RoleController.canRemoveSystem, isConnected),
onClick.stopPropagation.compose(_.sampleCollectSome(selected)) --> (system =>
Modal.showConfirmation(
"Confirm removal",
span(
child.text <-- Signal
.fromFuture(rds.systemForId(system.system.systemId))
.map(_.flatten.map(_.name).getOrElse(s"?? ${system.system.systemId}"))
.map(n => s"Remove system $n?")
),
actions.contramap(_ => MapAction.Remove(system.system.systemId)),
isDestructive = true
)
removeSystemConfirm(system, actions)(using rds)
)
),
toolbarButtonS(
Expand Down Expand Up @@ -233,3 +223,21 @@ private def systemAddView(
)
)
)

private[map] def removeSystemConfirm(system: MapSystemSnapshot, actions: WriteBus[MapAction])(using
rds: ReferenceDataStore
) =
Modal.showConfirmation(
"Confirm removal",
span(
child.text <--
Signal
.fromFuture(rds.systemForId(system.system.systemId))
.map(_.flatten.map(_.name).getOrElse(s"?? ${system.system.systemId}"))
.map(solarName =>
system.system.name.map(n => s"Remove system $n ($solarName)?").getOrElse(s"Remove system $solarName?")
)
),
actions.contramap(_ => MapAction.Remove(system.system.systemId)),
isDestructive = true
)

0 comments on commit 2050285

Please sign in to comment.