From ffa764ea3e74f1b3788da0bd91a683e6c0e8d184 Mon Sep 17 00:00:00 2001 From: Maciej Nasinski Date: Mon, 22 Aug 2022 17:35:27 +0200 Subject: [PATCH 01/14] turn off on panel --- R/FilteredData.R | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/R/FilteredData.R b/R/FilteredData.R index f9e1e5892..35d39704b 100644 --- a/R/FilteredData.R +++ b/R/FilteredData.R @@ -589,6 +589,18 @@ FilteredData <- R6::R6Class( # nolint div( id = ns(NULL), # used for hiding / showing include_css_files(pattern = "filter-panel"), + div( + id = ns("switch-button"), + class = "inline-block", + shinyWidgets::switchInput( + ns("filter_turn_onoff"), + label = "TURN", + onLabel = "ON", + offLabel = "OFF", + value = TRUE, + handleWidth = "80px" + ) + ), div( id = ns("filters_overview"), # not used, can be used to customize CSS behavior class = "well", @@ -759,6 +771,23 @@ FilteredData <- R6::R6Class( # nolint } ) + observeEvent( + eventExpr = list(input[["filter_turn_onoff"]]), + handlerExpr = { + if (isFALSE(input[["filter_turn_onoff"]])) { + shinyjs::hide("filter_add_vars") + shinyjs::hide("filter_active_vars") + private$cached_states <- self$get_filter_state() + self$remove_all_filter_states() + } else { + shinyjs::show("filter_add_vars") + shinyjs::show("filter_active_vars") + if (length(private$cached_states) && (length(self$get_filter_state()) == 0)) { + self$set_filter_state(private$cached_states) + } + } + }, ignoreNULL = TRUE) + observeEvent( eventExpr = active_datanames(), handlerExpr = { @@ -903,6 +932,8 @@ FilteredData <- R6::R6Class( # nolint # reactive i.e. filtered data reactive_data = list(), + cached_states = NULL, + # we implement these functions as checks rather than returning logicals so they can # give informative error messages immediately From ee8188ef04c4f24b7a229d3c07bc2db683ccdf34 Mon Sep 17 00:00:00 2001 From: Maciej Nasinski Date: Tue, 23 Aug 2022 11:46:53 +0200 Subject: [PATCH 02/14] disable --- R/FilteredData.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/FilteredData.R b/R/FilteredData.R index 35d39704b..7ce1abed8 100644 --- a/R/FilteredData.R +++ b/R/FilteredData.R @@ -775,13 +775,13 @@ FilteredData <- R6::R6Class( # nolint eventExpr = list(input[["filter_turn_onoff"]]), handlerExpr = { if (isFALSE(input[["filter_turn_onoff"]])) { - shinyjs::hide("filter_add_vars") - shinyjs::hide("filter_active_vars") + shinyjs::disable("filter_add_vars") + shinyjs::disable("filter_active_vars") private$cached_states <- self$get_filter_state() self$remove_all_filter_states() } else { - shinyjs::show("filter_add_vars") - shinyjs::show("filter_active_vars") + shinyjs::enable("filter_add_vars") + shinyjs::enable("filter_active_vars") if (length(private$cached_states) && (length(self$get_filter_state()) == 0)) { self$set_filter_state(private$cached_states) } From ef37b85809b90b7e06e6bafde78b707a71b5b52f Mon Sep 17 00:00:00 2001 From: Maciej Nasinski Date: Wed, 24 Aug 2022 17:35:39 +0200 Subject: [PATCH 03/14] polish --- R/FilteredData.R | 56 ++++++++++++++++++++++++++++----------- R/filter_panel_api.R | 34 +++++++++++++++++++++--- inst/css/filter-panel.css | 5 ++++ man/CDISCFilteredData.Rd | 2 ++ man/FilterPanelAPI.Rd | 20 ++++++++++++++ man/FilteredData.Rd | 20 ++++++++++++++ 6 files changed, 118 insertions(+), 19 deletions(-) diff --git a/R/FilteredData.R b/R/FilteredData.R index 7ce1abed8..d333ffbfe 100644 --- a/R/FilteredData.R +++ b/R/FilteredData.R @@ -506,6 +506,7 @@ FilteredData <- R6::R6Class( # nolint ) } logger::log_trace("FilteredData$set_filter_state initialized, dataname: { paste(names(state), collapse = ' ') }") + invisible(NULL) }, @@ -516,6 +517,8 @@ FilteredData <- R6::R6Class( # nolint #' #' @return `NULL` remove_filter_state = function(state) { + checkmate::assert_subset(names(state), self$datanames()) + logger::log_trace("FilteredData$remove_filter_state called, dataname: { paste(names(state), collapse = ' ') }") for (dataname in names(state)) { @@ -524,6 +527,7 @@ FilteredData <- R6::R6Class( # nolint } logger::log_trace("FilteredData$remove_filter_state done, dataname: { paste(names(state), collapse = ' ') }") + invisible(NULL) }, @@ -573,6 +577,29 @@ FilteredData <- R6::R6Class( # nolint restore_state_from_bookmark = function(state, check_data_hash = TRUE) { stop("Pure virtual method") }, + filter_panel_disable = function() { + private$filter_turn <- FALSE + shinyjs::disable("filter_add_vars") + shinyjs::disable("filter_active_vars") + private$cached_states <- self$get_filter_state() + self$remove_all_filter_states() + invisible(NULL) + }, + filter_panel_enable = function() { + private$filter_turn <- TRUE + shinyjs::enable("filter_add_vars") + shinyjs::enable("filter_active_vars") + if (length(private$cached_states) && (length(self$get_filter_state()) == 0)) { + self$set_filter_state(private$cached_states) + } + invisible(NULL) + }, + get_filter_turn = function() { + private$filter_turn + }, + get_filter_panel_ui_id = function() { + private$filter_panel_ui_id + }, # shiny modules ----- @@ -595,9 +622,8 @@ FilteredData <- R6::R6Class( # nolint shinyWidgets::switchInput( ns("filter_turn_onoff"), label = "TURN", - onLabel = "ON", - offLabel = "OFF", value = TRUE, + inline = FALSE, handleWidth = "80px" ) ), @@ -771,22 +797,17 @@ FilteredData <- R6::R6Class( # nolint } ) + private$filter_panel_ui_id <- session$ns(NULL) observeEvent( - eventExpr = list(input[["filter_turn_onoff"]]), + eventExpr = input[["filter_turn_onoff"]], handlerExpr = { - if (isFALSE(input[["filter_turn_onoff"]])) { - shinyjs::disable("filter_add_vars") - shinyjs::disable("filter_active_vars") - private$cached_states <- self$get_filter_state() - self$remove_all_filter_states() + if (isTRUE(input[["filter_turn_onoff"]])) { + self$filter_panel_enable() } else { - shinyjs::enable("filter_add_vars") - shinyjs::enable("filter_active_vars") - if (length(private$cached_states) && (length(self$get_filter_state()) == 0)) { - self$set_filter_state(private$cached_states) - } + self$filter_panel_disable() } - }, ignoreNULL = TRUE) + }, ignoreNULL = TRUE + ) observeEvent( eventExpr = active_datanames(), @@ -920,6 +941,12 @@ FilteredData <- R6::R6Class( # nolint # private attributes ---- filtered_datasets = list(), + # turn on / off filter panel + filter_turn = TRUE, + + # filter panel ui id + filter_panel_ui_id = character(0), + # whether the datasets had a reproducibility check .check = FALSE, @@ -931,7 +958,6 @@ FilteredData <- R6::R6Class( # nolint # reactive i.e. filtered data reactive_data = list(), - cached_states = NULL, # we implement these functions as checks rather than returning logicals so they can diff --git a/R/filter_panel_api.R b/R/filter_panel_api.R index 60efd7dfe..f119a0ab3 100644 --- a/R/filter_panel_api.R +++ b/R/filter_panel_api.R @@ -62,7 +62,11 @@ FilterPanelAPI <- R6::R6Class( # nolint #' #' @return `NULL` set_filter_state = function(filter) { - private$filtered_data$set_filter_state(filter) + if (private$filtered_data$get_filter_turn()) { + private$filtered_data$set_filter_state(filter) + } else { + warning("Filter Panel is turn off so the action can not be applied with api.") + } invisible(NULL) }, @@ -73,7 +77,11 @@ FilterPanelAPI <- R6::R6Class( # nolint #' #' @return `NULL` remove_filter_state = function(filter) { - private$filtered_data$remove_filter_state(filter) + if (private$filtered_data$get_filter_turn()) { + private$filtered_data$remove_filter_state(filter) + } else { + warning("Filter Panel is turn off so the action can not be applied with api.") + } invisible(NULL) }, @@ -83,8 +91,26 @@ FilterPanelAPI <- R6::R6Class( # nolint #' #' @return `NULL` remove_all_filter_states = function(datanames) { - datanames_to_remove <- if (missing(datanames)) private$filtered_data$datanames() else datanames - private$filtered_data$remove_all_filter_states(datanames = datanames_to_remove) + if (private$filtered_data$get_filter_turn()) { + datanames_to_remove <- if (missing(datanames)) private$filtered_data$datanames() else datanames + private$filtered_data$remove_all_filter_states(datanames = datanames_to_remove) + } else { + warning("Filter Panel is turn off so the action can not be applied with api.") + } + invisible(NULL) + }, + #' @description Toggle the state of the Filter Panel turn on/off button. + #' @param id (`character(1)`)\cr + #' `id` to the toggle button. + #' + #' @return `NULL` + filter_panel_toggle = function() { + shinyjs::runjs( + sprintf( + '$("#%s-filter_turn_onoff").click();', + private$filtered_data$get_filter_panel_ui_id() + ) + ) invisible(NULL) } ), diff --git a/inst/css/filter-panel.css b/inst/css/filter-panel.css index e3985e2b8..327786dbd 100644 --- a/inst/css/filter-panel.css +++ b/inst/css/filter-panel.css @@ -4,9 +4,14 @@ position: relative; } +.inline-block { + position: inline-block; +} + .float-right { float: right; } + .float-left { float: left; } diff --git a/man/CDISCFilteredData.Rd b/man/CDISCFilteredData.Rd index 68084146b..6ac205323 100644 --- a/man/CDISCFilteredData.Rd +++ b/man/CDISCFilteredData.Rd @@ -76,6 +76,8 @@ isolate(datasets$get_filter_state()) \if{html}{\out{
Inherited methods
    +
  • teal.slice::FilteredData$filter_panel_disable()
  • +
  • teal.slice::FilteredData$filter_panel_enable()
  • teal.slice::FilteredData$get_check()
  • teal.slice::FilteredData$get_code()
  • teal.slice::FilteredData$get_data()
  • diff --git a/man/FilterPanelAPI.Rd b/man/FilterPanelAPI.Rd index 5536b4ae8..e2006253b 100644 --- a/man/FilterPanelAPI.Rd +++ b/man/FilterPanelAPI.Rd @@ -45,6 +45,8 @@ isolate(fpa$get_filter_state()) \item \href{#method-FilterPanelAPI-set_filter_state}{\code{FilterPanelAPI$set_filter_state()}} \item \href{#method-FilterPanelAPI-remove_filter_state}{\code{FilterPanelAPI$remove_filter_state()}} \item \href{#method-FilterPanelAPI-remove_all_filter_states}{\code{FilterPanelAPI$remove_all_filter_states()}} +\item \href{#method-FilterPanelAPI-filter_panel_disable}{\code{FilterPanelAPI$filter_panel_disable()}} +\item \href{#method-FilterPanelAPI-filter_panel_enable}{\code{FilterPanelAPI$filter_panel_enable()}} \item \href{#method-FilterPanelAPI-clone}{\code{FilterPanelAPI$clone()}} } } @@ -143,6 +145,24 @@ datanames to remove their \code{FilterStates} or empty which removes all \code{F \subsection{Returns}{ \code{NULL} } +} +\if{html}{\out{
    }} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FilterPanelAPI-filter_panel_disable}{}}} +\subsection{Method \code{filter_panel_disable()}}{ +\subsection{Usage}{ +\if{html}{\out{
    }}\preformatted{FilterPanelAPI$filter_panel_disable(input)}\if{html}{\out{
    }} +} + +} +\if{html}{\out{
    }} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FilterPanelAPI-filter_panel_enable}{}}} +\subsection{Method \code{filter_panel_enable()}}{ +\subsection{Usage}{ +\if{html}{\out{
    }}\preformatted{FilterPanelAPI$filter_panel_enable(input)}\if{html}{\out{
    }} +} + } \if{html}{\out{
    }} \if{html}{\out{}} diff --git a/man/FilteredData.Rd b/man/FilteredData.Rd index cb9556ea2..dd669cdbb 100644 --- a/man/FilteredData.Rd +++ b/man/FilteredData.Rd @@ -171,6 +171,8 @@ shiny::isolate(datasets$get_filter_state()) \item \href{#method-FilteredData-srv_filter_panel}{\code{FilteredData$srv_filter_panel()}} \item \href{#method-FilteredData-ui_filter_overview}{\code{FilteredData$ui_filter_overview()}} \item \href{#method-FilteredData-srv_filter_overview}{\code{FilteredData$srv_filter_overview()}} +\item \href{#method-FilteredData-filter_panel_disable}{\code{FilteredData$filter_panel_disable()}} +\item \href{#method-FilteredData-filter_panel_enable}{\code{FilteredData$filter_panel_enable()}} \item \href{#method-FilteredData-clone}{\code{FilteredData$clone()}} } } @@ -922,6 +924,24 @@ panel will be hidden.} \subsection{Returns}{ \code{moduleServer} function which returns \code{NULL} } +} +\if{html}{\out{
    }} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FilteredData-filter_panel_disable}{}}} +\subsection{Method \code{filter_panel_disable()}}{ +\subsection{Usage}{ +\if{html}{\out{
    }}\preformatted{FilteredData$filter_panel_disable(input)}\if{html}{\out{
    }} +} + +} +\if{html}{\out{
    }} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FilteredData-filter_panel_enable}{}}} +\subsection{Method \code{filter_panel_enable()}}{ +\subsection{Usage}{ +\if{html}{\out{
    }}\preformatted{FilteredData$filter_panel_enable(input)}\if{html}{\out{
    }} +} + } \if{html}{\out{
    }} \if{html}{\out{}} From d1fbd697a63d0f0e75bf09fcc98774b64140dd36 Mon Sep 17 00:00:00 2001 From: Maciej Nasinski Date: Wed, 24 Aug 2022 17:47:07 +0200 Subject: [PATCH 04/14] docs --- R/FilteredData.R | 4 +++ man/CDISCFilteredData.Rd | 2 ++ man/FilterPanelAPI.Rd | 28 ++++++++-------- man/FilteredData.Rd | 72 ++++++++++++++++++++++++++-------------- 4 files changed, 69 insertions(+), 37 deletions(-) diff --git a/R/FilteredData.R b/R/FilteredData.R index d333ffbfe..09c6c8a4d 100644 --- a/R/FilteredData.R +++ b/R/FilteredData.R @@ -577,6 +577,7 @@ FilteredData <- R6::R6Class( # nolint restore_state_from_bookmark = function(state, check_data_hash = TRUE) { stop("Pure virtual method") }, + #' @description disable the filter panel filter_panel_disable = function() { private$filter_turn <- FALSE shinyjs::disable("filter_add_vars") @@ -585,6 +586,7 @@ FilteredData <- R6::R6Class( # nolint self$remove_all_filter_states() invisible(NULL) }, + #' @description enable the filter panel filter_panel_enable = function() { private$filter_turn <- TRUE shinyjs::enable("filter_add_vars") @@ -594,9 +596,11 @@ FilteredData <- R6::R6Class( # nolint } invisible(NULL) }, + #' @description get the state of filter panel, if it is activated get_filter_turn = function() { private$filter_turn }, + #' @description get the id of the filter panel ui get_filter_panel_ui_id = function() { private$filter_panel_ui_id }, diff --git a/man/CDISCFilteredData.Rd b/man/CDISCFilteredData.Rd index 6ac205323..4d998f678 100644 --- a/man/CDISCFilteredData.Rd +++ b/man/CDISCFilteredData.Rd @@ -82,7 +82,9 @@ isolate(datasets$get_filter_state())
  • teal.slice::FilteredData$get_code()
  • teal.slice::FilteredData$get_data()
  • teal.slice::FilteredData$get_datalabel()
  • +
  • teal.slice::FilteredData$get_filter_panel_ui_id()
  • teal.slice::FilteredData$get_filter_state()
  • +
  • teal.slice::FilteredData$get_filter_turn()
  • teal.slice::FilteredData$get_filtered_dataset()
  • teal.slice::FilteredData$get_formatted_filter_state()
  • teal.slice::FilteredData$get_join_keys()
  • diff --git a/man/FilterPanelAPI.Rd b/man/FilterPanelAPI.Rd index e2006253b..acc0fcb6d 100644 --- a/man/FilterPanelAPI.Rd +++ b/man/FilterPanelAPI.Rd @@ -45,8 +45,7 @@ isolate(fpa$get_filter_state()) \item \href{#method-FilterPanelAPI-set_filter_state}{\code{FilterPanelAPI$set_filter_state()}} \item \href{#method-FilterPanelAPI-remove_filter_state}{\code{FilterPanelAPI$remove_filter_state()}} \item \href{#method-FilterPanelAPI-remove_all_filter_states}{\code{FilterPanelAPI$remove_all_filter_states()}} -\item \href{#method-FilterPanelAPI-filter_panel_disable}{\code{FilterPanelAPI$filter_panel_disable()}} -\item \href{#method-FilterPanelAPI-filter_panel_enable}{\code{FilterPanelAPI$filter_panel_enable()}} +\item \href{#method-FilterPanelAPI-filter_panel_toggle}{\code{FilterPanelAPI$filter_panel_toggle()}} \item \href{#method-FilterPanelAPI-clone}{\code{FilterPanelAPI$clone()}} } } @@ -147,22 +146,25 @@ datanames to remove their \code{FilterStates} or empty which removes all \code{F } } \if{html}{\out{
    }} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FilterPanelAPI-filter_panel_disable}{}}} -\subsection{Method \code{filter_panel_disable()}}{ +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FilterPanelAPI-filter_panel_toggle}{}}} +\subsection{Method \code{filter_panel_toggle()}}{ +Toggle the state of the Filter Panel turn on/off button. \subsection{Usage}{ -\if{html}{\out{
    }}\preformatted{FilterPanelAPI$filter_panel_disable(input)}\if{html}{\out{
    }} +\if{html}{\out{
    }}\preformatted{FilterPanelAPI$filter_panel_toggle()}\if{html}{\out{
    }} } +\subsection{Arguments}{ +\if{html}{\out{
    }} +\describe{ +\item{\code{id}}{(\code{character(1)})\cr +\code{id} to the toggle button.} } -\if{html}{\out{
    }} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FilterPanelAPI-filter_panel_enable}{}}} -\subsection{Method \code{filter_panel_enable()}}{ -\subsection{Usage}{ -\if{html}{\out{
    }}\preformatted{FilterPanelAPI$filter_panel_enable(input)}\if{html}{\out{
    }} +\if{html}{\out{
    }} +} +\subsection{Returns}{ +\code{NULL} } - } \if{html}{\out{
    }} \if{html}{\out{}} diff --git a/man/FilteredData.Rd b/man/FilteredData.Rd index dd669cdbb..5102b1ff6 100644 --- a/man/FilteredData.Rd +++ b/man/FilteredData.Rd @@ -167,12 +167,14 @@ shiny::isolate(datasets$get_filter_state()) \item \href{#method-FilteredData-remove_filter_state}{\code{FilteredData$remove_filter_state()}} \item \href{#method-FilteredData-remove_all_filter_states}{\code{FilteredData$remove_all_filter_states()}} \item \href{#method-FilteredData-restore_state_from_bookmark}{\code{FilteredData$restore_state_from_bookmark()}} +\item \href{#method-FilteredData-filter_panel_disable}{\code{FilteredData$filter_panel_disable()}} +\item \href{#method-FilteredData-filter_panel_enable}{\code{FilteredData$filter_panel_enable()}} +\item \href{#method-FilteredData-get_filter_turn}{\code{FilteredData$get_filter_turn()}} +\item \href{#method-FilteredData-get_filter_panel_ui_id}{\code{FilteredData$get_filter_panel_ui_id()}} \item \href{#method-FilteredData-ui_filter_panel}{\code{FilteredData$ui_filter_panel()}} \item \href{#method-FilteredData-srv_filter_panel}{\code{FilteredData$srv_filter_panel()}} \item \href{#method-FilteredData-ui_filter_overview}{\code{FilteredData$ui_filter_overview()}} \item \href{#method-FilteredData-srv_filter_overview}{\code{FilteredData$srv_filter_overview()}} -\item \href{#method-FilteredData-filter_panel_disable}{\code{FilteredData$filter_panel_disable()}} -\item \href{#method-FilteredData-filter_panel_enable}{\code{FilteredData$filter_panel_enable()}} \item \href{#method-FilteredData-clone}{\code{FilteredData$clone()}} } } @@ -821,15 +823,55 @@ containing fields \code{data_hash}, \code{filter_states} and \code{preproc_code}.} \item{\code{check_data_hash}}{(\code{logical}) whether to check that \code{md5sums} agree -for the data; may not make sense with randomly generated data per session +for the data; may not make sense with randomly generated data per session} +} +\if{html}{\out{}} +} +} +\if{html}{\out{
    }} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FilteredData-filter_panel_disable}{}}} +\subsection{Method \code{filter_panel_disable()}}{ +disable the filter panel +\subsection{Usage}{ +\if{html}{\out{
    }}\preformatted{FilteredData$filter_panel_disable()}\if{html}{\out{
    }} +} + +} +\if{html}{\out{
    }} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FilteredData-filter_panel_enable}{}}} +\subsection{Method \code{filter_panel_enable()}}{ +enable the filter panel +\subsection{Usage}{ +\if{html}{\out{
    }}\preformatted{FilteredData$filter_panel_enable()}\if{html}{\out{
    }} +} + +} +\if{html}{\out{
    }} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FilteredData-get_filter_turn}{}}} +\subsection{Method \code{get_filter_turn()}}{ +get the state of filter panel, if it is activated +\subsection{Usage}{ +\if{html}{\out{
    }}\preformatted{FilteredData$get_filter_turn()}\if{html}{\out{
    }} +} + +} +\if{html}{\out{
    }} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-FilteredData-get_filter_panel_ui_id}{}}} +\subsection{Method \code{get_filter_panel_ui_id()}}{ +get the id of the filter panel ui Module for the right filter panel in the teal app with a filter overview panel and a filter variable panel. This panel contains info about the number of observations left in -the (active) datasets and allows to filter the datasets.} -} -\if{html}{\out{}} +the (active) datasets and allows to filter the datasets. +\subsection{Usage}{ +\if{html}{\out{
    }}\preformatted{FilteredData$get_filter_panel_ui_id()}\if{html}{\out{
    }} } + } \if{html}{\out{
    }} \if{html}{\out{}} @@ -924,24 +966,6 @@ panel will be hidden.} \subsection{Returns}{ \code{moduleServer} function which returns \code{NULL} } -} -\if{html}{\out{
    }} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FilteredData-filter_panel_disable}{}}} -\subsection{Method \code{filter_panel_disable()}}{ -\subsection{Usage}{ -\if{html}{\out{
    }}\preformatted{FilteredData$filter_panel_disable(input)}\if{html}{\out{
    }} -} - -} -\if{html}{\out{
    }} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-FilteredData-filter_panel_enable}{}}} -\subsection{Method \code{filter_panel_enable()}}{ -\subsection{Usage}{ -\if{html}{\out{
    }}\preformatted{FilteredData$filter_panel_enable(input)}\if{html}{\out{
    }} -} - } \if{html}{\out{
    }} \if{html}{\out{}} From 59d9f5eafd2a770bdac0b06223a7d5e4af7dd23e Mon Sep 17 00:00:00 2001 From: Maciej Nasinski Date: Mon, 29 Aug 2022 15:52:21 +0200 Subject: [PATCH 05/14] tests --- tests/testthat/test-FilteredData.R | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/testthat/test-FilteredData.R b/tests/testthat/test-FilteredData.R index 026b00c21..c03abe283 100644 --- a/tests/testthat/test-FilteredData.R +++ b/tests/testthat/test-FilteredData.R @@ -576,3 +576,22 @@ testthat::test_that("get_data assert the `filtered` argument is logical(1)", { regexp = "Assertion on 'filtered' failed: Must be of type 'logical flag', not 'character'" ) }) + +testthat::test_that("filter_panel_disable and filter_panel_enable", { + filtered_data <- FilteredData$new(data_objects = list("iris" = list(dataset = iris)), join_keys = NULL) + filtered_data$set_filter_state(list(iris = list(Sepal.Width = c(3, 4)))) + shiny::testServer( + filtered_data$srv_filter_panel, + expr = { + testthat::expect_length(filtered_data$get_filter_state(), 1) + testthat::expect_true(filtered_data$get_filter_turn()) + filtered_data$filter_panel_disable() + testthat::expect_length(filtered_data$get_filter_state(), 0) + testthat::expect_false(filtered_data$get_filter_turn()) + filtered_data$filter_panel_enable() + testthat::expect_length(filtered_data$get_filter_state(), 1) + testthat::expect_true(filtered_data$get_filter_turn()) + } + ) +}) + From 0c16055a1241a570ffecf71444e07984d887ee7e Mon Sep 17 00:00:00 2001 From: Maciej Nasinski Date: Tue, 30 Aug 2022 09:24:07 +0200 Subject: [PATCH 06/14] tests --- tests/testthat/test-FilteredData.R | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/testthat/test-FilteredData.R b/tests/testthat/test-FilteredData.R index c03abe283..0e8356e16 100644 --- a/tests/testthat/test-FilteredData.R +++ b/tests/testthat/test-FilteredData.R @@ -577,6 +577,31 @@ testthat::test_that("get_data assert the `filtered` argument is logical(1)", { ) }) +testthat::test_that("filter_panel_disable", { + filtered_data <- FilteredData$new(data_objects = list("iris" = list(dataset = iris)), join_keys = NULL) + filtered_data$set_filter_state(list(iris = list(Sepal.Width = c(3, 4)))) + shiny::testServer( + filtered_data$srv_filter_panel, + expr = { + filtered_data$filter_panel_disable() + testthat::expect_length(filtered_data$get_filter_state(), 0) + } + ) +}) + +testthat::test_that("filter_panel_enable", { + filtered_data <- FilteredData$new(data_objects = list("iris" = list(dataset = iris)), join_keys = NULL) + filtered_data$set_filter_state(list(iris = list(Sepal.Width = c(3, 4)))) + shiny::testServer( + filtered_data$srv_filter_panel, + expr = { + filtered_data$filter_panel_enable() + testthat::expect_length(filtered_data$get_filter_state(), 1) + testthat::expect_equal(filtered_data$get_filter_state()$iris$Sepal.Width$selected, c(3, 4)) + } + ) +}) + testthat::test_that("filter_panel_disable and filter_panel_enable", { filtered_data <- FilteredData$new(data_objects = list("iris" = list(dataset = iris)), join_keys = NULL) filtered_data$set_filter_state(list(iris = list(Sepal.Width = c(3, 4)))) From 77350312940f5fa1fd864146bd3d6aebbfd3974d Mon Sep 17 00:00:00 2001 From: Maciej Nasinski Date: Tue, 30 Aug 2022 09:41:08 +0200 Subject: [PATCH 07/14] tests --- tests/testthat/test-FilteredData.R | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/testthat/test-FilteredData.R b/tests/testthat/test-FilteredData.R index 0e8356e16..189f73100 100644 --- a/tests/testthat/test-FilteredData.R +++ b/tests/testthat/test-FilteredData.R @@ -620,3 +620,22 @@ testthat::test_that("filter_panel_disable and filter_panel_enable", { ) }) +testthat::test_that("turn filed by default equal to TRUE", { + filtered_data <- FilteredData$new(data_objects = list("iris" = list(dataset = iris)), join_keys = NULL) + testthat::expect_true(filtered_data$get_filter_turn()) +}) + +testthat::test_that("get_filter_panel_ui_id - empty when no shiny session", { + filtered_data <- FilteredData$new(data_objects = list("iris" = list(dataset = iris)), join_keys = NULL) + testthat::expect_length(filtered_data$get_filter_panel_ui_id(), 0) +}) + +testthat::test_that("get_filter_panel_ui_id - non-empty when in shiny session", { + filtered_data <- FilteredData$new(data_objects = list("iris" = list(dataset = iris)), join_keys = NULL) + shiny::testServer( + filtered_data$srv_filter_panel, + expr = { + testthat::expect_length(filtered_data$get_filter_panel_ui_id(), 1) + } + ) +}) From f4dc8cafd53d89cdfac80f09507f76fdbbaa8684 Mon Sep 17 00:00:00 2001 From: Maciej Nasinski Date: Tue, 30 Aug 2022 10:05:26 +0200 Subject: [PATCH 08/14] tests --- tests/testthat/test-FilteredData.R | 1 + tests/testthat/test-filter_panel_api.R | 67 ++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/tests/testthat/test-FilteredData.R b/tests/testthat/test-FilteredData.R index 189f73100..7c8601cac 100644 --- a/tests/testthat/test-FilteredData.R +++ b/tests/testthat/test-FilteredData.R @@ -639,3 +639,4 @@ testthat::test_that("get_filter_panel_ui_id - non-empty when in shiny session", } ) }) + diff --git a/tests/testthat/test-filter_panel_api.R b/tests/testthat/test-filter_panel_api.R index 31bc7ce7d..3bff55afe 100644 --- a/tests/testthat/test-filter_panel_api.R +++ b/tests/testthat/test-filter_panel_api.R @@ -132,3 +132,70 @@ testthat::test_that( ) } ) + + +testthat::test_that("filter_panel_api neutral when filter panel is disabled", { + shiny::testServer( + filtered_data$srv_filter_panel, + expr = { + filtered_data <- teal.slice:::init_filtered_data(list(iris = list(dataset = iris), mtcars = list(dataset = mtcars))) + filtered_data$filter_panel_disable() + fs <- FilterPanelAPI$new(filtered_data) + filter_list <- list( + iris = list( + Sepal.Length = list(c(5.1, 6.4)), + Species = c("setosa", "versicolor") + ), + mtcars = list( + hp = list(selected = c(52, 65), keep_na = FALSE, keep_inf = FALSE) + ) + ) + testthat::expect_warning(fs$set_filter_state(filter_list)) + testthat::expect_warning(fs$remove_all_filter_states(datanames = "iris")) + fs_wo_attr <- isolate(fs$get_filter_state()) + attr(fs_wo_attr, "formatted") <- NULL + names(fs_wo_attr) <- NULL + + testthat::expect_equal( + fs_wo_attr, + list() + ) + } + ) +}) + + +testthat::test_that("filter_panel_api disable enable", { + shiny::testServer( + filtered_data$srv_filter_panel, + expr = { + filtered_data <- teal.slice:::init_filtered_data(list(iris = list(dataset = iris), mtcars = list(dataset = mtcars))) + filtered_data$filter_panel_disable() + fs <- FilterPanelAPI$new(filtered_data) + filter_list <- list( + iris = list( + Sepal.Length = list(c(5.1, 6.4)), + Species = c("setosa", "versicolor") + ), + mtcars = list( + hp = list(selected = c(52, 65), keep_na = FALSE, keep_inf = FALSE) + ) + ) + testthat::expect_warning(fs$set_filter_state(filter_list)) + testthat::expect_warning(fs$remove_all_filter_states(datanames = "iris")) + filtered_data$filter_panel_enable() + fs$set_filter_state(filter_list) + fs$remove_all_filter_states(datanames = "iris") + fs_wo_attr <- isolate(fs$get_filter_state()) + attr(fs_wo_attr, "formatted") <- NULL + + testthat::expect_equal( + fs_wo_attr, + list(mtcars = list( + hp = list(selected = c(52, 65), keep_na = FALSE, keep_inf = FALSE) + )) + ) + } + ) +}) + From 71729a73d4477d0f390e44d920e9fabb83370c82 Mon Sep 17 00:00:00 2001 From: Maciej Nasinski Date: Tue, 30 Aug 2022 10:47:53 +0200 Subject: [PATCH 09/14] tests --- tests/testthat/test-filter_panel_api.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-filter_panel_api.R b/tests/testthat/test-filter_panel_api.R index 3bff55afe..2aa929863 100644 --- a/tests/testthat/test-filter_panel_api.R +++ b/tests/testthat/test-filter_panel_api.R @@ -165,7 +165,7 @@ testthat::test_that("filter_panel_api neutral when filter panel is disabled", { }) -testthat::test_that("filter_panel_api disable enable", { +testthat::test_that("filter_panel_api under disable/enable filter panel", { shiny::testServer( filtered_data$srv_filter_panel, expr = { From b4a8483d719f66c26eca59f15e0510980ec33990 Mon Sep 17 00:00:00 2001 From: Maciej Nasinski Date: Fri, 2 Sep 2022 12:44:46 +0200 Subject: [PATCH 10/14] logger --- R/FilteredData.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/FilteredData.R b/R/FilteredData.R index 09c6c8a4d..014ed4820 100644 --- a/R/FilteredData.R +++ b/R/FilteredData.R @@ -807,8 +807,10 @@ FilteredData <- R6::R6Class( # nolint handlerExpr = { if (isTRUE(input[["filter_turn_onoff"]])) { self$filter_panel_enable() + logger::log_trace("Enable the Filtered Panel with the filter_panel_enable method") } else { self$filter_panel_disable() + logger::log_trace("Disable the Filtered Panel with the filter_panel_enable method") } }, ignoreNULL = TRUE ) From 56e3a4c2110822e698d6b58c413838d6c01abc43 Mon Sep 17 00:00:00 2001 From: Maciej Nasinski Date: Mon, 17 Oct 2022 14:11:22 +0200 Subject: [PATCH 11/14] shinyWidgets::prettySwitch --- R/FilteredData.R | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/R/FilteredData.R b/R/FilteredData.R index 92be0cfe8..3460f382a 100644 --- a/R/FilteredData.R +++ b/R/FilteredData.R @@ -636,12 +636,15 @@ FilteredData <- R6::R6Class( # nolint div( id = ns("switch-button"), class = "inline-block", - shinyWidgets::switchInput( + shinyWidgets::prettySwitch( ns("filter_turn_onoff"), - label = "TURN", + label = "Active Filtering", + status = "success", + fill = TRUE, value = TRUE, inline = FALSE, - handleWidth = "80px" + width = 80, + ) ), div( From 91b1ce360d58ae4e43d7ba62b72d3173902047e9 Mon Sep 17 00:00:00 2001 From: Maciej Nasinski Date: Mon, 17 Oct 2022 18:03:11 +0200 Subject: [PATCH 12/14] right align --- R/FilteredData.R | 11 +++++++---- inst/css/filter-panel.css | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/R/FilteredData.R b/R/FilteredData.R index 3460f382a..4362123c4 100644 --- a/R/FilteredData.R +++ b/R/FilteredData.R @@ -635,16 +635,19 @@ FilteredData <- R6::R6Class( # nolint include_css_files(pattern = "filter-panel"), div( id = ns("switch-button"), - class = "inline-block", + class = "flex", + style = "justify-content: right;", + div( + title = "Active Filtering", shinyWidgets::prettySwitch( ns("filter_turn_onoff"), - label = "Active Filtering", + label = "", status = "success", fill = TRUE, value = TRUE, inline = FALSE, - width = 80, - + width = 30 + ) ) ), div( diff --git a/inst/css/filter-panel.css b/inst/css/filter-panel.css index 25e6b2aca..41ef36a23 100644 --- a/inst/css/filter-panel.css +++ b/inst/css/filter-panel.css @@ -44,6 +44,10 @@ margin-bottom: 1rem; } +.mr-4 { + margin-right: 1rem; +} + .justify-content-center { justify-content: center; } From fd185eacc4f10647f7f940087ea44d68b631f1c0 Mon Sep 17 00:00:00 2001 From: Maciej Nasinski Date: Mon, 17 Oct 2022 18:03:47 +0200 Subject: [PATCH 13/14] styler --- R/FilteredData.R | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/R/FilteredData.R b/R/FilteredData.R index 4362123c4..f7b2d256e 100644 --- a/R/FilteredData.R +++ b/R/FilteredData.R @@ -639,15 +639,15 @@ FilteredData <- R6::R6Class( # nolint style = "justify-content: right;", div( title = "Active Filtering", - shinyWidgets::prettySwitch( - ns("filter_turn_onoff"), - label = "", - status = "success", - fill = TRUE, - value = TRUE, - inline = FALSE, - width = 30 - ) + shinyWidgets::prettySwitch( + ns("filter_turn_onoff"), + label = "", + status = "success", + fill = TRUE, + value = TRUE, + inline = FALSE, + width = 30 + ) ) ), div( From 13345c635d9edb209686e7bb4eacbb47e34e6548 Mon Sep 17 00:00:00 2001 From: Maciej Nasinski Date: Mon, 17 Oct 2022 18:20:01 +0200 Subject: [PATCH 14/14] rm style --- R/FilteredData.R | 3 +-- inst/css/filter-panel.css | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/R/FilteredData.R b/R/FilteredData.R index f7b2d256e..1dd3ef84e 100644 --- a/R/FilteredData.R +++ b/R/FilteredData.R @@ -635,8 +635,7 @@ FilteredData <- R6::R6Class( # nolint include_css_files(pattern = "filter-panel"), div( id = ns("switch-button"), - class = "flex", - style = "justify-content: right;", + class = "flex justify-content-right", div( title = "Active Filtering", shinyWidgets::prettySwitch( diff --git a/inst/css/filter-panel.css b/inst/css/filter-panel.css index 41ef36a23..7d46f6171 100644 --- a/inst/css/filter-panel.css +++ b/inst/css/filter-panel.css @@ -52,6 +52,10 @@ justify-content: center; } +.justify-content-right { + justify-content: right; +} + .date_reset_button { padding: 0; padding-top: 4px;