Skip to content

Commit 4152971

Browse files
committed
hide bulk menu when no role is selected
Includes server protection for attempting writes with no selected role
1 parent bd5b986 commit 4152971

2 files changed

Lines changed: 24 additions & 8 deletions

File tree

R/mod_listings.R

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -598,10 +598,25 @@ listings_server <- function(module_id,
598598
targets = review_column_indices[[4]])
599599
)
600600
)
601+
602+
# TODO: find a place for this if
603+
if (checkmate::test_string(input[[REV$ID$ROLE]], min.chars = 1)) {
604+
bulk_render <- sprintf(
605+
"function(settings, json) {
606+
dv_listings.render_bulk_menu(settings.sTableId + \"_wrapper\", [%s], '%s');
607+
}", paste(paste0("'", review[["choices"]], "'"), collapse = ", "),
608+
ns(REV$ID$REVIEW_SELECT)
609+
)
610+
} else {
611+
bulk_render <- ""
612+
}
601613
} else {
614+
bulk_render <- ""
602615
review_col_count <- 0
603616
}
604617

618+
619+
605620
DT::datatable(
606621
data = table_data[["data"]],
607622
colnames = table_data[["col_names"]],
@@ -619,14 +634,7 @@ listings_server <- function(module_id,
619634
# FIXME: Update to use https://datatables.net/reference/option/layout
620635
dom = "<'top'>rtilp", # Buttons, filtering, processing display element, table, information summary, length, pagination
621636
fixedColumns = list(left = review_col_count),
622-
initComplete = htmlwidgets::JS(
623-
sprintf(
624-
"function(settings, json) {
625-
dv_listings.render_bulk_menu(settings.sTableId + \"_wrapper\", [%s], '%s');
626-
}", paste(paste0("'", review[["choices"]], "'"), collapse = ", "),
627-
ns(REV$ID$REVIEW_SELECT)
628-
)
629-
),
637+
initComplete = htmlwidgets::JS(bulk_render),
630638
drawCallback = htmlwidgets::JS("
631639
function (settings) {
632640
$(settings.nTableWrapper).find('thead input[type=\"search\"]').removeAttr('disabled');

R/review.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,14 @@ REV_logic_2 <- function(ns, state, input, review, datasets, selected_dataset_lis
513513
shiny::observeEvent(input[[REV$ID$REVIEW_SELECT]], {
514514
role <- input[[REV$ID$ROLE]]
515515

516+
if (!checkmate::test_string(role, min.chars = 1)) {
517+
msg <- "Attempted write with unset role"
518+
shiny::showNotification(msg, type = "warning")
519+
warning(msg)
520+
shiny::req(FALSE)
521+
}
522+
523+
516524
dataset_list_name <- selected_dataset_list_name()
517525
dataset_name <- selected_dataset_name()
518526

0 commit comments

Comments
 (0)