-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
176 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,28 +6,34 @@ library(shinyGovstyle) | |
#' @description | ||
#' Create the standard DfE R-Shiny support and feedback dashboard panel. | ||
#' | ||
#' @param team_email Your team e-mail address as a string, this must be a education.gov.uk email | ||
#' @param team_email Your team e-mail address, must be a education.gov.uk email | ||
#' @param repo_name The repository name as listed on GitHub | ||
#' @param ees_publication Whether the parent publication is hosted on Explore Education Statistics | ||
#' @param publication_name The parent publication name | ||
#' @param publication_stub The parent publication stub on Explore Education Statistics | ||
#' @param alt_href Alternative link to the parent publication (if not hosted on Explore Education Statistics) | ||
#' @param ees_publication Whether the source publication is hosted on | ||
#' Explore Education Statistics | ||
#' @param publication_name The source publication name | ||
#' @param publication_stub The source publication stub on | ||
#' Explore Education Statistics | ||
#' @param alt_href Alternative link to the parent publication | ||
#' (if not hosted on Explore Education Statistics) | ||
#' @param form_url URL to a feedback form for the dashboard | ||
#' @param cookie_status_output name of cookie status output object | ||
#' | ||
#' @return | ||
#' @return a standardised panel for a public R Shiny dashboard in DfE | ||
#' @export | ||
#' | ||
#' @examples | ||
#' # TODO: add basic example of EES publication | ||
#' # TODO: add basic example of non-EES publication | ||
support_panel <- function( | ||
team_email = "", | ||
repo_name = "", | ||
ees_publication = TRUE, | ||
publication_name = NULL, | ||
publication_stub = "", | ||
alt_href = NULL, | ||
form_url = NULL) { | ||
|
||
# Check that the team_email is a valid email | ||
form_url = NULL, | ||
cookie_status_output = "") { | ||
# Check that the team_email is a valid dfe email ---------------------------- | ||
is_valid_dfe_email <- function(email) { | ||
grepl( | ||
"\\<[A-Z0-9._%+-][email protected]\\>", | ||
|
@@ -39,10 +45,26 @@ support_panel <- function( | |
if (is_valid_dfe_email(team_email) == FALSE) { | ||
stop( | ||
"You have entered an invalid email in the team_email argument. | ||
Please enter a @education.gov.uk email.") | ||
Please enter a @education.gov.uk email." | ||
) | ||
} | ||
# Check that the repo_name is a valid dfe repo ------------------------------ | ||
is_valid_repo_name <- function(url) { | ||
grepl( | ||
"\\https://github.com/dfe-analytical-services/+.", | ||
as.character(url), | ||
ignore.case = TRUE | ||
) | ||
} | ||
|
||
if (is_valid_repo_name(repo_name) == FALSE) { | ||
stop( | ||
"Please ensure the repo URL points to a repository on the | ||
dfe-analytical-services GitHub area." | ||
) | ||
} | ||
|
||
# Build the support page ---------------------------------------------------- | ||
shiny::tabPanel( | ||
"Support and feedback", | ||
shinyGovstyle::gov_main_layout( | ||
|
@@ -56,10 +78,15 @@ support_panel <- function( | |
"This dashboard is a new service that we are developing. | ||
If you have any feedback or suggestions for improvements, | ||
please submit them using our ", | ||
shiny::tags$a(href = form_url, "feedback form", .noWS = c("after")) | ||
shiny::tags$a( | ||
href = form_url, | ||
"feedback form", | ||
.noWS = c("after") | ||
) | ||
) | ||
} else { | ||
shiny::tags$p("This dashboard is a new service that we are developing.") | ||
shiny::tags$p("This dashboard is a new service that we are | ||
developing.") | ||
}, | ||
shiny::tags$p( | ||
paste0( | ||
|
@@ -74,36 +101,57 @@ support_panel <- function( | |
shiny::tags$a( | ||
href = paste0("mailto:", team_email), | ||
team_email, | ||
.noWS = c("after")), | ||
.noWS = c("after") | ||
), | ||
"." | ||
), | ||
shiny::tags$h2("Find more information on the data"), | ||
if (ees_publication) { | ||
shiny::tags$p( | ||
"The parent statistical release of this dashboard, | ||
along with methodological information, is available at the following link: ", | ||
along with methodological information, is available at the | ||
following link: ", | ||
shiny::tags$a( | ||
href = paste0("https://explore-education-statistics.service.gov.uk/find-statistics/", publication_stub), | ||
ifelse(!is.null(publication_name), publication_name, "Explore Education Statistics"), | ||
href = paste0( | ||
"https://explore-education-statistics.service.gov.uk | ||
/find-statistics/", | ||
publication_stub | ||
), | ||
ifelse(!is.null(publication_name), | ||
publication_name, | ||
"Explore Education Statistics" | ||
), | ||
.noWS = c("after") | ||
), | ||
". The statistical release provides additional ", | ||
shiny::tags$a( | ||
href = paste0("https://explore-education-statistics.service.gov.uk/find-statistics/", publication_stub, "/data guidance"), | ||
href = paste0( | ||
"https://explore-education-statistics | ||
.service.gov.uk/find-statistics/", | ||
publication_stub, | ||
"/data guidance" | ||
), | ||
"data guidance", | ||
.noWS = c("after") | ||
), | ||
" and ", | ||
shiny::tags$a( | ||
href = paste0("https://explore-education-statistics.service.gov.uk/find-statistics/", publication_stub, "#explore-data-and-files"), | ||
href = paste0( | ||
"https://explore-education-statistics | ||
.service.gov.uk/find-statistics/", | ||
publication_stub, | ||
"#explore-data-and-files" | ||
), | ||
"tools to access and interogate the underling data", | ||
.noWS = c("after") | ||
), | ||
" contained in this dashboard." | ||
) | ||
} else { | ||
shiny::tags$p( | ||
"The parent statistical release of this dashboard, along with methodological information, is available at the following link: ", | ||
"The parent statistical release of this dashboard, | ||
along with methodological information, | ||
is available at the following link: ", | ||
shiny::tags$a( | ||
href = alt_href, | ||
publication_name, | ||
|
@@ -113,17 +161,28 @@ support_panel <- function( | |
}, | ||
shiny::tags$h2("Contact us"), | ||
shiny::tags$p( | ||
"If you have questions about the dashboard or data within it, please contact us at ", | ||
shiny::tags$a(href = paste0("mailto:", team_email), team_email, .noWS = c("after")) | ||
"If you have questions about the dashboard or data within it, | ||
please contact us at ", | ||
shiny::tags$a( | ||
href = paste0("mailto:", team_email), | ||
team_email, | ||
.noWS = c("after") | ||
) | ||
), | ||
shiny::tags$h2("See the source code"), | ||
shiny::tags$p( | ||
"The source code for this dashboard is available in our ", | ||
shiny::tags$a(href = paste0("https://github.com/dfe-analytical-services/", repo_name), "GitHub repository", .noWS = c("after")), | ||
shiny::tags$a( | ||
href = paste0( | ||
"https://github.com/dfe-analytical-services/", repo_name | ||
), | ||
"GitHub repository", | ||
.noWS = c("after") | ||
), | ||
"." | ||
), | ||
shiny::tags$h2("Use of cookies"), | ||
shiny::textOutput("cookie_status"), | ||
shiny::textOutput(cookie_status_output), | ||
shiny::actionButton("remove", "Reset cookie consent"), | ||
) | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,85 @@ | ||
test_that("email needs to follow standard pattern", { | ||
# Test that a @education.gov.uk passes | ||
expect_no_error(support_panel(team_email = "[email protected]")) | ||
expect_no_error(support_panel(team_email = "[email protected]")) | ||
expect_no_error( | ||
support_panel( | ||
team_email = "[email protected]", | ||
repo_name = "https://github.com/dfe-analytical-services/dfeshiny" | ||
) | ||
) | ||
expect_no_error( | ||
support_panel( | ||
team_email = "[email protected]", | ||
repo_name = "https://github.com/dfe-analytical-services/dfeshiny" | ||
) | ||
) | ||
|
||
# Testing that it will fail if it follows the [email protected] pattern | ||
expect_error(support_panel(team_email = "[email protected]")) | ||
expect_error(support_panel(team_email = "[email protected]")) | ||
expect_error( | ||
support_panel( | ||
team_email = "[email protected]", | ||
repo_name = "https://github.com/dfe-analytical-services/dfeshiny" | ||
) | ||
) | ||
expect_error( | ||
support_panel( | ||
team_email = "[email protected]", | ||
repo_name = "https://github.com/dfe-analytical-services/dfeshiny" | ||
) | ||
) | ||
|
||
# Testing that it will fail if there is no final dot and section | ||
expect_error(support_panel(team_email = "thisshoulfail@something")) | ||
expect_error( | ||
support_panel( | ||
team_email = "thisshoulfail@something", | ||
repo_name = "https://github.com/dfe-analytical-services/dfeshiny" | ||
) | ||
) | ||
|
||
# Test Wales will fail | ||
expect_error(support_panel(team_email = "[email protected]")) | ||
expect_error( | ||
support_panel( | ||
team_email = "[email protected]", | ||
repo_name = "https://github.com/dfe-analytical-services/dfeshiny" | ||
) | ||
) | ||
|
||
# Test that it fails if there is no @ symbol | ||
expect_error(support_panel(team_email = "team.team")) | ||
expect_error( | ||
support_panel( | ||
team_email = "team.team", | ||
repo_name = "https://github.com/dfe-analytical-services/dfeshiny" | ||
) | ||
) | ||
}) | ||
|
||
test_that("repo URL needs to follow standard pattern", { | ||
# Test that a github repo in dfe analytical services passes | ||
expect_no_error( | ||
support_panel( | ||
team_email = "[email protected]", | ||
repo_name = "https://github.com/dfe-analytical-services/dfeshiny" | ||
) | ||
) | ||
|
||
# Testing that it will fail if it's on GitHub but not in DfE area | ||
expect_error( | ||
support_panel( | ||
team_email = "[email protected]", | ||
repo_name = "https://github.com/cjrace/dfeR" | ||
) | ||
) | ||
expect_error( | ||
support_panel( | ||
team_email = "[email protected]", | ||
repo_name = "https://github.com/DfE-R-Community/ggdfe" | ||
) | ||
) | ||
|
||
# Testing that it will fail if there is no final dot and section | ||
expect_error( | ||
support_panel( | ||
team_email = "[email protected]", | ||
repo_name = "https://explore-education-statistics.service.gov.uk/" | ||
) | ||
) | ||
}) |