From 69d5c714cd18f48f87eb22108a0a2c8ad3691236 Mon Sep 17 00:00:00 2001 From: m7pr Date: Mon, 23 Oct 2023 14:04:59 +0200 Subject: [PATCH] change extract/drop_landing into extract/drop_module with class argument --- R/init.R | 4 ++-- R/module_teal.R | 11 +---------- R/modules.R | 15 ++++++++------- man/{drop_landing.Rd => drop_module.Rd} | 10 +++++----- man/{extract_landing.Rd => extract_module.Rd} | 10 +++++----- 5 files changed, 21 insertions(+), 29 deletions(-) rename man/{drop_landing.Rd => drop_module.Rd} (51%) rename man/{extract_landing.Rd => extract_module.Rd} (51%) diff --git a/R/init.R b/R/init.R index d019994f86..cc71084d4c 100644 --- a/R/init.R +++ b/R/init.R @@ -139,9 +139,9 @@ init <- function(data, modules <- do.call(teal::modules, modules) } - landing <- extract_landing(modules) + landing <- extract_module(modules, "teal_module_landing") if (length(landing) > 1L) stop("teal only supports apps with one module of `tm_landing_popup` class.") - modules <- drop_landing(modules) + modules <- drop_module(modules, "teal_module_landing") # resolve modules datanames datanames <- teal.data::get_dataname(data) diff --git a/R/module_teal.R b/R/module_teal.R index fbce6ed5bd..5f068b483b 100644 --- a/R/module_teal.R +++ b/R/module_teal.R @@ -226,16 +226,7 @@ srv_teal <- function(id, modules, raw_data, filter = teal_slices()) { }) reporter <- teal.reporter::Reporter$new() - is_any_previewer <- function(modules) { - if (inherits(modules, "teal_modules")) { - any(unlist(lapply(modules$children, is_any_previewer), use.names = FALSE)) - } else if (inherits(modules, "teal_module_previewer")) { - TRUE - } else { - FALSE - } - } - if (is_arg_used(modules, "reporter") && !is_any_previewer(modules)) { + if (is_arg_used(modules, "reporter") && length(extract_module(modules, 'teal_module_previewer')) == 0) { modules <- append_module(modules, reporter_previewer_module()) } diff --git a/R/modules.R b/R/modules.R index 3064937c26..4b9e9edeea 100644 --- a/R/modules.R +++ b/R/modules.R @@ -103,25 +103,26 @@ append_module <- function(modules, module) { modules } -#' Extract a `teal_module_landing` from list of `modules` +#' Extract specific class from a list of `modules` #' @param modules `teal_modules` #' @keywords internal #' @return `teal_module_landing` -extract_landing <- function(modules) { - if (inherits(modules, "teal_module_landing")) { +extract_module <- function(modules, class) { + if (inherits(modules, class)) { modules } else if (inherits(modules, "teal_module")) { NULL } else if (inherits(modules, "teal_modules")) { - Filter(function(x) length(x) > 0L, lapply(modules$children, extract_landing)) + Filter(function(x) length(x) > 0L, lapply(modules$children, extract_module)) } } -#' Remove a `teal_module_landing` from list of `modules` + +#' Remove a specific class from list of `modules` #' @param modules `teal_modules` #' @keywords internal #' @return `teal_modules` -drop_landing <- function(modules) { - if (inherits(modules, "teal_module_landing")) { +drop_module <- function(modules, class) { + if (inherits(modules, class)) { NULL } else if (inherits(modules, "teal_module")) { modules diff --git a/man/drop_landing.Rd b/man/drop_module.Rd similarity index 51% rename from man/drop_landing.Rd rename to man/drop_module.Rd index 7e46431fe5..d29d808c4d 100644 --- a/man/drop_landing.Rd +++ b/man/drop_module.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/modules.R -\name{drop_landing} -\alias{drop_landing} -\title{Remove a \code{teal_module_landing} from list of \code{modules}} +\name{drop_module} +\alias{drop_module} +\title{Remove a specific class from list of \code{modules}} \usage{ -drop_landing(modules) +drop_module(modules, class) } \arguments{ \item{modules}{\code{teal_modules}} @@ -13,6 +13,6 @@ drop_landing(modules) \code{teal_modules} } \description{ -Remove a \code{teal_module_landing} from list of \code{modules} +Remove a specific class from list of \code{modules} } \keyword{internal} diff --git a/man/extract_landing.Rd b/man/extract_module.Rd similarity index 51% rename from man/extract_landing.Rd rename to man/extract_module.Rd index 71a78ede66..5c6213a038 100644 --- a/man/extract_landing.Rd +++ b/man/extract_module.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/modules.R -\name{extract_landing} -\alias{extract_landing} -\title{Extract a \code{teal_module_landing} from list of \code{modules}} +\name{extract_module} +\alias{extract_module} +\title{Extract specific class from a list of \code{modules}} \usage{ -extract_landing(modules) +extract_module(modules, class) } \arguments{ \item{modules}{\code{teal_modules}} @@ -13,6 +13,6 @@ extract_landing(modules) \code{teal_module_landing} } \description{ -Extract a \code{teal_module_landing} from list of \code{modules} +Extract specific class from a list of \code{modules} } \keyword{internal}