From fa4373288cc8c63ec08b3cf39ddda9287ec1f5b4 Mon Sep 17 00:00:00 2001 From: m7pr Date: Tue, 26 Sep 2023 14:46:53 +0200 Subject: [PATCH] `add_card_button_srv` allows to specify `card_fun` with `label` parameter for card's title & content customization. --- NEWS.md | 2 ++ R/AddCardModule.R | 22 +++++++++++++--------- man/add_card_button_srv.Rd | 13 +++++++------ 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/NEWS.md b/NEWS.md index 188d66c4..f9a63928 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # teal.reporter 0.2.1.9003 +* `add_card_button_srv` allows to specify `card_fun` with `label` parameter for card's title & content customization. + # teal.reporter 0.2.1 ### Miscellaneous diff --git a/R/AddCardModule.R b/R/AddCardModule.R index d9f639a3..7398e552 100644 --- a/R/AddCardModule.R +++ b/R/AddCardModule.R @@ -70,20 +70,20 @@ add_card_button_ui <- function(id) { #' #' @param id `character(1)` this `shiny` module's id. #' @param reporter [`Reporter`] instance. -#' @param card_fun `function` which returns a [`ReportCard`] instance, -#' the function has optional `card` and `comment` arguments. -#' If the `card` argument is added then the `ReportCard` instance is automatically created for the user. -#' If the `comment` argument is not specified then it is added automatically at the end of the Card. -#' The card name set by default in `card_fun` will be overcome by the `label` input which will be set automatically -#' when adding a card. -#' +#' @param card_fun `function` which returns a [`ReportCard`] instance. It can have optional `card` and `comment` +#' parameters. If `card` parameter is added, then the `ReportCard` instance is created for the user. Use `comment` +#' parameter to pass it's value whenever you prefer with `card$append_text()` - if `card_fun` does not have `comment` +#' parameter, then `comment` from `Add Card` UI module will be added at the end of the content of the card. If `label` +#' parameter is provided, you can use it to customize appearance of the `card name` and use if to specify `card` content +#' with `card$append_text()` - if `card_fun` does not have `label` parameter, then `card name` will be set to the name +#' passed in `Add Card` UI module, but no text will be added to the content of the `card`. #' #' @return `shiny::moduleServer` #' @export add_card_button_srv <- function(id, reporter, card_fun) { checkmate::assert_function(card_fun) checkmate::assert_class(reporter, "Reporter") - checkmate::assert_subset(names(formals(card_fun)), c("card", "comment"), empty.ok = TRUE) + checkmate::assert_subset(names(formals(card_fun)), c("card", "comment", "label"), empty.ok = TRUE) shiny::moduleServer( id, @@ -151,12 +151,16 @@ add_card_button_srv <- function(id, reporter, card_fun) { card_fun_args_nams <- names(formals(card_fun)) has_card_arg <- "card" %in% card_fun_args_nams has_comment_arg <- "comment" %in% card_fun_args_nams + has_label_arg <- "label" %in% card_fun_args_nams arg_list <- list() if (has_comment_arg) { arg_list <- c(arg_list, list(comment = input$comment)) } + if (has_label_arg) { + arg_list <- c(arg_list, list(label = input$label)) + } if (has_card_arg) { # The default_card is defined here because formals() returns a pairedlist object @@ -191,7 +195,7 @@ add_card_button_srv <- function(id, reporter, card_fun) { card$append_text(input$comment) } - if (length(input$label) == 1 && input$label != "") { + if (!has_label_arg && length(input$label) == 1 && input$label != "") { card$set_name(input$label) } diff --git a/man/add_card_button_srv.Rd b/man/add_card_button_srv.Rd index 0e8b0253..86a1ab45 100644 --- a/man/add_card_button_srv.Rd +++ b/man/add_card_button_srv.Rd @@ -11,12 +11,13 @@ add_card_button_srv(id, reporter, card_fun) \item{reporter}{\code{\link{Reporter}} instance.} -\item{card_fun}{\code{function} which returns a \code{\link{ReportCard}} instance, -the function has optional \code{card} and \code{comment} arguments. -If the \code{card} argument is added then the \code{ReportCard} instance is automatically created for the user. -If the \code{comment} argument is not specified then it is added automatically at the end of the Card. -The card name set by default in \code{card_fun} will be overcome by the \code{label} input which will be set automatically -when adding a card.} +\item{card_fun}{\code{function} which returns a \code{\link{ReportCard}} instance. It can have optional \code{card} and \code{comment} +parameters. If \code{card} parameter is added, then the \code{ReportCard} instance is created for the user. Use \code{comment} +parameter to pass it's value whenever you prefer with \code{card$append_text()} - if \code{card_fun} does not have \code{comment} +parameter, then \code{comment} from \verb{Add Card} UI module will be added at the end of the content of the card. If \code{label} +parameter is provided, you can use it to customize appearance of the \verb{card name} and use if to specify \code{card} content +with \code{card$append_text()} - if \code{card_fun} does not have \code{label} parameter, then \verb{card name} will be set to the name +passed in \verb{Add Card} UI module, but no text will be added to the content of the \code{card}.} } \value{ \code{shiny::moduleServer}