Skip to content

Commit

Permalink
Merge branch '15-add-function-to-set-up-precommit' of https://github.…
Browse files Browse the repository at this point in the history
…com/dfe-analytical-services/dfeshiny into 15-add-function-to-set-up-precommit
  • Loading branch information
oadetayo committed Feb 19, 2025
2 parents e596a16 + 1854e49 commit 4016d32
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 94 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:

name: lint.yaml

permissions: read-all

jobs:
lint:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::lintr, local::.

- name: Lint
run: |
# Pin the lintr version to avoid breaking changes with newer 3.2.0 version
# See: https://github.com/apache/arrow/pull/45524
pak::pak("[email protected]")
lintr::lint_package()
shell: Rscript {0}
env:
LINTR_ERROR_ON_LINT: true
56 changes: 0 additions & 56 deletions .github/workflows/lintr.yml

This file was deleted.

50 changes: 40 additions & 10 deletions R/custom_disconnect_message.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#' Create the HTML overlay panel to appear when a user loses connection to a dashboard.
#'
#' @param refresh the text to appear that will refresh the page when clicked
#' @param reset the text to appear that will reset the page when clicked
#' @param links A vector of possible URLs for the public site. Should mostly just be a single URL,
#' but can be two URLs if an overflow site has been set up
#' @param publication_name The parent publication name
Expand All @@ -16,6 +17,7 @@
#' @param custom_refresh Custom refresh link, defaults to refreshing the page, main value is if you
#' have bookmarking enabled and want the refresh to send to the initial view instead of reloading
#' any bookmarks
#' @param custom_reset Custom reset link, defaults to resetting the page
#'
#' @importFrom htmltools tags tagList
#'
Expand Down Expand Up @@ -49,22 +51,17 @@
#' custom_refresh = "https://department-for-education.shinyapps.io/my-dashboard"
#' )
custom_disconnect_message <- function(
refresh = "Refresh page",
refresh = "refresh page (attempting to keep your last known selections)",
reset = "reset page (removing any previous selections)",
dashboard_title = NULL,
links = NULL,
publication_name = NULL,
publication_link = NULL,
support_contact = "[email protected]",
custom_refresh = NULL) {
custom_refresh = NULL,
custom_reset = NULL) {
# Check links are valid
is_valid_sites_list <- function(sites) {
lapply(
stringr::str_trim(sites), startsWith,
"https://department-for-education.shinyapps.io/"
)
}

if (FALSE %in% is_valid_sites_list(links) ||
if (FALSE %in% validate_dashboard_url(links) ||
"https://department-for-education.shinyapps.io/" %in% links) { # nolint: [indentation_linter]
stop("You have entered an invalid site link in the links argument.")
}
Expand All @@ -84,6 +81,21 @@ custom_disconnect_message <- function(
}
}

if (!is.null(custom_reset)) {
is_valid_reset <- function(reset) {
startsWith(stringr::str_trim(reset), "https://department-for-education.shinyapps.io/")
}

if (is_valid_reset(custom_reset) == FALSE) {
stop(
paste0(
"You have entered an invalid site link in the custom_reset argument. It must be a site",
" on shinyapps.io."
)
)
}
}

pub_prefix <- c(
"https://explore-education-statistics.service.gov.uk/find-statistics/",
"https://www.explore-education-statistics.service.gov.uk/find-statistics/",
Expand All @@ -107,6 +119,7 @@ custom_disconnect_message <- function(
# TODO: Add email validation once a11y panel PR is in

checkmate::assert_string(refresh)
checkmate::assert_string(reset)

# Attach CSS from inst/www/css/visually-hidden.css
dependency <- htmltools::htmlDependency(
Expand Down Expand Up @@ -165,6 +178,23 @@ custom_disconnect_message <- function(
.noWS = c("after")
)
},
", or ",
if (is.null(custom_reset)) {
tags$a(
id = "ss-reset-link",
href = "#",
reset,
onclick = "window.location.reload(false);",
.noWS = c("after")
)
} else {
tags$a(
id = "ss-reset-link",
href = custom_reset,
reset,
.noWS = c("after")
)
},
"."
),
if (length(links) > 1) {
Expand Down
2 changes: 1 addition & 1 deletion R/validation.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ validate_dashboard_url <- function(url) {
as.character(url),
ignore.case = TRUE
)
if (!valid) {
if (!all(valid)) {
stop(paste(url, "is not a valid DfE dashboard deployment URL"))
}
}
Expand Down
45 changes: 22 additions & 23 deletions dfeshiny.Rproj
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
Version: 1.0
ProjectId: 542ddaed-ab53-4f0c-8930-7994a4453a0d

RestoreWorkspace: No
SaveWorkspace: No
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes
LineEndingConversion: Posix

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace
Version: 1.0

RestoreWorkspace: No
SaveWorkspace: No
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes
LineEndingConversion: Posix

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace
10 changes: 8 additions & 2 deletions man/custom_disconnect_message.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions tests/testthat/test-custom_disconnect_message.R
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,13 @@ test_that("Can customise refresh link, but not too much", {
)
)
})


test_that("Reset and Refresh links appear", {
expect_no_error(
custom_disconnect_message(
refresh = "Refresh page",
reset = "Reset page"
)
)
})
4 changes: 2 additions & 2 deletions vignettes/using-the-dfeshiny-deploy-template.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ At the root of your project, add a file called
`deploy_parameters.yaml`.\
Below is an example with optional parameters:

```{yaml}
```
dashboard_name: "my-cool-dashboard"
deploy_target: "shinyapps"
```
Expand All @@ -62,7 +62,7 @@ reusable workflow.

Here is a minimal example:

```{yaml}
```
name: Deploy Dashboard
on:
Expand Down

0 comments on commit 4016d32

Please sign in to comment.