diff --git a/NEWS.md b/NEWS.md index 58ffbb7ed..65c52186c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # testthat (development version) +* `snapshot_review()` includes a reject button and only displays the file navigation and the skip button if there are multiple files to review (#2025). * New `snapshot_download_gh()` makes it easy to get snapshots off GitHub and into your local package (#1779). * 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) * `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) diff --git a/R/snapshot-manage.R b/R/snapshot-manage.R index fa1321b85..0c40b9741 100644 --- a/R/snapshot-manage.R +++ b/R/snapshot-manage.R @@ -73,15 +73,16 @@ review_app <- function(name, old_path, new_path, ...) { ui <- shiny::fluidPage( style = "margin: 0.5em", shiny::fluidRow( - style = "display: flex", + style = "display: flex; margin-bottom: 0.5em", shiny::div( style = "flex: 1 1", - shiny::selectInput("cases", NULL, case_index, width = "100%") + if (n > 1) shiny::selectInput("cases", NULL, case_index, width = "100%") ), shiny::div( class = "btn-group", style = "margin-left: 1em; flex: 0 0 auto", - shiny::actionButton("skip", "Skip"), + shiny::actionButton("reject", "Reject", class = "btn-danger"), + if (n > 1) shiny::actionButton("skip", "Skip"), shiny::actionButton("accept", "Accept", class = "btn-success"), ) ), @@ -90,11 +91,14 @@ review_app <- function(name, old_path, new_path, ...) { ) ) server <- function(input, output, session) { - i <- shiny::reactive(as.numeric(input$cases)) + i <- shiny::reactive(if (n == 1) 1L else as.numeric(input$cases)) output$diff <- diffviewer::visual_diff_render({ diffviewer::visual_diff(old_path[[i()]], new_path[[i()]]) }) + # Can't skip if there's only one file to review + shiny::updateActionButton(session, "skip", disabled = (n <= 1)) + # Handle buttons - after clicking update move input$cases to next case, # and remove current case (for accept/reject). If no cases left, close app shiny::observeEvent(input$reject, { @@ -122,6 +126,10 @@ review_app <- function(name, old_path, new_path, ...) { choices = case_index[!handled], selected = i ) + + n_left <- sum(!handled) + # Disable skip button if only one case remains + shiny::updateActionButton(session, "skip", disabled = (n_left <= 1)) } next_case <- function() { if (all(handled)) {