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

feat: added support for events from the filter panel #681

Merged
merged 12 commits into from
Jul 13, 2022
Merged
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
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
* Deprecated `merge_expression` argument in `get_rcode_srv` and `get_rcode` has been removed.
* Deprecated `session` argument in `get_rcode` function.

# Miscellaneous

* Enhanced the burger button so it is disabled when the filter panel is not used.

# teal 0.11.1

### Enhancements
Expand Down
23 changes: 21 additions & 2 deletions R/module_tabs_with_filters.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ ui_tabs_with_filters <- function(id, modules, datasets) {
filter_panel_btn <- tags$li(
style = "flex-grow : 1;",
tags$a(
id = "filter_hamburger",
href = "javascript:void(0)",
class = "menubtn",
onclick = "toggle_sidebar();",
onclick = "toggleFilterPanel();", # see sidebar.js
title = "Toggle filter panels",
tags$span(icon("fas fa-bars"))
)
Expand Down Expand Up @@ -162,10 +163,28 @@ srv_tabs_with_filters <- function(id, datasets, modules, reporter = teal.reporte
"srv_tabs_with_filters@1 changing active module to: { deparse1(active_module()$label) }."
)
datasets$handle_active_datanames(datanames = active_module()$filters)
}
},
ignoreNULL = FALSE
)

datasets$srv_filter_panel(id = "filter_panel", active_datanames = active_datanames)

# to handle per module filter = NULL
observeEvent(
eventExpr = active_datanames(),
handlerExpr = {
script <- if (length(active_datanames()) == 0 || is.null(active_datanames())) {
# hide the filter panel and disable the burger button
"handleNoActiveDatasets();"
} else {
# show the filter panel and enable the burger button
"handleActiveDatasetsPresent();"
}
shinyjs::runjs(script)
},
ignoreNULL = FALSE
)

teal.slice::set_filter_state(datasets = datasets, filter = filter)
showNotification("Data loaded - App fully started up")

Expand Down
7 changes: 7 additions & 0 deletions inst/css/sidebar.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@
.nav {
display: flex;
}

/* disable any anchor with the disabled class*/
a.disabled {
pointer-events: none;
cursor: default;
color: grey;
}
39 changes: 30 additions & 9 deletions inst/js/sidebar.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
// used to collapse and expand the filter panel in teal apps
var filter_open = true;
function toggle_sidebar() {
if ($("#teal_secondary_col").css("display") == "none") {
$("#teal_primary_col").attr("class", "col-sm-9").resize();
$("#teal_secondary_col").delay(600).fadeIn(50);
filter_open = true;
} else {
$("#teal_secondary_col").fadeOut(1);
$("#teal_primary_col").attr("class", "col-sm-12").resize();
filter_open = false;
const hideSidebar = () => {
$("#teal_secondary_col").fadeOut(1);
$("#teal_primary_col").attr("class", "col-sm-12").resize();
};
const showSidebar = () => {
$("#teal_primary_col").attr("class", "col-sm-9").resize();
$("#teal_secondary_col").delay(600).fadeIn(50);
};
const toggleFilterPanel = () => {
if (
filter_open &&
getComputedStyle(document.getElementById("teal_secondary_col")).display ===
"none"
) {
showSidebar();
return;
}
filter_open = !filter_open;
if (filter_open) showSidebar();
else hideSidebar();
};

// Function to hide filter panel and disable the burger button
const handleNoActiveDatasets = () => {
$("#filter_hamburger").addClass("disabled");
hideSidebar();
};
// Function to show filter panel and enable the burger button
const handleActiveDatasetsPresent = () => {
$("#filter_hamburger").removeClass("disabled");
if (filter_open) showSidebar();
}