-
Notifications
You must be signed in to change notification settings - Fork 0
Improve picks ui when single choice #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
762d76a
dd473fb
55c8481
5f5743f
8e466db
c541422
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -8,8 +8,13 @@ | |||||
| #' @param id (`character(1)`) shiny module's id | ||||||
| #' @param label (`shiny.tag`) Label displayed on a badge. | ||||||
| #' @param content (`shiny.tag`) Content of a drop-down. | ||||||
| #' @param badge_context (`character(1)`) Variation content of the badge i.e: "primary", "secondary" ... | ||||||
| #' @param fixed (`logical(1)`) Whether to return a badge with dropdown (default) or simple fixed badge if set to TRUE | ||||||
| #' @keywords internal | ||||||
| badge_dropdown <- function(id, label, content) { | ||||||
| badge_dropdown <- function(id, label, content, badge_context = "primary", fixed = FALSE) { | ||||||
| checkmate::assert_character(badge_context) | ||||||
| checkmate::assert_logical(fixed) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not only logical but also to be of length one and not accept NA values
Suggested change
|
||||||
|
|
||||||
| ns <- shiny::NS(id) | ||||||
| htmltools::tagList( | ||||||
| htmltools::singleton(htmltools::tags$head( | ||||||
|
|
@@ -20,11 +25,15 @@ badge_dropdown <- function(id, label, content) { | |||||
| class = "badge-dropdown-wrapper", | ||||||
| htmltools::tags$span( | ||||||
| id = ns("summary_badge"), | ||||||
| class = "badge bg-primary rounded-pill badge-dropdown", | ||||||
| style = "cursor: pointer;", | ||||||
| class = sprintf("badge bg-%s rounded-pill badge-dropdown", badge_context), | ||||||
| style = ifelse(fixed, "", "cursor: pointer"), | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not important but I think there was some recommendations to use
Suggested change
|
||||||
| tags$span(class = "badge-dropdown-label", label), | ||||||
| tags$span(class = "badge-dropdown-icon", bsicons::bs_icon("caret-down-fill")), | ||||||
| onclick = sprintf("toggleBadgeDropdown('%s', '%s')", ns("summary_badge"), ns("inputs_container")) | ||||||
| if (isFALSE(fixed)) tags$span(class = "badge-dropdown-icon", bsicons::bs_icon("caret-down-fill")), | ||||||
| onclick = ifelse( | ||||||
| fixed, | ||||||
| "", | ||||||
| sprintf("toggleBadgeDropdown('%s', '%s')", ns("summary_badge"), ns("inputs_container")) | ||||||
| ) | ||||||
| ), | ||||||
| htmltools::tags$div( | ||||||
| content, | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,11 +58,20 @@ picks_ui.list <- function(id, picks, container) { | |
| picks_ui.picks <- function(id, picks, container) { | ||
| ns <- shiny::NS(id) | ||
| badge_label <- shiny::uiOutput(ns("summary"), container = htmltools::tags$span) | ||
|
|
||
| content <- lapply(picks, function(x) .pick_ui(id = ns(methods::is(x)))) | ||
| htmltools::tags$div( | ||
| if (missing(container)) { | ||
| badge_dropdown(id = ns("inputs"), label = badge_label, htmltools::tagList(content)) | ||
| if (isTRUE(attr(picks$variables, "fixed")) && isTRUE(attr(picks$datasets, "fixed"))) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would iterate through the whole elements of picks and check with Se also my comment about |
||
| badge_dropdown( | ||
| id = ns("inputs"), | ||
| label = badge_label, | ||
| htmltools::tagList(content), | ||
| badge_context = "secondary", | ||
| fixed = TRUE | ||
| ) | ||
| } else { | ||
| badge_dropdown(id = ns("inputs"), label = badge_label, htmltools::tagList(content)) | ||
| } | ||
| } else { | ||
| if (!any(sapply(htmltools::tags, identical, container))) { | ||
| stop("Container should be one of `htmltools::tags`") | ||
|
|
@@ -244,8 +253,18 @@ picks_srv.picks <- function(id, picks, data) { | |
| logger::log_debug(".pick_srv@1 rerender {pick_type} input") | ||
| .validate_is_eager(choices()) | ||
| .validate_is_eager(selected()) | ||
| if (isTRUE(args$fixed) || length(choices()) <= 1) { | ||
| if (!length(choices()) || isTRUE(args$fixed)) { | ||
| NULL | ||
| } else if (length(choices()) == 1 && isFALSE(args$fixed)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this new conditional? Wouldn't it be catch up by the latest |
||
| .pick_ui_categorical( | ||
| session$ns("selected"), | ||
| label = sprintf("Select %s:", pick_type), | ||
| choices = choices(), | ||
| selected = selected(), | ||
| multiple = args$multiple, | ||
| choicesOpt = list(content = isolate(choices_opt_content())), | ||
| args = args[!names(args) %in% c("multiple")] | ||
| ) | ||
| } else if (.is_ranged(choices()) && inherits(choices(), "Date")) { | ||
| .pick_ui_date( | ||
| session$ns("range"), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| Analyse | ||
| UI | ||
| dropdown | ||
| schemas |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the description of the new
badge_contextargument and I see it inherits the color from teal.But do we need the
fixed = FALSEargument? If it is fixed there is no dropdown so we might want to use a different function that generates the UI.