Skip to content

Commit 5a95f4f

Browse files
authored
feat: hide buttons when canXXXRow argument is FALSE. (#18)
This indicates that the user never wants to use this feature of editbl. Thus completely hiding the buttons provides cleaner UI.
1 parent 4a1bfe0 commit 5a95f4f

8 files changed

Lines changed: 59 additions & 32 deletions

File tree

editbl/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: editbl
22
Type: Package
33
Version: 1.3.1
4-
Date: 2025-09-24
4+
Date: 2025-09-30
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/R/eDT.R

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,13 +1647,13 @@ createCloneButtonHTML <- function(
16471647
16481648
#' Re-usable documentation
16491649
#' @param canEditRow can be either of the following:
1650-
#' - `logical`, e.g. TRUE or FALSE
1650+
#' - `logical`, e.g. TRUE or FALSE. In case of `FALSE`, buttons will not be visible except for new rows.
16511651
#' - `function`. Needs as input an argument `row` which accepts a single row `tibble` and as output TRUE/FALSE.
16521652
#' @param canCloneRow can be either of the following:
1653-
#' - `logical`, e.g. TRUE or FALSE
1653+
#' - `logical`, e.g. TRUE or FALSE. In case of `FALSE`, buttons will not be visible except for new rows.
16541654
#' - `function`. Needs as input an argument `row` which accepts a single row `tibble` and as output TRUE/FALSE.
16551655
#' @param canDeleteRow can be either of the following:
1656-
#' - `logical`, e.g. TRUE or FALSE
1656+
#' - `logical`, e.g. TRUE or FALSE. In case of `FALSE`, buttons will not be visible except for new rows.
16571657
#' - `function`. Needs as input an argument `row` which accepts a single row `tibble` and as output TRUE/FALSE.
16581658
#' @keywords internal
16591659
canXXXRowTemplate <- function(canEditRow, canCloneRow, canDeleteRow){
@@ -1679,19 +1679,45 @@ createButtons <- function(
16791679
canCloneRow = TRUE,
16801680
statusCol = '_editbl_status'
16811681
){
1682-
deleteButton <- createDeleteButtonHTML(
1683-
ns=ns,
1684-
suffix=suffix,
1685-
disabled = !evalCanDeleteRow(row=row, canDeleteRow=canDeleteRow, statusCol=statusCol))
1686-
editButton <- createEditButtonHTML(
1687-
ns=ns,
1688-
suffix=suffix,
1689-
disabled = !evalCanEditRow(row=row, canEditRow=canEditRow, statusCol=statusCol))
1690-
cloneButton <- createCloneButtonHTML(
1691-
ns = ns,
1692-
suffix = suffix,
1693-
disabled = !evalCanCloneRow(row = row, canCloneRow = canCloneRow, statusCol = statusCol))
1694-
1682+
# Hide delete completely if canDeleteRow = FALSE. With the exception of newly created rows.
1683+
if(is.logical(canDeleteRow)
1684+
&& !canDeleteRow
1685+
&& (is.null(statusCol) || row[[statusCol]] != 'inserted')
1686+
){
1687+
deleteButton <- ""
1688+
} else {
1689+
deleteButton <- createDeleteButtonHTML(
1690+
ns=ns,
1691+
suffix=suffix,
1692+
disabled = !evalCanDeleteRow(row=row, canDeleteRow=canDeleteRow, statusCol=statusCol))
1693+
}
1694+
1695+
# Hide edit completely if canEditRow = FALSE. With the exception of newly created rows.
1696+
if(is.logical(canEditRow)
1697+
&& !canEditRow
1698+
&& (is.null(statusCol) || row[[statusCol]] != 'inserted')
1699+
){
1700+
editButton <- ""
1701+
} else {
1702+
editButton <- createEditButtonHTML(
1703+
ns=ns,
1704+
suffix=suffix,
1705+
disabled = !evalCanEditRow(row=row, canEditRow=canEditRow, statusCol=statusCol))
1706+
}
1707+
1708+
# Hide clone button completely if canCloneRow = FALSE. With the exception of newly created rows.
1709+
if(is.logical(canCloneRow)
1710+
&& !canCloneRow
1711+
&& (is.null(statusCol) || row[[statusCol]] != 'inserted')
1712+
){
1713+
cloneButton <- ""
1714+
} else {
1715+
cloneButton <- createCloneButtonHTML(
1716+
ns = ns,
1717+
suffix = suffix,
1718+
disabled = !evalCanCloneRow(row = row, canCloneRow = canCloneRow, statusCol = statusCol))
1719+
}
1720+
16951721
result <- sprintf('<div class="btn-group">%1$s%2$s%3$s</div>',
16961722
deleteButton,
16971723
editButton,

editbl/inst/NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
1.3.1
22
o Remove non-exported functions from documentation.
33
o FIX: saving changes for single-column data
4+
o FEAT: hide buttons when canXXXRow argument is FALSE.
45
1.3.0
56
o FIX: castToTemplate removed first row of adapted data in case the template was empty.
67
o FEAT: Add a clone button for each row.

editbl/man/addButtons.Rd

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

editbl/man/canXXXRowTemplate.Rd

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

editbl/man/createButtons.Rd

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

editbl/man/eDT.Rd

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

editbl/man/initData.Rd

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

0 commit comments

Comments
 (0)