Skip to content
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

Enable $isActive() in modules, v2 #85

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions R/conductor.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Conductor <- R6::R6Class(
defaultStepOptions = NULL, mathjax = FALSE,
progress = FALSE, onComplete = NULL, onCancel = NULL,
onHide = NULL, onShow = NULL, onStart = NULL,
onActive = NULL, onInactive = NULL) {
onActive = NULL, onInactive = NULL, id = NULL) {

private$globals <- list(
exitOnEsc = exitOnEsc,
Expand Down Expand Up @@ -126,6 +126,10 @@ Conductor <- R6::R6Class(
)
}

if (!is.null(id)) {
private$id <- id
}

private$mathjax <- mathjax
invisible(self)
},
Expand Down Expand Up @@ -671,8 +675,17 @@ Conductor <- R6::R6Class(
isActive = function(session = NULL) {
if(is.null(session)) {
session <- shiny::getDefaultReactiveDomain()
}
session$input[[paste0(private$id, "_is_active")]]
} else {
# If we pass a module session, then the id was wrapped in ns() so that
# the module detects it. However, it means that I have to remove the
# module prefix before session$input[[<id>]] since [[.reactivevalues
# already takes care of adding a prefix.
#
# I don't think I have a way to get the prefix from the session$input
# object so I remove everything before the first dash.
id <- gsub(".*-", "", private$id)
}
session$input[[paste0(id, "_is_active")]]
}
)
)
3 changes: 1 addition & 2 deletions inst/packer/conductor.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions tests/testthat/_snaps/basic.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# foo

"<div aria-describedby=\"step1-description\" aria-labelledby=\"step1-label\" role=\"dialog\" tabindex=\"0\" class=\"shepherd-has-title shepherd-element shepherd-enabled\" data-shepherd-step-id=\"step1\" data-popper-placement=\"right\" style=\"position: absolute; inset: 0px auto auto 0px; margin: 0px; transform: translate(327px, 0px);\"><div class=\"shepherd-arrow\" data-popper-arrow=\"\" style=\"position: absolute; top: 0px; transform: translate(0px, 34px);\"><\/div> <div class=\"shepherd-content\"><header class=\"shepherd-header\"><h3 id=\"step1-label\" class=\"shepherd-title\">hello welcome on this tour<\/h3> <\/header> <div class=\"shepherd-text\" id=\"step1-description\">This is the content of the modal<\/div> <footer class=\"shepherd-footer\"><button class=\" shepherd-button shepherd-button-secondary\" tabindex=\"0\">Previous<\/button><button class=\" shepherd-button \" tabindex=\"0\">Next<\/button><\/footer><\/div><\/div>"
"<div aria-describedby=\"step1-description\" aria-labelledby=\"step1-label\" role=\"dialog\" tabindex=\"0\" class=\"shepherd-has-title shepherd-element shepherd-enabled\" data-shepherd-step-id=\"step1\" data-popper-placement=\"right\" style=\"position: absolute; left: 315px; top: 0px;\"><div class=\"shepherd-arrow\" data-popper-arrow=\"\" style=\"top: 34.25px;\"><\/div> <div class=\"shepherd-content\"><header class=\"shepherd-header\"><h3 id=\"step1-label\" class=\"shepherd-title\">hello welcome on this tour<\/h3> <\/header> <div class=\"shepherd-text\" id=\"step1-description\">This is the content of the modal<\/div> <footer class=\"shepherd-footer\"><button class=\" shepherd-button shepherd-button-secondary\" tabindex=\"0\" type=\"button\">Previous<\/button><button class=\" shepherd-button \" tabindex=\"0\" type=\"button\">Next<\/button><\/footer><\/div><\/div>"

---

"<div aria-labelledby=\"step2-label\" role=\"dialog\" tabindex=\"0\" class=\"shepherd-has-title shepherd-element shepherd-centered shepherd-enabled\" data-shepherd-step-id=\"step2\" data-popper-placement=\"bottom\" style=\"position: fixed; left: 50%; top: 50%; margin: 0px; transform: translate(-50%, -50%);\"> <div class=\"shepherd-content\"><header class=\"shepherd-header\"><h3 id=\"step2-label\" class=\"shepherd-title\">hi<\/h3> <\/header> <footer class=\"shepherd-footer\"><button class=\" shepherd-button shepherd-button-secondary\" tabindex=\"0\">Previous<\/button><button class=\" shepherd-button \" tabindex=\"0\">Next<\/button><\/footer><\/div><\/div>"
"<div aria-labelledby=\"step2-label\" role=\"dialog\" tabindex=\"0\" class=\"shepherd-has-title shepherd-element shepherd-centered shepherd-enabled\" data-shepherd-step-id=\"step2\" data-popper-placement=\"bottom\" style=\"position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);\"> <div class=\"shepherd-content\"><header class=\"shepherd-header\"><h3 id=\"step2-label\" class=\"shepherd-title\">hi<\/h3> <\/header> <footer class=\"shepherd-footer\"><button class=\" shepherd-button shepherd-button-secondary\" tabindex=\"0\" type=\"button\">Previous<\/button><button class=\" shepherd-button \" tabindex=\"0\" type=\"button\">Next<\/button><\/footer><\/div><\/div>"

---

"<div aria-labelledby=\"step3-label\" role=\"dialog\" tabindex=\"0\" class=\"shepherd-has-title shepherd-element shepherd-enabled\" data-shepherd-step-id=\"step3\" data-popper-placement=\"right\" style=\"position: absolute; inset: 0px auto auto 0px; margin: 0px; transform: translate(327px, 72px);\"><div class=\"shepherd-arrow\" data-popper-arrow=\"\" style=\"position: absolute; top: 0px; transform: translate(0px, 36px);\"><\/div> <div class=\"shepherd-content\"><header class=\"shepherd-header\"><h3 id=\"step3-label\" class=\"shepherd-title\">This is the content of the modal<\/h3> <\/header> <footer class=\"shepherd-footer\"><button class=\" shepherd-button shepherd-button-secondary\" tabindex=\"0\">Previous<\/button><button class=\" shepherd-button \" tabindex=\"0\">Next<\/button><\/footer><\/div><\/div>"
"<div aria-labelledby=\"step3-label\" role=\"dialog\" tabindex=\"0\" class=\"shepherd-has-title shepherd-element shepherd-enabled\" data-shepherd-step-id=\"step3\" data-popper-placement=\"right\" style=\"position: absolute; left: 315px; top: 72.25px;\"><div class=\"shepherd-arrow\" data-popper-arrow=\"\" style=\"top: 36px;\"><\/div> <div class=\"shepherd-content\"><header class=\"shepherd-header\"><h3 id=\"step3-label\" class=\"shepherd-title\">This is the content of the modal<\/h3> <\/header> <footer class=\"shepherd-footer\"><button class=\" shepherd-button shepherd-button-secondary\" tabindex=\"0\" type=\"button\">Previous<\/button><button class=\" shepherd-button \" tabindex=\"0\" type=\"button\">Next<\/button><\/footer><\/div><\/div>"

---

Expand Down
Loading