Skip to content

Commit 89be008

Browse files
JasperSchjschelfhout
andauthored
feat: expose modifications (#21)
* feat: expose modifications * Documentation * Only expose saved modifications. + Add vignette with advise on how to implement custom logic * documentation * improve documentation * Update README * Update vignette * change README --------- Co-authored-by: jschelfhout <jschelfhout@openanalytics.eu>
1 parent 5a95f4f commit 89be008

11 files changed

Lines changed: 347 additions & 22 deletions

editbl/DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: editbl
22
Type: Package
3-
Version: 1.3.1
4-
Date: 2025-09-30
3+
Version: 1.3.2
4+
Date: 2026-05-20
55
Title: 'DT' Extension for CRUD (Create, Read, Update, Delete) Applications in 'shiny'
66
Authors@R: c(person("Jasper", "Schelfhout", "", "jasper.schelfhout@openanalytics.eu",
77
role = c("aut", "cre")),

editbl/NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
S3method(e_rows_delete,default)
34
S3method(e_rows_insert,default)
45
S3method(e_rows_insert,dtplyr_step)
56
S3method(e_rows_insert,tbl_dbi)
@@ -14,6 +15,7 @@ export(connectDB)
1415
export(customButton)
1516
export(eDT)
1617
export(eDTOutput)
18+
export(e_rows_delete)
1719
export(e_rows_insert)
1820
export(e_rows_update)
1921
export(foreignTbl)

editbl/R/eDT.R

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ eDTOutput <- function(id,...) {
9191
#' - result `reactive` modified version of `data` (saved)
9292
#' - state `reactive` current state of the `data` (unsaved)
9393
#' - selected `reactive` selected rows of the `data` (unsaved)
94+
#' - edited `reactive` edited rows (saved)
95+
#' - inserted `reactive` inserted rows (saved)
96+
#' - deleted `reactive` deleted rows (saved)
9497
#'
9598
#' @examples
9699
#' ## Only run this example in interactive R sessions
@@ -1119,7 +1122,7 @@ eDTServer <- function(
11191122
# inserts
11201123
inserted <- effectiveInserted()
11211124
if(!checkForeignTbls(inserted, foreignTbls())){
1122-
stop("You made invalid edits to a row.")
1125+
stop("You made invalid inserts.")
11231126
}
11241127
inserted <- inserted[,cols,drop=FALSE]
11251128

@@ -1140,7 +1143,7 @@ eDTServer <- function(
11401143
dbplyr::remote_table(result))[base::colnames(deleted)])
11411144
}
11421145

1143-
result <- rows_delete(
1146+
result <- e_rows_delete(
11441147
x = result,
11451148
y = deleted,
11461149
by = keys(),
@@ -1189,7 +1192,12 @@ eDTServer <- function(
11891192
# }
11901193
}
11911194

1195+
# Data to return to user
11921196
rv$committedData <- result
1197+
rv$inserted <- inserted
1198+
rv$edited <- edited
1199+
rv$deleted <- deleted
1200+
11931201

11941202
# Set modified and rendered to comitted version
11951203
# re-read data in case of in_place modification
@@ -1288,7 +1296,10 @@ eDTServer <- function(
12881296
return(list(
12891297
result = result,
12901298
state = reactive({castToTemplate(rv$modifiedData[!rv$modifiedData[[deleteCol]],dataVars()], data())}),
1291-
selected = reactive({castToTemplate(selected()[,dataVars()], data())})
1299+
selected = reactive({castToTemplate(selected()[,dataVars()], data())}),
1300+
inserted = reactive({castToTemplate(rv$inserted[,dataVars()], data())}),
1301+
edited = reactive({castToTemplate(rv$edited[,dataVars()], data())}),
1302+
deleted = reactive({castToTemplate(rv$deleted[,dataVars()], data())})
12921303
))
12931304
}
12941305
)

editbl/R/tbl.R

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,43 @@
1+
#' Delete rows from a tibble
2+
#' @details Mainly a wrapper around \code{\link[dplyr]{rows_delete}}.
3+
#' Allows for specific implementations should the behavior differ from what's needed by `editbl`.
4+
#' Reason for separate method is to avoid conflicts on package loading.
5+
#'
6+
#' @inheritParams dplyr::rows_delete
7+
#' @inherit dplyr::rows_delete return details
8+
#' @export
9+
e_rows_delete <- function(
10+
x,
11+
y,
12+
by = NULL,
13+
...,
14+
unmatched = c("error", "ignore"),
15+
copy = FALSE,
16+
in_place = FALSE){
17+
UseMethod("e_rows_delete")
18+
}
19+
20+
#' @inherit e_rows_delete
21+
#' @export
122
#' @importFrom dplyr rows_delete
2-
NULL
23+
e_rows_delete.default <- function(
24+
x,
25+
y,
26+
by = NULL,
27+
...,
28+
unmatched = c("error", "ignore"),
29+
copy = FALSE,
30+
in_place = FALSE){
31+
dplyr::rows_delete(
32+
x = x,
33+
y = y,
34+
by = by,
35+
... ,
36+
unmatched = unmatched,
37+
copy = copy,
38+
in_place = in_place)
39+
}
40+
341

442
#' Insert rows into a tibble
543
#' @details Mainly a wrapper around \code{\link[dplyr]{rows_insert}}.

editbl/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Advanced examples can be found in the [vignettes](https://github.com/openanalyti
6060
* Transactional commits (currently for `tbl_dbi` class and non in-place editing)
6161
* Default values for new rows (UUID's, 'current date', 'inserted by', ...)
6262
* Possible to set row level security
63+
* Custom logic/checks before saving ([guidelines](https://github.com/openanalytics/editbl/blob/main/editbl/vignettes/howto_custom_logic.rmd))
6364

6465
### Constraints and normalized tables
6566

@@ -139,7 +140,7 @@ Should you run into problems take a look [here](https://github.com/openanalytics
139140
It just sends its updates to the backend by matching on the keys of a row. If other users have in the meantime made conflicting adjustments,
140141
the changes you made might not be executed correctly or errors might be thrown.
141142

142-
## General future goals for this package
143+
## Roadmap
143144

144145
* Full `dplyr` compatibility so support for different backends is easily facilitated. Now there are 2 methods (`e_rows_update`, `e_rows_insert`) that need to be implemented to support a new backend.
145146
* Full `DT` compatibility, including all extensions.

editbl/man/eDT.Rd

Lines changed: 21 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

editbl/man/e_rows_delete.Rd

Lines changed: 76 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

editbl/man/e_rows_delete.default.Rd

Lines changed: 76 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

editbl/man/standardizeArgument_colnames.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)