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

set content category for outputs and revisions #993

Merged
merged 5 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 8 additions & 3 deletions R/client-cloud.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ cloudClient <- function(service, authInfo) {
GET(service, authInfo, path, query)
},

createApplication = function(name, title, template, accountId, appMode) {
createApplication = function(name, title, template, accountId, appMode, contentCategory) {
mslynch marked this conversation as resolved.
Show resolved Hide resolved
json <- list()
json$name <- name
json$application_type <- if (appMode %in% c("rmd-static", "quarto-static", "static")) "static" else "connect"
Expand All @@ -180,6 +180,10 @@ cloudClient <- function(service, authInfo) {
json$space <- currentProject$space_id
}

if (!is.null(contentCategory)) {
mslynch marked this conversation as resolved.
Show resolved Hide resolved
json$content_category <- contentCategory
}

output <- POST_JSON(service, authInfo, "/outputs", json)
path <- paste0("/applications/", output$source_id)
application <- GET(service, authInfo, path)
Expand Down Expand Up @@ -224,9 +228,10 @@ cloudClient <- function(service, authInfo) {
)
},

createRevision = function(application) {
createRevision = function(application, contentCategory) {
path <- paste0("/outputs/", application$id, "/revisions")
revision <- POST_JSON(service, authInfo, path, data.frame())
json <- list(content_category = contentCategory)
revision <- POST_JSON(service, authInfo, path, contentCategory)
mslynch marked this conversation as resolved.
Show resolved Hide resolved
revision$application_id
},

Expand Down
2 changes: 1 addition & 1 deletion R/client-connect.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ connectClient <- function(service, authInfo) {
listApplicationsRequest(service, authInfo, path, query, "applications")
},

createApplication = function(name, title, template, accountId, appMode) {
createApplication = function(name, title, template, accountId, appMode, contentCategory) {
# add name; inject title if specified
details <- list(name = name)
if (!is.null(title) && nzchar(title))
Expand Down
2 changes: 1 addition & 1 deletion R/client-shinyapps.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ shinyAppsClient <- function(service, authInfo) {
GET(service, authInfo, path, query)
},

createApplication = function(name, title, template, accountId, appMode) {
createApplication = function(name, title, template, accountId, appMode, contentCategory) {
json <- list()
json$name <- name
# the title field is only used on connect
Expand Down
5 changes: 3 additions & 2 deletions R/deployApp.R
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@ deployApp <- function(appDir = getwd(),
target$appTitle,
"shiny",
accountDetails$accountId,
appMetadata$appMode
appMetadata$appMode,
contentCategory
)
taskComplete(quiet, "Created application with id {.val {application$id}}")
} else {
Expand All @@ -402,7 +403,7 @@ deployApp <- function(appDir = getwd(),
taskComplete(quiet, "Found application {.url {application$url}}")

if (identical(application$type, "static")) {
application$application_id <- client$createRevision(application)
application$application_id <- client$createRevision(application, contentCategory)
}

application
Expand Down
13 changes: 8 additions & 5 deletions tests/testthat/test-client-cloud.R
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ test_that("Create application", {
)
client <- cloudClient(fakeService, NULL)

app <- client$createApplication("test app", "unused?", "unused?", "unused?", "shiny")
app <- client$createApplication("test app", "unused?", "unused?", "unused?", "shiny", NULL)

expect_equal(app$id, 1)
expect_equal(app$application_id, 2)
Expand All @@ -309,6 +309,7 @@ test_that("Create static application", {
content = function(methodAndPath, match, contentFile, ...) {
content <- jsonlite::fromJSON(readChar(contentFile, file.info(contentFile)$size))
expect_equal(content$application_type, "static")
expect_equal(content$content_category, "document")
list(
"id" = 1,
"source_id" = 2,
Expand Down Expand Up @@ -339,7 +340,7 @@ test_that("Create static application", {
)
client <- cloudClient(fakeService, NULL)

app <- client$createApplication("test app", "unused?", "unused?", "unused?", "static")
app <- client$createApplication("test app", "unused?", "unused?", "unused?", "static", "document")

expect_equal(app$id, 1)
expect_equal(app$application_id, 2)
Expand All @@ -353,6 +354,7 @@ test_that("Create static server-side-rendered application", {
content <- jsonlite::fromJSON(readChar(contentFile, file.info(contentFile)$size))
expect_equal(content$application_type, "static")
expect_equal(content$render_by, "server")
expect_equal(content$content_category, "document")
list(
"id" = 1,
"source_id" = 2,
Expand Down Expand Up @@ -383,7 +385,7 @@ test_that("Create static server-side-rendered application", {
)
client <- cloudClient(fakeService, NULL)

app <- client$createApplication("test app", "unused?", "unused?", "unused?", "quarto-static")
app <- client$createApplication("test app", "unused?", "unused?", "unused?", "quarto-static", "document")

expect_equal(app$id, 1)
expect_equal(app$application_id, 2)
Expand Down Expand Up @@ -452,6 +454,7 @@ test_that("Create static RMD application", {
content <- jsonlite::fromJSON(readChar(contentFile, file.info(contentFile)$size))
expect_equal(content$application_type, "static")
expect_equal(content$render_by, "server")
expect_equal(content$content_category, "document")
list(
"id" = 1,
"source_id" = 2,
Expand Down Expand Up @@ -482,7 +485,7 @@ test_that("Create static RMD application", {
)
client <- cloudClient(fakeService, NULL)

app <- client$createApplication("test app", "unused?", "unused?", "1", "rmd-static")
app <- client$createApplication("test app", "unused?", "unused?", "1", "rmd-static", "document")

expect_equal(app$id, 1)
expect_equal(app$application_id, 2)
Expand Down Expand Up @@ -537,7 +540,7 @@ test_that("Create application with linked source project", {
)
client <- cloudClient(fakeService, NULL)

app <- client$createApplication("test app", "unused?", "unused?", "unused?", "static")
app <- client$createApplication("test app", "unused?", "unused?", "unused?", "static", NULL)

expect_equal(app$id, 1)
expect_equal(app$application_id, 2)
Expand Down