Skip to content

Commit d77ef35

Browse files
authored
Merge pull request #11 from cynkra/2-extend-column-def
2 extend column def
2 parents f187405 + ef7e3ef commit d77ef35

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

R/cheetah.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ cheetah <- function(
2727
is.null(columns) |
2828
is_named_list(columns) & names(columns) %in% colnames(data)
2929
)
30+
column_style_check(columns)
31+
3032
columns <- toJSON(add_field_to_list(columns), auto_unbox = TRUE)
3133

3234
# Only show rownames if they are character strings (meaningful) and rownames is TRUE

R/cheetah_utils.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ column_def <- function(
44
min_width = NULL,
55
max_width = NULL,
66
column_type = NULL,
7-
action = NULL
7+
action = NULL,
8+
style = NULL
89
) {
910
list(
1011
caption = name,
1112
width = width,
1213
minWidth = min_width,
1314
maxWidth = max_width,
1415
columnType = column_type,
15-
action = action
16+
action = action,
17+
style = style
1618
)
1719
}

R/utils.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,12 @@ add_field_to_list <- function(x) {
2020
convert_row_column <- function(data) {
2121
tibble::rownames_to_column(data, "_row")
2222
}
23+
24+
column_style_check <- function(columns) {
25+
lapply(columns, function(x){
26+
if("style" %in% names(x) && !is.null(x$style)) {
27+
stopifnot("The style attribute expects a list" = is.list(x$style) && !is.null(names(x$style)))
28+
}
29+
})
30+
invisible()
31+
}

tests/testthat/test-utils.R

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ test_that("test utils", {
44

55
expect_named(
66
column_def(name = "Sepal_Length"),
7-
c("caption", "width", "minWidth", "maxWidth", "columnType", "action")
7+
c("caption", "width", "minWidth",
8+
"maxWidth", "columnType", "action",
9+
"style")
810
)
911
})
12+
13+
test_that("test column style check", {
14+
15+
columns <- list(
16+
Sepal.Length = column_def(name = "Sepal_Length"),
17+
Species = column_def(style = "red")
18+
)
19+
20+
expect_error(column_style_check(columns), "The style attribute expects a list")
21+
})
22+

0 commit comments

Comments
 (0)