Skip to content

Commit 0b896ac

Browse files
authored
Improve review UI (#2174)
* Add a reject button * Only display file nav + skip button if multiple files to review Fixes #2025
1 parent 0c13060 commit 0b896ac

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# testthat (development version)
22

3+
* `snapshot_review()` includes a reject button and only displays the file navigation and the skip button if there are multiple files to review (#2025).
34
* New `snapshot_download_gh()` makes it easy to get snapshots off GitHub and into your local package (#1779).
45
* New `local_mocked_s3_method()`, `local_mocked_s4_method()`, and `local_mocked_r6_class()` allow you to mock S3 and S4 methods and R6 classes (#1892, #1916)
56
* `expect_snapshot_file(name=)` must have a unique file path. If a snapshot file attempts to be saved with a duplicate `name`, an error will be thrown. (#1592)

R/snapshot-manage.R

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,16 @@ review_app <- function(name, old_path, new_path, ...) {
7373
ui <- shiny::fluidPage(
7474
style = "margin: 0.5em",
7575
shiny::fluidRow(
76-
style = "display: flex",
76+
style = "display: flex; margin-bottom: 0.5em",
7777
shiny::div(
7878
style = "flex: 1 1",
79-
shiny::selectInput("cases", NULL, case_index, width = "100%")
79+
if (n > 1) shiny::selectInput("cases", NULL, case_index, width = "100%")
8080
),
8181
shiny::div(
8282
class = "btn-group",
8383
style = "margin-left: 1em; flex: 0 0 auto",
84-
shiny::actionButton("skip", "Skip"),
84+
shiny::actionButton("reject", "Reject", class = "btn-danger"),
85+
if (n > 1) shiny::actionButton("skip", "Skip"),
8586
shiny::actionButton("accept", "Accept", class = "btn-success"),
8687
)
8788
),
@@ -90,11 +91,14 @@ review_app <- function(name, old_path, new_path, ...) {
9091
)
9192
)
9293
server <- function(input, output, session) {
93-
i <- shiny::reactive(as.numeric(input$cases))
94+
i <- shiny::reactive(if (n == 1) 1L else as.numeric(input$cases))
9495
output$diff <- diffviewer::visual_diff_render({
9596
diffviewer::visual_diff(old_path[[i()]], new_path[[i()]])
9697
})
9798

99+
# Can't skip if there's only one file to review
100+
shiny::updateActionButton(session, "skip", disabled = (n <= 1))
101+
98102
# Handle buttons - after clicking update move input$cases to next case,
99103
# and remove current case (for accept/reject). If no cases left, close app
100104
shiny::observeEvent(input$reject, {
@@ -122,6 +126,10 @@ review_app <- function(name, old_path, new_path, ...) {
122126
choices = case_index[!handled],
123127
selected = i
124128
)
129+
130+
n_left <- sum(!handled)
131+
# Disable skip button if only one case remains
132+
shiny::updateActionButton(session, "skip", disabled = (n_left <= 1))
125133
}
126134
next_case <- function() {
127135
if (all(handled)) {

0 commit comments

Comments
 (0)