Skip to content

Commit

Permalink
Merge pull request #593 from Sage-Bionetworks/FDS-505-empty-folder-wa…
Browse files Browse the repository at this point in the history
…rning

Fds 505 empty folder warning
  • Loading branch information
afwillia authored Mar 15, 2024
2 parents 492465b + 049d79d commit a2ca2d9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 39 deletions.
81 changes: 42 additions & 39 deletions server.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ shinyServer(function(input, output, session) {
shinyjs::hide("box_preview")
shinyjs::hide("box_validate")
shinyjs::hide("box_submit")

# initial loading page
observeEvent(input$cookie, {
# login and update session
Expand Down Expand Up @@ -459,14 +459,6 @@ shinyServer(function(input, output, session) {
dcWaiter("hide")
})

observeEvent(input$dropdown_template, {
shinyjs::enable("btn_template")
shinyjs::enable("btn_template_select")
updateSelectInput(session, "header_dropdown_template",
choices = input$dropdown_template
)
})

# Goal of this button is to get the files within a folder the user selects
observeEvent(input$btn_folder, {
dcWaiter("show", msg = paste0("Getting data"), color = primary_col())
Expand All @@ -482,7 +474,7 @@ shinyServer(function(input, output, session) {
sapply(clean_tags[1:2], FUN = hide)


if (selected$schema_type() %in% c("record", "file")) {
# if (selected$schema_type() %in% c("record", "file")) {
# check number of files if it's file-based template
# This gets files using the synapse REST API
# get file list in selected folder
Expand Down Expand Up @@ -512,7 +504,7 @@ shinyServer(function(input, output, session) {
# update files list in the folder
data_list$files(list2Vector(file_list))
}
}
# }
})

observeEvent(input$dropdown_folder, {
Expand All @@ -526,34 +518,6 @@ shinyServer(function(input, output, session) {
})

observeEvent(data_list$files(), ignoreInit = TRUE, {
warn_text <- NULL
if (length(data_list$folders()) == 0) {
# add warning if there is no folder in the selected project
warn_text <- paste0(
"please create a folder in the ",
strong(sQuote(input$dropdown_project)),
" prior to submitting templates."
)
}
if (is.null(data_list$files())) {
# display warning message if folder is empty and data type is file-based
warn_text <- paste0(
strong(sQuote(input$dropdown_folder)), " folder is empty,
please upload your data before generating manifest.",
"<br>", strong(sQuote(input$dropdown_template)),
" requires data files to be uploaded prior to generating and submitting templates.",
"<br>", "Filling in a template before uploading your data,
may result in errors and delays in your data submission later."
)
}

# if there is warning from above checks
if (!is.null(warn_text)) {
# display warnings
output$text_template_warn <- renderUI(tagList(br(), span(class = "warn_msg", HTML(warn_text))))
show("div_template_warn")
}

dcWaiter("hide")
})

Expand All @@ -579,6 +543,8 @@ shinyServer(function(input, output, session) {
# update selected schema template name
observeEvent(input$dropdown_template,
{
req(input$tabs %in% "tab_template_select")
warn_text <- reactiveVal(NULL)
shinyjs::enable("btn_template_select")
# update reactive selected values for schema
selected$schema(data_list$template()[input$dropdown_template])
Expand All @@ -594,6 +560,43 @@ shinyServer(function(input, output, session) {

# clean all tags related with selected template
sapply(clean_tags, FUN = hide)

if (length(data_list$folders()) == 0) {
# add warning if there is no folder in the selected project
warn_text(paste0(
"please create a folder in the ",
strong(sQuote(input$dropdown_project)),
" prior to submitting templates."
))
}
if (all(is.na(data_list$files())) & selected$schema_type() == "file") {
# display warning message if folder is empty and data type is file-based
warn_text(paste0(
strong(sQuote(input$dropdown_folder)), " folder is empty,
please upload your data before generating manifest.",
"<br>", strong(sQuote(input$dropdown_template)),
" requires data files to be uploaded prior to generating and submitting templates.",
"<br>", "Filling in a template before uploading your data,
may result in errors and delays in your data submission later."
))
}

# if there is warning from above checks
if (!is.null(warn_text())) {
# display warnings
output$text_template_warn <- renderUI(tagList(br(), span(class = "warn_msg", HTML(warn_text()))))
show("div_template_warn")
# nx_report_warning(
# title = "No data uploaded in folder",
# HTML(warn_text())
# )
}

shinyjs::enable("btn_template")
shinyjs::enable("btn_template_select")
updateSelectInput(session, "header_dropdown_template",
choices = input$dropdown_template
)
},
ignoreInit = TRUE
)
Expand Down
5 changes: 5 additions & 0 deletions ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ ui <- shinydashboardPlus::dashboardPage(
label = NULL,
choices = "Generating..."
),
hidden(div(
id = "div_template_warn",
height = "100%",
htmlOutput("text_template_warn")
)),
actionButton("btn_template_select", "Download template",
class = "btn-primary-color"
),
Expand Down

0 comments on commit a2ca2d9

Please sign in to comment.