Skip to content

Commit

Permalink
Merge pull request #3 from blockr-org/cleanup
Browse files Browse the repository at this point in the history
out factor ui_fields_one_column
  • Loading branch information
christophsax authored Jan 25, 2024
2 parents 23a4def + ada7b53 commit 041d26a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 73 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Generated by roxygen2: do not edit by hand

S3method(ui_fields,admiral_dpc_block)
S3method(ui_fields,filter_expr_block)
export(admiral_dpc_block)
export(filter_expr_block)
import(blockr)
Expand Down
38 changes: 2 additions & 36 deletions R/admiral-dpc-block.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,41 +132,7 @@ admiral_dpc_block <- function(data, ...) {
initialize_block(new_admiral_dpc_block(data, ...), data)
}



# A simple, one column layout
#
# we need the fields, not the rendered fields, that's why I can't use the layout
# methods

#' @importFrom shiny p tags div
#' @export
ui_fields.admiral_dpc_block <- function(x, ns, inputs_hidden, ...) {

html_card <- function(field, field_name) {
div(
div(
tags$h5(attr(field, "title")),
div(
class = c("text-muted small mb-2"),
attr(field, "descr")
)
),
tags$div(
class = "w-100",
ui_input(field, id = ns(field_name), name = NULL)
)
)
}

cards <- Map(
html_card,
field = x,
field_name = names(x)
)

div(
class = sprintf("block-inputs %s", inputs_hidden),
div(cards, class = "mt-3")
)

ui_fields_one_column(x = x, ns = ns, inputs_hidden = inputs_hidden)
}
50 changes: 13 additions & 37 deletions R/filter-expr-block.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,17 @@ filter_expr_expression <- function(value = c(a = "2.1", b = "4.5")) {

new_filter_expr_block <- function(data, value = NULL, ...) {
fields <- list(
# value = new_keyvalue_field(value = value),
value = new_keyvalue_field(value = value, submit = TRUE, multiple = TRUE, key = "none"),
value = new_keyvalue_field(
value = value,
submit = TRUE,
multiple = TRUE,
key = "none",
title = "Keep rows that match a condition",
descr = "The filter() function is used to subset a data frame, retaining
all rows that satisfy your conditions. To be retained, the row
must produce a value of TRUE for all conditions."

),
expression = new_hidden_field(filter_expr_expression)
)

Expand All @@ -46,40 +55,7 @@ filter_expr_block <- function(data, ...) {
initialize_block(new_filter_expr_block(data, ...), data)
}


# A simple, one column layout
#
# we need the fields, not the rendered fields, that's why I can't use the layout
# methods

#' @importFrom shiny p tags div
#' @export
ui_fields.filter_expr_block <- function(x, ns, inputs_hidden, ...) {

html_card <- function(field, field_name) {
div(
div(
tags$h5(attr(field, "title")),
div(
class = c("text-muted small mb-2"),
attr(field, "descr")
)
),
tags$div(
class = "w-100",
ui_input(field, id = ns(field_name), name = NULL)
)
)
}

cards <- Map(
html_card,
field = x,
field_name = names(x)
)

div(
class = sprintf("block-inputs %s", inputs_hidden),
div(cards, class = "mt-3")
)

ui_fields_one_column(x = x, ns = ns, inputs_hidden = inputs_hidden)
}
34 changes: 34 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#' A simple, one column layout
#'
#' we need the fields, not the rendered fields, that's why we won't use layout
#'
#' @noRd
#' @importFrom shiny p tags div
ui_fields_one_column <- function(x, ns, inputs_hidden) {
html_card <- function(field, field_name) {
div(
div(
tags$h5(attr(field, "title")),
div(
class = c("text-muted small mb-2"),
attr(field, "descr")
)
),
tags$div(
class = "w-100",
ui_input(field, id = ns(field_name), name = NULL)
)
)
}

cards <- Map(
html_card,
field = x,
field_name = names(x)
)

div(
class = sprintf("block-inputs %s", inputs_hidden),
div(cards, class = "mt-3")
)
}

0 comments on commit 041d26a

Please sign in to comment.