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

Code refinement #3

Merged
merged 4 commits into from
May 10, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.RData
.Ruserdata
.DS_Store
.Renviron
22 changes: 11 additions & 11 deletions app/logic/api_utils.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
box::use(
dplyr[filter],
glue[glue],
httr2[
request,
req_auth_bearer_token,
req_dry_run,
req_perform,
resp_body_string,
req_user_agent
req_user_agent,
request,
resp_body_string
],
magrittr[`%>%`],
jsonlite[fromJSON],
dplyr[filter],
glue[glue]
magrittr[`%>%`],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Elkem had an older R version at first so we used %>% instead of |>. What do you think about changing all the pipes to the modern one and removing the magrittr dependency entirely?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can keep it, magrittr will be there as the dependency of dplyr, so this way we can extend the backwards compatibility with no cost.

)

#' Simple function to get the access token from environment
Expand All @@ -30,7 +30,7 @@ get_access_token <- function() {
#' Simple function to make an API url
#' @param host Character. Default CONNECT_SERVER set as an envvar
#' @param endpoint Character. Default is "content"
#' @param versioned Logical. Whether to use versioned API. Default is FALSE
#' @param version Logical. Whether to use versioned API. Default is "v1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense grammatically as well as logically. Thanks for this change!

#' @return url for the API
get_api_url <- function(
host = Sys.getenv("CONNECT_SERVER"),
Expand All @@ -44,7 +44,7 @@ get_api_url <- function(
#'
#' @param app_mode_filter Character. The filter for app_mode in the API
#' response. Default is "shiny".
#' @param url Character. The URL for API endpoint
#' @param endpoint Character. Default is "content"
#' @param dry_run Logical. Whether to dry run the API for debugging.
#' Default is FALSE
#' @export
Expand Down Expand Up @@ -77,7 +77,7 @@ get_app_list <- function(
#' Function to get a list of all jobs for a specific app
#'
#' @param guid Character. The guid for the app in question
#' @param url Character. The URL for API endpoint
#' @param endpoint Character. Default is "content"
#' @param dry_run Logical. Whether to dry run the API for debugging.
#' Default is FALSE
#' @export
Expand Down Expand Up @@ -112,7 +112,7 @@ get_job_list <- function(
#'
#' @param guid Character. The guid for the app in question
#' @param job_key Character. The key for the job in question
#' @param url Character. The URL for API endpoint
#' @param endpoint Character. Default is "content"
#' @param tail Logical. Whether to show the tail only for the logs
#' @param dry_run Logical. Whether to dry run the API for debugging.
#' Default is FALSE
Expand Down Expand Up @@ -152,7 +152,7 @@ get_job_logs <- function(
#'
#' @param guid Character. The guid for the app in question
#' @param job_key Character. The key for the job in quesrtion
#' @param url Character. The URL for API endpoint
#' @param endpoint Character. Default is "content"
#' @param dry_run Logical. Whether to dry run the API for debugging.
#' Default is FALSE
#' @export
Expand Down
7 changes: 3 additions & 4 deletions app/logic/app_table_utils.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
box::use(
shiny[
a,
div,
span,
icon,
a,
span,
strong
],
glue[glue]
)

box::use(
app/logic/general_utils[format_timestamp]
app/logic/general_utils[format_timestamp],
)

#' Function to process each row for the app table
Expand Down
6 changes: 1 addition & 5 deletions app/logic/job_list_utils.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
box::use(
shiny[
div,
span,
icon,
a,
strong
],
glue[glue]
)

box::use(
app/logic/general_utils[format_timestamp]
app/logic/general_utils[format_timestamp],
)


Expand Down
8 changes: 4 additions & 4 deletions app/logic/logs_utils.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
box::use(
glue[glue],
shiny[
icon,
div
]
div,
icon
],
)

box::use(
app/logic/general_utils[check_text_error, format_timestamp]
app/logic/general_utils[check_text_error, format_timestamp],
)

#' Function to process each row for the log table
Expand Down
34 changes: 18 additions & 16 deletions app/main.R
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
# nolint start: box_func_import_count_linter
box::use(
dplyr[select],
magrittr[`%>%`],
shiny[
NS,
moduleServer,
div,
fluidPage,
img,
isTruthy,
moduleServer,
NS,
observeEvent,
p,
reactive,
reactiveValues,
observeEvent,
isTruthy,
tags,
tagList,
renderUI,
uiOutput,
img,
removeUI,
p,
fluidPage
renderUI,
tagList,
tags,
uiOutput
],
magrittr[`%>%`],
dplyr[select],
shinycssloaders[withSpinner]
shinycssloaders[withSpinner],
)
# nolint end

box::use(
app/logic/api_utils[get_app_list],
app/view/mod_app_table,
app/view/mod_header,
app/view/mod_job_list,
app/view/mod_logs,
app/view/mod_header,
app/logic/api_utils[get_app_list]
)

#' @export
Expand Down
28 changes: 13 additions & 15 deletions app/view/mod_app_table.R
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
box::use(
shiny[
NS,
div,
moduleServer,
reactive
dplyr[
mutate,
select
],
magrittr[`%>%`],
reactable[
colDef,
getReactableState,
reactable,
renderReactable,
reactableOutput,
getReactableState,
colDef
renderReactable
],
dplyr[
select,
mutate
shiny[
moduleServer,
NS,
reactive
],
magrittr[`%>%`],
glue[glue],
shinycssloaders[withSpinner]
shinycssloaders[withSpinner],
)

box::use(
app/logic/app_table_utils[process_app_data]
app/logic/app_table_utils[process_app_data],
)

#' @export
Expand Down
12 changes: 5 additions & 7 deletions app/view/mod_header.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
box::use(
shiny[
NS,
moduleServer,
actionLink,
div,
img,
h2,
icon,
actionButton,
actionLink
]
img,
moduleServer,
NS
],
)

#' @export
Expand Down
29 changes: 14 additions & 15 deletions app/view/mod_job_list.R
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
box::use(
shiny[
moduleServer,
NS,
div,
reactive,
req
dplyr[
mutate,
select
],
magrittr[`%>%`],
reactable[
colDef,
getReactableState,
reactable,
renderReactable,
reactableOutput,
getReactableState,
colDef
renderReactable
],
dplyr[
select,
mutate
shiny[
moduleServer,
NS,
reactive,
req
],
magrittr[`%>%`],
shinycssloaders[withSpinner]
shinycssloaders[withSpinner],
)

box::use(
app/logic/api_utils[get_job_list],
app/logic/job_list_utils[process_job_data]
app/logic/job_list_utils[process_job_data],
)

#' @export
Expand Down
38 changes: 20 additions & 18 deletions app/view/mod_logs.R
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
# nolint start: box_func_import_count_linter
box::use(
dplyr[mutate],
glue[glue],
magrittr[`%>%`],
reactable[
colDef,
reactable,
reactableOutput,
renderReactable
],
shinycssloaders[withSpinner],
shiny[
moduleServer,
NS,
div,
reactive,
req,
downloadButton,
downloadHandler,
icon,
moduleServer,
NS,
observeEvent,
reactive,
renderUI,
uiOutput,
observeEvent
],
reactable[
reactable,
renderReactable,
reactableOutput,
colDef
req,
uiOutput
],
dplyr[mutate],
magrittr[`%>%`],
glue[glue],
shinycssloaders[withSpinner]
)
# nolint end

box::use(
app/logic/api_utils[get_job_logs, download_job_logs],
app/logic/logs_utils[process_log_data]
app/logic/api_utils[download_job_logs, get_job_logs],
app/logic/logs_utils[process_log_data],
)

#' @export
Expand Down
1 change: 0 additions & 1 deletion dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ library(reactable)
library(rhino)
library(rsconnect)
library(shinycssloaders)
library(usethis)
Loading
Loading